blob: 6bcbbedac36238ffe8ac250fbae24a6d8bc84503 [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:
Nico Huber0ef2eb82024-07-19 21:38:17 +020051 case CHIPSET_SNOW_RIDGE:
Nico Huber5e0d9b02024-07-19 21:44:52 +020052 case CHIPSET_METEOR_LAKE:
Nico Huberd5a61ef2024-11-06 23:55:44 +010053 case CHIPSET_LUNAR_LAKE:
David Hendricksa5216362017-08-08 20:02:22 -070054 return 16;
Nico Huberfa622942017-03-24 17:25:37 +010055 case CHIPSET_100_SERIES_SUNRISE_POINT:
56 return 10;
57 case CHIPSET_9_SERIES_WILDCAT_POINT_LP:
58 case CHIPSET_9_SERIES_WILDCAT_POINT:
59 case CHIPSET_8_SERIES_LYNX_POINT_LP:
60 case CHIPSET_8_SERIES_LYNX_POINT:
61 case CHIPSET_8_SERIES_WELLSBURG:
62 if (cont->NR <= 6)
63 return cont->NR + 1;
64 else
65 return -1;
66 default:
67 if (cont->NR <= 4)
68 return cont->NR + 1;
69 else
70 return -1;
71 }
72}
73
74ssize_t ich_number_of_masters(const enum ich_chipset cs, const struct ich_desc_content *const cont)
75{
David Hendricksa5216362017-08-08 20:02:22 -070076 switch (cs) {
77 case CHIPSET_C620_SERIES_LEWISBURG:
Nico Huber42daab12024-07-16 00:27:27 +020078 case CHIPSET_C740_SERIES_EMMITSBURG:
Nico Huber0ef2eb82024-07-19 21:38:17 +020079 case CHIPSET_SNOW_RIDGE:
Nico Huber5e0d9b02024-07-19 21:44:52 +020080 case CHIPSET_METEOR_LAKE:
Nico Huber82fe1232024-07-19 17:28:47 +020081 return 6;
Nico Huberd5a61ef2024-11-06 23:55:44 +010082 case CHIPSET_LUNAR_LAKE:
83 return 7;
Nico Huberd2d39932019-01-18 16:49:37 +010084 case CHIPSET_APOLLO_LAKE:
Angel Pons4db0fdf2020-07-10 17:04:10 +020085 case CHIPSET_GEMINI_LAKE:
Werner Zehe57d4e42022-01-03 09:44:29 +010086 case CHIPSET_ELKHART_LAKE:
Nico Huber82fe1232024-07-19 17:28:47 +020087 return 2;
David Hendricksa5216362017-08-08 20:02:22 -070088 default:
Nico Huber82fe1232024-07-19 17:28:47 +020089 if (cs >= SPI_ENGINE_PCH100)
90 return 5;
David Hendricksa5216362017-08-08 20:02:22 -070091 if (cont->NM < MAX_NUM_MASTERS)
92 return cont->NM + 1;
93 }
94
95 return -1;
Nico Huberfa622942017-03-24 17:25:37 +010096}
97
Nico Huber157b8182024-07-19 17:48:12 +020098static bool has_classic_proc_straps(const enum ich_chipset cs)
99{
100 switch (cs) {
101 case CHIPSET_100_SERIES_SUNRISE_POINT:
102 case CHIPSET_C620_SERIES_LEWISBURG:
Nico Huber42daab12024-07-16 00:27:27 +0200103 case CHIPSET_C740_SERIES_EMMITSBURG:
Nico Huber157b8182024-07-19 17:48:12 +0200104 return true;
105 default:
106 return cs < SPI_ENGINE_PCH100;
107 }
108}
109
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000110void prettyprint_ich_reg_vscc(uint32_t reg_val, int verbosity, bool print_vcl)
Stefan Tauner1e146392011-09-15 23:52:55 +0000111{
112 print(verbosity, "BES=0x%x, ", (reg_val & VSCC_BES) >> VSCC_BES_OFF);
113 print(verbosity, "WG=%d, ", (reg_val & VSCC_WG) >> VSCC_WG_OFF);
114 print(verbosity, "WSR=%d, ", (reg_val & VSCC_WSR) >> VSCC_WSR_OFF);
115 print(verbosity, "WEWS=%d, ", (reg_val & VSCC_WEWS) >> VSCC_WEWS_OFF);
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000116 print(verbosity, "EO=0x%x", (reg_val & VSCC_EO) >> VSCC_EO_OFF);
117 if (print_vcl)
118 print(verbosity, ", VCL=%d", (reg_val & VSCC_VCL) >> VSCC_VCL_OFF);
119 print(verbosity, "\n");
Stefan Tauner1e146392011-09-15 23:52:55 +0000120}
121
122#define getFCBA(cont) (((cont)->FLMAP0 << 4) & 0x00000ff0)
123#define getFRBA(cont) (((cont)->FLMAP0 >> 12) & 0x00000ff0)
124#define getFMBA(cont) (((cont)->FLMAP1 << 4) & 0x00000ff0)
125#define getFISBA(cont) (((cont)->FLMAP1 >> 12) & 0x00000ff0)
126#define getFMSBA(cont) (((cont)->FLMAP2 << 4) & 0x00000ff0)
127
Nico Huber67d71792017-06-17 03:10:15 +0200128void prettyprint_ich_chipset(enum ich_chipset cs)
129{
130 static const char *const chipset_names[] = {
131 "Unknown ICH", "ICH8", "ICH9", "ICH10",
132 "5 series Ibex Peak", "6 series Cougar Point", "7 series Panther Point",
Nico Huberdfd06472024-07-14 23:45:05 +0200133 "Baytrail", "8 series Lynx Point", "8 series Lynx Point LP", "8 series Wellsburg",
Nico Huber67d71792017-06-17 03:10:15 +0200134 "9 series Wildcat Point", "9 series Wildcat Point LP", "100 series Sunrise Point",
Angel Pons4db0fdf2020-07-10 17:04:10 +0200135 "C620 series Lewisburg", "300/400 series Cannon/Comet Point",
Nico Huber29c23dd2022-12-21 15:25:09 +0000136 "500/600 series Tiger/Alder Point", "Apollo Lake", "Gemini Lake", "Elkhart Lake",
Nico Huberd5a61ef2024-11-06 23:55:44 +0100137 "C740 series Emmitsburg", "Snow Ridge", "Meteor Lake", "Lunar Lake",
Nico Huber67d71792017-06-17 03:10:15 +0200138 };
139 if (cs < CHIPSET_ICH8 || cs - CHIPSET_ICH8 + 1 >= ARRAY_SIZE(chipset_names))
140 cs = 0;
141 else
142 cs = cs - CHIPSET_ICH8 + 1;
143 msg_pdbg2("Assuming chipset '%s'.\n", chipset_names[cs]);
144}
145
Stefan Tauner1e146392011-09-15 23:52:55 +0000146void prettyprint_ich_descriptors(enum ich_chipset cs, const struct ich_descriptors *desc)
147{
Nico Huberfa622942017-03-24 17:25:37 +0100148 prettyprint_ich_descriptor_content(cs, &desc->content);
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000149 prettyprint_ich_descriptor_component(cs, desc);
Nico Huberfa622942017-03-24 17:25:37 +0100150 prettyprint_ich_descriptor_region(cs, desc);
151 prettyprint_ich_descriptor_master(cs, desc);
Nico Huberad186312016-05-02 15:15:29 +0200152#ifdef ICH_DESCRIPTORS_FROM_DUMP_ONLY
Stefan Taunerb3850962011-12-24 00:00:32 +0000153 if (cs >= CHIPSET_ICH8) {
154 prettyprint_ich_descriptor_upper_map(&desc->upper);
155 prettyprint_ich_descriptor_straps(cs, desc);
156 }
Nico Huberad186312016-05-02 15:15:29 +0200157#endif /* ICH_DESCRIPTORS_FROM_DUMP_ONLY */
Stefan Tauner1e146392011-09-15 23:52:55 +0000158}
159
Nico Huberfa622942017-03-24 17:25:37 +0100160void prettyprint_ich_descriptor_content(enum ich_chipset cs, const struct ich_desc_content *cont)
Stefan Tauner1e146392011-09-15 23:52:55 +0000161{
162 msg_pdbg2("=== Content Section ===\n");
163 msg_pdbg2("FLVALSIG 0x%08x\n", cont->FLVALSIG);
164 msg_pdbg2("FLMAP0 0x%08x\n", cont->FLMAP0);
165 msg_pdbg2("FLMAP1 0x%08x\n", cont->FLMAP1);
166 msg_pdbg2("FLMAP2 0x%08x\n", cont->FLMAP2);
167 msg_pdbg2("\n");
168
169 msg_pdbg2("--- Details ---\n");
Nico Huberfa622942017-03-24 17:25:37 +0100170 msg_pdbg2("NR (Number of Regions): %5zd\n", ich_number_of_regions(cs, cont));
171 msg_pdbg2("FRBA (Flash Region Base Address): 0x%03x\n", getFRBA(cont));
172 msg_pdbg2("NC (Number of Components): %5d\n", cont->NC + 1);
173 msg_pdbg2("FCBA (Flash Component Base Address): 0x%03x\n", getFCBA(cont));
Nico Huberd2d39932019-01-18 16:49:37 +0100174 msg_pdbg2("ISL (ICH/PCH/SoC Strap Length): %5d\n", cont->ISL);
175 msg_pdbg2("FISBA/FPSBA (Flash ICH/PCH/SoC Strap Base Addr): 0x%03x\n", getFISBA(cont));
Nico Huberfa622942017-03-24 17:25:37 +0100176 msg_pdbg2("NM (Number of Masters): %5zd\n", ich_number_of_masters(cs, cont));
177 msg_pdbg2("FMBA (Flash Master Base Address): 0x%03x\n", getFMBA(cont));
Nico Huber157b8182024-07-19 17:48:12 +0200178 if (has_classic_proc_straps(cs)) {
179 msg_pdbg2("MSL/PSL (MCH/PROC Strap Length): %5d\n", cont->MSL);
180 msg_pdbg2("FMSBA (Flash MCH/PROC Strap Base Address): 0x%03x\n", getFMSBA(cont));
181 }
Stefan Tauner1e146392011-09-15 23:52:55 +0000182 msg_pdbg2("\n");
183}
184
Nico Huberdfd06472024-07-14 23:45:05 +0200185static unsigned int get_density_index(
186 enum ich_chipset cs, const struct ich_descriptors *desc, unsigned int component)
187{
188 if (cs < CHIPSET_HAS_NEW_COMPONENT_DENSITY) {
189 if (component == 0)
190 return desc->component.dens_old.comp1_density;
191 else
192 return desc->component.dens_old.comp2_density;
193 } else {
194 if (component == 0)
195 return desc->component.dens_new.comp1_density;
196 else
197 return desc->component.dens_new.comp2_density;
198 }
199}
200
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000201static const char *pprint_density(enum ich_chipset cs, const struct ich_descriptors *desc, uint8_t idx)
202{
203 if (idx > 1) {
204 msg_perr("Only ICH SPI component index 0 or 1 are supported yet.\n");
Nico Huberdfd06472024-07-14 23:45:05 +0200205 return "unknown";
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000206 }
Nico Huberdfd06472024-07-14 23:45:05 +0200207 if (cs == CHIPSET_ICH_UNKNOWN)
208 return "unknown";
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000209
210 if (desc->content.NC == 0 && idx > 0)
211 return "unused";
212
213 static const char * const size_str[] = {
214 "512 kB", /* 0000 */
215 "1 MB", /* 0001 */
216 "2 MB", /* 0010 */
217 "4 MB", /* 0011 */
218 "8 MB", /* 0100 */
219 "16 MB", /* 0101 */ /* Maximum up to Lynx Point (excl.) */
220 "32 MB", /* 0110 */
221 "64 MB", /* 0111 */
222 };
Nico Huberdfd06472024-07-14 23:45:05 +0200223 const unsigned int max_idx = cs < CHIPSET_HAS_NEW_COMPONENT_DENSITY ? 5 : 7;
224 const unsigned int size_idx = get_density_index(cs, desc, idx);
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000225
Nico Huberdfd06472024-07-14 23:45:05 +0200226 if (size_idx > max_idx)
227 return "reserved";
228
229 return size_str[size_idx];
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000230}
231
232static const char *pprint_freq(enum ich_chipset cs, uint8_t value)
Stefan Tauner1e146392011-09-15 23:52:55 +0000233{
Nico Huber0ef2eb82024-07-19 21:38:17 +0200234 static const char *const freq_str[][8] = { {
Nico Huber129e9382019-06-06 15:43:27 +0200235 "20 MHz",
236 "33 MHz",
237 "reserved",
238 "reserved",
239 "50 MHz", /* New since Ibex Peak */
240 "reserved",
241 "reserved",
242 "reserved"
Nico Huberfa622942017-03-24 17:25:37 +0100243 }, {
Nico Huber129e9382019-06-06 15:43:27 +0200244 "reserved",
245 "reserved",
246 "48 MHz",
247 "reserved",
248 "30 MHz",
249 "reserved",
250 "17 MHz",
251 "reserved"
Nico Huberd2d39932019-01-18 16:49:37 +0100252 }, {
253 "reserved",
254 "50 MHz",
255 "40 MHz",
256 "reserved",
257 "25 MHz",
258 "reserved",
259 "14 MHz / 17 MHz",
260 "reserved"
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200261 }, {
262 "100 MHz",
263 "50 MHz",
264 "reserved",
265 "33 MHz",
266 "25 MHz",
267 "reserved",
268 "14 MHz",
269 "reserved"
Werner Zehe57d4e42022-01-03 09:44:29 +0100270 }, {
271 "reserved",
272 "50 MHz",
273 "reserved",
274 "reserved",
275 "33 MHz",
276 "20 MHz",
277 "reserved",
278 "reserved",
Nico Huber0ef2eb82024-07-19 21:38:17 +0200279 }, {
280 "reserved",
281 "48 MHz",
282 "32 MHz",
283 "reserved",
284 "24 MHz",
285 "19.2 MHz",
286 "13.7 MHz",
287 "reserved",
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200288 }};
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000289
290 switch (cs) {
291 case CHIPSET_ICH8:
292 case CHIPSET_ICH9:
293 case CHIPSET_ICH10:
294 if (value > 1)
295 return "reserved";
Richard Hughesdb7482b2018-12-19 12:04:30 +0000296 /* Fall through. */
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000297 case CHIPSET_5_SERIES_IBEX_PEAK:
298 case CHIPSET_6_SERIES_COUGAR_POINT:
299 case CHIPSET_7_SERIES_PANTHER_POINT:
300 case CHIPSET_8_SERIES_LYNX_POINT:
Duncan Laurie4095ed72014-08-20 15:39:32 +0000301 case CHIPSET_BAYTRAIL:
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000302 case CHIPSET_8_SERIES_LYNX_POINT_LP:
303 case CHIPSET_8_SERIES_WELLSBURG:
Duncan Laurie823096e2014-08-20 15:39:38 +0000304 case CHIPSET_9_SERIES_WILDCAT_POINT:
Nico Huber51205912017-03-17 17:59:54 +0100305 case CHIPSET_9_SERIES_WILDCAT_POINT_LP:
Nico Huberfa622942017-03-24 17:25:37 +0100306 return freq_str[0][value];
307 case CHIPSET_100_SERIES_SUNRISE_POINT:
David Hendricksa5216362017-08-08 20:02:22 -0700308 case CHIPSET_C620_SERIES_LEWISBURG:
Nico Huber2a5dfaf2019-07-04 16:01:51 +0200309 case CHIPSET_300_SERIES_CANNON_POINT:
Nico Huberfa622942017-03-24 17:25:37 +0100310 return freq_str[1][value];
Nico Huberd2d39932019-01-18 16:49:37 +0100311 case CHIPSET_APOLLO_LAKE:
Angel Pons4db0fdf2020-07-10 17:04:10 +0200312 case CHIPSET_GEMINI_LAKE:
Nico Huberd2d39932019-01-18 16:49:37 +0100313 return freq_str[2][value];
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200314 case CHIPSET_500_SERIES_TIGER_POINT:
Nico Huber42daab12024-07-16 00:27:27 +0200315 case CHIPSET_C740_SERIES_EMMITSBURG:
Nico Huber5e0d9b02024-07-19 21:44:52 +0200316 case CHIPSET_METEOR_LAKE:
Nico Huberd5a61ef2024-11-06 23:55:44 +0100317 case CHIPSET_LUNAR_LAKE:
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200318 return freq_str[3][value];
Werner Zehe57d4e42022-01-03 09:44:29 +0100319 case CHIPSET_ELKHART_LAKE:
320 return freq_str[4][value];
Nico Huber0ef2eb82024-07-19 21:38:17 +0200321 case CHIPSET_SNOW_RIDGE:
322 return freq_str[5][value];
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000323 case CHIPSET_ICH_UNKNOWN:
324 default:
325 return "unknown";
326 }
327}
328
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200329static void pprint_read_freq(enum ich_chipset cs, uint8_t value)
330{
Nico Huber0ef2eb82024-07-19 21:38:17 +0200331 static const char *const freq_str[][8] = { {
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200332 "20 MHz",
333 "24 MHz",
334 "30 MHz",
335 "48 MHz",
336 "60 MHz",
337 "reserved",
338 "reserved",
339 "reserved"
Nico Huber0ef2eb82024-07-19 21:38:17 +0200340 }, {
341 "16 MHz",
342 "19.2 MHz",
343 "24 MHz",
344 "32 MHz",
345 "48 MHz",
346 "reserved",
347 "reserved",
348 "reserved"
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200349 }};
350
351 switch (cs) {
352 case CHIPSET_300_SERIES_CANNON_POINT:
353 msg_pdbg2("eSPI/EC Bus Clock Frequency: %s\n", freq_str[0][value]);
354 return;
Nico Huber0ef2eb82024-07-19 21:38:17 +0200355 case CHIPSET_SNOW_RIDGE:
356 msg_pdbg2("eSPI/EC Bus Clock Frequency: %s\n", freq_str[1][value]);
357 return;
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200358 case CHIPSET_500_SERIES_TIGER_POINT:
Nico Huber5e0d9b02024-07-19 21:44:52 +0200359 case CHIPSET_METEOR_LAKE:
Nico Huberd5a61ef2024-11-06 23:55:44 +0100360 case CHIPSET_LUNAR_LAKE:
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200361 msg_pdbg2("Read Clock Frequency: %s\n", "reserved");
362 return;
363 default:
364 msg_pdbg2("Read Clock Frequency: %s\n", pprint_freq(cs, value));
365 return;
366 }
367}
368
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000369void prettyprint_ich_descriptor_component(enum ich_chipset cs, const struct ich_descriptors *desc)
370{
Nico Huberb2ad9fd2024-07-14 23:18:53 +0200371 const bool has_flill1 = cs >= SPI_ENGINE_PCH100;
Stefan Tauner1e146392011-09-15 23:52:55 +0000372
373 msg_pdbg2("=== Component Section ===\n");
374 msg_pdbg2("FLCOMP 0x%08x\n", desc->component.FLCOMP);
375 msg_pdbg2("FLILL 0x%08x\n", desc->component.FLILL );
Nico Huberd2d39932019-01-18 16:49:37 +0100376 if (has_flill1)
Nico Huberfa622942017-03-24 17:25:37 +0100377 msg_pdbg2("FLILL1 0x%08x\n", desc->component.FLILL1);
Stefan Tauner1e146392011-09-15 23:52:55 +0000378 msg_pdbg2("\n");
379
380 msg_pdbg2("--- Details ---\n");
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000381 msg_pdbg2("Component 1 density: %s\n", pprint_density(cs, desc, 0));
Stefan Tauner1e146392011-09-15 23:52:55 +0000382 if (desc->content.NC)
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000383 msg_pdbg2("Component 2 density: %s\n", pprint_density(cs, desc, 1));
Stefan Tauner1e146392011-09-15 23:52:55 +0000384 else
385 msg_pdbg2("Component 2 is not used.\n");
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200386
387 pprint_read_freq(cs, desc->component.modes.freq_read);
388
Tai-Hong Wu60dead42015-01-05 23:00:14 +0000389 msg_pdbg2("Read ID and Status Clock Freq.: %s\n", pprint_freq(cs, desc->component.modes.freq_read_id));
390 msg_pdbg2("Write and Erase Clock Freq.: %s\n", pprint_freq(cs, desc->component.modes.freq_write));
391 msg_pdbg2("Fast Read is %ssupported.\n", desc->component.modes.fastread ? "" : "not ");
392 if (desc->component.modes.fastread)
Stefan Tauner1e146392011-09-15 23:52:55 +0000393 msg_pdbg2("Fast Read Clock Frequency: %s\n",
Tai-Hong Wu60dead42015-01-05 23:00:14 +0000394 pprint_freq(cs, desc->component.modes.freq_fastread));
Nico Huber3f75d442024-07-14 19:17:56 +0200395 switch (cs) {
396 case CHIPSET_7_SERIES_PANTHER_POINT:
397 case CHIPSET_8_SERIES_LYNX_POINT:
398 case CHIPSET_BAYTRAIL:
399 case CHIPSET_8_SERIES_LYNX_POINT_LP:
400 case CHIPSET_8_SERIES_WELLSBURG:
401 case CHIPSET_9_SERIES_WILDCAT_POINT:
402 case CHIPSET_9_SERIES_WILDCAT_POINT_LP:
403 case CHIPSET_100_SERIES_SUNRISE_POINT:
404 case CHIPSET_APOLLO_LAKE:
405 case CHIPSET_C620_SERIES_LEWISBURG:
Nico Huber0ef2eb82024-07-19 21:38:17 +0200406 case CHIPSET_SNOW_RIDGE:
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000407 msg_pdbg2("Dual Output Fast Read Support: %sabled\n",
Werner Zehd3e8fd92022-01-25 07:02:49 +0100408 desc->component.modes.dual_output ? "en" : "dis");
Nico Huber3f75d442024-07-14 19:17:56 +0200409 break;
410 default:
411 break;
412 }
David Hendricksa5216362017-08-08 20:02:22 -0700413
Felix Singerd68a0ec2022-08-19 03:23:35 +0200414 bool has_forbidden_opcode = false;
David Hendricksa5216362017-08-08 20:02:22 -0700415 if (desc->component.FLILL != 0) {
Felix Singerd68a0ec2022-08-19 03:23:35 +0200416 has_forbidden_opcode = true;
Stefan Tauner1e146392011-09-15 23:52:55 +0000417 msg_pdbg2("Invalid instruction 0: 0x%02x\n",
418 desc->component.invalid_instr0);
419 msg_pdbg2("Invalid instruction 1: 0x%02x\n",
420 desc->component.invalid_instr1);
421 msg_pdbg2("Invalid instruction 2: 0x%02x\n",
422 desc->component.invalid_instr2);
423 msg_pdbg2("Invalid instruction 3: 0x%02x\n",
424 desc->component.invalid_instr3);
David Hendricksa5216362017-08-08 20:02:22 -0700425 }
Nico Huberd2d39932019-01-18 16:49:37 +0100426 if (has_flill1) {
David Hendricksa5216362017-08-08 20:02:22 -0700427 if (desc->component.FLILL1 != 0) {
Felix Singerd68a0ec2022-08-19 03:23:35 +0200428 has_forbidden_opcode = true;
Nico Huberfa622942017-03-24 17:25:37 +0100429 msg_pdbg2("Invalid instruction 4: 0x%02x\n",
430 desc->component.invalid_instr4);
431 msg_pdbg2("Invalid instruction 5: 0x%02x\n",
432 desc->component.invalid_instr5);
433 msg_pdbg2("Invalid instruction 6: 0x%02x\n",
434 desc->component.invalid_instr6);
435 msg_pdbg2("Invalid instruction 7: 0x%02x\n",
436 desc->component.invalid_instr7);
437 }
Stefan Tauner1e146392011-09-15 23:52:55 +0000438 }
David Hendricksa5216362017-08-08 20:02:22 -0700439 if (!has_forbidden_opcode)
440 msg_pdbg2("No forbidden opcodes.\n");
441
Stefan Tauner1e146392011-09-15 23:52:55 +0000442 msg_pdbg2("\n");
443}
444
445static void pprint_freg(const struct ich_desc_region *reg, uint32_t i)
446{
Nico Huberfa622942017-03-24 17:25:37 +0100447 static const char *const region_names[] = {
Nico Huberd2d39932019-01-18 16:49:37 +0100448 "Descr.", "BIOS", "ME", "GbE", "Platf.", "DevExp", "BIOS2", "unknown",
Nico Huber5e0d9b02024-07-19 21:44:52 +0200449 "EC/BMC", "unknown", "SSE/IE", "10GbE/NIS", "OpROM", "iRC", "unknown", "PTT"
Stefan Tauner1e146392011-09-15 23:52:55 +0000450 };
Nico Huberfa622942017-03-24 17:25:37 +0100451 if (i >= ARRAY_SIZE(region_names)) {
Stefan Tauner1e146392011-09-15 23:52:55 +0000452 msg_pdbg2("%s: region index too high.\n", __func__);
453 return;
454 }
455 uint32_t base = ICH_FREG_BASE(reg->FLREGs[i]);
456 uint32_t limit = ICH_FREG_LIMIT(reg->FLREGs[i]);
Nico Huber0ef2eb82024-07-19 21:38:17 +0200457 msg_pdbg2("Region %d (%-9s) ", i, region_names[i]);
Stefan Tauner1e146392011-09-15 23:52:55 +0000458 if (base > limit)
459 msg_pdbg2("is unused.\n");
460 else
Nico Huber0bb3f712017-03-29 16:44:33 +0200461 msg_pdbg2("0x%08x - 0x%08x\n", base, limit);
Stefan Tauner1e146392011-09-15 23:52:55 +0000462}
463
Nico Huberfa622942017-03-24 17:25:37 +0100464void prettyprint_ich_descriptor_region(const enum ich_chipset cs, const struct ich_descriptors *const desc)
Stefan Tauner1e146392011-09-15 23:52:55 +0000465{
Nico Huber519be662018-12-23 20:03:35 +0100466 ssize_t i;
Nico Huberfa622942017-03-24 17:25:37 +0100467 const ssize_t nr = ich_number_of_regions(cs, &desc->content);
Stefan Tauner1e146392011-09-15 23:52:55 +0000468 msg_pdbg2("=== Region Section ===\n");
Nico Huberfa622942017-03-24 17:25:37 +0100469 if (nr < 0) {
Stefan Tauner1e146392011-09-15 23:52:55 +0000470 msg_pdbg2("%s: number of regions too high (%d).\n", __func__,
Nico Huberfa622942017-03-24 17:25:37 +0100471 desc->content.NR + 1);
Stefan Tauner1e146392011-09-15 23:52:55 +0000472 return;
473 }
Nico Huberfa622942017-03-24 17:25:37 +0100474 for (i = 0; i < nr; i++)
Nico Huber519be662018-12-23 20:03:35 +0100475 msg_pdbg2("FLREG%zd 0x%08x\n", i, desc->region.FLREGs[i]);
Stefan Tauner1e146392011-09-15 23:52:55 +0000476 msg_pdbg2("\n");
477
478 msg_pdbg2("--- Details ---\n");
Nico Huberfa622942017-03-24 17:25:37 +0100479 for (i = 0; i < nr; i++)
Nico Huber519be662018-12-23 20:03:35 +0100480 pprint_freg(&desc->region, (uint32_t)i);
Stefan Tauner1e146392011-09-15 23:52:55 +0000481 msg_pdbg2("\n");
482}
483
Nico Huberb3cc2c62024-07-15 00:45:17 +0200484static char prettify_flag(const unsigned int mask, const unsigned int bit, const char flag)
485{
486 return mask & (1 << bit) ? flag : ' ';
487}
488
489/* Takes NULL-terminated lists of names, assumes max. 5 chars per name. */
490static void prettyprint_pch100_masters(
491 const struct ich_descriptors *const desc,
492 const unsigned int number_masters, const char *const masters[],
493 const unsigned int number_regions, const char *const regions[])
494{
495 unsigned int m, r;
496
497 msg_pdbg2(" ");
498 for (r = 0; r < number_regions && regions[r] != NULL; ++r)
499 msg_pdbg2(" %-5s", regions[r]);
500 msg_pdbg2("\n");
501
502 for (m = 0; m < number_masters; ++m) {
503 const unsigned int ext_start = 12;
504
505 if (masters[m] == NULL)
506 break;
507
508 const struct ich_desc_master_region_access master = desc->master.mstr[m];
509
510 msg_pdbg2("%-5s", masters[m]);
511 for (r = 0; r < ext_start && r < number_regions && regions[r] != NULL; ++r)
512 msg_pdbg2(" %c%c ",
513 prettify_flag(master.read, r, 'r'),
514 prettify_flag(master.write, r, 'w'));
515 for (; r < number_regions && regions[r] != NULL; ++r)
516 msg_pdbg2(" %c%c ",
517 prettify_flag(master.ext_read, r - ext_start, 'r'),
518 prettify_flag(master.ext_write, r - ext_start, 'w'));
519 msg_pdbg2("\n");
520 }
521}
522
Nico Huberfa622942017-03-24 17:25:37 +0100523void prettyprint_ich_descriptor_master(const enum ich_chipset cs, const struct ich_descriptors *const desc)
Stefan Tauner1e146392011-09-15 23:52:55 +0000524{
Nico Huber519be662018-12-23 20:03:35 +0100525 ssize_t i;
Nico Huberfa622942017-03-24 17:25:37 +0100526 const ssize_t nm = ich_number_of_masters(cs, &desc->content);
Stefan Tauner1e146392011-09-15 23:52:55 +0000527 msg_pdbg2("=== Master Section ===\n");
Nico Huberfa622942017-03-24 17:25:37 +0100528 if (nm < 0) {
529 msg_pdbg2("%s: number of masters too high (%d).\n", __func__,
530 desc->content.NM + 1);
531 return;
532 }
533 for (i = 0; i < nm; i++)
Nico Huber519be662018-12-23 20:03:35 +0100534 msg_pdbg2("FLMSTR%zd 0x%08x\n", i + 1, desc->master.FLMSTRs[i]);
Stefan Tauner1e146392011-09-15 23:52:55 +0000535 msg_pdbg2("\n");
536
537 msg_pdbg2("--- Details ---\n");
Nico Huberb3cc2c62024-07-15 00:45:17 +0200538 if (cs >= SPI_ENGINE_PCH100) {
539 const ssize_t nr = ich_number_of_regions(cs, &desc->content);
540 if (nr < 0)
Nico Huberfa622942017-03-24 17:25:37 +0100541 return;
Nico Huberfa622942017-03-24 17:25:37 +0100542
Nico Huberb3cc2c62024-07-15 00:45:17 +0200543 if (cs == CHIPSET_APOLLO_LAKE ||
544 cs == CHIPSET_GEMINI_LAKE ||
545 cs == CHIPSET_ELKHART_LAKE) {
546 const char *const masters[] = {
547 "BIOS", "TXE", NULL
548 };
549 const char *const regions[] = {
550 " FD", "IFWI", " TXE", " n/a", "Pltf.", "DevExp", NULL
551 };
552 prettyprint_pch100_masters(desc, nm, masters, nr, regions);
Nico Huber42daab12024-07-16 00:27:27 +0200553 } else if (cs == CHIPSET_C620_SERIES_LEWISBURG ||
554 cs == CHIPSET_C740_SERIES_EMMITSBURG) {
Nico Huberb3cc2c62024-07-15 00:45:17 +0200555 const char *const masters[] = {
556 "BIOS", "ME", "GbE", "DE", "BMC", "IE", NULL
557 };
558 const char *const regions[] = {
559 " FD ", " BIOS", " ME ", " GbE ", "Pltf.",
David Hendricksa5216362017-08-08 20:02:22 -0700560 " DE ", "BIOS2", " Reg7", " BMC ", " DE2 ",
561 " IE ", "10GbE", "OpROM", "Reg13", "Reg14",
Nico Huberb3cc2c62024-07-15 00:45:17 +0200562 "Reg15", NULL
563 };
564 prettyprint_pch100_masters(desc, nm, masters, nr, regions);
Nico Huberd5a61ef2024-11-06 23:55:44 +0100565 } else if (cs == CHIPSET_LUNAR_LAKE) {
566 const char *const masters[] = {
567 "BIOS", "CSME", "GbE", "rsvd.", "EC", "PSE", "SSE", NULL
568 };
569 const char *const regions[] = {
570 " FD ", "BIOS ", "CSME ", " GbE ", "Pltf.",
571 "Reg5 ", "Reg6 ", "Reg7 ", " EC ", "Reg9 ",
572 " PSE ", "Reg11", "Reg12", "Reg13", "Reg14",
573 "Reg15", NULL
574 };
575 prettyprint_pch100_masters(desc, nm, masters, nr, regions);
Nico Huberb3cc2c62024-07-15 00:45:17 +0200576 } else {
577 const char *const masters[] = {
Nico Huber5e0d9b02024-07-19 21:44:52 +0200578 "BIOS", "ME", "GbE", "NAC", "EC", "SSE", NULL
Nico Huberb3cc2c62024-07-15 00:45:17 +0200579 };
580 const char *const regions[] = {
581 " FD ", "BIOS ", " ME ", " GbE ", "Pltf.",
Nico Huber0ef2eb82024-07-19 21:38:17 +0200582 "Reg5 ", "BIOS2", "Reg7 ", " EC ", "Reg9 ",
Nico Huber5e0d9b02024-07-19 21:44:52 +0200583 " SSE ", " NIS ", "Reg12", " iRC ", "Reg14",
Nico Huber0ef2eb82024-07-19 21:38:17 +0200584 " PTT ", NULL
Nico Huberb3cc2c62024-07-15 00:45:17 +0200585 };
586 prettyprint_pch100_masters(desc, nm, masters, nr, regions);
Nico Huberd2d39932019-01-18 16:49:37 +0100587 }
Nico Huberfa622942017-03-24 17:25:37 +0100588 } else {
589 const struct ich_desc_master *const mstr = &desc->master;
590 msg_pdbg2(" Descr. BIOS ME GbE Platf.\n");
591 msg_pdbg2("BIOS %c%c %c%c %c%c %c%c %c%c\n",
592 (mstr->BIOS_descr_r) ?'r':' ', (mstr->BIOS_descr_w) ?'w':' ',
593 (mstr->BIOS_BIOS_r) ?'r':' ', (mstr->BIOS_BIOS_w) ?'w':' ',
594 (mstr->BIOS_ME_r) ?'r':' ', (mstr->BIOS_ME_w) ?'w':' ',
595 (mstr->BIOS_GbE_r) ?'r':' ', (mstr->BIOS_GbE_w) ?'w':' ',
596 (mstr->BIOS_plat_r) ?'r':' ', (mstr->BIOS_plat_w) ?'w':' ');
597 msg_pdbg2("ME %c%c %c%c %c%c %c%c %c%c\n",
598 (mstr->ME_descr_r) ?'r':' ', (mstr->ME_descr_w) ?'w':' ',
599 (mstr->ME_BIOS_r) ?'r':' ', (mstr->ME_BIOS_w) ?'w':' ',
600 (mstr->ME_ME_r) ?'r':' ', (mstr->ME_ME_w) ?'w':' ',
601 (mstr->ME_GbE_r) ?'r':' ', (mstr->ME_GbE_w) ?'w':' ',
602 (mstr->ME_plat_r) ?'r':' ', (mstr->ME_plat_w) ?'w':' ');
603 msg_pdbg2("GbE %c%c %c%c %c%c %c%c %c%c\n",
604 (mstr->GbE_descr_r) ?'r':' ', (mstr->GbE_descr_w) ?'w':' ',
605 (mstr->GbE_BIOS_r) ?'r':' ', (mstr->GbE_BIOS_w) ?'w':' ',
606 (mstr->GbE_ME_r) ?'r':' ', (mstr->GbE_ME_w) ?'w':' ',
607 (mstr->GbE_GbE_r) ?'r':' ', (mstr->GbE_GbE_w) ?'w':' ',
608 (mstr->GbE_plat_r) ?'r':' ', (mstr->GbE_plat_w) ?'w':' ');
609 }
Stefan Tauner1e146392011-09-15 23:52:55 +0000610 msg_pdbg2("\n");
611}
612
Jacob Garberbeeb8bc2019-06-21 15:24:17 -0600613static void prettyprint_ich_descriptor_straps_ich8(const struct ich_descriptors *desc)
Stefan Taunerb3850962011-12-24 00:00:32 +0000614{
615 static const char * const str_GPIO12[4] = {
616 "GPIO12",
617 "LAN PHY Power Control Function (Native Output)",
618 "GLAN_DOCK# (Native Input)",
619 "invalid configuration",
620 };
621
622 msg_pdbg2("--- MCH details ---\n");
623 msg_pdbg2("ME B is %sabled.\n", desc->north.ich8.MDB ? "dis" : "en");
624 msg_pdbg2("\n");
625
626 msg_pdbg2("--- ICH details ---\n");
627 msg_pdbg2("ME SMBus Address 1: 0x%02x\n", desc->south.ich8.ASD);
628 msg_pdbg2("ME SMBus Address 2: 0x%02x\n", desc->south.ich8.ASD2);
629 msg_pdbg2("ME SMBus Controller is connected to the %s.\n",
630 desc->south.ich8.MESM2SEL ? "SMLink pins" : "SMBus pins");
631 msg_pdbg2("SPI CS1 is used for %s.\n",
632 desc->south.ich8.SPICS1_LANPHYPC_SEL ?
633 "LAN PHY Power Control Function" :
634 "SPI Chip Select");
635 msg_pdbg2("GPIO12 is used as %s.\n",
636 str_GPIO12[desc->south.ich8.GPIO12_SEL]);
637 msg_pdbg2("PCIe Port 6 is used for %s.\n",
638 desc->south.ich8.GLAN_PCIE_SEL ? "integrated LAN" : "PCI Express");
639 msg_pdbg2("%sn BMC Mode: "
640 "Intel AMT SMBus Controller 1 is connected to %s.\n",
641 desc->south.ich8.BMCMODE ? "I" : "Not i",
642 desc->south.ich8.BMCMODE ? "SMLink" : "SMBus");
643 msg_pdbg2("TCO is in %s Mode.\n",
644 desc->south.ich8.TCOMODE ? "Advanced TCO" : "Legacy/Compatible");
645 msg_pdbg2("ME A is %sabled.\n",
646 desc->south.ich8.ME_DISABLE ? "dis" : "en");
647 msg_pdbg2("\n");
648}
649
650static void prettyprint_ich_descriptor_straps_56_pciecs(uint8_t conf, uint8_t off)
651{
652 msg_pdbg2("PCI Express Port Configuration Strap %d: ", off+1);
653
654 off *= 4;
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000655 switch (conf){
Stefan Taunerb3850962011-12-24 00:00:32 +0000656 case 0:
657 msg_pdbg2("4x1 Ports %d-%d (x1)", 1+off, 4+off);
658 break;
659 case 1:
660 msg_pdbg2("1x2, 2x1 Port %d (x2), Port %d (disabled), "
661 "Ports %d, %d (x1)", 1+off, 2+off, 3+off, 4+off);
662 break;
663 case 2:
664 msg_pdbg2("2x2 Port %d (x2), Port %d (x2), Ports "
665 "%d, %d (disabled)", 1+off, 3+off, 2+off, 4+off);
666 break;
667 case 3:
668 msg_pdbg2("1x4 Port %d (x4), Ports %d-%d (disabled)",
669 1+off, 2+off, 4+off);
670 break;
671 }
672 msg_pdbg2("\n");
673}
674
Jacob Garberbeeb8bc2019-06-21 15:24:17 -0600675static void prettyprint_ich_descriptor_pchstraps45678_56(const struct ich_desc_south_strap *s)
Stefan Taunerb3850962011-12-24 00:00:32 +0000676{
677 /* PCHSTRP4 */
678 msg_pdbg2("Intel PHY is %s.\n",
679 (s->ibex.PHYCON == 2) ? "connected" :
680 (s->ibex.PHYCON == 0) ? "disconnected" : "reserved");
681 msg_pdbg2("GbE MAC SMBus address is %sabled.\n",
682 s->ibex.GBEMAC_SMBUS_ADDR_EN ? "en" : "dis");
683 msg_pdbg2("GbE MAC SMBus address: 0x%02x\n",
684 s->ibex.GBEMAC_SMBUS_ADDR);
685 msg_pdbg2("GbE PHY SMBus address: 0x%02x\n",
686 s->ibex.GBEPHY_SMBUS_ADDR);
687
688 /* PCHSTRP5 */
689 /* PCHSTRP6 */
690 /* PCHSTRP7 */
691 msg_pdbg2("Intel ME SMBus Subsystem Vendor ID: 0x%04x\n",
692 s->ibex.MESMA2UDID_VENDOR);
693 msg_pdbg2("Intel ME SMBus Subsystem Device ID: 0x%04x\n",
694 s->ibex.MESMA2UDID_VENDOR);
695
696 /* PCHSTRP8 */
697}
698
Jacob Garberbeeb8bc2019-06-21 15:24:17 -0600699static void prettyprint_ich_descriptor_pchstraps111213_56(const struct ich_desc_south_strap *s)
Stefan Taunerb3850962011-12-24 00:00:32 +0000700{
701 /* PCHSTRP11 */
702 msg_pdbg2("SMLink1 GP Address is %sabled.\n",
703 s->ibex.SML1GPAEN ? "en" : "dis");
704 msg_pdbg2("SMLink1 controller General Purpose Target address: 0x%02x\n",
705 s->ibex.SML1GPA);
706 msg_pdbg2("SMLink1 I2C Target address is %sabled.\n",
707 s->ibex.SML1I2CAEN ? "en" : "dis");
708 msg_pdbg2("SMLink1 I2C Target address: 0x%02x\n",
709 s->ibex.SML1I2CA);
710
711 /* PCHSTRP12 */
712 /* PCHSTRP13 */
713}
714
Jacob Garberbeeb8bc2019-06-21 15:24:17 -0600715static void prettyprint_ich_descriptor_straps_ibex(const struct ich_desc_south_strap *s)
Stefan Taunerb3850962011-12-24 00:00:32 +0000716{
Stefan Tauner67d163d2013-01-15 17:37:48 +0000717 static const uint8_t dec_t209min[4] = {
Stefan Taunerb3850962011-12-24 00:00:32 +0000718 100,
719 50,
720 5,
721 1
722 };
723
724 msg_pdbg2("--- PCH ---\n");
725
726 /* PCHSTRP0 */
727 msg_pdbg2("Chipset configuration Softstrap 2: %d\n", s->ibex.cs_ss2);
728 msg_pdbg2("Intel ME SMBus Select is %sabled.\n",
729 s->ibex.SMB_EN ? "en" : "dis");
730 msg_pdbg2("SMLink0 segment is %sabled.\n",
731 s->ibex.SML0_EN ? "en" : "dis");
732 msg_pdbg2("SMLink1 segment is %sabled.\n",
733 s->ibex.SML1_EN ? "en" : "dis");
734 msg_pdbg2("SMLink1 Frequency: %s\n",
735 (s->ibex.SML1FRQ == 1) ? "100 kHz" : "reserved");
736 msg_pdbg2("Intel ME SMBus Frequency: %s\n",
737 (s->ibex.SMB0FRQ == 1) ? "100 kHz" : "reserved");
738 msg_pdbg2("SMLink0 Frequency: %s\n",
739 (s->ibex.SML0FRQ == 1) ? "100 kHz" : "reserved");
740 msg_pdbg2("GPIO12 is used as %s.\n", s->ibex.LANPHYPC_GP12_SEL ?
741 "LAN_PHY_PWR_CTRL" : "general purpose output");
742 msg_pdbg2("Chipset configuration Softstrap 1: %d\n", s->ibex.cs_ss1);
743 msg_pdbg2("DMI RequesterID Checks are %sabled.\n",
744 s->ibex.DMI_REQID_DIS ? "en" : "dis");
745 msg_pdbg2("BIOS Boot-Block size (BBBS): %d kB.\n",
746 1 << (6 + s->ibex.BBBS));
747
748 /* PCHSTRP1 */
749 msg_pdbg2("Chipset configuration Softstrap 3: 0x%x\n", s->ibex.cs_ss3);
750
751 /* PCHSTRP2 */
752 msg_pdbg2("ME SMBus ASD address is %sabled.\n",
753 s->ibex.MESMASDEN ? "en" : "dis");
754 msg_pdbg2("ME SMBus Controller ASD Target address: 0x%02x\n",
755 s->ibex.MESMASDA);
756 msg_pdbg2("ME SMBus I2C address is %sabled.\n",
757 s->ibex.MESMI2CEN ? "en" : "dis");
758 msg_pdbg2("ME SMBus I2C target address: 0x%02x\n",
759 s->ibex.MESMI2CA);
760
761 /* PCHSTRP3 */
762 prettyprint_ich_descriptor_pchstraps45678_56(s);
763 /* PCHSTRP9 */
764 prettyprint_ich_descriptor_straps_56_pciecs(s->ibex.PCIEPCS1, 0);
765 prettyprint_ich_descriptor_straps_56_pciecs(s->ibex.PCIEPCS1, 1);
766 msg_pdbg2("PCIe Lane Reversal 1: PCIe Lanes 0-3 are %sreserved.\n",
767 s->ibex.PCIELR1 ? "" : "not ");
768 msg_pdbg2("PCIe Lane Reversal 2: PCIe Lanes 4-7 are %sreserved.\n",
769 s->ibex.PCIELR2 ? "" : "not ");
770 msg_pdbg2("DMI Lane Reversal: DMI Lanes 0-3 are %sreserved.\n",
771 s->ibex.DMILR ? "" : "not ");
772 msg_pdbg2("Default PHY PCIe Port is %d.\n", s->ibex.PHY_PCIEPORTSEL+1);
773 msg_pdbg2("Integrated MAC/PHY communication over PCIe is %sabled.\n",
774 s->ibex.PHY_PCIE_EN ? "en" : "dis");
775
776 /* PCHSTRP10 */
777 msg_pdbg2("Management Engine will boot from %sflash.\n",
778 s->ibex.ME_BOOT_FLASH ? "" : "ROM, then ");
779 msg_pdbg2("Chipset configuration Softstrap 5: %d\n", s->ibex.cs_ss5);
780 msg_pdbg2("Virtualization Engine Enable 1 is %sabled.\n",
781 s->ibex.VE_EN ? "en" : "dis");
782 msg_pdbg2("ME Memory-attached Debug Display Device is %sabled.\n",
783 s->ibex.MMDDE ? "en" : "dis");
784 msg_pdbg2("ME Memory-attached Debug Display Device address: 0x%02x\n",
785 s->ibex.MMADDR);
786 msg_pdbg2("Chipset configuration Softstrap 7: %d\n", s->ibex.cs_ss7);
787 msg_pdbg2("Integrated Clocking Configuration is %d.\n",
788 (s->ibex.ICC_SEL == 7) ? 0 : s->ibex.ICC_SEL);
789 msg_pdbg2("PCH Signal CL_RST1# does %sassert when Intel ME performs a "
790 "reset.\n", s->ibex.MER_CL1 ? "" : "not ");
791
792 prettyprint_ich_descriptor_pchstraps111213_56(s);
793
794 /* PCHSTRP14 */
795 msg_pdbg2("Virtualization Engine Enable 2 is %sabled.\n",
796 s->ibex.VE_EN2 ? "en" : "dis");
797 msg_pdbg2("Virtualization Engine will boot from %sflash.\n",
798 s->ibex.VE_BOOT_FLASH ? "" : "ROM, then ");
799 msg_pdbg2("Braidwood SSD functionality is %sabled.\n",
800 s->ibex.BW_SSD ? "en" : "dis");
801 msg_pdbg2("Braidwood NVMHCI functionality is %sabled.\n",
802 s->ibex.NVMHCI_EN ? "en" : "dis");
803
804 /* PCHSTRP15 */
805 msg_pdbg2("Chipset configuration Softstrap 6: %d\n", s->ibex.cs_ss6);
806 msg_pdbg2("Integrated wired LAN Solution is %sabled.\n",
807 s->ibex.IWL_EN ? "en" : "dis");
808 msg_pdbg2("t209 min Timing: %d ms\n",
809 dec_t209min[s->ibex.t209min]);
810 msg_pdbg2("\n");
811}
812
Jacob Garberbeeb8bc2019-06-21 15:24:17 -0600813static void prettyprint_ich_descriptor_straps_cougar(const struct ich_desc_south_strap *s)
Stefan Taunerb3850962011-12-24 00:00:32 +0000814{
815 msg_pdbg2("--- PCH ---\n");
816
817 /* PCHSTRP0 */
818 msg_pdbg2("Chipset configuration Softstrap 1: %d\n", s->cougar.cs_ss1);
819 msg_pdbg2("Intel ME SMBus Select is %sabled.\n",
820 s->ibex.SMB_EN ? "en" : "dis");
821 msg_pdbg2("SMLink0 segment is %sabled.\n",
822 s->ibex.SML0_EN ? "en" : "dis");
823 msg_pdbg2("SMLink1 segment is %sabled.\n",
824 s->ibex.SML1_EN ? "en" : "dis");
825 msg_pdbg2("SMLink1 Frequency: %s\n",
826 (s->ibex.SML1FRQ == 1) ? "100 kHz" : "reserved");
827 msg_pdbg2("Intel ME SMBus Frequency: %s\n",
828 (s->ibex.SMB0FRQ == 1) ? "100 kHz" : "reserved");
829 msg_pdbg2("SMLink0 Frequency: %s\n",
830 (s->ibex.SML0FRQ == 1) ? "100 kHz" : "reserved");
831 msg_pdbg2("GPIO12 is used as %s.\n", s->ibex.LANPHYPC_GP12_SEL ?
832 "LAN_PHY_PWR_CTRL" : "general purpose output");
833 msg_pdbg2("LinkSec is %sabled.\n",
834 s->cougar.LINKSEC_DIS ? "en" : "dis");
835 msg_pdbg2("DMI RequesterID Checks are %sabled.\n",
836 s->ibex.DMI_REQID_DIS ? "en" : "dis");
837 msg_pdbg2("BIOS Boot-Block size (BBBS): %d kB.\n",
838 1 << (6 + s->ibex.BBBS));
839
840 /* PCHSTRP1 */
841 msg_pdbg2("Chipset configuration Softstrap 3: 0x%x\n", s->ibex.cs_ss3);
842 msg_pdbg2("Chipset configuration Softstrap 2: 0x%x\n", s->ibex.cs_ss2);
843
844 /* PCHSTRP2 */
845 msg_pdbg2("ME SMBus ASD address is %sabled.\n",
846 s->ibex.MESMASDEN ? "en" : "dis");
847 msg_pdbg2("ME SMBus Controller ASD Target address: 0x%02x\n",
848 s->ibex.MESMASDA);
849 msg_pdbg2("ME SMBus MCTP Address is %sabled.\n",
850 s->cougar.MESMMCTPAEN ? "en" : "dis");
851 msg_pdbg2("ME SMBus MCTP target address: 0x%02x\n",
852 s->cougar.MESMMCTPA);
853 msg_pdbg2("ME SMBus I2C address is %sabled.\n",
854 s->ibex.MESMI2CEN ? "en" : "dis");
855 msg_pdbg2("ME SMBus I2C target address: 0x%02x\n",
856 s->ibex.MESMI2CA);
857
858 /* PCHSTRP3 */
859 prettyprint_ich_descriptor_pchstraps45678_56(s);
860 /* PCHSTRP9 */
861 prettyprint_ich_descriptor_straps_56_pciecs(s->ibex.PCIEPCS1, 0);
862 prettyprint_ich_descriptor_straps_56_pciecs(s->ibex.PCIEPCS1, 1);
863 msg_pdbg2("PCIe Lane Reversal 1: PCIe Lanes 0-3 are %sreserved.\n",
864 s->ibex.PCIELR1 ? "" : "not ");
865 msg_pdbg2("PCIe Lane Reversal 2: PCIe Lanes 4-7 are %sreserved.\n",
866 s->ibex.PCIELR2 ? "" : "not ");
867 msg_pdbg2("DMI Lane Reversal: DMI Lanes 0-3 are %sreserved.\n",
868 s->ibex.DMILR ? "" : "not ");
869 msg_pdbg2("ME Debug status writes over SMBUS are %sabled.\n",
870 s->cougar.MDSMBE_EN ? "en" : "dis");
871 msg_pdbg2("ME Debug SMBus Emergency Mode address: 0x%02x (raw)\n",
872 s->cougar.MDSMBE_ADD);
873 msg_pdbg2("Default PHY PCIe Port is %d.\n", s->ibex.PHY_PCIEPORTSEL+1);
874 msg_pdbg2("Integrated MAC/PHY communication over PCIe is %sabled.\n",
875 s->ibex.PHY_PCIE_EN ? "en" : "dis");
876 msg_pdbg2("PCIe ports Subtractive Decode Agent is %sabled.\n",
877 s->cougar.SUB_DECODE_EN ? "en" : "dis");
878 msg_pdbg2("GPIO74 is used as %s.\n", s->cougar.PCHHOT_SML1ALERT_SEL ?
879 "PCHHOT#" : "SML1ALERT#");
880
881 /* PCHSTRP10 */
882 msg_pdbg2("Management Engine will boot from %sflash.\n",
883 s->ibex.ME_BOOT_FLASH ? "" : "ROM, then ");
884
885 msg_pdbg2("ME Debug SMBus Emergency Mode is %sabled.\n",
886 s->cougar.MDSMBE_EN ? "en" : "dis");
887 msg_pdbg2("ME Debug SMBus Emergency Mode Address: 0x%02x\n",
888 s->cougar.MDSMBE_ADD);
889
890 msg_pdbg2("Integrated Clocking Configuration used: %d\n",
891 s->cougar.ICC_SEL);
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000892 msg_pdbg2("PCH Signal CL_RST1# does %sassert when Intel ME performs a reset.\n",
893 s->ibex.MER_CL1 ? "" : "not ");
Stefan Taunerb3850962011-12-24 00:00:32 +0000894 msg_pdbg2("ICC Profile is selected by %s.\n",
895 s->cougar.ICC_PRO_SEL ? "Softstraps" : "BIOS");
896 msg_pdbg2("Deep SX is %ssupported on the platform.\n",
897 s->cougar.Deep_SX_EN ? "not " : "");
898 msg_pdbg2("ME Debug LAN Emergency Mode is %sabled.\n",
899 s->cougar.ME_DBG_LAN ? "en" : "dis");
900
901 prettyprint_ich_descriptor_pchstraps111213_56(s);
902
903 /* PCHSTRP14 */
904 /* PCHSTRP15 */
905 msg_pdbg2("Chipset configuration Softstrap 6: %d\n", s->cougar.cs_ss6);
906 msg_pdbg2("Integrated wired LAN is %sabled.\n",
907 s->cougar.IWL_EN ? "en" : "dis");
908 msg_pdbg2("Chipset configuration Softstrap 5: %d\n", s->cougar.cs_ss5);
909 msg_pdbg2("SMLink1 provides temperature from %s.\n",
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000910 s->cougar.SMLINK1_THERM_SEL ? "PCH only" : "the CPU, PCH and DIMMs");
Stefan Taunerb3850962011-12-24 00:00:32 +0000911 msg_pdbg2("GPIO29 is used as %s.\n", s->cougar.SLP_LAN_GP29_SEL ?
912 "general purpose output" : "SLP_LAN#");
913
914 /* PCHSTRP16 */
915 /* PCHSTRP17 */
916 msg_pdbg2("Integrated Clock: %s Clock Mode\n",
917 s->cougar.ICML ? "Buffered Through" : "Full Integrated");
918 msg_pdbg2("\n");
919}
920
921void prettyprint_ich_descriptor_straps(enum ich_chipset cs, const struct ich_descriptors *desc)
922{
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000923 unsigned int i, max_count;
Stefan Taunerb3850962011-12-24 00:00:32 +0000924 msg_pdbg2("=== Softstraps ===\n");
925
Nico Huber157b8182024-07-19 17:48:12 +0200926 if (has_classic_proc_straps(cs)) {
927 max_count = MIN(ARRAY_SIZE(desc->north.STRPs), desc->content.MSL);
928 if (max_count < desc->content.MSL) {
929 msg_pdbg2("MSL (%u) is greater than the current maximum of %u entries.\n",
930 desc->content.MSL, max_count);
931 msg_pdbg2("Only the first %u entries will be printed.\n", max_count);
932 }
Stefan Taunerb3850962011-12-24 00:00:32 +0000933
Nico Huber157b8182024-07-19 17:48:12 +0200934 msg_pdbg2("--- North/MCH/PROC (%d entries) ---\n", max_count);
935 for (i = 0; i < max_count; i++)
936 msg_pdbg2("STRP%-2d = 0x%08x\n", i, desc->north.STRPs[i]);
937 msg_pdbg2("\n");
938 }
Stefan Taunerb3850962011-12-24 00:00:32 +0000939
Nico Huber519be662018-12-23 20:03:35 +0100940 max_count = MIN(ARRAY_SIZE(desc->south.STRPs), desc->content.ISL);
Nico Huberd7c75522017-03-29 16:31:49 +0200941 if (max_count < desc->content.ISL) {
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000942 msg_pdbg2("ISL (%u) is greater than the current maximum of %u entries.\n",
943 desc->content.ISL, max_count);
944 msg_pdbg2("Only the first %u entries will be printed.\n", max_count);
Nico Huberd7c75522017-03-29 16:31:49 +0200945 }
Stefan Taunerb3850962011-12-24 00:00:32 +0000946
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000947 msg_pdbg2("--- South/ICH/PCH (%d entries) ---\n", max_count);
948 for (i = 0; i < max_count; i++)
Stefan Taunerb3850962011-12-24 00:00:32 +0000949 msg_pdbg2("STRP%-2d = 0x%08x\n", i, desc->south.STRPs[i]);
950 msg_pdbg2("\n");
951
952 switch (cs) {
953 case CHIPSET_ICH8:
954 if (sizeof(desc->north.ich8) / 4 != desc->content.MSL)
955 msg_pdbg2("Detailed North/MCH/PROC information is "
956 "probably not reliable, printing anyway.\n");
957 if (sizeof(desc->south.ich8) / 4 != desc->content.ISL)
958 msg_pdbg2("Detailed South/ICH/PCH information is "
959 "probably not reliable, printing anyway.\n");
960 prettyprint_ich_descriptor_straps_ich8(desc);
961 break;
962 case CHIPSET_5_SERIES_IBEX_PEAK:
963 /* PCH straps only. PROCSTRPs are unknown. */
964 if (sizeof(desc->south.ibex) / 4 != desc->content.ISL)
965 msg_pdbg2("Detailed South/ICH/PCH information is "
966 "probably not reliable, printing anyway.\n");
967 prettyprint_ich_descriptor_straps_ibex(&desc->south);
968 break;
969 case CHIPSET_6_SERIES_COUGAR_POINT:
970 /* PCH straps only. PROCSTRP0 is "reserved". */
971 if (sizeof(desc->south.cougar) / 4 != desc->content.ISL)
972 msg_pdbg2("Detailed South/ICH/PCH information is "
973 "probably not reliable, printing anyway.\n");
974 prettyprint_ich_descriptor_straps_cougar(&desc->south);
975 break;
976 case CHIPSET_ICH_UNKNOWN:
977 break;
978 default:
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000979 msg_pdbg2("The meaning of the descriptor straps are unknown yet.\n\n");
Stefan Taunerb3850962011-12-24 00:00:32 +0000980 break;
981 }
982}
983
Jacob Garberbeeb8bc2019-06-21 15:24:17 -0600984static void prettyprint_rdid(uint32_t reg_val)
Stefan Taunerb3850962011-12-24 00:00:32 +0000985{
986 uint8_t mid = reg_val & 0xFF;
987 uint16_t did = ((reg_val >> 16) & 0xFF) | (reg_val & 0xFF00);
988 msg_pdbg2("Manufacturer ID 0x%02x, Device ID 0x%04x\n", mid, did);
989}
990
991void prettyprint_ich_descriptor_upper_map(const struct ich_desc_upper_map *umap)
992{
993 int i;
994 msg_pdbg2("=== Upper Map Section ===\n");
995 msg_pdbg2("FLUMAP1 0x%08x\n", umap->FLUMAP1);
996 msg_pdbg2("\n");
997
998 msg_pdbg2("--- Details ---\n");
999 msg_pdbg2("VTL (length in DWORDS) = %d\n", umap->VTL);
1000 msg_pdbg2("VTBA (base address) = 0x%6.6x\n", getVTBA(umap));
1001 msg_pdbg2("\n");
1002
1003 msg_pdbg2("VSCC Table: %d entries\n", umap->VTL/2);
Stefan Taunera1a14ec2012-08-13 08:45:13 +00001004 for (i = 0; i < umap->VTL/2; i++) {
Stefan Taunerb3850962011-12-24 00:00:32 +00001005 uint32_t jid = umap->vscc_table[i].JID;
1006 uint32_t vscc = umap->vscc_table[i].VSCC;
1007 msg_pdbg2(" JID%d = 0x%08x\n", i, jid);
1008 msg_pdbg2(" VSCC%d = 0x%08x\n", i, vscc);
Martin Rothf6c1cb12022-03-15 10:55:25 -06001009 msg_pdbg2(" "); /* indentation */
Stefan Taunerb3850962011-12-24 00:00:32 +00001010 prettyprint_rdid(jid);
Martin Rothf6c1cb12022-03-15 10:55:25 -06001011 msg_pdbg2(" "); /* indentation */
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001012 prettyprint_ich_reg_vscc(vscc, 0, false);
Stefan Taunerb3850962011-12-24 00:00:32 +00001013 }
1014 msg_pdbg2("\n");
1015}
1016
David Hendricks66565a72021-09-20 21:56:40 -07001017static inline void warn_peculiar_desc(const char *const name)
Nico Huber964007a2021-06-17 21:12:47 +02001018{
Nico Huber964007a2021-06-17 21:12:47 +02001019 msg_pwarn("Peculiar flash descriptor, assuming %s compatibility.\n", name);
1020}
1021
Nico Huber1dc3d422017-06-17 00:09:31 +02001022/*
1023 * Guesses a minimum chipset version based on the maximum number of
Nico Huber3ad9aad2021-06-17 22:05:00 +02001024 * soft straps per generation and presence of the MIP base (MDTBA).
Nico Huber1dc3d422017-06-17 00:09:31 +02001025 */
Nico Huberdb878fb2024-07-19 17:37:09 +02001026static enum ich_chipset guess_ich_chipset(const struct ich_desc_content *const content,
1027 const struct ich_desc_upper_map *const upper)
Nico Huber1dc3d422017-06-17 00:09:31 +02001028{
1029 if (content->ICCRIBA == 0x00) {
1030 if (content->MSL == 0 && content->ISL <= 2)
1031 return CHIPSET_ICH8;
Nico Huber83b01c82021-06-17 21:20:09 +02001032 if (content->ISL <= 2)
Nico Huber1dc3d422017-06-17 00:09:31 +02001033 return CHIPSET_ICH9;
Nico Huber83b01c82021-06-17 21:20:09 +02001034 if (content->ISL <= 10)
Nico Huber1dc3d422017-06-17 00:09:31 +02001035 return CHIPSET_ICH10;
David Hendricks66565a72021-09-20 21:56:40 -07001036 if (content->ISL <= 16)
1037 return CHIPSET_5_SERIES_IBEX_PEAK;
Nico Huber83b01c82021-06-17 21:20:09 +02001038 if (content->FLMAP2 == 0) {
Nico Huber81965f32021-06-17 23:25:35 +02001039 if (content->ISL == 19)
1040 return CHIPSET_APOLLO_LAKE;
David Hendricks66565a72021-09-20 21:56:40 -07001041 if (content->ISL == 23)
1042 return CHIPSET_GEMINI_LAKE;
1043 warn_peculiar_desc("Gemini Lake");
Nico Huber81965f32021-06-17 23:25:35 +02001044 return CHIPSET_GEMINI_LAKE;
Nico Huberd2d39932019-01-18 16:49:37 +01001045 }
Nico Huber42daab12024-07-16 00:27:27 +02001046 if (content->NM == 6) {
1047 /* 0x8b is from the SPI Guide, but not yet seen in the wild. */
1048 if (0x50 <= content->ISL && content->ISL <= 0x8b)
1049 return CHIPSET_C740_SERIES_EMMITSBURG;
1050 warn_peculiar_desc("C740 series");
1051 return CHIPSET_C740_SERIES_EMMITSBURG;
1052 }
David Hendricks66565a72021-09-20 21:56:40 -07001053 warn_peculiar_desc("Ibex Peak");
Nico Huber1dc3d422017-06-17 00:09:31 +02001054 return CHIPSET_5_SERIES_IBEX_PEAK;
Nico Huber3ad9aad2021-06-17 22:05:00 +02001055 } else if (upper->MDTBA == 0x00) {
1056 if (content->ICCRIBA < 0x31 && content->FMSBA < 0x30) {
1057 if (content->MSL == 0 && content->ISL <= 17)
1058 return CHIPSET_BAYTRAIL;
1059 if (content->MSL <= 1 && content->ISL <= 18)
1060 return CHIPSET_6_SERIES_COUGAR_POINT;
David Hendricks66565a72021-09-20 21:56:40 -07001061 if (content->MSL <= 1 && content->ISL <= 21)
1062 return CHIPSET_8_SERIES_LYNX_POINT;
1063 warn_peculiar_desc("Lynx Point");
Nico Huber81965f32021-06-17 23:25:35 +02001064 return CHIPSET_8_SERIES_LYNX_POINT;
Nico Huber3ad9aad2021-06-17 22:05:00 +02001065 }
1066 if (content->NM == 6) {
David Hendricks66565a72021-09-20 21:56:40 -07001067 if (content->ICCRIBA <= 0x34)
1068 return CHIPSET_C620_SERIES_LEWISBURG;
1069 warn_peculiar_desc("C620 series");
Nico Huber2a5dfaf2019-07-04 16:01:51 +02001070 return CHIPSET_C620_SERIES_LEWISBURG;
Nico Huber3ad9aad2021-06-17 22:05:00 +02001071 }
David Hendricks66565a72021-09-20 21:56:40 -07001072 if (content->ICCRIBA == 0x31)
1073 return CHIPSET_100_SERIES_SUNRISE_POINT;
1074 warn_peculiar_desc("100 series");
Nico Huber83b01c82021-06-17 21:20:09 +02001075 return CHIPSET_100_SERIES_SUNRISE_POINT;
Nico Huber0ef2eb82024-07-19 21:38:17 +02001076 } else if (content->FLMAP2 == 0xffffffff) {
1077 if (content->ISL == 0x8f)
1078 return CHIPSET_SNOW_RIDGE;
1079 warn_peculiar_desc("Snow Ridge");
1080 return CHIPSET_SNOW_RIDGE;
Nico Huber1dc3d422017-06-17 00:09:31 +02001081 } else {
David Hendricks66565a72021-09-20 21:56:40 -07001082 if (content->ICCRIBA == 0x34)
1083 return CHIPSET_300_SERIES_CANNON_POINT;
Michał Żygowski5c9f5422021-06-16 15:13:54 +02001084 if (content->CSSL == 0x11)
1085 return CHIPSET_500_SERIES_TIGER_POINT;
Nico Huber29c23dd2022-12-21 15:25:09 +00001086 if (content->CSSL == 0x14) /* backwards compatible Alder Point */
1087 return CHIPSET_500_SERIES_TIGER_POINT;
Nico Huber756b6b32022-12-21 17:15:13 +00001088 if (content->CSSL == 0x03) {
Nico Huber5e0d9b02024-07-19 21:44:52 +02001089 if (content->CSSO == 0x58) {
Nico Huber756b6b32022-12-21 17:15:13 +00001090 return CHIPSET_ELKHART_LAKE;
Nico Huber5e0d9b02024-07-19 21:44:52 +02001091 } else if (content->CSSO == 0x6c) { /* backwards compatible Jasper Lake */
Nico Huber756b6b32022-12-21 17:15:13 +00001092 return CHIPSET_300_SERIES_CANNON_POINT;
Nico Huber5e0d9b02024-07-19 21:44:52 +02001093 } else if (content->CSSO == 0x70) {
Nico Huberd5a61ef2024-11-06 23:55:44 +01001094 /* 0x7d from in SPI guide, 0x7e found in the wild */
1095 if (content->ISL == 0x7d || content->ISL == 0x7e)
1096 return CHIPSET_LUNAR_LAKE;
Nico Huber5e0d9b02024-07-19 21:44:52 +02001097 if (content->ISL == 0x82)
1098 return CHIPSET_METEOR_LAKE;
1099 }
1100 }
1101 if (content->ISL >= 0x82) {
1102 warn_peculiar_desc("Meteor Lake");
1103 return CHIPSET_METEOR_LAKE;
Nico Huber756b6b32022-12-21 17:15:13 +00001104 }
Michał Żygowski5c9f5422021-06-16 15:13:54 +02001105 msg_pwarn("Unknown flash descriptor, assuming 500 series compatibility.\n");
1106 return CHIPSET_500_SERIES_TIGER_POINT;
Nico Huber1dc3d422017-06-17 00:09:31 +02001107 }
1108}
1109
Stefan Taunerb3850962011-12-24 00:00:32 +00001110/* len is the length of dump in bytes */
Nico Huberfa622942017-03-24 17:25:37 +01001111int read_ich_descriptors_from_dump(const uint32_t *const dump, const size_t len,
1112 enum ich_chipset *const cs, struct ich_descriptors *const desc)
Stefan Taunerb3850962011-12-24 00:00:32 +00001113{
Nico Huber519be662018-12-23 20:03:35 +01001114 ssize_t i, max_count;
1115 size_t pch_bug_offset = 0;
Stefan Taunerb3850962011-12-24 00:00:32 +00001116
1117 if (dump == NULL || desc == NULL)
1118 return ICH_RET_PARAM;
1119
1120 if (dump[0] != DESCRIPTOR_MODE_SIGNATURE) {
1121 if (dump[4] == DESCRIPTOR_MODE_SIGNATURE)
1122 pch_bug_offset = 4;
1123 else
1124 return ICH_RET_ERR;
1125 }
1126
1127 /* map */
Nico Huber9e14aed2017-03-28 17:08:46 +02001128 if (len < (4 + pch_bug_offset) * 4)
Stefan Taunerb3850962011-12-24 00:00:32 +00001129 return ICH_RET_OOB;
1130 desc->content.FLVALSIG = dump[0 + pch_bug_offset];
1131 desc->content.FLMAP0 = dump[1 + pch_bug_offset];
1132 desc->content.FLMAP1 = dump[2 + pch_bug_offset];
1133 desc->content.FLMAP2 = dump[3 + pch_bug_offset];
1134
1135 /* component */
Nico Huber9e14aed2017-03-28 17:08:46 +02001136 if (len < getFCBA(&desc->content) + 3 * 4)
Stefan Taunerb3850962011-12-24 00:00:32 +00001137 return ICH_RET_OOB;
1138 desc->component.FLCOMP = dump[(getFCBA(&desc->content) >> 2) + 0];
1139 desc->component.FLILL = dump[(getFCBA(&desc->content) >> 2) + 1];
1140 desc->component.FLPB = dump[(getFCBA(&desc->content) >> 2) + 2];
1141
Nico Huber8a03c902021-06-17 21:23:29 +02001142 /* upper map */
1143 desc->upper.FLUMAP1 = dump[(UPPER_MAP_OFFSET >> 2) + 0];
1144
1145 /* VTL is 8 bits long. Quote from the Ibex Peak SPI programming guide:
1146 * "Identifies the 1s based number of DWORDS contained in the VSCC
1147 * Table. Each SPI component entry in the table is 2 DWORDS long." So
1148 * the maximum of 255 gives us 127.5 SPI components(!?) 8 bytes each. A
1149 * check ensures that the maximum offset actually accessed is available.
1150 */
1151 if (len < getVTBA(&desc->upper) + (desc->upper.VTL / 2 * 8))
1152 return ICH_RET_OOB;
1153
1154 for (i = 0; i < desc->upper.VTL/2; i++) {
1155 desc->upper.vscc_table[i].JID = dump[(getVTBA(&desc->upper) >> 2) + i * 2 + 0];
1156 desc->upper.vscc_table[i].VSCC = dump[(getVTBA(&desc->upper) >> 2) + i * 2 + 1];
1157 }
1158
Nico Huber67d71792017-06-17 03:10:15 +02001159 if (*cs == CHIPSET_ICH_UNKNOWN) {
Nico Huberdb878fb2024-07-19 17:37:09 +02001160 *cs = guess_ich_chipset(&desc->content, &desc->upper);
Nico Huber67d71792017-06-17 03:10:15 +02001161 prettyprint_ich_chipset(*cs);
1162 }
Nico Huberfa622942017-03-24 17:25:37 +01001163
Stefan Taunerb3850962011-12-24 00:00:32 +00001164 /* region */
Nico Huberfa622942017-03-24 17:25:37 +01001165 const ssize_t nr = ich_number_of_regions(*cs, &desc->content);
Nico Huber519be662018-12-23 20:03:35 +01001166 if (nr < 0 || len < getFRBA(&desc->content) + (size_t)nr * 4)
Stefan Taunerb3850962011-12-24 00:00:32 +00001167 return ICH_RET_OOB;
Nico Huberfa622942017-03-24 17:25:37 +01001168 for (i = 0; i < nr; i++)
1169 desc->region.FLREGs[i] = dump[(getFRBA(&desc->content) >> 2) + i];
Stefan Taunerb3850962011-12-24 00:00:32 +00001170
1171 /* master */
Nico Huberfa622942017-03-24 17:25:37 +01001172 const ssize_t nm = ich_number_of_masters(*cs, &desc->content);
Nico Huber519be662018-12-23 20:03:35 +01001173 if (nm < 0 || len < getFMBA(&desc->content) + (size_t)nm * 4)
Stefan Taunerb3850962011-12-24 00:00:32 +00001174 return ICH_RET_OOB;
Nico Huberfa622942017-03-24 17:25:37 +01001175 for (i = 0; i < nm; i++)
1176 desc->master.FLMSTRs[i] = dump[(getFMBA(&desc->content) >> 2) + i];
Stefan Taunerb3850962011-12-24 00:00:32 +00001177
Nico Huber157b8182024-07-19 17:48:12 +02001178 if (has_classic_proc_straps(*cs)) {
1179 /* MCH/PROC (aka. North) straps */
1180 if (len < getFMSBA(&desc->content) + desc->content.MSL * 4)
1181 return ICH_RET_OOB;
Stefan Taunerb3850962011-12-24 00:00:32 +00001182
Nico Huber157b8182024-07-19 17:48:12 +02001183 /* limit the range to be written */
1184 max_count = MIN(sizeof(desc->north.STRPs) / 4, desc->content.MSL);
1185 for (i = 0; i < max_count; i++)
1186 desc->north.STRPs[i] = dump[(getFMSBA(&desc->content) >> 2) + i];
1187 }
Stefan Taunerb3850962011-12-24 00:00:32 +00001188
1189 /* ICH/PCH (aka. South) straps */
1190 if (len < getFISBA(&desc->content) + desc->content.ISL * 4)
1191 return ICH_RET_OOB;
1192
1193 /* limit the range to be written */
Nico Huber519be662018-12-23 20:03:35 +01001194 max_count = MIN(sizeof(desc->south.STRPs) / 4, desc->content.ISL);
Stefan Taunera1a14ec2012-08-13 08:45:13 +00001195 for (i = 0; i < max_count; i++)
1196 desc->south.STRPs[i] = dump[(getFISBA(&desc->content) >> 2) + i];
Stefan Taunerb3850962011-12-24 00:00:32 +00001197
1198 return ICH_RET_OK;
1199}
1200
Nico Huberad186312016-05-02 15:15:29 +02001201#ifndef ICH_DESCRIPTORS_FROM_DUMP_ONLY
Stefan Taunerb3850962011-12-24 00:00:32 +00001202
Stefan Taunerd0c5dc22011-10-20 12:57:14 +00001203/** Returns the integer representation of the component density with index
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001204\em idx in bytes or -1 if the correct size can not be determined. */
1205int getFCBA_component_density(enum ich_chipset cs, const struct ich_descriptors *desc, uint8_t idx)
Stefan Taunerd0c5dc22011-10-20 12:57:14 +00001206{
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001207 if (idx > 1) {
Stefan Taunera1a14ec2012-08-13 08:45:13 +00001208 msg_perr("Only ICH SPI component index 0 or 1 are supported yet.\n");
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001209 return -1;
Stefan Taunerd0c5dc22011-10-20 12:57:14 +00001210 }
Nico Huberdfd06472024-07-14 23:45:05 +02001211 if (cs == CHIPSET_ICH_UNKNOWN) {
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001212 msg_pwarn("Density encoding is unknown on this chipset.\n");
1213 return -1;
Stefan Taunerd0c5dc22011-10-20 12:57:14 +00001214 }
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001215
Nico Huberdfd06472024-07-14 23:45:05 +02001216 if (desc->content.NC == 0 && idx > 0)
1217 return 0;
1218
1219 const unsigned int max_idx = cs < CHIPSET_HAS_NEW_COMPONENT_DENSITY ? 5 : 7;
1220 const unsigned int size_idx = get_density_index(cs, desc, idx);
1221
1222 if (size_idx > max_idx) {
Tai-Hong Wu60dead42015-01-05 23:00:14 +00001223 msg_perr("Density of ICH SPI component with index %d is invalid.\n"
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001224 "Encoded density is 0x%x while maximum allowed is 0x%x.\n",
Nico Huberdfd06472024-07-14 23:45:05 +02001225 idx, size_idx, max_idx);
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001226 return -1;
1227 }
1228
Nico Huberdfd06472024-07-14 23:45:05 +02001229 return 1 << (19 + size_idx);
Stefan Taunerd0c5dc22011-10-20 12:57:14 +00001230}
1231
Nico Huber8d494992017-06-19 12:18:33 +02001232/* Only used by ichspi.c */
1233#if CONFIG_INTERNAL == 1 && (defined(__i386__) || defined(__x86_64__))
Nico Huberd54e4f42017-03-23 23:45:47 +01001234static uint32_t read_descriptor_reg(enum ich_chipset cs, uint8_t section, uint16_t offset, void *spibar)
Stefan Tauner1e146392011-09-15 23:52:55 +00001235{
1236 uint32_t control = 0;
1237 control |= (section << FDOC_FDSS_OFF) & FDOC_FDSS;
1238 control |= (offset << FDOC_FDSI_OFF) & FDOC_FDSI;
Nico Huberb2ad9fd2024-07-14 23:18:53 +02001239
1240 if (cs >= SPI_ENGINE_PCH100) {
Nico Huberd54e4f42017-03-23 23:45:47 +01001241 mmio_le_writel(control, spibar + PCH100_REG_FDOC);
1242 return mmio_le_readl(spibar + PCH100_REG_FDOD);
Nico Huberb2ad9fd2024-07-14 23:18:53 +02001243 } else {
Nico Huberd54e4f42017-03-23 23:45:47 +01001244 mmio_le_writel(control, spibar + ICH9_REG_FDOC);
1245 return mmio_le_readl(spibar + ICH9_REG_FDOD);
1246 }
Stefan Tauner1e146392011-09-15 23:52:55 +00001247}
1248
Nico Huberd54e4f42017-03-23 23:45:47 +01001249int read_ich_descriptors_via_fdo(enum ich_chipset cs, void *spibar, struct ich_descriptors *desc)
Stefan Tauner1e146392011-09-15 23:52:55 +00001250{
Nico Huber519be662018-12-23 20:03:35 +01001251 ssize_t i;
Stefan Tauner1e146392011-09-15 23:52:55 +00001252 struct ich_desc_region *r = &desc->region;
1253
1254 /* Test if bit-fields are working as expected.
1255 * FIXME: Replace this with dynamic bitfield fixup
1256 */
1257 for (i = 0; i < 4; i++)
1258 desc->region.FLREGs[i] = 0x5A << (i * 8);
Nico Huberfa622942017-03-24 17:25:37 +01001259 if (r->old_reg[0].base != 0x005A || r->old_reg[0].limit != 0x0000 ||
1260 r->old_reg[1].base != 0x1A00 || r->old_reg[1].limit != 0x0000 ||
1261 r->old_reg[2].base != 0x0000 || r->old_reg[2].limit != 0x005A ||
1262 r->old_reg[3].base != 0x0000 || r->old_reg[3].limit != 0x1A00) {
Stefan Tauner1e146392011-09-15 23:52:55 +00001263 msg_pdbg("The combination of compiler and CPU architecture used"
1264 "does not lay out bit-fields as expected, sorry.\n");
Nico Huberfa622942017-03-24 17:25:37 +01001265 msg_pspew("r->old_reg[0].base = 0x%04X (0x005A)\n", r->old_reg[0].base);
1266 msg_pspew("r->old_reg[0].limit = 0x%04X (0x0000)\n", r->old_reg[0].limit);
1267 msg_pspew("r->old_reg[1].base = 0x%04X (0x1A00)\n", r->old_reg[1].base);
1268 msg_pspew("r->old_reg[1].limit = 0x%04X (0x0000)\n", r->old_reg[1].limit);
1269 msg_pspew("r->old_reg[2].base = 0x%04X (0x0000)\n", r->old_reg[2].base);
1270 msg_pspew("r->old_reg[2].limit = 0x%04X (0x005A)\n", r->old_reg[2].limit);
1271 msg_pspew("r->old_reg[3].base = 0x%04X (0x0000)\n", r->old_reg[3].base);
1272 msg_pspew("r->old_reg[3].limit = 0x%04X (0x1A00)\n", r->old_reg[3].limit);
Stefan Tauner1e146392011-09-15 23:52:55 +00001273 return ICH_RET_ERR;
1274 }
1275
Stefan Taunera1a14ec2012-08-13 08:45:13 +00001276 msg_pdbg2("Reading flash descriptors mapped by the chipset via FDOC/FDOD...");
Stefan Tauner1e146392011-09-15 23:52:55 +00001277 /* content section */
Nico Huberd54e4f42017-03-23 23:45:47 +01001278 desc->content.FLVALSIG = read_descriptor_reg(cs, 0, 0, spibar);
1279 desc->content.FLMAP0 = read_descriptor_reg(cs, 0, 1, spibar);
1280 desc->content.FLMAP1 = read_descriptor_reg(cs, 0, 2, spibar);
1281 desc->content.FLMAP2 = read_descriptor_reg(cs, 0, 3, spibar);
Stefan Tauner1e146392011-09-15 23:52:55 +00001282
1283 /* component section */
Nico Huberd54e4f42017-03-23 23:45:47 +01001284 desc->component.FLCOMP = read_descriptor_reg(cs, 1, 0, spibar);
1285 desc->component.FLILL = read_descriptor_reg(cs, 1, 1, spibar);
1286 desc->component.FLPB = read_descriptor_reg(cs, 1, 2, spibar);
Stefan Tauner1e146392011-09-15 23:52:55 +00001287
1288 /* region section */
Nico Huberfa622942017-03-24 17:25:37 +01001289 const ssize_t nr = ich_number_of_regions(cs, &desc->content);
1290 if (nr < 0) {
Stefan Tauner1e146392011-09-15 23:52:55 +00001291 msg_pdbg2("%s: number of regions too high (%d) - failed\n",
Nico Huberfa622942017-03-24 17:25:37 +01001292 __func__, desc->content.NR + 1);
Stefan Tauner1e146392011-09-15 23:52:55 +00001293 return ICH_RET_ERR;
1294 }
Nico Huberfa622942017-03-24 17:25:37 +01001295 for (i = 0; i < nr; i++)
Nico Huberd54e4f42017-03-23 23:45:47 +01001296 desc->region.FLREGs[i] = read_descriptor_reg(cs, 2, i, spibar);
Stefan Tauner1e146392011-09-15 23:52:55 +00001297
1298 /* master section */
Nico Huberfa622942017-03-24 17:25:37 +01001299 const ssize_t nm = ich_number_of_masters(cs, &desc->content);
1300 if (nm < 0) {
1301 msg_pdbg2("%s: number of masters too high (%d) - failed\n",
1302 __func__, desc->content.NM + 1);
1303 return ICH_RET_ERR;
1304 }
1305 for (i = 0; i < nm; i++)
1306 desc->master.FLMSTRs[i] = read_descriptor_reg(cs, 3, i, spibar);
Stefan Tauner1e146392011-09-15 23:52:55 +00001307
1308 /* Accessing the strap section via FDOC/D is only possible on ICH8 and
1309 * reading the upper map is impossible on all chipsets, so don't bother.
1310 */
1311
1312 msg_pdbg2(" done.\n");
1313 return ICH_RET_OK;
1314}
Nico Huber8d494992017-06-19 12:18:33 +02001315#endif
Nico Huber305f4172013-06-14 11:55:26 +02001316
1317/**
1318 * @brief Read a layout from the dump of an Intel ICH descriptor.
1319 *
1320 * @param layout Pointer where to store the layout.
1321 * @param dump The descriptor dump to read from.
1322 * @param len The length of the descriptor dump.
1323 *
1324 * @return 0 on success,
Nico Huber70461a92019-06-15 14:56:19 +02001325 * 1 if the descriptor couldn't be parsed,
1326 * 2 when out of memory.
Nico Huber305f4172013-06-14 11:55:26 +02001327 */
Nico Huber5bd990c2019-06-16 19:46:46 +02001328int layout_from_ich_descriptors(
Nico Huberc3b02dc2023-08-12 01:13:45 +02001329 struct flashprog_layout **const layout,
Nico Huber5bd990c2019-06-16 19:46:46 +02001330 const void *const dump, const size_t len)
Nico Huber305f4172013-06-14 11:55:26 +02001331{
Nico Huberfa622942017-03-24 17:25:37 +01001332 static const char *const regions[] = {
David Hendricksa5216362017-08-08 20:02:22 -07001333 "fd", "bios", "me", "gbe", "pd", "reg5", "bios2", "reg7", "ec", "reg9", "ie",
1334 "10gbe", "reg12", "reg13", "reg14", "reg15"
Nico Huberfa622942017-03-24 17:25:37 +01001335 };
Nico Huber305f4172013-06-14 11:55:26 +02001336
1337 struct ich_descriptors desc;
Nico Huberfa622942017-03-24 17:25:37 +01001338 enum ich_chipset cs = CHIPSET_ICH_UNKNOWN;
1339 if (read_ich_descriptors_from_dump(dump, len, &cs, &desc))
Nico Huber305f4172013-06-14 11:55:26 +02001340 return 1;
1341
Nico Huberc3b02dc2023-08-12 01:13:45 +02001342 if (flashprog_layout_new(layout))
Nico Huber5bd990c2019-06-16 19:46:46 +02001343 return 2;
Nico Huber305f4172013-06-14 11:55:26 +02001344
Nico Huber92e0b622019-06-15 15:55:11 +02001345 ssize_t i;
Nico Huber519be662018-12-23 20:03:35 +01001346 const ssize_t nr = MIN(ich_number_of_regions(cs, &desc.content), (ssize_t)ARRAY_SIZE(regions));
Nico Huber92e0b622019-06-15 15:55:11 +02001347 for (i = 0; i < nr; ++i) {
Nico Huber305f4172013-06-14 11:55:26 +02001348 const chipoff_t base = ICH_FREG_BASE(desc.region.FLREGs[i]);
Nico Huber0bb3f712017-03-29 16:44:33 +02001349 const chipoff_t limit = ICH_FREG_LIMIT(desc.region.FLREGs[i]);
Nico Huber305f4172013-06-14 11:55:26 +02001350 if (limit <= base)
1351 continue;
Nico Huberc3b02dc2023-08-12 01:13:45 +02001352 if (flashprog_layout_add_region(*layout, base, limit, regions[i])) {
1353 flashprog_layout_release(*layout);
Nico Huber5bd990c2019-06-16 19:46:46 +02001354 *layout = NULL;
Nico Huber70461a92019-06-15 14:56:19 +02001355 return 2;
Nico Huber5bd990c2019-06-16 19:46:46 +02001356 }
Nico Huber305f4172013-06-14 11:55:26 +02001357 }
Nico Huber305f4172013-06-14 11:55:26 +02001358 return 0;
1359}
1360
Nico Huberad186312016-05-02 15:15:29 +02001361#endif /* ICH_DESCRIPTORS_FROM_DUMP_ONLY */