blob: 207adb07db84179ca883e54c7bcc50cdf21c1a84 [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 Huber42daab12024-07-16 00:27:27 +020047 case CHIPSET_C740_SERIES_EMMITSBURG:
Nico Huber2a5dfaf2019-07-04 16:01:51 +020048 case CHIPSET_300_SERIES_CANNON_POINT:
Michał Żygowski5c9f5422021-06-16 15:13:54 +020049 case CHIPSET_500_SERIES_TIGER_POINT:
Werner Zehe57d4e42022-01-03 09:44:29 +010050 case CHIPSET_ELKHART_LAKE:
David Hendricksa5216362017-08-08 20:02:22 -070051 return 16;
Nico Huberfa622942017-03-24 17:25:37 +010052 case CHIPSET_100_SERIES_SUNRISE_POINT:
53 return 10;
54 case CHIPSET_9_SERIES_WILDCAT_POINT_LP:
55 case CHIPSET_9_SERIES_WILDCAT_POINT:
56 case CHIPSET_8_SERIES_LYNX_POINT_LP:
57 case CHIPSET_8_SERIES_LYNX_POINT:
58 case CHIPSET_8_SERIES_WELLSBURG:
59 if (cont->NR <= 6)
60 return cont->NR + 1;
61 else
62 return -1;
63 default:
64 if (cont->NR <= 4)
65 return cont->NR + 1;
66 else
67 return -1;
68 }
69}
70
71ssize_t ich_number_of_masters(const enum ich_chipset cs, const struct ich_desc_content *const cont)
72{
David Hendricksa5216362017-08-08 20:02:22 -070073 switch (cs) {
74 case CHIPSET_C620_SERIES_LEWISBURG:
Nico Huber42daab12024-07-16 00:27:27 +020075 case CHIPSET_C740_SERIES_EMMITSBURG:
Nico Huber82fe1232024-07-19 17:28:47 +020076 return 6;
Nico Huberd2d39932019-01-18 16:49:37 +010077 case CHIPSET_APOLLO_LAKE:
Angel Pons4db0fdf2020-07-10 17:04:10 +020078 case CHIPSET_GEMINI_LAKE:
Werner Zehe57d4e42022-01-03 09:44:29 +010079 case CHIPSET_ELKHART_LAKE:
Nico Huber82fe1232024-07-19 17:28:47 +020080 return 2;
David Hendricksa5216362017-08-08 20:02:22 -070081 default:
Nico Huber82fe1232024-07-19 17:28:47 +020082 if (cs >= SPI_ENGINE_PCH100)
83 return 5;
David Hendricksa5216362017-08-08 20:02:22 -070084 if (cont->NM < MAX_NUM_MASTERS)
85 return cont->NM + 1;
86 }
87
88 return -1;
Nico Huberfa622942017-03-24 17:25:37 +010089}
90
Nico Huber157b8182024-07-19 17:48:12 +020091static bool has_classic_proc_straps(const enum ich_chipset cs)
92{
93 switch (cs) {
94 case CHIPSET_100_SERIES_SUNRISE_POINT:
95 case CHIPSET_C620_SERIES_LEWISBURG:
Nico Huber42daab12024-07-16 00:27:27 +020096 case CHIPSET_C740_SERIES_EMMITSBURG:
Nico Huber157b8182024-07-19 17:48:12 +020097 return true;
98 default:
99 return cs < SPI_ENGINE_PCH100;
100 }
101}
102
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000103void prettyprint_ich_reg_vscc(uint32_t reg_val, int verbosity, bool print_vcl)
Stefan Tauner1e146392011-09-15 23:52:55 +0000104{
105 print(verbosity, "BES=0x%x, ", (reg_val & VSCC_BES) >> VSCC_BES_OFF);
106 print(verbosity, "WG=%d, ", (reg_val & VSCC_WG) >> VSCC_WG_OFF);
107 print(verbosity, "WSR=%d, ", (reg_val & VSCC_WSR) >> VSCC_WSR_OFF);
108 print(verbosity, "WEWS=%d, ", (reg_val & VSCC_WEWS) >> VSCC_WEWS_OFF);
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000109 print(verbosity, "EO=0x%x", (reg_val & VSCC_EO) >> VSCC_EO_OFF);
110 if (print_vcl)
111 print(verbosity, ", VCL=%d", (reg_val & VSCC_VCL) >> VSCC_VCL_OFF);
112 print(verbosity, "\n");
Stefan Tauner1e146392011-09-15 23:52:55 +0000113}
114
115#define getFCBA(cont) (((cont)->FLMAP0 << 4) & 0x00000ff0)
116#define getFRBA(cont) (((cont)->FLMAP0 >> 12) & 0x00000ff0)
117#define getFMBA(cont) (((cont)->FLMAP1 << 4) & 0x00000ff0)
118#define getFISBA(cont) (((cont)->FLMAP1 >> 12) & 0x00000ff0)
119#define getFMSBA(cont) (((cont)->FLMAP2 << 4) & 0x00000ff0)
120
Nico Huber67d71792017-06-17 03:10:15 +0200121void prettyprint_ich_chipset(enum ich_chipset cs)
122{
123 static const char *const chipset_names[] = {
124 "Unknown ICH", "ICH8", "ICH9", "ICH10",
125 "5 series Ibex Peak", "6 series Cougar Point", "7 series Panther Point",
Nico Huberdfd06472024-07-14 23:45:05 +0200126 "Baytrail", "8 series Lynx Point", "8 series Lynx Point LP", "8 series Wellsburg",
Nico Huber67d71792017-06-17 03:10:15 +0200127 "9 series Wildcat Point", "9 series Wildcat Point LP", "100 series Sunrise Point",
Angel Pons4db0fdf2020-07-10 17:04:10 +0200128 "C620 series Lewisburg", "300/400 series Cannon/Comet Point",
Nico Huber29c23dd2022-12-21 15:25:09 +0000129 "500/600 series Tiger/Alder Point", "Apollo Lake", "Gemini Lake", "Elkhart Lake",
Nico Huber42daab12024-07-16 00:27:27 +0200130 "C740 series Emmitsburg",
Nico Huber67d71792017-06-17 03:10:15 +0200131 };
132 if (cs < CHIPSET_ICH8 || cs - CHIPSET_ICH8 + 1 >= ARRAY_SIZE(chipset_names))
133 cs = 0;
134 else
135 cs = cs - CHIPSET_ICH8 + 1;
136 msg_pdbg2("Assuming chipset '%s'.\n", chipset_names[cs]);
137}
138
Stefan Tauner1e146392011-09-15 23:52:55 +0000139void prettyprint_ich_descriptors(enum ich_chipset cs, const struct ich_descriptors *desc)
140{
Nico Huberfa622942017-03-24 17:25:37 +0100141 prettyprint_ich_descriptor_content(cs, &desc->content);
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000142 prettyprint_ich_descriptor_component(cs, desc);
Nico Huberfa622942017-03-24 17:25:37 +0100143 prettyprint_ich_descriptor_region(cs, desc);
144 prettyprint_ich_descriptor_master(cs, desc);
Nico Huberad186312016-05-02 15:15:29 +0200145#ifdef ICH_DESCRIPTORS_FROM_DUMP_ONLY
Stefan Taunerb3850962011-12-24 00:00:32 +0000146 if (cs >= CHIPSET_ICH8) {
147 prettyprint_ich_descriptor_upper_map(&desc->upper);
148 prettyprint_ich_descriptor_straps(cs, desc);
149 }
Nico Huberad186312016-05-02 15:15:29 +0200150#endif /* ICH_DESCRIPTORS_FROM_DUMP_ONLY */
Stefan Tauner1e146392011-09-15 23:52:55 +0000151}
152
Nico Huberfa622942017-03-24 17:25:37 +0100153void prettyprint_ich_descriptor_content(enum ich_chipset cs, const struct ich_desc_content *cont)
Stefan Tauner1e146392011-09-15 23:52:55 +0000154{
155 msg_pdbg2("=== Content Section ===\n");
156 msg_pdbg2("FLVALSIG 0x%08x\n", cont->FLVALSIG);
157 msg_pdbg2("FLMAP0 0x%08x\n", cont->FLMAP0);
158 msg_pdbg2("FLMAP1 0x%08x\n", cont->FLMAP1);
159 msg_pdbg2("FLMAP2 0x%08x\n", cont->FLMAP2);
160 msg_pdbg2("\n");
161
162 msg_pdbg2("--- Details ---\n");
Nico Huberfa622942017-03-24 17:25:37 +0100163 msg_pdbg2("NR (Number of Regions): %5zd\n", ich_number_of_regions(cs, cont));
164 msg_pdbg2("FRBA (Flash Region Base Address): 0x%03x\n", getFRBA(cont));
165 msg_pdbg2("NC (Number of Components): %5d\n", cont->NC + 1);
166 msg_pdbg2("FCBA (Flash Component Base Address): 0x%03x\n", getFCBA(cont));
Nico Huberd2d39932019-01-18 16:49:37 +0100167 msg_pdbg2("ISL (ICH/PCH/SoC Strap Length): %5d\n", cont->ISL);
168 msg_pdbg2("FISBA/FPSBA (Flash ICH/PCH/SoC Strap Base Addr): 0x%03x\n", getFISBA(cont));
Nico Huberfa622942017-03-24 17:25:37 +0100169 msg_pdbg2("NM (Number of Masters): %5zd\n", ich_number_of_masters(cs, cont));
170 msg_pdbg2("FMBA (Flash Master Base Address): 0x%03x\n", getFMBA(cont));
Nico Huber157b8182024-07-19 17:48:12 +0200171 if (has_classic_proc_straps(cs)) {
172 msg_pdbg2("MSL/PSL (MCH/PROC Strap Length): %5d\n", cont->MSL);
173 msg_pdbg2("FMSBA (Flash MCH/PROC Strap Base Address): 0x%03x\n", getFMSBA(cont));
174 }
Stefan Tauner1e146392011-09-15 23:52:55 +0000175 msg_pdbg2("\n");
176}
177
Nico Huberdfd06472024-07-14 23:45:05 +0200178static unsigned int get_density_index(
179 enum ich_chipset cs, const struct ich_descriptors *desc, unsigned int component)
180{
181 if (cs < CHIPSET_HAS_NEW_COMPONENT_DENSITY) {
182 if (component == 0)
183 return desc->component.dens_old.comp1_density;
184 else
185 return desc->component.dens_old.comp2_density;
186 } else {
187 if (component == 0)
188 return desc->component.dens_new.comp1_density;
189 else
190 return desc->component.dens_new.comp2_density;
191 }
192}
193
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000194static const char *pprint_density(enum ich_chipset cs, const struct ich_descriptors *desc, uint8_t idx)
195{
196 if (idx > 1) {
197 msg_perr("Only ICH SPI component index 0 or 1 are supported yet.\n");
Nico Huberdfd06472024-07-14 23:45:05 +0200198 return "unknown";
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000199 }
Nico Huberdfd06472024-07-14 23:45:05 +0200200 if (cs == CHIPSET_ICH_UNKNOWN)
201 return "unknown";
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000202
203 if (desc->content.NC == 0 && idx > 0)
204 return "unused";
205
206 static const char * const size_str[] = {
207 "512 kB", /* 0000 */
208 "1 MB", /* 0001 */
209 "2 MB", /* 0010 */
210 "4 MB", /* 0011 */
211 "8 MB", /* 0100 */
212 "16 MB", /* 0101 */ /* Maximum up to Lynx Point (excl.) */
213 "32 MB", /* 0110 */
214 "64 MB", /* 0111 */
215 };
Nico Huberdfd06472024-07-14 23:45:05 +0200216 const unsigned int max_idx = cs < CHIPSET_HAS_NEW_COMPONENT_DENSITY ? 5 : 7;
217 const unsigned int size_idx = get_density_index(cs, desc, idx);
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000218
Nico Huberdfd06472024-07-14 23:45:05 +0200219 if (size_idx > max_idx)
220 return "reserved";
221
222 return size_str[size_idx];
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000223}
224
225static const char *pprint_freq(enum ich_chipset cs, uint8_t value)
Stefan Tauner1e146392011-09-15 23:52:55 +0000226{
Werner Zehe57d4e42022-01-03 09:44:29 +0100227 static const char *const freq_str[5][8] = { {
Nico Huber129e9382019-06-06 15:43:27 +0200228 "20 MHz",
229 "33 MHz",
230 "reserved",
231 "reserved",
232 "50 MHz", /* New since Ibex Peak */
233 "reserved",
234 "reserved",
235 "reserved"
Nico Huberfa622942017-03-24 17:25:37 +0100236 }, {
Nico Huber129e9382019-06-06 15:43:27 +0200237 "reserved",
238 "reserved",
239 "48 MHz",
240 "reserved",
241 "30 MHz",
242 "reserved",
243 "17 MHz",
244 "reserved"
Nico Huberd2d39932019-01-18 16:49:37 +0100245 }, {
246 "reserved",
247 "50 MHz",
248 "40 MHz",
249 "reserved",
250 "25 MHz",
251 "reserved",
252 "14 MHz / 17 MHz",
253 "reserved"
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200254 }, {
255 "100 MHz",
256 "50 MHz",
257 "reserved",
258 "33 MHz",
259 "25 MHz",
260 "reserved",
261 "14 MHz",
262 "reserved"
Werner Zehe57d4e42022-01-03 09:44:29 +0100263 }, {
264 "reserved",
265 "50 MHz",
266 "reserved",
267 "reserved",
268 "33 MHz",
269 "20 MHz",
270 "reserved",
271 "reserved",
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200272 }};
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000273
274 switch (cs) {
275 case CHIPSET_ICH8:
276 case CHIPSET_ICH9:
277 case CHIPSET_ICH10:
278 if (value > 1)
279 return "reserved";
Richard Hughesdb7482b2018-12-19 12:04:30 +0000280 /* Fall through. */
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000281 case CHIPSET_5_SERIES_IBEX_PEAK:
282 case CHIPSET_6_SERIES_COUGAR_POINT:
283 case CHIPSET_7_SERIES_PANTHER_POINT:
284 case CHIPSET_8_SERIES_LYNX_POINT:
Duncan Laurie4095ed72014-08-20 15:39:32 +0000285 case CHIPSET_BAYTRAIL:
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000286 case CHIPSET_8_SERIES_LYNX_POINT_LP:
287 case CHIPSET_8_SERIES_WELLSBURG:
Duncan Laurie823096e2014-08-20 15:39:38 +0000288 case CHIPSET_9_SERIES_WILDCAT_POINT:
Nico Huber51205912017-03-17 17:59:54 +0100289 case CHIPSET_9_SERIES_WILDCAT_POINT_LP:
Nico Huberfa622942017-03-24 17:25:37 +0100290 return freq_str[0][value];
291 case CHIPSET_100_SERIES_SUNRISE_POINT:
David Hendricksa5216362017-08-08 20:02:22 -0700292 case CHIPSET_C620_SERIES_LEWISBURG:
Nico Huber2a5dfaf2019-07-04 16:01:51 +0200293 case CHIPSET_300_SERIES_CANNON_POINT:
Nico Huberfa622942017-03-24 17:25:37 +0100294 return freq_str[1][value];
Nico Huberd2d39932019-01-18 16:49:37 +0100295 case CHIPSET_APOLLO_LAKE:
Angel Pons4db0fdf2020-07-10 17:04:10 +0200296 case CHIPSET_GEMINI_LAKE:
Nico Huberd2d39932019-01-18 16:49:37 +0100297 return freq_str[2][value];
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200298 case CHIPSET_500_SERIES_TIGER_POINT:
Nico Huber42daab12024-07-16 00:27:27 +0200299 case CHIPSET_C740_SERIES_EMMITSBURG:
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200300 return freq_str[3][value];
Werner Zehe57d4e42022-01-03 09:44:29 +0100301 case CHIPSET_ELKHART_LAKE:
302 return freq_str[4][value];
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000303 case CHIPSET_ICH_UNKNOWN:
304 default:
305 return "unknown";
306 }
307}
308
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200309static void pprint_read_freq(enum ich_chipset cs, uint8_t value)
310{
311 static const char *const freq_str[1][8] = { {
312 "20 MHz",
313 "24 MHz",
314 "30 MHz",
315 "48 MHz",
316 "60 MHz",
317 "reserved",
318 "reserved",
319 "reserved"
320 }};
321
322 switch (cs) {
323 case CHIPSET_300_SERIES_CANNON_POINT:
324 msg_pdbg2("eSPI/EC Bus Clock Frequency: %s\n", freq_str[0][value]);
325 return;
326 case CHIPSET_500_SERIES_TIGER_POINT:
327 msg_pdbg2("Read Clock Frequency: %s\n", "reserved");
328 return;
329 default:
330 msg_pdbg2("Read Clock Frequency: %s\n", pprint_freq(cs, value));
331 return;
332 }
333}
334
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000335void prettyprint_ich_descriptor_component(enum ich_chipset cs, const struct ich_descriptors *desc)
336{
Nico Huberb2ad9fd2024-07-14 23:18:53 +0200337 const bool has_flill1 = cs >= SPI_ENGINE_PCH100;
Stefan Tauner1e146392011-09-15 23:52:55 +0000338
339 msg_pdbg2("=== Component Section ===\n");
340 msg_pdbg2("FLCOMP 0x%08x\n", desc->component.FLCOMP);
341 msg_pdbg2("FLILL 0x%08x\n", desc->component.FLILL );
Nico Huberd2d39932019-01-18 16:49:37 +0100342 if (has_flill1)
Nico Huberfa622942017-03-24 17:25:37 +0100343 msg_pdbg2("FLILL1 0x%08x\n", desc->component.FLILL1);
Stefan Tauner1e146392011-09-15 23:52:55 +0000344 msg_pdbg2("\n");
345
346 msg_pdbg2("--- Details ---\n");
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000347 msg_pdbg2("Component 1 density: %s\n", pprint_density(cs, desc, 0));
Stefan Tauner1e146392011-09-15 23:52:55 +0000348 if (desc->content.NC)
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000349 msg_pdbg2("Component 2 density: %s\n", pprint_density(cs, desc, 1));
Stefan Tauner1e146392011-09-15 23:52:55 +0000350 else
351 msg_pdbg2("Component 2 is not used.\n");
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200352
353 pprint_read_freq(cs, desc->component.modes.freq_read);
354
Tai-Hong Wu60dead42015-01-05 23:00:14 +0000355 msg_pdbg2("Read ID and Status Clock Freq.: %s\n", pprint_freq(cs, desc->component.modes.freq_read_id));
356 msg_pdbg2("Write and Erase Clock Freq.: %s\n", pprint_freq(cs, desc->component.modes.freq_write));
357 msg_pdbg2("Fast Read is %ssupported.\n", desc->component.modes.fastread ? "" : "not ");
358 if (desc->component.modes.fastread)
Stefan Tauner1e146392011-09-15 23:52:55 +0000359 msg_pdbg2("Fast Read Clock Frequency: %s\n",
Tai-Hong Wu60dead42015-01-05 23:00:14 +0000360 pprint_freq(cs, desc->component.modes.freq_fastread));
Nico Huber3f75d442024-07-14 19:17:56 +0200361 switch (cs) {
362 case CHIPSET_7_SERIES_PANTHER_POINT:
363 case CHIPSET_8_SERIES_LYNX_POINT:
364 case CHIPSET_BAYTRAIL:
365 case CHIPSET_8_SERIES_LYNX_POINT_LP:
366 case CHIPSET_8_SERIES_WELLSBURG:
367 case CHIPSET_9_SERIES_WILDCAT_POINT:
368 case CHIPSET_9_SERIES_WILDCAT_POINT_LP:
369 case CHIPSET_100_SERIES_SUNRISE_POINT:
370 case CHIPSET_APOLLO_LAKE:
371 case CHIPSET_C620_SERIES_LEWISBURG:
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000372 msg_pdbg2("Dual Output Fast Read Support: %sabled\n",
Werner Zehd3e8fd92022-01-25 07:02:49 +0100373 desc->component.modes.dual_output ? "en" : "dis");
Nico Huber3f75d442024-07-14 19:17:56 +0200374 break;
375 default:
376 break;
377 }
David Hendricksa5216362017-08-08 20:02:22 -0700378
Felix Singerd68a0ec2022-08-19 03:23:35 +0200379 bool has_forbidden_opcode = false;
David Hendricksa5216362017-08-08 20:02:22 -0700380 if (desc->component.FLILL != 0) {
Felix Singerd68a0ec2022-08-19 03:23:35 +0200381 has_forbidden_opcode = true;
Stefan Tauner1e146392011-09-15 23:52:55 +0000382 msg_pdbg2("Invalid instruction 0: 0x%02x\n",
383 desc->component.invalid_instr0);
384 msg_pdbg2("Invalid instruction 1: 0x%02x\n",
385 desc->component.invalid_instr1);
386 msg_pdbg2("Invalid instruction 2: 0x%02x\n",
387 desc->component.invalid_instr2);
388 msg_pdbg2("Invalid instruction 3: 0x%02x\n",
389 desc->component.invalid_instr3);
David Hendricksa5216362017-08-08 20:02:22 -0700390 }
Nico Huberd2d39932019-01-18 16:49:37 +0100391 if (has_flill1) {
David Hendricksa5216362017-08-08 20:02:22 -0700392 if (desc->component.FLILL1 != 0) {
Felix Singerd68a0ec2022-08-19 03:23:35 +0200393 has_forbidden_opcode = true;
Nico Huberfa622942017-03-24 17:25:37 +0100394 msg_pdbg2("Invalid instruction 4: 0x%02x\n",
395 desc->component.invalid_instr4);
396 msg_pdbg2("Invalid instruction 5: 0x%02x\n",
397 desc->component.invalid_instr5);
398 msg_pdbg2("Invalid instruction 6: 0x%02x\n",
399 desc->component.invalid_instr6);
400 msg_pdbg2("Invalid instruction 7: 0x%02x\n",
401 desc->component.invalid_instr7);
402 }
Stefan Tauner1e146392011-09-15 23:52:55 +0000403 }
David Hendricksa5216362017-08-08 20:02:22 -0700404 if (!has_forbidden_opcode)
405 msg_pdbg2("No forbidden opcodes.\n");
406
Stefan Tauner1e146392011-09-15 23:52:55 +0000407 msg_pdbg2("\n");
408}
409
410static void pprint_freg(const struct ich_desc_region *reg, uint32_t i)
411{
Nico Huberfa622942017-03-24 17:25:37 +0100412 static const char *const region_names[] = {
Nico Huberd2d39932019-01-18 16:49:37 +0100413 "Descr.", "BIOS", "ME", "GbE", "Platf.", "DevExp", "BIOS2", "unknown",
David Hendricksa5216362017-08-08 20:02:22 -0700414 "EC/BMC", "unknown", "IE", "10GbE", "unknown", "unknown", "unknown", "unknown"
Stefan Tauner1e146392011-09-15 23:52:55 +0000415 };
Nico Huberfa622942017-03-24 17:25:37 +0100416 if (i >= ARRAY_SIZE(region_names)) {
Stefan Tauner1e146392011-09-15 23:52:55 +0000417 msg_pdbg2("%s: region index too high.\n", __func__);
418 return;
419 }
420 uint32_t base = ICH_FREG_BASE(reg->FLREGs[i]);
421 uint32_t limit = ICH_FREG_LIMIT(reg->FLREGs[i]);
Nico Huberfa622942017-03-24 17:25:37 +0100422 msg_pdbg2("Region %d (%-7s) ", i, region_names[i]);
Stefan Tauner1e146392011-09-15 23:52:55 +0000423 if (base > limit)
424 msg_pdbg2("is unused.\n");
425 else
Nico Huber0bb3f712017-03-29 16:44:33 +0200426 msg_pdbg2("0x%08x - 0x%08x\n", base, limit);
Stefan Tauner1e146392011-09-15 23:52:55 +0000427}
428
Nico Huberfa622942017-03-24 17:25:37 +0100429void prettyprint_ich_descriptor_region(const enum ich_chipset cs, const struct ich_descriptors *const desc)
Stefan Tauner1e146392011-09-15 23:52:55 +0000430{
Nico Huber519be662018-12-23 20:03:35 +0100431 ssize_t i;
Nico Huberfa622942017-03-24 17:25:37 +0100432 const ssize_t nr = ich_number_of_regions(cs, &desc->content);
Stefan Tauner1e146392011-09-15 23:52:55 +0000433 msg_pdbg2("=== Region Section ===\n");
Nico Huberfa622942017-03-24 17:25:37 +0100434 if (nr < 0) {
Stefan Tauner1e146392011-09-15 23:52:55 +0000435 msg_pdbg2("%s: number of regions too high (%d).\n", __func__,
Nico Huberfa622942017-03-24 17:25:37 +0100436 desc->content.NR + 1);
Stefan Tauner1e146392011-09-15 23:52:55 +0000437 return;
438 }
Nico Huberfa622942017-03-24 17:25:37 +0100439 for (i = 0; i < nr; i++)
Nico Huber519be662018-12-23 20:03:35 +0100440 msg_pdbg2("FLREG%zd 0x%08x\n", i, desc->region.FLREGs[i]);
Stefan Tauner1e146392011-09-15 23:52:55 +0000441 msg_pdbg2("\n");
442
443 msg_pdbg2("--- Details ---\n");
Nico Huberfa622942017-03-24 17:25:37 +0100444 for (i = 0; i < nr; i++)
Nico Huber519be662018-12-23 20:03:35 +0100445 pprint_freg(&desc->region, (uint32_t)i);
Stefan Tauner1e146392011-09-15 23:52:55 +0000446 msg_pdbg2("\n");
447}
448
Nico Huberb3cc2c62024-07-15 00:45:17 +0200449static char prettify_flag(const unsigned int mask, const unsigned int bit, const char flag)
450{
451 return mask & (1 << bit) ? flag : ' ';
452}
453
454/* Takes NULL-terminated lists of names, assumes max. 5 chars per name. */
455static void prettyprint_pch100_masters(
456 const struct ich_descriptors *const desc,
457 const unsigned int number_masters, const char *const masters[],
458 const unsigned int number_regions, const char *const regions[])
459{
460 unsigned int m, r;
461
462 msg_pdbg2(" ");
463 for (r = 0; r < number_regions && regions[r] != NULL; ++r)
464 msg_pdbg2(" %-5s", regions[r]);
465 msg_pdbg2("\n");
466
467 for (m = 0; m < number_masters; ++m) {
468 const unsigned int ext_start = 12;
469
470 if (masters[m] == NULL)
471 break;
472
473 const struct ich_desc_master_region_access master = desc->master.mstr[m];
474
475 msg_pdbg2("%-5s", masters[m]);
476 for (r = 0; r < ext_start && r < number_regions && regions[r] != NULL; ++r)
477 msg_pdbg2(" %c%c ",
478 prettify_flag(master.read, r, 'r'),
479 prettify_flag(master.write, r, 'w'));
480 for (; r < number_regions && regions[r] != NULL; ++r)
481 msg_pdbg2(" %c%c ",
482 prettify_flag(master.ext_read, r - ext_start, 'r'),
483 prettify_flag(master.ext_write, r - ext_start, 'w'));
484 msg_pdbg2("\n");
485 }
486}
487
Nico Huberfa622942017-03-24 17:25:37 +0100488void prettyprint_ich_descriptor_master(const enum ich_chipset cs, const struct ich_descriptors *const desc)
Stefan Tauner1e146392011-09-15 23:52:55 +0000489{
Nico Huber519be662018-12-23 20:03:35 +0100490 ssize_t i;
Nico Huberfa622942017-03-24 17:25:37 +0100491 const ssize_t nm = ich_number_of_masters(cs, &desc->content);
Stefan Tauner1e146392011-09-15 23:52:55 +0000492 msg_pdbg2("=== Master Section ===\n");
Nico Huberfa622942017-03-24 17:25:37 +0100493 if (nm < 0) {
494 msg_pdbg2("%s: number of masters too high (%d).\n", __func__,
495 desc->content.NM + 1);
496 return;
497 }
498 for (i = 0; i < nm; i++)
Nico Huber519be662018-12-23 20:03:35 +0100499 msg_pdbg2("FLMSTR%zd 0x%08x\n", i + 1, desc->master.FLMSTRs[i]);
Stefan Tauner1e146392011-09-15 23:52:55 +0000500 msg_pdbg2("\n");
501
502 msg_pdbg2("--- Details ---\n");
Nico Huberb3cc2c62024-07-15 00:45:17 +0200503 if (cs >= SPI_ENGINE_PCH100) {
504 const ssize_t nr = ich_number_of_regions(cs, &desc->content);
505 if (nr < 0)
Nico Huberfa622942017-03-24 17:25:37 +0100506 return;
Nico Huberfa622942017-03-24 17:25:37 +0100507
Nico Huberb3cc2c62024-07-15 00:45:17 +0200508 if (cs == CHIPSET_APOLLO_LAKE ||
509 cs == CHIPSET_GEMINI_LAKE ||
510 cs == CHIPSET_ELKHART_LAKE) {
511 const char *const masters[] = {
512 "BIOS", "TXE", NULL
513 };
514 const char *const regions[] = {
515 " FD", "IFWI", " TXE", " n/a", "Pltf.", "DevExp", NULL
516 };
517 prettyprint_pch100_masters(desc, nm, masters, nr, regions);
Nico Huber42daab12024-07-16 00:27:27 +0200518 } else if (cs == CHIPSET_C620_SERIES_LEWISBURG ||
519 cs == CHIPSET_C740_SERIES_EMMITSBURG) {
Nico Huberb3cc2c62024-07-15 00:45:17 +0200520 const char *const masters[] = {
521 "BIOS", "ME", "GbE", "DE", "BMC", "IE", NULL
522 };
523 const char *const regions[] = {
524 " FD ", " BIOS", " ME ", " GbE ", "Pltf.",
David Hendricksa5216362017-08-08 20:02:22 -0700525 " DE ", "BIOS2", " Reg7", " BMC ", " DE2 ",
526 " IE ", "10GbE", "OpROM", "Reg13", "Reg14",
Nico Huberb3cc2c62024-07-15 00:45:17 +0200527 "Reg15", NULL
528 };
529 prettyprint_pch100_masters(desc, nm, masters, nr, regions);
530 } else {
531 const char *const masters[] = {
532 "BIOS", "ME", "GbE", "unkn.", "EC", NULL
533 };
534 const char *const regions[] = {
535 " FD ", "BIOS ", " ME ", " GbE ", "Pltf.",
536 "Reg5 ", "Reg6 ", "Reg7 ", " EC ", "Reg9 ",
537 "Reg10", "Reg11", "Reg12", "Reg13", "Reg14",
538 "Reg15", NULL
539 };
540 prettyprint_pch100_masters(desc, nm, masters, nr, regions);
Nico Huberd2d39932019-01-18 16:49:37 +0100541 }
Nico Huberfa622942017-03-24 17:25:37 +0100542 } else {
543 const struct ich_desc_master *const mstr = &desc->master;
544 msg_pdbg2(" Descr. BIOS ME GbE Platf.\n");
545 msg_pdbg2("BIOS %c%c %c%c %c%c %c%c %c%c\n",
546 (mstr->BIOS_descr_r) ?'r':' ', (mstr->BIOS_descr_w) ?'w':' ',
547 (mstr->BIOS_BIOS_r) ?'r':' ', (mstr->BIOS_BIOS_w) ?'w':' ',
548 (mstr->BIOS_ME_r) ?'r':' ', (mstr->BIOS_ME_w) ?'w':' ',
549 (mstr->BIOS_GbE_r) ?'r':' ', (mstr->BIOS_GbE_w) ?'w':' ',
550 (mstr->BIOS_plat_r) ?'r':' ', (mstr->BIOS_plat_w) ?'w':' ');
551 msg_pdbg2("ME %c%c %c%c %c%c %c%c %c%c\n",
552 (mstr->ME_descr_r) ?'r':' ', (mstr->ME_descr_w) ?'w':' ',
553 (mstr->ME_BIOS_r) ?'r':' ', (mstr->ME_BIOS_w) ?'w':' ',
554 (mstr->ME_ME_r) ?'r':' ', (mstr->ME_ME_w) ?'w':' ',
555 (mstr->ME_GbE_r) ?'r':' ', (mstr->ME_GbE_w) ?'w':' ',
556 (mstr->ME_plat_r) ?'r':' ', (mstr->ME_plat_w) ?'w':' ');
557 msg_pdbg2("GbE %c%c %c%c %c%c %c%c %c%c\n",
558 (mstr->GbE_descr_r) ?'r':' ', (mstr->GbE_descr_w) ?'w':' ',
559 (mstr->GbE_BIOS_r) ?'r':' ', (mstr->GbE_BIOS_w) ?'w':' ',
560 (mstr->GbE_ME_r) ?'r':' ', (mstr->GbE_ME_w) ?'w':' ',
561 (mstr->GbE_GbE_r) ?'r':' ', (mstr->GbE_GbE_w) ?'w':' ',
562 (mstr->GbE_plat_r) ?'r':' ', (mstr->GbE_plat_w) ?'w':' ');
563 }
Stefan Tauner1e146392011-09-15 23:52:55 +0000564 msg_pdbg2("\n");
565}
566
Jacob Garberbeeb8bc2019-06-21 15:24:17 -0600567static void prettyprint_ich_descriptor_straps_ich8(const struct ich_descriptors *desc)
Stefan Taunerb3850962011-12-24 00:00:32 +0000568{
569 static const char * const str_GPIO12[4] = {
570 "GPIO12",
571 "LAN PHY Power Control Function (Native Output)",
572 "GLAN_DOCK# (Native Input)",
573 "invalid configuration",
574 };
575
576 msg_pdbg2("--- MCH details ---\n");
577 msg_pdbg2("ME B is %sabled.\n", desc->north.ich8.MDB ? "dis" : "en");
578 msg_pdbg2("\n");
579
580 msg_pdbg2("--- ICH details ---\n");
581 msg_pdbg2("ME SMBus Address 1: 0x%02x\n", desc->south.ich8.ASD);
582 msg_pdbg2("ME SMBus Address 2: 0x%02x\n", desc->south.ich8.ASD2);
583 msg_pdbg2("ME SMBus Controller is connected to the %s.\n",
584 desc->south.ich8.MESM2SEL ? "SMLink pins" : "SMBus pins");
585 msg_pdbg2("SPI CS1 is used for %s.\n",
586 desc->south.ich8.SPICS1_LANPHYPC_SEL ?
587 "LAN PHY Power Control Function" :
588 "SPI Chip Select");
589 msg_pdbg2("GPIO12 is used as %s.\n",
590 str_GPIO12[desc->south.ich8.GPIO12_SEL]);
591 msg_pdbg2("PCIe Port 6 is used for %s.\n",
592 desc->south.ich8.GLAN_PCIE_SEL ? "integrated LAN" : "PCI Express");
593 msg_pdbg2("%sn BMC Mode: "
594 "Intel AMT SMBus Controller 1 is connected to %s.\n",
595 desc->south.ich8.BMCMODE ? "I" : "Not i",
596 desc->south.ich8.BMCMODE ? "SMLink" : "SMBus");
597 msg_pdbg2("TCO is in %s Mode.\n",
598 desc->south.ich8.TCOMODE ? "Advanced TCO" : "Legacy/Compatible");
599 msg_pdbg2("ME A is %sabled.\n",
600 desc->south.ich8.ME_DISABLE ? "dis" : "en");
601 msg_pdbg2("\n");
602}
603
604static void prettyprint_ich_descriptor_straps_56_pciecs(uint8_t conf, uint8_t off)
605{
606 msg_pdbg2("PCI Express Port Configuration Strap %d: ", off+1);
607
608 off *= 4;
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000609 switch (conf){
Stefan Taunerb3850962011-12-24 00:00:32 +0000610 case 0:
611 msg_pdbg2("4x1 Ports %d-%d (x1)", 1+off, 4+off);
612 break;
613 case 1:
614 msg_pdbg2("1x2, 2x1 Port %d (x2), Port %d (disabled), "
615 "Ports %d, %d (x1)", 1+off, 2+off, 3+off, 4+off);
616 break;
617 case 2:
618 msg_pdbg2("2x2 Port %d (x2), Port %d (x2), Ports "
619 "%d, %d (disabled)", 1+off, 3+off, 2+off, 4+off);
620 break;
621 case 3:
622 msg_pdbg2("1x4 Port %d (x4), Ports %d-%d (disabled)",
623 1+off, 2+off, 4+off);
624 break;
625 }
626 msg_pdbg2("\n");
627}
628
Jacob Garberbeeb8bc2019-06-21 15:24:17 -0600629static void prettyprint_ich_descriptor_pchstraps45678_56(const struct ich_desc_south_strap *s)
Stefan Taunerb3850962011-12-24 00:00:32 +0000630{
631 /* PCHSTRP4 */
632 msg_pdbg2("Intel PHY is %s.\n",
633 (s->ibex.PHYCON == 2) ? "connected" :
634 (s->ibex.PHYCON == 0) ? "disconnected" : "reserved");
635 msg_pdbg2("GbE MAC SMBus address is %sabled.\n",
636 s->ibex.GBEMAC_SMBUS_ADDR_EN ? "en" : "dis");
637 msg_pdbg2("GbE MAC SMBus address: 0x%02x\n",
638 s->ibex.GBEMAC_SMBUS_ADDR);
639 msg_pdbg2("GbE PHY SMBus address: 0x%02x\n",
640 s->ibex.GBEPHY_SMBUS_ADDR);
641
642 /* PCHSTRP5 */
643 /* PCHSTRP6 */
644 /* PCHSTRP7 */
645 msg_pdbg2("Intel ME SMBus Subsystem Vendor ID: 0x%04x\n",
646 s->ibex.MESMA2UDID_VENDOR);
647 msg_pdbg2("Intel ME SMBus Subsystem Device ID: 0x%04x\n",
648 s->ibex.MESMA2UDID_VENDOR);
649
650 /* PCHSTRP8 */
651}
652
Jacob Garberbeeb8bc2019-06-21 15:24:17 -0600653static void prettyprint_ich_descriptor_pchstraps111213_56(const struct ich_desc_south_strap *s)
Stefan Taunerb3850962011-12-24 00:00:32 +0000654{
655 /* PCHSTRP11 */
656 msg_pdbg2("SMLink1 GP Address is %sabled.\n",
657 s->ibex.SML1GPAEN ? "en" : "dis");
658 msg_pdbg2("SMLink1 controller General Purpose Target address: 0x%02x\n",
659 s->ibex.SML1GPA);
660 msg_pdbg2("SMLink1 I2C Target address is %sabled.\n",
661 s->ibex.SML1I2CAEN ? "en" : "dis");
662 msg_pdbg2("SMLink1 I2C Target address: 0x%02x\n",
663 s->ibex.SML1I2CA);
664
665 /* PCHSTRP12 */
666 /* PCHSTRP13 */
667}
668
Jacob Garberbeeb8bc2019-06-21 15:24:17 -0600669static void prettyprint_ich_descriptor_straps_ibex(const struct ich_desc_south_strap *s)
Stefan Taunerb3850962011-12-24 00:00:32 +0000670{
Stefan Tauner67d163d2013-01-15 17:37:48 +0000671 static const uint8_t dec_t209min[4] = {
Stefan Taunerb3850962011-12-24 00:00:32 +0000672 100,
673 50,
674 5,
675 1
676 };
677
678 msg_pdbg2("--- PCH ---\n");
679
680 /* PCHSTRP0 */
681 msg_pdbg2("Chipset configuration Softstrap 2: %d\n", s->ibex.cs_ss2);
682 msg_pdbg2("Intel ME SMBus Select is %sabled.\n",
683 s->ibex.SMB_EN ? "en" : "dis");
684 msg_pdbg2("SMLink0 segment is %sabled.\n",
685 s->ibex.SML0_EN ? "en" : "dis");
686 msg_pdbg2("SMLink1 segment is %sabled.\n",
687 s->ibex.SML1_EN ? "en" : "dis");
688 msg_pdbg2("SMLink1 Frequency: %s\n",
689 (s->ibex.SML1FRQ == 1) ? "100 kHz" : "reserved");
690 msg_pdbg2("Intel ME SMBus Frequency: %s\n",
691 (s->ibex.SMB0FRQ == 1) ? "100 kHz" : "reserved");
692 msg_pdbg2("SMLink0 Frequency: %s\n",
693 (s->ibex.SML0FRQ == 1) ? "100 kHz" : "reserved");
694 msg_pdbg2("GPIO12 is used as %s.\n", s->ibex.LANPHYPC_GP12_SEL ?
695 "LAN_PHY_PWR_CTRL" : "general purpose output");
696 msg_pdbg2("Chipset configuration Softstrap 1: %d\n", s->ibex.cs_ss1);
697 msg_pdbg2("DMI RequesterID Checks are %sabled.\n",
698 s->ibex.DMI_REQID_DIS ? "en" : "dis");
699 msg_pdbg2("BIOS Boot-Block size (BBBS): %d kB.\n",
700 1 << (6 + s->ibex.BBBS));
701
702 /* PCHSTRP1 */
703 msg_pdbg2("Chipset configuration Softstrap 3: 0x%x\n", s->ibex.cs_ss3);
704
705 /* PCHSTRP2 */
706 msg_pdbg2("ME SMBus ASD address is %sabled.\n",
707 s->ibex.MESMASDEN ? "en" : "dis");
708 msg_pdbg2("ME SMBus Controller ASD Target address: 0x%02x\n",
709 s->ibex.MESMASDA);
710 msg_pdbg2("ME SMBus I2C address is %sabled.\n",
711 s->ibex.MESMI2CEN ? "en" : "dis");
712 msg_pdbg2("ME SMBus I2C target address: 0x%02x\n",
713 s->ibex.MESMI2CA);
714
715 /* PCHSTRP3 */
716 prettyprint_ich_descriptor_pchstraps45678_56(s);
717 /* PCHSTRP9 */
718 prettyprint_ich_descriptor_straps_56_pciecs(s->ibex.PCIEPCS1, 0);
719 prettyprint_ich_descriptor_straps_56_pciecs(s->ibex.PCIEPCS1, 1);
720 msg_pdbg2("PCIe Lane Reversal 1: PCIe Lanes 0-3 are %sreserved.\n",
721 s->ibex.PCIELR1 ? "" : "not ");
722 msg_pdbg2("PCIe Lane Reversal 2: PCIe Lanes 4-7 are %sreserved.\n",
723 s->ibex.PCIELR2 ? "" : "not ");
724 msg_pdbg2("DMI Lane Reversal: DMI Lanes 0-3 are %sreserved.\n",
725 s->ibex.DMILR ? "" : "not ");
726 msg_pdbg2("Default PHY PCIe Port is %d.\n", s->ibex.PHY_PCIEPORTSEL+1);
727 msg_pdbg2("Integrated MAC/PHY communication over PCIe is %sabled.\n",
728 s->ibex.PHY_PCIE_EN ? "en" : "dis");
729
730 /* PCHSTRP10 */
731 msg_pdbg2("Management Engine will boot from %sflash.\n",
732 s->ibex.ME_BOOT_FLASH ? "" : "ROM, then ");
733 msg_pdbg2("Chipset configuration Softstrap 5: %d\n", s->ibex.cs_ss5);
734 msg_pdbg2("Virtualization Engine Enable 1 is %sabled.\n",
735 s->ibex.VE_EN ? "en" : "dis");
736 msg_pdbg2("ME Memory-attached Debug Display Device is %sabled.\n",
737 s->ibex.MMDDE ? "en" : "dis");
738 msg_pdbg2("ME Memory-attached Debug Display Device address: 0x%02x\n",
739 s->ibex.MMADDR);
740 msg_pdbg2("Chipset configuration Softstrap 7: %d\n", s->ibex.cs_ss7);
741 msg_pdbg2("Integrated Clocking Configuration is %d.\n",
742 (s->ibex.ICC_SEL == 7) ? 0 : s->ibex.ICC_SEL);
743 msg_pdbg2("PCH Signal CL_RST1# does %sassert when Intel ME performs a "
744 "reset.\n", s->ibex.MER_CL1 ? "" : "not ");
745
746 prettyprint_ich_descriptor_pchstraps111213_56(s);
747
748 /* PCHSTRP14 */
749 msg_pdbg2("Virtualization Engine Enable 2 is %sabled.\n",
750 s->ibex.VE_EN2 ? "en" : "dis");
751 msg_pdbg2("Virtualization Engine will boot from %sflash.\n",
752 s->ibex.VE_BOOT_FLASH ? "" : "ROM, then ");
753 msg_pdbg2("Braidwood SSD functionality is %sabled.\n",
754 s->ibex.BW_SSD ? "en" : "dis");
755 msg_pdbg2("Braidwood NVMHCI functionality is %sabled.\n",
756 s->ibex.NVMHCI_EN ? "en" : "dis");
757
758 /* PCHSTRP15 */
759 msg_pdbg2("Chipset configuration Softstrap 6: %d\n", s->ibex.cs_ss6);
760 msg_pdbg2("Integrated wired LAN Solution is %sabled.\n",
761 s->ibex.IWL_EN ? "en" : "dis");
762 msg_pdbg2("t209 min Timing: %d ms\n",
763 dec_t209min[s->ibex.t209min]);
764 msg_pdbg2("\n");
765}
766
Jacob Garberbeeb8bc2019-06-21 15:24:17 -0600767static void prettyprint_ich_descriptor_straps_cougar(const struct ich_desc_south_strap *s)
Stefan Taunerb3850962011-12-24 00:00:32 +0000768{
769 msg_pdbg2("--- PCH ---\n");
770
771 /* PCHSTRP0 */
772 msg_pdbg2("Chipset configuration Softstrap 1: %d\n", s->cougar.cs_ss1);
773 msg_pdbg2("Intel ME SMBus Select is %sabled.\n",
774 s->ibex.SMB_EN ? "en" : "dis");
775 msg_pdbg2("SMLink0 segment is %sabled.\n",
776 s->ibex.SML0_EN ? "en" : "dis");
777 msg_pdbg2("SMLink1 segment is %sabled.\n",
778 s->ibex.SML1_EN ? "en" : "dis");
779 msg_pdbg2("SMLink1 Frequency: %s\n",
780 (s->ibex.SML1FRQ == 1) ? "100 kHz" : "reserved");
781 msg_pdbg2("Intel ME SMBus Frequency: %s\n",
782 (s->ibex.SMB0FRQ == 1) ? "100 kHz" : "reserved");
783 msg_pdbg2("SMLink0 Frequency: %s\n",
784 (s->ibex.SML0FRQ == 1) ? "100 kHz" : "reserved");
785 msg_pdbg2("GPIO12 is used as %s.\n", s->ibex.LANPHYPC_GP12_SEL ?
786 "LAN_PHY_PWR_CTRL" : "general purpose output");
787 msg_pdbg2("LinkSec is %sabled.\n",
788 s->cougar.LINKSEC_DIS ? "en" : "dis");
789 msg_pdbg2("DMI RequesterID Checks are %sabled.\n",
790 s->ibex.DMI_REQID_DIS ? "en" : "dis");
791 msg_pdbg2("BIOS Boot-Block size (BBBS): %d kB.\n",
792 1 << (6 + s->ibex.BBBS));
793
794 /* PCHSTRP1 */
795 msg_pdbg2("Chipset configuration Softstrap 3: 0x%x\n", s->ibex.cs_ss3);
796 msg_pdbg2("Chipset configuration Softstrap 2: 0x%x\n", s->ibex.cs_ss2);
797
798 /* PCHSTRP2 */
799 msg_pdbg2("ME SMBus ASD address is %sabled.\n",
800 s->ibex.MESMASDEN ? "en" : "dis");
801 msg_pdbg2("ME SMBus Controller ASD Target address: 0x%02x\n",
802 s->ibex.MESMASDA);
803 msg_pdbg2("ME SMBus MCTP Address is %sabled.\n",
804 s->cougar.MESMMCTPAEN ? "en" : "dis");
805 msg_pdbg2("ME SMBus MCTP target address: 0x%02x\n",
806 s->cougar.MESMMCTPA);
807 msg_pdbg2("ME SMBus I2C address is %sabled.\n",
808 s->ibex.MESMI2CEN ? "en" : "dis");
809 msg_pdbg2("ME SMBus I2C target address: 0x%02x\n",
810 s->ibex.MESMI2CA);
811
812 /* PCHSTRP3 */
813 prettyprint_ich_descriptor_pchstraps45678_56(s);
814 /* PCHSTRP9 */
815 prettyprint_ich_descriptor_straps_56_pciecs(s->ibex.PCIEPCS1, 0);
816 prettyprint_ich_descriptor_straps_56_pciecs(s->ibex.PCIEPCS1, 1);
817 msg_pdbg2("PCIe Lane Reversal 1: PCIe Lanes 0-3 are %sreserved.\n",
818 s->ibex.PCIELR1 ? "" : "not ");
819 msg_pdbg2("PCIe Lane Reversal 2: PCIe Lanes 4-7 are %sreserved.\n",
820 s->ibex.PCIELR2 ? "" : "not ");
821 msg_pdbg2("DMI Lane Reversal: DMI Lanes 0-3 are %sreserved.\n",
822 s->ibex.DMILR ? "" : "not ");
823 msg_pdbg2("ME Debug status writes over SMBUS are %sabled.\n",
824 s->cougar.MDSMBE_EN ? "en" : "dis");
825 msg_pdbg2("ME Debug SMBus Emergency Mode address: 0x%02x (raw)\n",
826 s->cougar.MDSMBE_ADD);
827 msg_pdbg2("Default PHY PCIe Port is %d.\n", s->ibex.PHY_PCIEPORTSEL+1);
828 msg_pdbg2("Integrated MAC/PHY communication over PCIe is %sabled.\n",
829 s->ibex.PHY_PCIE_EN ? "en" : "dis");
830 msg_pdbg2("PCIe ports Subtractive Decode Agent is %sabled.\n",
831 s->cougar.SUB_DECODE_EN ? "en" : "dis");
832 msg_pdbg2("GPIO74 is used as %s.\n", s->cougar.PCHHOT_SML1ALERT_SEL ?
833 "PCHHOT#" : "SML1ALERT#");
834
835 /* PCHSTRP10 */
836 msg_pdbg2("Management Engine will boot from %sflash.\n",
837 s->ibex.ME_BOOT_FLASH ? "" : "ROM, then ");
838
839 msg_pdbg2("ME Debug SMBus Emergency Mode is %sabled.\n",
840 s->cougar.MDSMBE_EN ? "en" : "dis");
841 msg_pdbg2("ME Debug SMBus Emergency Mode Address: 0x%02x\n",
842 s->cougar.MDSMBE_ADD);
843
844 msg_pdbg2("Integrated Clocking Configuration used: %d\n",
845 s->cougar.ICC_SEL);
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000846 msg_pdbg2("PCH Signal CL_RST1# does %sassert when Intel ME performs a reset.\n",
847 s->ibex.MER_CL1 ? "" : "not ");
Stefan Taunerb3850962011-12-24 00:00:32 +0000848 msg_pdbg2("ICC Profile is selected by %s.\n",
849 s->cougar.ICC_PRO_SEL ? "Softstraps" : "BIOS");
850 msg_pdbg2("Deep SX is %ssupported on the platform.\n",
851 s->cougar.Deep_SX_EN ? "not " : "");
852 msg_pdbg2("ME Debug LAN Emergency Mode is %sabled.\n",
853 s->cougar.ME_DBG_LAN ? "en" : "dis");
854
855 prettyprint_ich_descriptor_pchstraps111213_56(s);
856
857 /* PCHSTRP14 */
858 /* PCHSTRP15 */
859 msg_pdbg2("Chipset configuration Softstrap 6: %d\n", s->cougar.cs_ss6);
860 msg_pdbg2("Integrated wired LAN is %sabled.\n",
861 s->cougar.IWL_EN ? "en" : "dis");
862 msg_pdbg2("Chipset configuration Softstrap 5: %d\n", s->cougar.cs_ss5);
863 msg_pdbg2("SMLink1 provides temperature from %s.\n",
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000864 s->cougar.SMLINK1_THERM_SEL ? "PCH only" : "the CPU, PCH and DIMMs");
Stefan Taunerb3850962011-12-24 00:00:32 +0000865 msg_pdbg2("GPIO29 is used as %s.\n", s->cougar.SLP_LAN_GP29_SEL ?
866 "general purpose output" : "SLP_LAN#");
867
868 /* PCHSTRP16 */
869 /* PCHSTRP17 */
870 msg_pdbg2("Integrated Clock: %s Clock Mode\n",
871 s->cougar.ICML ? "Buffered Through" : "Full Integrated");
872 msg_pdbg2("\n");
873}
874
875void prettyprint_ich_descriptor_straps(enum ich_chipset cs, const struct ich_descriptors *desc)
876{
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000877 unsigned int i, max_count;
Stefan Taunerb3850962011-12-24 00:00:32 +0000878 msg_pdbg2("=== Softstraps ===\n");
879
Nico Huber157b8182024-07-19 17:48:12 +0200880 if (has_classic_proc_straps(cs)) {
881 max_count = MIN(ARRAY_SIZE(desc->north.STRPs), desc->content.MSL);
882 if (max_count < desc->content.MSL) {
883 msg_pdbg2("MSL (%u) is greater than the current maximum of %u entries.\n",
884 desc->content.MSL, max_count);
885 msg_pdbg2("Only the first %u entries will be printed.\n", max_count);
886 }
Stefan Taunerb3850962011-12-24 00:00:32 +0000887
Nico Huber157b8182024-07-19 17:48:12 +0200888 msg_pdbg2("--- North/MCH/PROC (%d entries) ---\n", max_count);
889 for (i = 0; i < max_count; i++)
890 msg_pdbg2("STRP%-2d = 0x%08x\n", i, desc->north.STRPs[i]);
891 msg_pdbg2("\n");
892 }
Stefan Taunerb3850962011-12-24 00:00:32 +0000893
Nico Huber519be662018-12-23 20:03:35 +0100894 max_count = MIN(ARRAY_SIZE(desc->south.STRPs), desc->content.ISL);
Nico Huberd7c75522017-03-29 16:31:49 +0200895 if (max_count < desc->content.ISL) {
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000896 msg_pdbg2("ISL (%u) is greater than the current maximum of %u entries.\n",
897 desc->content.ISL, max_count);
898 msg_pdbg2("Only the first %u entries will be printed.\n", max_count);
Nico Huberd7c75522017-03-29 16:31:49 +0200899 }
Stefan Taunerb3850962011-12-24 00:00:32 +0000900
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000901 msg_pdbg2("--- South/ICH/PCH (%d entries) ---\n", max_count);
902 for (i = 0; i < max_count; i++)
Stefan Taunerb3850962011-12-24 00:00:32 +0000903 msg_pdbg2("STRP%-2d = 0x%08x\n", i, desc->south.STRPs[i]);
904 msg_pdbg2("\n");
905
906 switch (cs) {
907 case CHIPSET_ICH8:
908 if (sizeof(desc->north.ich8) / 4 != desc->content.MSL)
909 msg_pdbg2("Detailed North/MCH/PROC information is "
910 "probably not reliable, printing anyway.\n");
911 if (sizeof(desc->south.ich8) / 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_ich8(desc);
915 break;
916 case CHIPSET_5_SERIES_IBEX_PEAK:
917 /* PCH straps only. PROCSTRPs are unknown. */
918 if (sizeof(desc->south.ibex) / 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_ibex(&desc->south);
922 break;
923 case CHIPSET_6_SERIES_COUGAR_POINT:
924 /* PCH straps only. PROCSTRP0 is "reserved". */
925 if (sizeof(desc->south.cougar) / 4 != desc->content.ISL)
926 msg_pdbg2("Detailed South/ICH/PCH information is "
927 "probably not reliable, printing anyway.\n");
928 prettyprint_ich_descriptor_straps_cougar(&desc->south);
929 break;
930 case CHIPSET_ICH_UNKNOWN:
931 break;
932 default:
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000933 msg_pdbg2("The meaning of the descriptor straps are unknown yet.\n\n");
Stefan Taunerb3850962011-12-24 00:00:32 +0000934 break;
935 }
936}
937
Jacob Garberbeeb8bc2019-06-21 15:24:17 -0600938static void prettyprint_rdid(uint32_t reg_val)
Stefan Taunerb3850962011-12-24 00:00:32 +0000939{
940 uint8_t mid = reg_val & 0xFF;
941 uint16_t did = ((reg_val >> 16) & 0xFF) | (reg_val & 0xFF00);
942 msg_pdbg2("Manufacturer ID 0x%02x, Device ID 0x%04x\n", mid, did);
943}
944
945void prettyprint_ich_descriptor_upper_map(const struct ich_desc_upper_map *umap)
946{
947 int i;
948 msg_pdbg2("=== Upper Map Section ===\n");
949 msg_pdbg2("FLUMAP1 0x%08x\n", umap->FLUMAP1);
950 msg_pdbg2("\n");
951
952 msg_pdbg2("--- Details ---\n");
953 msg_pdbg2("VTL (length in DWORDS) = %d\n", umap->VTL);
954 msg_pdbg2("VTBA (base address) = 0x%6.6x\n", getVTBA(umap));
955 msg_pdbg2("\n");
956
957 msg_pdbg2("VSCC Table: %d entries\n", umap->VTL/2);
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000958 for (i = 0; i < umap->VTL/2; i++) {
Stefan Taunerb3850962011-12-24 00:00:32 +0000959 uint32_t jid = umap->vscc_table[i].JID;
960 uint32_t vscc = umap->vscc_table[i].VSCC;
961 msg_pdbg2(" JID%d = 0x%08x\n", i, jid);
962 msg_pdbg2(" VSCC%d = 0x%08x\n", i, vscc);
Martin Rothf6c1cb12022-03-15 10:55:25 -0600963 msg_pdbg2(" "); /* indentation */
Stefan Taunerb3850962011-12-24 00:00:32 +0000964 prettyprint_rdid(jid);
Martin Rothf6c1cb12022-03-15 10:55:25 -0600965 msg_pdbg2(" "); /* indentation */
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000966 prettyprint_ich_reg_vscc(vscc, 0, false);
Stefan Taunerb3850962011-12-24 00:00:32 +0000967 }
968 msg_pdbg2("\n");
969}
970
David Hendricks66565a72021-09-20 21:56:40 -0700971static inline void warn_peculiar_desc(const char *const name)
Nico Huber964007a2021-06-17 21:12:47 +0200972{
Nico Huber964007a2021-06-17 21:12:47 +0200973 msg_pwarn("Peculiar flash descriptor, assuming %s compatibility.\n", name);
974}
975
Nico Huber1dc3d422017-06-17 00:09:31 +0200976/*
977 * Guesses a minimum chipset version based on the maximum number of
Nico Huber3ad9aad2021-06-17 22:05:00 +0200978 * soft straps per generation and presence of the MIP base (MDTBA).
Nico Huber1dc3d422017-06-17 00:09:31 +0200979 */
Nico Huberdb878fb2024-07-19 17:37:09 +0200980static enum ich_chipset guess_ich_chipset(const struct ich_desc_content *const content,
981 const struct ich_desc_upper_map *const upper)
Nico Huber1dc3d422017-06-17 00:09:31 +0200982{
983 if (content->ICCRIBA == 0x00) {
984 if (content->MSL == 0 && content->ISL <= 2)
985 return CHIPSET_ICH8;
Nico Huber83b01c82021-06-17 21:20:09 +0200986 if (content->ISL <= 2)
Nico Huber1dc3d422017-06-17 00:09:31 +0200987 return CHIPSET_ICH9;
Nico Huber83b01c82021-06-17 21:20:09 +0200988 if (content->ISL <= 10)
Nico Huber1dc3d422017-06-17 00:09:31 +0200989 return CHIPSET_ICH10;
David Hendricks66565a72021-09-20 21:56:40 -0700990 if (content->ISL <= 16)
991 return CHIPSET_5_SERIES_IBEX_PEAK;
Nico Huber83b01c82021-06-17 21:20:09 +0200992 if (content->FLMAP2 == 0) {
Nico Huber81965f32021-06-17 23:25:35 +0200993 if (content->ISL == 19)
994 return CHIPSET_APOLLO_LAKE;
David Hendricks66565a72021-09-20 21:56:40 -0700995 if (content->ISL == 23)
996 return CHIPSET_GEMINI_LAKE;
997 warn_peculiar_desc("Gemini Lake");
Nico Huber81965f32021-06-17 23:25:35 +0200998 return CHIPSET_GEMINI_LAKE;
Nico Huberd2d39932019-01-18 16:49:37 +0100999 }
Nico Huber42daab12024-07-16 00:27:27 +02001000 if (content->NM == 6) {
1001 /* 0x8b is from the SPI Guide, but not yet seen in the wild. */
1002 if (0x50 <= content->ISL && content->ISL <= 0x8b)
1003 return CHIPSET_C740_SERIES_EMMITSBURG;
1004 warn_peculiar_desc("C740 series");
1005 return CHIPSET_C740_SERIES_EMMITSBURG;
1006 }
David Hendricks66565a72021-09-20 21:56:40 -07001007 warn_peculiar_desc("Ibex Peak");
Nico Huber1dc3d422017-06-17 00:09:31 +02001008 return CHIPSET_5_SERIES_IBEX_PEAK;
Nico Huber3ad9aad2021-06-17 22:05:00 +02001009 } else if (upper->MDTBA == 0x00) {
1010 if (content->ICCRIBA < 0x31 && content->FMSBA < 0x30) {
1011 if (content->MSL == 0 && content->ISL <= 17)
1012 return CHIPSET_BAYTRAIL;
1013 if (content->MSL <= 1 && content->ISL <= 18)
1014 return CHIPSET_6_SERIES_COUGAR_POINT;
David Hendricks66565a72021-09-20 21:56:40 -07001015 if (content->MSL <= 1 && content->ISL <= 21)
1016 return CHIPSET_8_SERIES_LYNX_POINT;
1017 warn_peculiar_desc("Lynx Point");
Nico Huber81965f32021-06-17 23:25:35 +02001018 return CHIPSET_8_SERIES_LYNX_POINT;
Nico Huber3ad9aad2021-06-17 22:05:00 +02001019 }
1020 if (content->NM == 6) {
David Hendricks66565a72021-09-20 21:56:40 -07001021 if (content->ICCRIBA <= 0x34)
1022 return CHIPSET_C620_SERIES_LEWISBURG;
1023 warn_peculiar_desc("C620 series");
Nico Huber2a5dfaf2019-07-04 16:01:51 +02001024 return CHIPSET_C620_SERIES_LEWISBURG;
Nico Huber3ad9aad2021-06-17 22:05:00 +02001025 }
David Hendricks66565a72021-09-20 21:56:40 -07001026 if (content->ICCRIBA == 0x31)
1027 return CHIPSET_100_SERIES_SUNRISE_POINT;
1028 warn_peculiar_desc("100 series");
Nico Huber83b01c82021-06-17 21:20:09 +02001029 return CHIPSET_100_SERIES_SUNRISE_POINT;
Nico Huber1dc3d422017-06-17 00:09:31 +02001030 } else {
David Hendricks66565a72021-09-20 21:56:40 -07001031 if (content->ICCRIBA == 0x34)
1032 return CHIPSET_300_SERIES_CANNON_POINT;
Michał Żygowski5c9f5422021-06-16 15:13:54 +02001033 if (content->CSSL == 0x11)
1034 return CHIPSET_500_SERIES_TIGER_POINT;
Nico Huber29c23dd2022-12-21 15:25:09 +00001035 if (content->CSSL == 0x14) /* backwards compatible Alder Point */
1036 return CHIPSET_500_SERIES_TIGER_POINT;
Nico Huber756b6b32022-12-21 17:15:13 +00001037 if (content->CSSL == 0x03) {
1038 if (content->CSSO == 0x58)
1039 return CHIPSET_ELKHART_LAKE;
1040 else if (content->CSSO == 0x6c) /* backwards compatible Jasper Lake */
1041 return CHIPSET_300_SERIES_CANNON_POINT;
1042 }
Michał Żygowski5c9f5422021-06-16 15:13:54 +02001043 msg_pwarn("Unknown flash descriptor, assuming 500 series compatibility.\n");
1044 return CHIPSET_500_SERIES_TIGER_POINT;
Nico Huber1dc3d422017-06-17 00:09:31 +02001045 }
1046}
1047
Stefan Taunerb3850962011-12-24 00:00:32 +00001048/* len is the length of dump in bytes */
Nico Huberfa622942017-03-24 17:25:37 +01001049int read_ich_descriptors_from_dump(const uint32_t *const dump, const size_t len,
1050 enum ich_chipset *const cs, struct ich_descriptors *const desc)
Stefan Taunerb3850962011-12-24 00:00:32 +00001051{
Nico Huber519be662018-12-23 20:03:35 +01001052 ssize_t i, max_count;
1053 size_t pch_bug_offset = 0;
Stefan Taunerb3850962011-12-24 00:00:32 +00001054
1055 if (dump == NULL || desc == NULL)
1056 return ICH_RET_PARAM;
1057
1058 if (dump[0] != DESCRIPTOR_MODE_SIGNATURE) {
1059 if (dump[4] == DESCRIPTOR_MODE_SIGNATURE)
1060 pch_bug_offset = 4;
1061 else
1062 return ICH_RET_ERR;
1063 }
1064
1065 /* map */
Nico Huber9e14aed2017-03-28 17:08:46 +02001066 if (len < (4 + pch_bug_offset) * 4)
Stefan Taunerb3850962011-12-24 00:00:32 +00001067 return ICH_RET_OOB;
1068 desc->content.FLVALSIG = dump[0 + pch_bug_offset];
1069 desc->content.FLMAP0 = dump[1 + pch_bug_offset];
1070 desc->content.FLMAP1 = dump[2 + pch_bug_offset];
1071 desc->content.FLMAP2 = dump[3 + pch_bug_offset];
1072
1073 /* component */
Nico Huber9e14aed2017-03-28 17:08:46 +02001074 if (len < getFCBA(&desc->content) + 3 * 4)
Stefan Taunerb3850962011-12-24 00:00:32 +00001075 return ICH_RET_OOB;
1076 desc->component.FLCOMP = dump[(getFCBA(&desc->content) >> 2) + 0];
1077 desc->component.FLILL = dump[(getFCBA(&desc->content) >> 2) + 1];
1078 desc->component.FLPB = dump[(getFCBA(&desc->content) >> 2) + 2];
1079
Nico Huber8a03c902021-06-17 21:23:29 +02001080 /* upper map */
1081 desc->upper.FLUMAP1 = dump[(UPPER_MAP_OFFSET >> 2) + 0];
1082
1083 /* VTL is 8 bits long. Quote from the Ibex Peak SPI programming guide:
1084 * "Identifies the 1s based number of DWORDS contained in the VSCC
1085 * Table. Each SPI component entry in the table is 2 DWORDS long." So
1086 * the maximum of 255 gives us 127.5 SPI components(!?) 8 bytes each. A
1087 * check ensures that the maximum offset actually accessed is available.
1088 */
1089 if (len < getVTBA(&desc->upper) + (desc->upper.VTL / 2 * 8))
1090 return ICH_RET_OOB;
1091
1092 for (i = 0; i < desc->upper.VTL/2; i++) {
1093 desc->upper.vscc_table[i].JID = dump[(getVTBA(&desc->upper) >> 2) + i * 2 + 0];
1094 desc->upper.vscc_table[i].VSCC = dump[(getVTBA(&desc->upper) >> 2) + i * 2 + 1];
1095 }
1096
Nico Huber67d71792017-06-17 03:10:15 +02001097 if (*cs == CHIPSET_ICH_UNKNOWN) {
Nico Huberdb878fb2024-07-19 17:37:09 +02001098 *cs = guess_ich_chipset(&desc->content, &desc->upper);
Nico Huber67d71792017-06-17 03:10:15 +02001099 prettyprint_ich_chipset(*cs);
1100 }
Nico Huberfa622942017-03-24 17:25:37 +01001101
Stefan Taunerb3850962011-12-24 00:00:32 +00001102 /* region */
Nico Huberfa622942017-03-24 17:25:37 +01001103 const ssize_t nr = ich_number_of_regions(*cs, &desc->content);
Nico Huber519be662018-12-23 20:03:35 +01001104 if (nr < 0 || len < getFRBA(&desc->content) + (size_t)nr * 4)
Stefan Taunerb3850962011-12-24 00:00:32 +00001105 return ICH_RET_OOB;
Nico Huberfa622942017-03-24 17:25:37 +01001106 for (i = 0; i < nr; i++)
1107 desc->region.FLREGs[i] = dump[(getFRBA(&desc->content) >> 2) + i];
Stefan Taunerb3850962011-12-24 00:00:32 +00001108
1109 /* master */
Nico Huberfa622942017-03-24 17:25:37 +01001110 const ssize_t nm = ich_number_of_masters(*cs, &desc->content);
Nico Huber519be662018-12-23 20:03:35 +01001111 if (nm < 0 || len < getFMBA(&desc->content) + (size_t)nm * 4)
Stefan Taunerb3850962011-12-24 00:00:32 +00001112 return ICH_RET_OOB;
Nico Huberfa622942017-03-24 17:25:37 +01001113 for (i = 0; i < nm; i++)
1114 desc->master.FLMSTRs[i] = dump[(getFMBA(&desc->content) >> 2) + i];
Stefan Taunerb3850962011-12-24 00:00:32 +00001115
Nico Huber157b8182024-07-19 17:48:12 +02001116 if (has_classic_proc_straps(*cs)) {
1117 /* MCH/PROC (aka. North) straps */
1118 if (len < getFMSBA(&desc->content) + desc->content.MSL * 4)
1119 return ICH_RET_OOB;
Stefan Taunerb3850962011-12-24 00:00:32 +00001120
Nico Huber157b8182024-07-19 17:48:12 +02001121 /* limit the range to be written */
1122 max_count = MIN(sizeof(desc->north.STRPs) / 4, desc->content.MSL);
1123 for (i = 0; i < max_count; i++)
1124 desc->north.STRPs[i] = dump[(getFMSBA(&desc->content) >> 2) + i];
1125 }
Stefan Taunerb3850962011-12-24 00:00:32 +00001126
1127 /* ICH/PCH (aka. South) straps */
1128 if (len < getFISBA(&desc->content) + desc->content.ISL * 4)
1129 return ICH_RET_OOB;
1130
1131 /* limit the range to be written */
Nico Huber519be662018-12-23 20:03:35 +01001132 max_count = MIN(sizeof(desc->south.STRPs) / 4, desc->content.ISL);
Stefan Taunera1a14ec2012-08-13 08:45:13 +00001133 for (i = 0; i < max_count; i++)
1134 desc->south.STRPs[i] = dump[(getFISBA(&desc->content) >> 2) + i];
Stefan Taunerb3850962011-12-24 00:00:32 +00001135
1136 return ICH_RET_OK;
1137}
1138
Nico Huberad186312016-05-02 15:15:29 +02001139#ifndef ICH_DESCRIPTORS_FROM_DUMP_ONLY
Stefan Taunerb3850962011-12-24 00:00:32 +00001140
Stefan Taunerd0c5dc22011-10-20 12:57:14 +00001141/** Returns the integer representation of the component density with index
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001142\em idx in bytes or -1 if the correct size can not be determined. */
1143int getFCBA_component_density(enum ich_chipset cs, const struct ich_descriptors *desc, uint8_t idx)
Stefan Taunerd0c5dc22011-10-20 12:57:14 +00001144{
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001145 if (idx > 1) {
Stefan Taunera1a14ec2012-08-13 08:45:13 +00001146 msg_perr("Only ICH SPI component index 0 or 1 are supported yet.\n");
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001147 return -1;
Stefan Taunerd0c5dc22011-10-20 12:57:14 +00001148 }
Nico Huberdfd06472024-07-14 23:45:05 +02001149 if (cs == CHIPSET_ICH_UNKNOWN) {
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001150 msg_pwarn("Density encoding is unknown on this chipset.\n");
1151 return -1;
Stefan Taunerd0c5dc22011-10-20 12:57:14 +00001152 }
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001153
Nico Huberdfd06472024-07-14 23:45:05 +02001154 if (desc->content.NC == 0 && idx > 0)
1155 return 0;
1156
1157 const unsigned int max_idx = cs < CHIPSET_HAS_NEW_COMPONENT_DENSITY ? 5 : 7;
1158 const unsigned int size_idx = get_density_index(cs, desc, idx);
1159
1160 if (size_idx > max_idx) {
Tai-Hong Wu60dead42015-01-05 23:00:14 +00001161 msg_perr("Density of ICH SPI component with index %d is invalid.\n"
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001162 "Encoded density is 0x%x while maximum allowed is 0x%x.\n",
Nico Huberdfd06472024-07-14 23:45:05 +02001163 idx, size_idx, max_idx);
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001164 return -1;
1165 }
1166
Nico Huberdfd06472024-07-14 23:45:05 +02001167 return 1 << (19 + size_idx);
Stefan Taunerd0c5dc22011-10-20 12:57:14 +00001168}
1169
Nico Huber8d494992017-06-19 12:18:33 +02001170/* Only used by ichspi.c */
1171#if CONFIG_INTERNAL == 1 && (defined(__i386__) || defined(__x86_64__))
Nico Huberd54e4f42017-03-23 23:45:47 +01001172static uint32_t read_descriptor_reg(enum ich_chipset cs, uint8_t section, uint16_t offset, void *spibar)
Stefan Tauner1e146392011-09-15 23:52:55 +00001173{
1174 uint32_t control = 0;
1175 control |= (section << FDOC_FDSS_OFF) & FDOC_FDSS;
1176 control |= (offset << FDOC_FDSI_OFF) & FDOC_FDSI;
Nico Huberb2ad9fd2024-07-14 23:18:53 +02001177
1178 if (cs >= SPI_ENGINE_PCH100) {
Nico Huberd54e4f42017-03-23 23:45:47 +01001179 mmio_le_writel(control, spibar + PCH100_REG_FDOC);
1180 return mmio_le_readl(spibar + PCH100_REG_FDOD);
Nico Huberb2ad9fd2024-07-14 23:18:53 +02001181 } else {
Nico Huberd54e4f42017-03-23 23:45:47 +01001182 mmio_le_writel(control, spibar + ICH9_REG_FDOC);
1183 return mmio_le_readl(spibar + ICH9_REG_FDOD);
1184 }
Stefan Tauner1e146392011-09-15 23:52:55 +00001185}
1186
Nico Huberd54e4f42017-03-23 23:45:47 +01001187int read_ich_descriptors_via_fdo(enum ich_chipset cs, void *spibar, struct ich_descriptors *desc)
Stefan Tauner1e146392011-09-15 23:52:55 +00001188{
Nico Huber519be662018-12-23 20:03:35 +01001189 ssize_t i;
Stefan Tauner1e146392011-09-15 23:52:55 +00001190 struct ich_desc_region *r = &desc->region;
1191
1192 /* Test if bit-fields are working as expected.
1193 * FIXME: Replace this with dynamic bitfield fixup
1194 */
1195 for (i = 0; i < 4; i++)
1196 desc->region.FLREGs[i] = 0x5A << (i * 8);
Nico Huberfa622942017-03-24 17:25:37 +01001197 if (r->old_reg[0].base != 0x005A || r->old_reg[0].limit != 0x0000 ||
1198 r->old_reg[1].base != 0x1A00 || r->old_reg[1].limit != 0x0000 ||
1199 r->old_reg[2].base != 0x0000 || r->old_reg[2].limit != 0x005A ||
1200 r->old_reg[3].base != 0x0000 || r->old_reg[3].limit != 0x1A00) {
Stefan Tauner1e146392011-09-15 23:52:55 +00001201 msg_pdbg("The combination of compiler and CPU architecture used"
1202 "does not lay out bit-fields as expected, sorry.\n");
Nico Huberfa622942017-03-24 17:25:37 +01001203 msg_pspew("r->old_reg[0].base = 0x%04X (0x005A)\n", r->old_reg[0].base);
1204 msg_pspew("r->old_reg[0].limit = 0x%04X (0x0000)\n", r->old_reg[0].limit);
1205 msg_pspew("r->old_reg[1].base = 0x%04X (0x1A00)\n", r->old_reg[1].base);
1206 msg_pspew("r->old_reg[1].limit = 0x%04X (0x0000)\n", r->old_reg[1].limit);
1207 msg_pspew("r->old_reg[2].base = 0x%04X (0x0000)\n", r->old_reg[2].base);
1208 msg_pspew("r->old_reg[2].limit = 0x%04X (0x005A)\n", r->old_reg[2].limit);
1209 msg_pspew("r->old_reg[3].base = 0x%04X (0x0000)\n", r->old_reg[3].base);
1210 msg_pspew("r->old_reg[3].limit = 0x%04X (0x1A00)\n", r->old_reg[3].limit);
Stefan Tauner1e146392011-09-15 23:52:55 +00001211 return ICH_RET_ERR;
1212 }
1213
Stefan Taunera1a14ec2012-08-13 08:45:13 +00001214 msg_pdbg2("Reading flash descriptors mapped by the chipset via FDOC/FDOD...");
Stefan Tauner1e146392011-09-15 23:52:55 +00001215 /* content section */
Nico Huberd54e4f42017-03-23 23:45:47 +01001216 desc->content.FLVALSIG = read_descriptor_reg(cs, 0, 0, spibar);
1217 desc->content.FLMAP0 = read_descriptor_reg(cs, 0, 1, spibar);
1218 desc->content.FLMAP1 = read_descriptor_reg(cs, 0, 2, spibar);
1219 desc->content.FLMAP2 = read_descriptor_reg(cs, 0, 3, spibar);
Stefan Tauner1e146392011-09-15 23:52:55 +00001220
1221 /* component section */
Nico Huberd54e4f42017-03-23 23:45:47 +01001222 desc->component.FLCOMP = read_descriptor_reg(cs, 1, 0, spibar);
1223 desc->component.FLILL = read_descriptor_reg(cs, 1, 1, spibar);
1224 desc->component.FLPB = read_descriptor_reg(cs, 1, 2, spibar);
Stefan Tauner1e146392011-09-15 23:52:55 +00001225
1226 /* region section */
Nico Huberfa622942017-03-24 17:25:37 +01001227 const ssize_t nr = ich_number_of_regions(cs, &desc->content);
1228 if (nr < 0) {
Stefan Tauner1e146392011-09-15 23:52:55 +00001229 msg_pdbg2("%s: number of regions too high (%d) - failed\n",
Nico Huberfa622942017-03-24 17:25:37 +01001230 __func__, desc->content.NR + 1);
Stefan Tauner1e146392011-09-15 23:52:55 +00001231 return ICH_RET_ERR;
1232 }
Nico Huberfa622942017-03-24 17:25:37 +01001233 for (i = 0; i < nr; i++)
Nico Huberd54e4f42017-03-23 23:45:47 +01001234 desc->region.FLREGs[i] = read_descriptor_reg(cs, 2, i, spibar);
Stefan Tauner1e146392011-09-15 23:52:55 +00001235
1236 /* master section */
Nico Huberfa622942017-03-24 17:25:37 +01001237 const ssize_t nm = ich_number_of_masters(cs, &desc->content);
1238 if (nm < 0) {
1239 msg_pdbg2("%s: number of masters too high (%d) - failed\n",
1240 __func__, desc->content.NM + 1);
1241 return ICH_RET_ERR;
1242 }
1243 for (i = 0; i < nm; i++)
1244 desc->master.FLMSTRs[i] = read_descriptor_reg(cs, 3, i, spibar);
Stefan Tauner1e146392011-09-15 23:52:55 +00001245
1246 /* Accessing the strap section via FDOC/D is only possible on ICH8 and
1247 * reading the upper map is impossible on all chipsets, so don't bother.
1248 */
1249
1250 msg_pdbg2(" done.\n");
1251 return ICH_RET_OK;
1252}
Nico Huber8d494992017-06-19 12:18:33 +02001253#endif
Nico Huber305f4172013-06-14 11:55:26 +02001254
1255/**
1256 * @brief Read a layout from the dump of an Intel ICH descriptor.
1257 *
1258 * @param layout Pointer where to store the layout.
1259 * @param dump The descriptor dump to read from.
1260 * @param len The length of the descriptor dump.
1261 *
1262 * @return 0 on success,
Nico Huber70461a92019-06-15 14:56:19 +02001263 * 1 if the descriptor couldn't be parsed,
1264 * 2 when out of memory.
Nico Huber305f4172013-06-14 11:55:26 +02001265 */
Nico Huber5bd990c2019-06-16 19:46:46 +02001266int layout_from_ich_descriptors(
Nico Huberc3b02dc2023-08-12 01:13:45 +02001267 struct flashprog_layout **const layout,
Nico Huber5bd990c2019-06-16 19:46:46 +02001268 const void *const dump, const size_t len)
Nico Huber305f4172013-06-14 11:55:26 +02001269{
Nico Huberfa622942017-03-24 17:25:37 +01001270 static const char *const regions[] = {
David Hendricksa5216362017-08-08 20:02:22 -07001271 "fd", "bios", "me", "gbe", "pd", "reg5", "bios2", "reg7", "ec", "reg9", "ie",
1272 "10gbe", "reg12", "reg13", "reg14", "reg15"
Nico Huberfa622942017-03-24 17:25:37 +01001273 };
Nico Huber305f4172013-06-14 11:55:26 +02001274
1275 struct ich_descriptors desc;
Nico Huberfa622942017-03-24 17:25:37 +01001276 enum ich_chipset cs = CHIPSET_ICH_UNKNOWN;
1277 if (read_ich_descriptors_from_dump(dump, len, &cs, &desc))
Nico Huber305f4172013-06-14 11:55:26 +02001278 return 1;
1279
Nico Huberc3b02dc2023-08-12 01:13:45 +02001280 if (flashprog_layout_new(layout))
Nico Huber5bd990c2019-06-16 19:46:46 +02001281 return 2;
Nico Huber305f4172013-06-14 11:55:26 +02001282
Nico Huber92e0b622019-06-15 15:55:11 +02001283 ssize_t i;
Nico Huber519be662018-12-23 20:03:35 +01001284 const ssize_t nr = MIN(ich_number_of_regions(cs, &desc.content), (ssize_t)ARRAY_SIZE(regions));
Nico Huber92e0b622019-06-15 15:55:11 +02001285 for (i = 0; i < nr; ++i) {
Nico Huber305f4172013-06-14 11:55:26 +02001286 const chipoff_t base = ICH_FREG_BASE(desc.region.FLREGs[i]);
Nico Huber0bb3f712017-03-29 16:44:33 +02001287 const chipoff_t limit = ICH_FREG_LIMIT(desc.region.FLREGs[i]);
Nico Huber305f4172013-06-14 11:55:26 +02001288 if (limit <= base)
1289 continue;
Nico Huberc3b02dc2023-08-12 01:13:45 +02001290 if (flashprog_layout_add_region(*layout, base, limit, regions[i])) {
1291 flashprog_layout_release(*layout);
Nico Huber5bd990c2019-06-16 19:46:46 +02001292 *layout = NULL;
Nico Huber70461a92019-06-15 14:56:19 +02001293 return 2;
Nico Huber5bd990c2019-06-16 19:46:46 +02001294 }
Nico Huber305f4172013-06-14 11:55:26 +02001295 }
Nico Huber305f4172013-06-14 11:55:26 +02001296 return 0;
1297}
1298
Nico Huberad186312016-05-02 15:15:29 +02001299#endif /* ICH_DESCRIPTORS_FROM_DUMP_ONLY */