blob: 0f941b4ef7727d4fd40919eb4043d858389c792e [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:
David Hendricksa5216362017-08-08 20:02:22 -070053 return 16;
Nico Huberfa622942017-03-24 17:25:37 +010054 case CHIPSET_100_SERIES_SUNRISE_POINT:
55 return 10;
56 case CHIPSET_9_SERIES_WILDCAT_POINT_LP:
57 case CHIPSET_9_SERIES_WILDCAT_POINT:
58 case CHIPSET_8_SERIES_LYNX_POINT_LP:
59 case CHIPSET_8_SERIES_LYNX_POINT:
60 case CHIPSET_8_SERIES_WELLSBURG:
61 if (cont->NR <= 6)
62 return cont->NR + 1;
63 else
64 return -1;
65 default:
66 if (cont->NR <= 4)
67 return cont->NR + 1;
68 else
69 return -1;
70 }
71}
72
73ssize_t ich_number_of_masters(const enum ich_chipset cs, const struct ich_desc_content *const cont)
74{
David Hendricksa5216362017-08-08 20:02:22 -070075 switch (cs) {
76 case CHIPSET_C620_SERIES_LEWISBURG:
Nico Huber42daab12024-07-16 00:27:27 +020077 case CHIPSET_C740_SERIES_EMMITSBURG:
Nico Huber0ef2eb82024-07-19 21:38:17 +020078 case CHIPSET_SNOW_RIDGE:
Nico Huber5e0d9b02024-07-19 21:44:52 +020079 case CHIPSET_METEOR_LAKE:
Nico Huber82fe1232024-07-19 17:28:47 +020080 return 6;
Nico Huberd2d39932019-01-18 16:49:37 +010081 case CHIPSET_APOLLO_LAKE:
Angel Pons4db0fdf2020-07-10 17:04:10 +020082 case CHIPSET_GEMINI_LAKE:
Werner Zehe57d4e42022-01-03 09:44:29 +010083 case CHIPSET_ELKHART_LAKE:
Nico Huber82fe1232024-07-19 17:28:47 +020084 return 2;
David Hendricksa5216362017-08-08 20:02:22 -070085 default:
Nico Huber82fe1232024-07-19 17:28:47 +020086 if (cs >= SPI_ENGINE_PCH100)
87 return 5;
David Hendricksa5216362017-08-08 20:02:22 -070088 if (cont->NM < MAX_NUM_MASTERS)
89 return cont->NM + 1;
90 }
91
92 return -1;
Nico Huberfa622942017-03-24 17:25:37 +010093}
94
Nico Huber157b8182024-07-19 17:48:12 +020095static bool has_classic_proc_straps(const enum ich_chipset cs)
96{
97 switch (cs) {
98 case CHIPSET_100_SERIES_SUNRISE_POINT:
99 case CHIPSET_C620_SERIES_LEWISBURG:
Nico Huber42daab12024-07-16 00:27:27 +0200100 case CHIPSET_C740_SERIES_EMMITSBURG:
Nico Huber157b8182024-07-19 17:48:12 +0200101 return true;
102 default:
103 return cs < SPI_ENGINE_PCH100;
104 }
105}
106
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000107void prettyprint_ich_reg_vscc(uint32_t reg_val, int verbosity, bool print_vcl)
Stefan Tauner1e146392011-09-15 23:52:55 +0000108{
109 print(verbosity, "BES=0x%x, ", (reg_val & VSCC_BES) >> VSCC_BES_OFF);
110 print(verbosity, "WG=%d, ", (reg_val & VSCC_WG) >> VSCC_WG_OFF);
111 print(verbosity, "WSR=%d, ", (reg_val & VSCC_WSR) >> VSCC_WSR_OFF);
112 print(verbosity, "WEWS=%d, ", (reg_val & VSCC_WEWS) >> VSCC_WEWS_OFF);
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000113 print(verbosity, "EO=0x%x", (reg_val & VSCC_EO) >> VSCC_EO_OFF);
114 if (print_vcl)
115 print(verbosity, ", VCL=%d", (reg_val & VSCC_VCL) >> VSCC_VCL_OFF);
116 print(verbosity, "\n");
Stefan Tauner1e146392011-09-15 23:52:55 +0000117}
118
119#define getFCBA(cont) (((cont)->FLMAP0 << 4) & 0x00000ff0)
120#define getFRBA(cont) (((cont)->FLMAP0 >> 12) & 0x00000ff0)
121#define getFMBA(cont) (((cont)->FLMAP1 << 4) & 0x00000ff0)
122#define getFISBA(cont) (((cont)->FLMAP1 >> 12) & 0x00000ff0)
123#define getFMSBA(cont) (((cont)->FLMAP2 << 4) & 0x00000ff0)
124
Nico Huber67d71792017-06-17 03:10:15 +0200125void prettyprint_ich_chipset(enum ich_chipset cs)
126{
127 static const char *const chipset_names[] = {
128 "Unknown ICH", "ICH8", "ICH9", "ICH10",
129 "5 series Ibex Peak", "6 series Cougar Point", "7 series Panther Point",
Nico Huberdfd06472024-07-14 23:45:05 +0200130 "Baytrail", "8 series Lynx Point", "8 series Lynx Point LP", "8 series Wellsburg",
Nico Huber67d71792017-06-17 03:10:15 +0200131 "9 series Wildcat Point", "9 series Wildcat Point LP", "100 series Sunrise Point",
Angel Pons4db0fdf2020-07-10 17:04:10 +0200132 "C620 series Lewisburg", "300/400 series Cannon/Comet Point",
Nico Huber29c23dd2022-12-21 15:25:09 +0000133 "500/600 series Tiger/Alder Point", "Apollo Lake", "Gemini Lake", "Elkhart Lake",
Nico Huber5e0d9b02024-07-19 21:44:52 +0200134 "C740 series Emmitsburg", "Snow Ridge", "Meteor Lake",
Nico Huber67d71792017-06-17 03:10:15 +0200135 };
136 if (cs < CHIPSET_ICH8 || cs - CHIPSET_ICH8 + 1 >= ARRAY_SIZE(chipset_names))
137 cs = 0;
138 else
139 cs = cs - CHIPSET_ICH8 + 1;
140 msg_pdbg2("Assuming chipset '%s'.\n", chipset_names[cs]);
141}
142
Stefan Tauner1e146392011-09-15 23:52:55 +0000143void prettyprint_ich_descriptors(enum ich_chipset cs, const struct ich_descriptors *desc)
144{
Nico Huberfa622942017-03-24 17:25:37 +0100145 prettyprint_ich_descriptor_content(cs, &desc->content);
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000146 prettyprint_ich_descriptor_component(cs, desc);
Nico Huberfa622942017-03-24 17:25:37 +0100147 prettyprint_ich_descriptor_region(cs, desc);
148 prettyprint_ich_descriptor_master(cs, desc);
Nico Huberad186312016-05-02 15:15:29 +0200149#ifdef ICH_DESCRIPTORS_FROM_DUMP_ONLY
Stefan Taunerb3850962011-12-24 00:00:32 +0000150 if (cs >= CHIPSET_ICH8) {
151 prettyprint_ich_descriptor_upper_map(&desc->upper);
152 prettyprint_ich_descriptor_straps(cs, desc);
153 }
Nico Huberad186312016-05-02 15:15:29 +0200154#endif /* ICH_DESCRIPTORS_FROM_DUMP_ONLY */
Stefan Tauner1e146392011-09-15 23:52:55 +0000155}
156
Nico Huberfa622942017-03-24 17:25:37 +0100157void prettyprint_ich_descriptor_content(enum ich_chipset cs, const struct ich_desc_content *cont)
Stefan Tauner1e146392011-09-15 23:52:55 +0000158{
159 msg_pdbg2("=== Content Section ===\n");
160 msg_pdbg2("FLVALSIG 0x%08x\n", cont->FLVALSIG);
161 msg_pdbg2("FLMAP0 0x%08x\n", cont->FLMAP0);
162 msg_pdbg2("FLMAP1 0x%08x\n", cont->FLMAP1);
163 msg_pdbg2("FLMAP2 0x%08x\n", cont->FLMAP2);
164 msg_pdbg2("\n");
165
166 msg_pdbg2("--- Details ---\n");
Nico Huberfa622942017-03-24 17:25:37 +0100167 msg_pdbg2("NR (Number of Regions): %5zd\n", ich_number_of_regions(cs, cont));
168 msg_pdbg2("FRBA (Flash Region Base Address): 0x%03x\n", getFRBA(cont));
169 msg_pdbg2("NC (Number of Components): %5d\n", cont->NC + 1);
170 msg_pdbg2("FCBA (Flash Component Base Address): 0x%03x\n", getFCBA(cont));
Nico Huberd2d39932019-01-18 16:49:37 +0100171 msg_pdbg2("ISL (ICH/PCH/SoC Strap Length): %5d\n", cont->ISL);
172 msg_pdbg2("FISBA/FPSBA (Flash ICH/PCH/SoC Strap Base Addr): 0x%03x\n", getFISBA(cont));
Nico Huberfa622942017-03-24 17:25:37 +0100173 msg_pdbg2("NM (Number of Masters): %5zd\n", ich_number_of_masters(cs, cont));
174 msg_pdbg2("FMBA (Flash Master Base Address): 0x%03x\n", getFMBA(cont));
Nico Huber157b8182024-07-19 17:48:12 +0200175 if (has_classic_proc_straps(cs)) {
176 msg_pdbg2("MSL/PSL (MCH/PROC Strap Length): %5d\n", cont->MSL);
177 msg_pdbg2("FMSBA (Flash MCH/PROC Strap Base Address): 0x%03x\n", getFMSBA(cont));
178 }
Stefan Tauner1e146392011-09-15 23:52:55 +0000179 msg_pdbg2("\n");
180}
181
Nico Huberdfd06472024-07-14 23:45:05 +0200182static unsigned int get_density_index(
183 enum ich_chipset cs, const struct ich_descriptors *desc, unsigned int component)
184{
185 if (cs < CHIPSET_HAS_NEW_COMPONENT_DENSITY) {
186 if (component == 0)
187 return desc->component.dens_old.comp1_density;
188 else
189 return desc->component.dens_old.comp2_density;
190 } else {
191 if (component == 0)
192 return desc->component.dens_new.comp1_density;
193 else
194 return desc->component.dens_new.comp2_density;
195 }
196}
197
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000198static const char *pprint_density(enum ich_chipset cs, const struct ich_descriptors *desc, uint8_t idx)
199{
200 if (idx > 1) {
201 msg_perr("Only ICH SPI component index 0 or 1 are supported yet.\n");
Nico Huberdfd06472024-07-14 23:45:05 +0200202 return "unknown";
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000203 }
Nico Huberdfd06472024-07-14 23:45:05 +0200204 if (cs == CHIPSET_ICH_UNKNOWN)
205 return "unknown";
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000206
207 if (desc->content.NC == 0 && idx > 0)
208 return "unused";
209
210 static const char * const size_str[] = {
211 "512 kB", /* 0000 */
212 "1 MB", /* 0001 */
213 "2 MB", /* 0010 */
214 "4 MB", /* 0011 */
215 "8 MB", /* 0100 */
216 "16 MB", /* 0101 */ /* Maximum up to Lynx Point (excl.) */
217 "32 MB", /* 0110 */
218 "64 MB", /* 0111 */
219 };
Nico Huberdfd06472024-07-14 23:45:05 +0200220 const unsigned int max_idx = cs < CHIPSET_HAS_NEW_COMPONENT_DENSITY ? 5 : 7;
221 const unsigned int size_idx = get_density_index(cs, desc, idx);
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000222
Nico Huberdfd06472024-07-14 23:45:05 +0200223 if (size_idx > max_idx)
224 return "reserved";
225
226 return size_str[size_idx];
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000227}
228
229static const char *pprint_freq(enum ich_chipset cs, uint8_t value)
Stefan Tauner1e146392011-09-15 23:52:55 +0000230{
Nico Huber0ef2eb82024-07-19 21:38:17 +0200231 static const char *const freq_str[][8] = { {
Nico Huber129e9382019-06-06 15:43:27 +0200232 "20 MHz",
233 "33 MHz",
234 "reserved",
235 "reserved",
236 "50 MHz", /* New since Ibex Peak */
237 "reserved",
238 "reserved",
239 "reserved"
Nico Huberfa622942017-03-24 17:25:37 +0100240 }, {
Nico Huber129e9382019-06-06 15:43:27 +0200241 "reserved",
242 "reserved",
243 "48 MHz",
244 "reserved",
245 "30 MHz",
246 "reserved",
247 "17 MHz",
248 "reserved"
Nico Huberd2d39932019-01-18 16:49:37 +0100249 }, {
250 "reserved",
251 "50 MHz",
252 "40 MHz",
253 "reserved",
254 "25 MHz",
255 "reserved",
256 "14 MHz / 17 MHz",
257 "reserved"
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200258 }, {
259 "100 MHz",
260 "50 MHz",
261 "reserved",
262 "33 MHz",
263 "25 MHz",
264 "reserved",
265 "14 MHz",
266 "reserved"
Werner Zehe57d4e42022-01-03 09:44:29 +0100267 }, {
268 "reserved",
269 "50 MHz",
270 "reserved",
271 "reserved",
272 "33 MHz",
273 "20 MHz",
274 "reserved",
275 "reserved",
Nico Huber0ef2eb82024-07-19 21:38:17 +0200276 }, {
277 "reserved",
278 "48 MHz",
279 "32 MHz",
280 "reserved",
281 "24 MHz",
282 "19.2 MHz",
283 "13.7 MHz",
284 "reserved",
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200285 }};
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000286
287 switch (cs) {
288 case CHIPSET_ICH8:
289 case CHIPSET_ICH9:
290 case CHIPSET_ICH10:
291 if (value > 1)
292 return "reserved";
Richard Hughesdb7482b2018-12-19 12:04:30 +0000293 /* Fall through. */
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000294 case CHIPSET_5_SERIES_IBEX_PEAK:
295 case CHIPSET_6_SERIES_COUGAR_POINT:
296 case CHIPSET_7_SERIES_PANTHER_POINT:
297 case CHIPSET_8_SERIES_LYNX_POINT:
Duncan Laurie4095ed72014-08-20 15:39:32 +0000298 case CHIPSET_BAYTRAIL:
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000299 case CHIPSET_8_SERIES_LYNX_POINT_LP:
300 case CHIPSET_8_SERIES_WELLSBURG:
Duncan Laurie823096e2014-08-20 15:39:38 +0000301 case CHIPSET_9_SERIES_WILDCAT_POINT:
Nico Huber51205912017-03-17 17:59:54 +0100302 case CHIPSET_9_SERIES_WILDCAT_POINT_LP:
Nico Huberfa622942017-03-24 17:25:37 +0100303 return freq_str[0][value];
304 case CHIPSET_100_SERIES_SUNRISE_POINT:
David Hendricksa5216362017-08-08 20:02:22 -0700305 case CHIPSET_C620_SERIES_LEWISBURG:
Nico Huber2a5dfaf2019-07-04 16:01:51 +0200306 case CHIPSET_300_SERIES_CANNON_POINT:
Nico Huberfa622942017-03-24 17:25:37 +0100307 return freq_str[1][value];
Nico Huberd2d39932019-01-18 16:49:37 +0100308 case CHIPSET_APOLLO_LAKE:
Angel Pons4db0fdf2020-07-10 17:04:10 +0200309 case CHIPSET_GEMINI_LAKE:
Nico Huberd2d39932019-01-18 16:49:37 +0100310 return freq_str[2][value];
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200311 case CHIPSET_500_SERIES_TIGER_POINT:
Nico Huber42daab12024-07-16 00:27:27 +0200312 case CHIPSET_C740_SERIES_EMMITSBURG:
Nico Huber5e0d9b02024-07-19 21:44:52 +0200313 case CHIPSET_METEOR_LAKE:
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200314 return freq_str[3][value];
Werner Zehe57d4e42022-01-03 09:44:29 +0100315 case CHIPSET_ELKHART_LAKE:
316 return freq_str[4][value];
Nico Huber0ef2eb82024-07-19 21:38:17 +0200317 case CHIPSET_SNOW_RIDGE:
318 return freq_str[5][value];
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000319 case CHIPSET_ICH_UNKNOWN:
320 default:
321 return "unknown";
322 }
323}
324
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200325static void pprint_read_freq(enum ich_chipset cs, uint8_t value)
326{
Nico Huber0ef2eb82024-07-19 21:38:17 +0200327 static const char *const freq_str[][8] = { {
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200328 "20 MHz",
329 "24 MHz",
330 "30 MHz",
331 "48 MHz",
332 "60 MHz",
333 "reserved",
334 "reserved",
335 "reserved"
Nico Huber0ef2eb82024-07-19 21:38:17 +0200336 }, {
337 "16 MHz",
338 "19.2 MHz",
339 "24 MHz",
340 "32 MHz",
341 "48 MHz",
342 "reserved",
343 "reserved",
344 "reserved"
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200345 }};
346
347 switch (cs) {
348 case CHIPSET_300_SERIES_CANNON_POINT:
349 msg_pdbg2("eSPI/EC Bus Clock Frequency: %s\n", freq_str[0][value]);
350 return;
Nico Huber0ef2eb82024-07-19 21:38:17 +0200351 case CHIPSET_SNOW_RIDGE:
352 msg_pdbg2("eSPI/EC Bus Clock Frequency: %s\n", freq_str[1][value]);
353 return;
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200354 case CHIPSET_500_SERIES_TIGER_POINT:
Nico Huber5e0d9b02024-07-19 21:44:52 +0200355 case CHIPSET_METEOR_LAKE:
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200356 msg_pdbg2("Read Clock Frequency: %s\n", "reserved");
357 return;
358 default:
359 msg_pdbg2("Read Clock Frequency: %s\n", pprint_freq(cs, value));
360 return;
361 }
362}
363
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000364void prettyprint_ich_descriptor_component(enum ich_chipset cs, const struct ich_descriptors *desc)
365{
Nico Huberb2ad9fd2024-07-14 23:18:53 +0200366 const bool has_flill1 = cs >= SPI_ENGINE_PCH100;
Stefan Tauner1e146392011-09-15 23:52:55 +0000367
368 msg_pdbg2("=== Component Section ===\n");
369 msg_pdbg2("FLCOMP 0x%08x\n", desc->component.FLCOMP);
370 msg_pdbg2("FLILL 0x%08x\n", desc->component.FLILL );
Nico Huberd2d39932019-01-18 16:49:37 +0100371 if (has_flill1)
Nico Huberfa622942017-03-24 17:25:37 +0100372 msg_pdbg2("FLILL1 0x%08x\n", desc->component.FLILL1);
Stefan Tauner1e146392011-09-15 23:52:55 +0000373 msg_pdbg2("\n");
374
375 msg_pdbg2("--- Details ---\n");
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000376 msg_pdbg2("Component 1 density: %s\n", pprint_density(cs, desc, 0));
Stefan Tauner1e146392011-09-15 23:52:55 +0000377 if (desc->content.NC)
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000378 msg_pdbg2("Component 2 density: %s\n", pprint_density(cs, desc, 1));
Stefan Tauner1e146392011-09-15 23:52:55 +0000379 else
380 msg_pdbg2("Component 2 is not used.\n");
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200381
382 pprint_read_freq(cs, desc->component.modes.freq_read);
383
Tai-Hong Wu60dead42015-01-05 23:00:14 +0000384 msg_pdbg2("Read ID and Status Clock Freq.: %s\n", pprint_freq(cs, desc->component.modes.freq_read_id));
385 msg_pdbg2("Write and Erase Clock Freq.: %s\n", pprint_freq(cs, desc->component.modes.freq_write));
386 msg_pdbg2("Fast Read is %ssupported.\n", desc->component.modes.fastread ? "" : "not ");
387 if (desc->component.modes.fastread)
Stefan Tauner1e146392011-09-15 23:52:55 +0000388 msg_pdbg2("Fast Read Clock Frequency: %s\n",
Tai-Hong Wu60dead42015-01-05 23:00:14 +0000389 pprint_freq(cs, desc->component.modes.freq_fastread));
Nico Huber3f75d442024-07-14 19:17:56 +0200390 switch (cs) {
391 case CHIPSET_7_SERIES_PANTHER_POINT:
392 case CHIPSET_8_SERIES_LYNX_POINT:
393 case CHIPSET_BAYTRAIL:
394 case CHIPSET_8_SERIES_LYNX_POINT_LP:
395 case CHIPSET_8_SERIES_WELLSBURG:
396 case CHIPSET_9_SERIES_WILDCAT_POINT:
397 case CHIPSET_9_SERIES_WILDCAT_POINT_LP:
398 case CHIPSET_100_SERIES_SUNRISE_POINT:
399 case CHIPSET_APOLLO_LAKE:
400 case CHIPSET_C620_SERIES_LEWISBURG:
Nico Huber0ef2eb82024-07-19 21:38:17 +0200401 case CHIPSET_SNOW_RIDGE:
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000402 msg_pdbg2("Dual Output Fast Read Support: %sabled\n",
Werner Zehd3e8fd92022-01-25 07:02:49 +0100403 desc->component.modes.dual_output ? "en" : "dis");
Nico Huber3f75d442024-07-14 19:17:56 +0200404 break;
405 default:
406 break;
407 }
David Hendricksa5216362017-08-08 20:02:22 -0700408
Felix Singerd68a0ec2022-08-19 03:23:35 +0200409 bool has_forbidden_opcode = false;
David Hendricksa5216362017-08-08 20:02:22 -0700410 if (desc->component.FLILL != 0) {
Felix Singerd68a0ec2022-08-19 03:23:35 +0200411 has_forbidden_opcode = true;
Stefan Tauner1e146392011-09-15 23:52:55 +0000412 msg_pdbg2("Invalid instruction 0: 0x%02x\n",
413 desc->component.invalid_instr0);
414 msg_pdbg2("Invalid instruction 1: 0x%02x\n",
415 desc->component.invalid_instr1);
416 msg_pdbg2("Invalid instruction 2: 0x%02x\n",
417 desc->component.invalid_instr2);
418 msg_pdbg2("Invalid instruction 3: 0x%02x\n",
419 desc->component.invalid_instr3);
David Hendricksa5216362017-08-08 20:02:22 -0700420 }
Nico Huberd2d39932019-01-18 16:49:37 +0100421 if (has_flill1) {
David Hendricksa5216362017-08-08 20:02:22 -0700422 if (desc->component.FLILL1 != 0) {
Felix Singerd68a0ec2022-08-19 03:23:35 +0200423 has_forbidden_opcode = true;
Nico Huberfa622942017-03-24 17:25:37 +0100424 msg_pdbg2("Invalid instruction 4: 0x%02x\n",
425 desc->component.invalid_instr4);
426 msg_pdbg2("Invalid instruction 5: 0x%02x\n",
427 desc->component.invalid_instr5);
428 msg_pdbg2("Invalid instruction 6: 0x%02x\n",
429 desc->component.invalid_instr6);
430 msg_pdbg2("Invalid instruction 7: 0x%02x\n",
431 desc->component.invalid_instr7);
432 }
Stefan Tauner1e146392011-09-15 23:52:55 +0000433 }
David Hendricksa5216362017-08-08 20:02:22 -0700434 if (!has_forbidden_opcode)
435 msg_pdbg2("No forbidden opcodes.\n");
436
Stefan Tauner1e146392011-09-15 23:52:55 +0000437 msg_pdbg2("\n");
438}
439
440static void pprint_freg(const struct ich_desc_region *reg, uint32_t i)
441{
Nico Huberfa622942017-03-24 17:25:37 +0100442 static const char *const region_names[] = {
Nico Huberd2d39932019-01-18 16:49:37 +0100443 "Descr.", "BIOS", "ME", "GbE", "Platf.", "DevExp", "BIOS2", "unknown",
Nico Huber5e0d9b02024-07-19 21:44:52 +0200444 "EC/BMC", "unknown", "SSE/IE", "10GbE/NIS", "OpROM", "iRC", "unknown", "PTT"
Stefan Tauner1e146392011-09-15 23:52:55 +0000445 };
Nico Huberfa622942017-03-24 17:25:37 +0100446 if (i >= ARRAY_SIZE(region_names)) {
Stefan Tauner1e146392011-09-15 23:52:55 +0000447 msg_pdbg2("%s: region index too high.\n", __func__);
448 return;
449 }
450 uint32_t base = ICH_FREG_BASE(reg->FLREGs[i]);
451 uint32_t limit = ICH_FREG_LIMIT(reg->FLREGs[i]);
Nico Huber0ef2eb82024-07-19 21:38:17 +0200452 msg_pdbg2("Region %d (%-9s) ", i, region_names[i]);
Stefan Tauner1e146392011-09-15 23:52:55 +0000453 if (base > limit)
454 msg_pdbg2("is unused.\n");
455 else
Nico Huber0bb3f712017-03-29 16:44:33 +0200456 msg_pdbg2("0x%08x - 0x%08x\n", base, limit);
Stefan Tauner1e146392011-09-15 23:52:55 +0000457}
458
Nico Huberfa622942017-03-24 17:25:37 +0100459void prettyprint_ich_descriptor_region(const enum ich_chipset cs, const struct ich_descriptors *const desc)
Stefan Tauner1e146392011-09-15 23:52:55 +0000460{
Nico Huber519be662018-12-23 20:03:35 +0100461 ssize_t i;
Nico Huberfa622942017-03-24 17:25:37 +0100462 const ssize_t nr = ich_number_of_regions(cs, &desc->content);
Stefan Tauner1e146392011-09-15 23:52:55 +0000463 msg_pdbg2("=== Region Section ===\n");
Nico Huberfa622942017-03-24 17:25:37 +0100464 if (nr < 0) {
Stefan Tauner1e146392011-09-15 23:52:55 +0000465 msg_pdbg2("%s: number of regions too high (%d).\n", __func__,
Nico Huberfa622942017-03-24 17:25:37 +0100466 desc->content.NR + 1);
Stefan Tauner1e146392011-09-15 23:52:55 +0000467 return;
468 }
Nico Huberfa622942017-03-24 17:25:37 +0100469 for (i = 0; i < nr; i++)
Nico Huber519be662018-12-23 20:03:35 +0100470 msg_pdbg2("FLREG%zd 0x%08x\n", i, desc->region.FLREGs[i]);
Stefan Tauner1e146392011-09-15 23:52:55 +0000471 msg_pdbg2("\n");
472
473 msg_pdbg2("--- Details ---\n");
Nico Huberfa622942017-03-24 17:25:37 +0100474 for (i = 0; i < nr; i++)
Nico Huber519be662018-12-23 20:03:35 +0100475 pprint_freg(&desc->region, (uint32_t)i);
Stefan Tauner1e146392011-09-15 23:52:55 +0000476 msg_pdbg2("\n");
477}
478
Nico Huberb3cc2c62024-07-15 00:45:17 +0200479static char prettify_flag(const unsigned int mask, const unsigned int bit, const char flag)
480{
481 return mask & (1 << bit) ? flag : ' ';
482}
483
484/* Takes NULL-terminated lists of names, assumes max. 5 chars per name. */
485static void prettyprint_pch100_masters(
486 const struct ich_descriptors *const desc,
487 const unsigned int number_masters, const char *const masters[],
488 const unsigned int number_regions, const char *const regions[])
489{
490 unsigned int m, r;
491
492 msg_pdbg2(" ");
493 for (r = 0; r < number_regions && regions[r] != NULL; ++r)
494 msg_pdbg2(" %-5s", regions[r]);
495 msg_pdbg2("\n");
496
497 for (m = 0; m < number_masters; ++m) {
498 const unsigned int ext_start = 12;
499
500 if (masters[m] == NULL)
501 break;
502
503 const struct ich_desc_master_region_access master = desc->master.mstr[m];
504
505 msg_pdbg2("%-5s", masters[m]);
506 for (r = 0; r < ext_start && r < number_regions && regions[r] != NULL; ++r)
507 msg_pdbg2(" %c%c ",
508 prettify_flag(master.read, r, 'r'),
509 prettify_flag(master.write, r, 'w'));
510 for (; r < number_regions && regions[r] != NULL; ++r)
511 msg_pdbg2(" %c%c ",
512 prettify_flag(master.ext_read, r - ext_start, 'r'),
513 prettify_flag(master.ext_write, r - ext_start, 'w'));
514 msg_pdbg2("\n");
515 }
516}
517
Nico Huberfa622942017-03-24 17:25:37 +0100518void prettyprint_ich_descriptor_master(const enum ich_chipset cs, const struct ich_descriptors *const desc)
Stefan Tauner1e146392011-09-15 23:52:55 +0000519{
Nico Huber519be662018-12-23 20:03:35 +0100520 ssize_t i;
Nico Huberfa622942017-03-24 17:25:37 +0100521 const ssize_t nm = ich_number_of_masters(cs, &desc->content);
Stefan Tauner1e146392011-09-15 23:52:55 +0000522 msg_pdbg2("=== Master Section ===\n");
Nico Huberfa622942017-03-24 17:25:37 +0100523 if (nm < 0) {
524 msg_pdbg2("%s: number of masters too high (%d).\n", __func__,
525 desc->content.NM + 1);
526 return;
527 }
528 for (i = 0; i < nm; i++)
Nico Huber519be662018-12-23 20:03:35 +0100529 msg_pdbg2("FLMSTR%zd 0x%08x\n", i + 1, desc->master.FLMSTRs[i]);
Stefan Tauner1e146392011-09-15 23:52:55 +0000530 msg_pdbg2("\n");
531
532 msg_pdbg2("--- Details ---\n");
Nico Huberb3cc2c62024-07-15 00:45:17 +0200533 if (cs >= SPI_ENGINE_PCH100) {
534 const ssize_t nr = ich_number_of_regions(cs, &desc->content);
535 if (nr < 0)
Nico Huberfa622942017-03-24 17:25:37 +0100536 return;
Nico Huberfa622942017-03-24 17:25:37 +0100537
Nico Huberb3cc2c62024-07-15 00:45:17 +0200538 if (cs == CHIPSET_APOLLO_LAKE ||
539 cs == CHIPSET_GEMINI_LAKE ||
540 cs == CHIPSET_ELKHART_LAKE) {
541 const char *const masters[] = {
542 "BIOS", "TXE", NULL
543 };
544 const char *const regions[] = {
545 " FD", "IFWI", " TXE", " n/a", "Pltf.", "DevExp", NULL
546 };
547 prettyprint_pch100_masters(desc, nm, masters, nr, regions);
Nico Huber42daab12024-07-16 00:27:27 +0200548 } else if (cs == CHIPSET_C620_SERIES_LEWISBURG ||
549 cs == CHIPSET_C740_SERIES_EMMITSBURG) {
Nico Huberb3cc2c62024-07-15 00:45:17 +0200550 const char *const masters[] = {
551 "BIOS", "ME", "GbE", "DE", "BMC", "IE", NULL
552 };
553 const char *const regions[] = {
554 " FD ", " BIOS", " ME ", " GbE ", "Pltf.",
David Hendricksa5216362017-08-08 20:02:22 -0700555 " DE ", "BIOS2", " Reg7", " BMC ", " DE2 ",
556 " IE ", "10GbE", "OpROM", "Reg13", "Reg14",
Nico Huberb3cc2c62024-07-15 00:45:17 +0200557 "Reg15", NULL
558 };
559 prettyprint_pch100_masters(desc, nm, masters, nr, regions);
560 } else {
561 const char *const masters[] = {
Nico Huber5e0d9b02024-07-19 21:44:52 +0200562 "BIOS", "ME", "GbE", "NAC", "EC", "SSE", NULL
Nico Huberb3cc2c62024-07-15 00:45:17 +0200563 };
564 const char *const regions[] = {
565 " FD ", "BIOS ", " ME ", " GbE ", "Pltf.",
Nico Huber0ef2eb82024-07-19 21:38:17 +0200566 "Reg5 ", "BIOS2", "Reg7 ", " EC ", "Reg9 ",
Nico Huber5e0d9b02024-07-19 21:44:52 +0200567 " SSE ", " NIS ", "Reg12", " iRC ", "Reg14",
Nico Huber0ef2eb82024-07-19 21:38:17 +0200568 " PTT ", NULL
Nico Huberb3cc2c62024-07-15 00:45:17 +0200569 };
570 prettyprint_pch100_masters(desc, nm, masters, nr, regions);
Nico Huberd2d39932019-01-18 16:49:37 +0100571 }
Nico Huberfa622942017-03-24 17:25:37 +0100572 } else {
573 const struct ich_desc_master *const mstr = &desc->master;
574 msg_pdbg2(" Descr. BIOS ME GbE Platf.\n");
575 msg_pdbg2("BIOS %c%c %c%c %c%c %c%c %c%c\n",
576 (mstr->BIOS_descr_r) ?'r':' ', (mstr->BIOS_descr_w) ?'w':' ',
577 (mstr->BIOS_BIOS_r) ?'r':' ', (mstr->BIOS_BIOS_w) ?'w':' ',
578 (mstr->BIOS_ME_r) ?'r':' ', (mstr->BIOS_ME_w) ?'w':' ',
579 (mstr->BIOS_GbE_r) ?'r':' ', (mstr->BIOS_GbE_w) ?'w':' ',
580 (mstr->BIOS_plat_r) ?'r':' ', (mstr->BIOS_plat_w) ?'w':' ');
581 msg_pdbg2("ME %c%c %c%c %c%c %c%c %c%c\n",
582 (mstr->ME_descr_r) ?'r':' ', (mstr->ME_descr_w) ?'w':' ',
583 (mstr->ME_BIOS_r) ?'r':' ', (mstr->ME_BIOS_w) ?'w':' ',
584 (mstr->ME_ME_r) ?'r':' ', (mstr->ME_ME_w) ?'w':' ',
585 (mstr->ME_GbE_r) ?'r':' ', (mstr->ME_GbE_w) ?'w':' ',
586 (mstr->ME_plat_r) ?'r':' ', (mstr->ME_plat_w) ?'w':' ');
587 msg_pdbg2("GbE %c%c %c%c %c%c %c%c %c%c\n",
588 (mstr->GbE_descr_r) ?'r':' ', (mstr->GbE_descr_w) ?'w':' ',
589 (mstr->GbE_BIOS_r) ?'r':' ', (mstr->GbE_BIOS_w) ?'w':' ',
590 (mstr->GbE_ME_r) ?'r':' ', (mstr->GbE_ME_w) ?'w':' ',
591 (mstr->GbE_GbE_r) ?'r':' ', (mstr->GbE_GbE_w) ?'w':' ',
592 (mstr->GbE_plat_r) ?'r':' ', (mstr->GbE_plat_w) ?'w':' ');
593 }
Stefan Tauner1e146392011-09-15 23:52:55 +0000594 msg_pdbg2("\n");
595}
596
Jacob Garberbeeb8bc2019-06-21 15:24:17 -0600597static void prettyprint_ich_descriptor_straps_ich8(const struct ich_descriptors *desc)
Stefan Taunerb3850962011-12-24 00:00:32 +0000598{
599 static const char * const str_GPIO12[4] = {
600 "GPIO12",
601 "LAN PHY Power Control Function (Native Output)",
602 "GLAN_DOCK# (Native Input)",
603 "invalid configuration",
604 };
605
606 msg_pdbg2("--- MCH details ---\n");
607 msg_pdbg2("ME B is %sabled.\n", desc->north.ich8.MDB ? "dis" : "en");
608 msg_pdbg2("\n");
609
610 msg_pdbg2("--- ICH details ---\n");
611 msg_pdbg2("ME SMBus Address 1: 0x%02x\n", desc->south.ich8.ASD);
612 msg_pdbg2("ME SMBus Address 2: 0x%02x\n", desc->south.ich8.ASD2);
613 msg_pdbg2("ME SMBus Controller is connected to the %s.\n",
614 desc->south.ich8.MESM2SEL ? "SMLink pins" : "SMBus pins");
615 msg_pdbg2("SPI CS1 is used for %s.\n",
616 desc->south.ich8.SPICS1_LANPHYPC_SEL ?
617 "LAN PHY Power Control Function" :
618 "SPI Chip Select");
619 msg_pdbg2("GPIO12 is used as %s.\n",
620 str_GPIO12[desc->south.ich8.GPIO12_SEL]);
621 msg_pdbg2("PCIe Port 6 is used for %s.\n",
622 desc->south.ich8.GLAN_PCIE_SEL ? "integrated LAN" : "PCI Express");
623 msg_pdbg2("%sn BMC Mode: "
624 "Intel AMT SMBus Controller 1 is connected to %s.\n",
625 desc->south.ich8.BMCMODE ? "I" : "Not i",
626 desc->south.ich8.BMCMODE ? "SMLink" : "SMBus");
627 msg_pdbg2("TCO is in %s Mode.\n",
628 desc->south.ich8.TCOMODE ? "Advanced TCO" : "Legacy/Compatible");
629 msg_pdbg2("ME A is %sabled.\n",
630 desc->south.ich8.ME_DISABLE ? "dis" : "en");
631 msg_pdbg2("\n");
632}
633
634static void prettyprint_ich_descriptor_straps_56_pciecs(uint8_t conf, uint8_t off)
635{
636 msg_pdbg2("PCI Express Port Configuration Strap %d: ", off+1);
637
638 off *= 4;
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000639 switch (conf){
Stefan Taunerb3850962011-12-24 00:00:32 +0000640 case 0:
641 msg_pdbg2("4x1 Ports %d-%d (x1)", 1+off, 4+off);
642 break;
643 case 1:
644 msg_pdbg2("1x2, 2x1 Port %d (x2), Port %d (disabled), "
645 "Ports %d, %d (x1)", 1+off, 2+off, 3+off, 4+off);
646 break;
647 case 2:
648 msg_pdbg2("2x2 Port %d (x2), Port %d (x2), Ports "
649 "%d, %d (disabled)", 1+off, 3+off, 2+off, 4+off);
650 break;
651 case 3:
652 msg_pdbg2("1x4 Port %d (x4), Ports %d-%d (disabled)",
653 1+off, 2+off, 4+off);
654 break;
655 }
656 msg_pdbg2("\n");
657}
658
Jacob Garberbeeb8bc2019-06-21 15:24:17 -0600659static void prettyprint_ich_descriptor_pchstraps45678_56(const struct ich_desc_south_strap *s)
Stefan Taunerb3850962011-12-24 00:00:32 +0000660{
661 /* PCHSTRP4 */
662 msg_pdbg2("Intel PHY is %s.\n",
663 (s->ibex.PHYCON == 2) ? "connected" :
664 (s->ibex.PHYCON == 0) ? "disconnected" : "reserved");
665 msg_pdbg2("GbE MAC SMBus address is %sabled.\n",
666 s->ibex.GBEMAC_SMBUS_ADDR_EN ? "en" : "dis");
667 msg_pdbg2("GbE MAC SMBus address: 0x%02x\n",
668 s->ibex.GBEMAC_SMBUS_ADDR);
669 msg_pdbg2("GbE PHY SMBus address: 0x%02x\n",
670 s->ibex.GBEPHY_SMBUS_ADDR);
671
672 /* PCHSTRP5 */
673 /* PCHSTRP6 */
674 /* PCHSTRP7 */
675 msg_pdbg2("Intel ME SMBus Subsystem Vendor ID: 0x%04x\n",
676 s->ibex.MESMA2UDID_VENDOR);
677 msg_pdbg2("Intel ME SMBus Subsystem Device ID: 0x%04x\n",
678 s->ibex.MESMA2UDID_VENDOR);
679
680 /* PCHSTRP8 */
681}
682
Jacob Garberbeeb8bc2019-06-21 15:24:17 -0600683static void prettyprint_ich_descriptor_pchstraps111213_56(const struct ich_desc_south_strap *s)
Stefan Taunerb3850962011-12-24 00:00:32 +0000684{
685 /* PCHSTRP11 */
686 msg_pdbg2("SMLink1 GP Address is %sabled.\n",
687 s->ibex.SML1GPAEN ? "en" : "dis");
688 msg_pdbg2("SMLink1 controller General Purpose Target address: 0x%02x\n",
689 s->ibex.SML1GPA);
690 msg_pdbg2("SMLink1 I2C Target address is %sabled.\n",
691 s->ibex.SML1I2CAEN ? "en" : "dis");
692 msg_pdbg2("SMLink1 I2C Target address: 0x%02x\n",
693 s->ibex.SML1I2CA);
694
695 /* PCHSTRP12 */
696 /* PCHSTRP13 */
697}
698
Jacob Garberbeeb8bc2019-06-21 15:24:17 -0600699static void prettyprint_ich_descriptor_straps_ibex(const struct ich_desc_south_strap *s)
Stefan Taunerb3850962011-12-24 00:00:32 +0000700{
Stefan Tauner67d163d2013-01-15 17:37:48 +0000701 static const uint8_t dec_t209min[4] = {
Stefan Taunerb3850962011-12-24 00:00:32 +0000702 100,
703 50,
704 5,
705 1
706 };
707
708 msg_pdbg2("--- PCH ---\n");
709
710 /* PCHSTRP0 */
711 msg_pdbg2("Chipset configuration Softstrap 2: %d\n", s->ibex.cs_ss2);
712 msg_pdbg2("Intel ME SMBus Select is %sabled.\n",
713 s->ibex.SMB_EN ? "en" : "dis");
714 msg_pdbg2("SMLink0 segment is %sabled.\n",
715 s->ibex.SML0_EN ? "en" : "dis");
716 msg_pdbg2("SMLink1 segment is %sabled.\n",
717 s->ibex.SML1_EN ? "en" : "dis");
718 msg_pdbg2("SMLink1 Frequency: %s\n",
719 (s->ibex.SML1FRQ == 1) ? "100 kHz" : "reserved");
720 msg_pdbg2("Intel ME SMBus Frequency: %s\n",
721 (s->ibex.SMB0FRQ == 1) ? "100 kHz" : "reserved");
722 msg_pdbg2("SMLink0 Frequency: %s\n",
723 (s->ibex.SML0FRQ == 1) ? "100 kHz" : "reserved");
724 msg_pdbg2("GPIO12 is used as %s.\n", s->ibex.LANPHYPC_GP12_SEL ?
725 "LAN_PHY_PWR_CTRL" : "general purpose output");
726 msg_pdbg2("Chipset configuration Softstrap 1: %d\n", s->ibex.cs_ss1);
727 msg_pdbg2("DMI RequesterID Checks are %sabled.\n",
728 s->ibex.DMI_REQID_DIS ? "en" : "dis");
729 msg_pdbg2("BIOS Boot-Block size (BBBS): %d kB.\n",
730 1 << (6 + s->ibex.BBBS));
731
732 /* PCHSTRP1 */
733 msg_pdbg2("Chipset configuration Softstrap 3: 0x%x\n", s->ibex.cs_ss3);
734
735 /* PCHSTRP2 */
736 msg_pdbg2("ME SMBus ASD address is %sabled.\n",
737 s->ibex.MESMASDEN ? "en" : "dis");
738 msg_pdbg2("ME SMBus Controller ASD Target address: 0x%02x\n",
739 s->ibex.MESMASDA);
740 msg_pdbg2("ME SMBus I2C address is %sabled.\n",
741 s->ibex.MESMI2CEN ? "en" : "dis");
742 msg_pdbg2("ME SMBus I2C target address: 0x%02x\n",
743 s->ibex.MESMI2CA);
744
745 /* PCHSTRP3 */
746 prettyprint_ich_descriptor_pchstraps45678_56(s);
747 /* PCHSTRP9 */
748 prettyprint_ich_descriptor_straps_56_pciecs(s->ibex.PCIEPCS1, 0);
749 prettyprint_ich_descriptor_straps_56_pciecs(s->ibex.PCIEPCS1, 1);
750 msg_pdbg2("PCIe Lane Reversal 1: PCIe Lanes 0-3 are %sreserved.\n",
751 s->ibex.PCIELR1 ? "" : "not ");
752 msg_pdbg2("PCIe Lane Reversal 2: PCIe Lanes 4-7 are %sreserved.\n",
753 s->ibex.PCIELR2 ? "" : "not ");
754 msg_pdbg2("DMI Lane Reversal: DMI Lanes 0-3 are %sreserved.\n",
755 s->ibex.DMILR ? "" : "not ");
756 msg_pdbg2("Default PHY PCIe Port is %d.\n", s->ibex.PHY_PCIEPORTSEL+1);
757 msg_pdbg2("Integrated MAC/PHY communication over PCIe is %sabled.\n",
758 s->ibex.PHY_PCIE_EN ? "en" : "dis");
759
760 /* PCHSTRP10 */
761 msg_pdbg2("Management Engine will boot from %sflash.\n",
762 s->ibex.ME_BOOT_FLASH ? "" : "ROM, then ");
763 msg_pdbg2("Chipset configuration Softstrap 5: %d\n", s->ibex.cs_ss5);
764 msg_pdbg2("Virtualization Engine Enable 1 is %sabled.\n",
765 s->ibex.VE_EN ? "en" : "dis");
766 msg_pdbg2("ME Memory-attached Debug Display Device is %sabled.\n",
767 s->ibex.MMDDE ? "en" : "dis");
768 msg_pdbg2("ME Memory-attached Debug Display Device address: 0x%02x\n",
769 s->ibex.MMADDR);
770 msg_pdbg2("Chipset configuration Softstrap 7: %d\n", s->ibex.cs_ss7);
771 msg_pdbg2("Integrated Clocking Configuration is %d.\n",
772 (s->ibex.ICC_SEL == 7) ? 0 : s->ibex.ICC_SEL);
773 msg_pdbg2("PCH Signal CL_RST1# does %sassert when Intel ME performs a "
774 "reset.\n", s->ibex.MER_CL1 ? "" : "not ");
775
776 prettyprint_ich_descriptor_pchstraps111213_56(s);
777
778 /* PCHSTRP14 */
779 msg_pdbg2("Virtualization Engine Enable 2 is %sabled.\n",
780 s->ibex.VE_EN2 ? "en" : "dis");
781 msg_pdbg2("Virtualization Engine will boot from %sflash.\n",
782 s->ibex.VE_BOOT_FLASH ? "" : "ROM, then ");
783 msg_pdbg2("Braidwood SSD functionality is %sabled.\n",
784 s->ibex.BW_SSD ? "en" : "dis");
785 msg_pdbg2("Braidwood NVMHCI functionality is %sabled.\n",
786 s->ibex.NVMHCI_EN ? "en" : "dis");
787
788 /* PCHSTRP15 */
789 msg_pdbg2("Chipset configuration Softstrap 6: %d\n", s->ibex.cs_ss6);
790 msg_pdbg2("Integrated wired LAN Solution is %sabled.\n",
791 s->ibex.IWL_EN ? "en" : "dis");
792 msg_pdbg2("t209 min Timing: %d ms\n",
793 dec_t209min[s->ibex.t209min]);
794 msg_pdbg2("\n");
795}
796
Jacob Garberbeeb8bc2019-06-21 15:24:17 -0600797static void prettyprint_ich_descriptor_straps_cougar(const struct ich_desc_south_strap *s)
Stefan Taunerb3850962011-12-24 00:00:32 +0000798{
799 msg_pdbg2("--- PCH ---\n");
800
801 /* PCHSTRP0 */
802 msg_pdbg2("Chipset configuration Softstrap 1: %d\n", s->cougar.cs_ss1);
803 msg_pdbg2("Intel ME SMBus Select is %sabled.\n",
804 s->ibex.SMB_EN ? "en" : "dis");
805 msg_pdbg2("SMLink0 segment is %sabled.\n",
806 s->ibex.SML0_EN ? "en" : "dis");
807 msg_pdbg2("SMLink1 segment is %sabled.\n",
808 s->ibex.SML1_EN ? "en" : "dis");
809 msg_pdbg2("SMLink1 Frequency: %s\n",
810 (s->ibex.SML1FRQ == 1) ? "100 kHz" : "reserved");
811 msg_pdbg2("Intel ME SMBus Frequency: %s\n",
812 (s->ibex.SMB0FRQ == 1) ? "100 kHz" : "reserved");
813 msg_pdbg2("SMLink0 Frequency: %s\n",
814 (s->ibex.SML0FRQ == 1) ? "100 kHz" : "reserved");
815 msg_pdbg2("GPIO12 is used as %s.\n", s->ibex.LANPHYPC_GP12_SEL ?
816 "LAN_PHY_PWR_CTRL" : "general purpose output");
817 msg_pdbg2("LinkSec is %sabled.\n",
818 s->cougar.LINKSEC_DIS ? "en" : "dis");
819 msg_pdbg2("DMI RequesterID Checks are %sabled.\n",
820 s->ibex.DMI_REQID_DIS ? "en" : "dis");
821 msg_pdbg2("BIOS Boot-Block size (BBBS): %d kB.\n",
822 1 << (6 + s->ibex.BBBS));
823
824 /* PCHSTRP1 */
825 msg_pdbg2("Chipset configuration Softstrap 3: 0x%x\n", s->ibex.cs_ss3);
826 msg_pdbg2("Chipset configuration Softstrap 2: 0x%x\n", s->ibex.cs_ss2);
827
828 /* PCHSTRP2 */
829 msg_pdbg2("ME SMBus ASD address is %sabled.\n",
830 s->ibex.MESMASDEN ? "en" : "dis");
831 msg_pdbg2("ME SMBus Controller ASD Target address: 0x%02x\n",
832 s->ibex.MESMASDA);
833 msg_pdbg2("ME SMBus MCTP Address is %sabled.\n",
834 s->cougar.MESMMCTPAEN ? "en" : "dis");
835 msg_pdbg2("ME SMBus MCTP target address: 0x%02x\n",
836 s->cougar.MESMMCTPA);
837 msg_pdbg2("ME SMBus I2C address is %sabled.\n",
838 s->ibex.MESMI2CEN ? "en" : "dis");
839 msg_pdbg2("ME SMBus I2C target address: 0x%02x\n",
840 s->ibex.MESMI2CA);
841
842 /* PCHSTRP3 */
843 prettyprint_ich_descriptor_pchstraps45678_56(s);
844 /* PCHSTRP9 */
845 prettyprint_ich_descriptor_straps_56_pciecs(s->ibex.PCIEPCS1, 0);
846 prettyprint_ich_descriptor_straps_56_pciecs(s->ibex.PCIEPCS1, 1);
847 msg_pdbg2("PCIe Lane Reversal 1: PCIe Lanes 0-3 are %sreserved.\n",
848 s->ibex.PCIELR1 ? "" : "not ");
849 msg_pdbg2("PCIe Lane Reversal 2: PCIe Lanes 4-7 are %sreserved.\n",
850 s->ibex.PCIELR2 ? "" : "not ");
851 msg_pdbg2("DMI Lane Reversal: DMI Lanes 0-3 are %sreserved.\n",
852 s->ibex.DMILR ? "" : "not ");
853 msg_pdbg2("ME Debug status writes over SMBUS are %sabled.\n",
854 s->cougar.MDSMBE_EN ? "en" : "dis");
855 msg_pdbg2("ME Debug SMBus Emergency Mode address: 0x%02x (raw)\n",
856 s->cougar.MDSMBE_ADD);
857 msg_pdbg2("Default PHY PCIe Port is %d.\n", s->ibex.PHY_PCIEPORTSEL+1);
858 msg_pdbg2("Integrated MAC/PHY communication over PCIe is %sabled.\n",
859 s->ibex.PHY_PCIE_EN ? "en" : "dis");
860 msg_pdbg2("PCIe ports Subtractive Decode Agent is %sabled.\n",
861 s->cougar.SUB_DECODE_EN ? "en" : "dis");
862 msg_pdbg2("GPIO74 is used as %s.\n", s->cougar.PCHHOT_SML1ALERT_SEL ?
863 "PCHHOT#" : "SML1ALERT#");
864
865 /* PCHSTRP10 */
866 msg_pdbg2("Management Engine will boot from %sflash.\n",
867 s->ibex.ME_BOOT_FLASH ? "" : "ROM, then ");
868
869 msg_pdbg2("ME Debug SMBus Emergency Mode is %sabled.\n",
870 s->cougar.MDSMBE_EN ? "en" : "dis");
871 msg_pdbg2("ME Debug SMBus Emergency Mode Address: 0x%02x\n",
872 s->cougar.MDSMBE_ADD);
873
874 msg_pdbg2("Integrated Clocking Configuration used: %d\n",
875 s->cougar.ICC_SEL);
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000876 msg_pdbg2("PCH Signal CL_RST1# does %sassert when Intel ME performs a reset.\n",
877 s->ibex.MER_CL1 ? "" : "not ");
Stefan Taunerb3850962011-12-24 00:00:32 +0000878 msg_pdbg2("ICC Profile is selected by %s.\n",
879 s->cougar.ICC_PRO_SEL ? "Softstraps" : "BIOS");
880 msg_pdbg2("Deep SX is %ssupported on the platform.\n",
881 s->cougar.Deep_SX_EN ? "not " : "");
882 msg_pdbg2("ME Debug LAN Emergency Mode is %sabled.\n",
883 s->cougar.ME_DBG_LAN ? "en" : "dis");
884
885 prettyprint_ich_descriptor_pchstraps111213_56(s);
886
887 /* PCHSTRP14 */
888 /* PCHSTRP15 */
889 msg_pdbg2("Chipset configuration Softstrap 6: %d\n", s->cougar.cs_ss6);
890 msg_pdbg2("Integrated wired LAN is %sabled.\n",
891 s->cougar.IWL_EN ? "en" : "dis");
892 msg_pdbg2("Chipset configuration Softstrap 5: %d\n", s->cougar.cs_ss5);
893 msg_pdbg2("SMLink1 provides temperature from %s.\n",
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000894 s->cougar.SMLINK1_THERM_SEL ? "PCH only" : "the CPU, PCH and DIMMs");
Stefan Taunerb3850962011-12-24 00:00:32 +0000895 msg_pdbg2("GPIO29 is used as %s.\n", s->cougar.SLP_LAN_GP29_SEL ?
896 "general purpose output" : "SLP_LAN#");
897
898 /* PCHSTRP16 */
899 /* PCHSTRP17 */
900 msg_pdbg2("Integrated Clock: %s Clock Mode\n",
901 s->cougar.ICML ? "Buffered Through" : "Full Integrated");
902 msg_pdbg2("\n");
903}
904
905void prettyprint_ich_descriptor_straps(enum ich_chipset cs, const struct ich_descriptors *desc)
906{
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000907 unsigned int i, max_count;
Stefan Taunerb3850962011-12-24 00:00:32 +0000908 msg_pdbg2("=== Softstraps ===\n");
909
Nico Huber157b8182024-07-19 17:48:12 +0200910 if (has_classic_proc_straps(cs)) {
911 max_count = MIN(ARRAY_SIZE(desc->north.STRPs), desc->content.MSL);
912 if (max_count < desc->content.MSL) {
913 msg_pdbg2("MSL (%u) is greater than the current maximum of %u entries.\n",
914 desc->content.MSL, max_count);
915 msg_pdbg2("Only the first %u entries will be printed.\n", max_count);
916 }
Stefan Taunerb3850962011-12-24 00:00:32 +0000917
Nico Huber157b8182024-07-19 17:48:12 +0200918 msg_pdbg2("--- North/MCH/PROC (%d entries) ---\n", max_count);
919 for (i = 0; i < max_count; i++)
920 msg_pdbg2("STRP%-2d = 0x%08x\n", i, desc->north.STRPs[i]);
921 msg_pdbg2("\n");
922 }
Stefan Taunerb3850962011-12-24 00:00:32 +0000923
Nico Huber519be662018-12-23 20:03:35 +0100924 max_count = MIN(ARRAY_SIZE(desc->south.STRPs), desc->content.ISL);
Nico Huberd7c75522017-03-29 16:31:49 +0200925 if (max_count < desc->content.ISL) {
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000926 msg_pdbg2("ISL (%u) is greater than the current maximum of %u entries.\n",
927 desc->content.ISL, max_count);
928 msg_pdbg2("Only the first %u entries will be printed.\n", max_count);
Nico Huberd7c75522017-03-29 16:31:49 +0200929 }
Stefan Taunerb3850962011-12-24 00:00:32 +0000930
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000931 msg_pdbg2("--- South/ICH/PCH (%d entries) ---\n", max_count);
932 for (i = 0; i < max_count; i++)
Stefan Taunerb3850962011-12-24 00:00:32 +0000933 msg_pdbg2("STRP%-2d = 0x%08x\n", i, desc->south.STRPs[i]);
934 msg_pdbg2("\n");
935
936 switch (cs) {
937 case CHIPSET_ICH8:
938 if (sizeof(desc->north.ich8) / 4 != desc->content.MSL)
939 msg_pdbg2("Detailed North/MCH/PROC information is "
940 "probably not reliable, printing anyway.\n");
941 if (sizeof(desc->south.ich8) / 4 != desc->content.ISL)
942 msg_pdbg2("Detailed South/ICH/PCH information is "
943 "probably not reliable, printing anyway.\n");
944 prettyprint_ich_descriptor_straps_ich8(desc);
945 break;
946 case CHIPSET_5_SERIES_IBEX_PEAK:
947 /* PCH straps only. PROCSTRPs are unknown. */
948 if (sizeof(desc->south.ibex) / 4 != desc->content.ISL)
949 msg_pdbg2("Detailed South/ICH/PCH information is "
950 "probably not reliable, printing anyway.\n");
951 prettyprint_ich_descriptor_straps_ibex(&desc->south);
952 break;
953 case CHIPSET_6_SERIES_COUGAR_POINT:
954 /* PCH straps only. PROCSTRP0 is "reserved". */
955 if (sizeof(desc->south.cougar) / 4 != desc->content.ISL)
956 msg_pdbg2("Detailed South/ICH/PCH information is "
957 "probably not reliable, printing anyway.\n");
958 prettyprint_ich_descriptor_straps_cougar(&desc->south);
959 break;
960 case CHIPSET_ICH_UNKNOWN:
961 break;
962 default:
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000963 msg_pdbg2("The meaning of the descriptor straps are unknown yet.\n\n");
Stefan Taunerb3850962011-12-24 00:00:32 +0000964 break;
965 }
966}
967
Jacob Garberbeeb8bc2019-06-21 15:24:17 -0600968static void prettyprint_rdid(uint32_t reg_val)
Stefan Taunerb3850962011-12-24 00:00:32 +0000969{
970 uint8_t mid = reg_val & 0xFF;
971 uint16_t did = ((reg_val >> 16) & 0xFF) | (reg_val & 0xFF00);
972 msg_pdbg2("Manufacturer ID 0x%02x, Device ID 0x%04x\n", mid, did);
973}
974
975void prettyprint_ich_descriptor_upper_map(const struct ich_desc_upper_map *umap)
976{
977 int i;
978 msg_pdbg2("=== Upper Map Section ===\n");
979 msg_pdbg2("FLUMAP1 0x%08x\n", umap->FLUMAP1);
980 msg_pdbg2("\n");
981
982 msg_pdbg2("--- Details ---\n");
983 msg_pdbg2("VTL (length in DWORDS) = %d\n", umap->VTL);
984 msg_pdbg2("VTBA (base address) = 0x%6.6x\n", getVTBA(umap));
985 msg_pdbg2("\n");
986
987 msg_pdbg2("VSCC Table: %d entries\n", umap->VTL/2);
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000988 for (i = 0; i < umap->VTL/2; i++) {
Stefan Taunerb3850962011-12-24 00:00:32 +0000989 uint32_t jid = umap->vscc_table[i].JID;
990 uint32_t vscc = umap->vscc_table[i].VSCC;
991 msg_pdbg2(" JID%d = 0x%08x\n", i, jid);
992 msg_pdbg2(" VSCC%d = 0x%08x\n", i, vscc);
Martin Rothf6c1cb12022-03-15 10:55:25 -0600993 msg_pdbg2(" "); /* indentation */
Stefan Taunerb3850962011-12-24 00:00:32 +0000994 prettyprint_rdid(jid);
Martin Rothf6c1cb12022-03-15 10:55:25 -0600995 msg_pdbg2(" "); /* indentation */
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000996 prettyprint_ich_reg_vscc(vscc, 0, false);
Stefan Taunerb3850962011-12-24 00:00:32 +0000997 }
998 msg_pdbg2("\n");
999}
1000
David Hendricks66565a72021-09-20 21:56:40 -07001001static inline void warn_peculiar_desc(const char *const name)
Nico Huber964007a2021-06-17 21:12:47 +02001002{
Nico Huber964007a2021-06-17 21:12:47 +02001003 msg_pwarn("Peculiar flash descriptor, assuming %s compatibility.\n", name);
1004}
1005
Nico Huber1dc3d422017-06-17 00:09:31 +02001006/*
1007 * Guesses a minimum chipset version based on the maximum number of
Nico Huber3ad9aad2021-06-17 22:05:00 +02001008 * soft straps per generation and presence of the MIP base (MDTBA).
Nico Huber1dc3d422017-06-17 00:09:31 +02001009 */
Nico Huberdb878fb2024-07-19 17:37:09 +02001010static enum ich_chipset guess_ich_chipset(const struct ich_desc_content *const content,
1011 const struct ich_desc_upper_map *const upper)
Nico Huber1dc3d422017-06-17 00:09:31 +02001012{
1013 if (content->ICCRIBA == 0x00) {
1014 if (content->MSL == 0 && content->ISL <= 2)
1015 return CHIPSET_ICH8;
Nico Huber83b01c82021-06-17 21:20:09 +02001016 if (content->ISL <= 2)
Nico Huber1dc3d422017-06-17 00:09:31 +02001017 return CHIPSET_ICH9;
Nico Huber83b01c82021-06-17 21:20:09 +02001018 if (content->ISL <= 10)
Nico Huber1dc3d422017-06-17 00:09:31 +02001019 return CHIPSET_ICH10;
David Hendricks66565a72021-09-20 21:56:40 -07001020 if (content->ISL <= 16)
1021 return CHIPSET_5_SERIES_IBEX_PEAK;
Nico Huber83b01c82021-06-17 21:20:09 +02001022 if (content->FLMAP2 == 0) {
Nico Huber81965f32021-06-17 23:25:35 +02001023 if (content->ISL == 19)
1024 return CHIPSET_APOLLO_LAKE;
David Hendricks66565a72021-09-20 21:56:40 -07001025 if (content->ISL == 23)
1026 return CHIPSET_GEMINI_LAKE;
1027 warn_peculiar_desc("Gemini Lake");
Nico Huber81965f32021-06-17 23:25:35 +02001028 return CHIPSET_GEMINI_LAKE;
Nico Huberd2d39932019-01-18 16:49:37 +01001029 }
Nico Huber42daab12024-07-16 00:27:27 +02001030 if (content->NM == 6) {
1031 /* 0x8b is from the SPI Guide, but not yet seen in the wild. */
1032 if (0x50 <= content->ISL && content->ISL <= 0x8b)
1033 return CHIPSET_C740_SERIES_EMMITSBURG;
1034 warn_peculiar_desc("C740 series");
1035 return CHIPSET_C740_SERIES_EMMITSBURG;
1036 }
David Hendricks66565a72021-09-20 21:56:40 -07001037 warn_peculiar_desc("Ibex Peak");
Nico Huber1dc3d422017-06-17 00:09:31 +02001038 return CHIPSET_5_SERIES_IBEX_PEAK;
Nico Huber3ad9aad2021-06-17 22:05:00 +02001039 } else if (upper->MDTBA == 0x00) {
1040 if (content->ICCRIBA < 0x31 && content->FMSBA < 0x30) {
1041 if (content->MSL == 0 && content->ISL <= 17)
1042 return CHIPSET_BAYTRAIL;
1043 if (content->MSL <= 1 && content->ISL <= 18)
1044 return CHIPSET_6_SERIES_COUGAR_POINT;
David Hendricks66565a72021-09-20 21:56:40 -07001045 if (content->MSL <= 1 && content->ISL <= 21)
1046 return CHIPSET_8_SERIES_LYNX_POINT;
1047 warn_peculiar_desc("Lynx Point");
Nico Huber81965f32021-06-17 23:25:35 +02001048 return CHIPSET_8_SERIES_LYNX_POINT;
Nico Huber3ad9aad2021-06-17 22:05:00 +02001049 }
1050 if (content->NM == 6) {
David Hendricks66565a72021-09-20 21:56:40 -07001051 if (content->ICCRIBA <= 0x34)
1052 return CHIPSET_C620_SERIES_LEWISBURG;
1053 warn_peculiar_desc("C620 series");
Nico Huber2a5dfaf2019-07-04 16:01:51 +02001054 return CHIPSET_C620_SERIES_LEWISBURG;
Nico Huber3ad9aad2021-06-17 22:05:00 +02001055 }
David Hendricks66565a72021-09-20 21:56:40 -07001056 if (content->ICCRIBA == 0x31)
1057 return CHIPSET_100_SERIES_SUNRISE_POINT;
1058 warn_peculiar_desc("100 series");
Nico Huber83b01c82021-06-17 21:20:09 +02001059 return CHIPSET_100_SERIES_SUNRISE_POINT;
Nico Huber0ef2eb82024-07-19 21:38:17 +02001060 } else if (content->FLMAP2 == 0xffffffff) {
1061 if (content->ISL == 0x8f)
1062 return CHIPSET_SNOW_RIDGE;
1063 warn_peculiar_desc("Snow Ridge");
1064 return CHIPSET_SNOW_RIDGE;
Nico Huber1dc3d422017-06-17 00:09:31 +02001065 } else {
David Hendricks66565a72021-09-20 21:56:40 -07001066 if (content->ICCRIBA == 0x34)
1067 return CHIPSET_300_SERIES_CANNON_POINT;
Michał Żygowski5c9f5422021-06-16 15:13:54 +02001068 if (content->CSSL == 0x11)
1069 return CHIPSET_500_SERIES_TIGER_POINT;
Nico Huber29c23dd2022-12-21 15:25:09 +00001070 if (content->CSSL == 0x14) /* backwards compatible Alder Point */
1071 return CHIPSET_500_SERIES_TIGER_POINT;
Nico Huber756b6b32022-12-21 17:15:13 +00001072 if (content->CSSL == 0x03) {
Nico Huber5e0d9b02024-07-19 21:44:52 +02001073 if (content->CSSO == 0x58) {
Nico Huber756b6b32022-12-21 17:15:13 +00001074 return CHIPSET_ELKHART_LAKE;
Nico Huber5e0d9b02024-07-19 21:44:52 +02001075 } else if (content->CSSO == 0x6c) { /* backwards compatible Jasper Lake */
Nico Huber756b6b32022-12-21 17:15:13 +00001076 return CHIPSET_300_SERIES_CANNON_POINT;
Nico Huber5e0d9b02024-07-19 21:44:52 +02001077 } else if (content->CSSO == 0x70) {
1078 if (content->ISL == 0x82)
1079 return CHIPSET_METEOR_LAKE;
1080 }
1081 }
1082 if (content->ISL >= 0x82) {
1083 warn_peculiar_desc("Meteor Lake");
1084 return CHIPSET_METEOR_LAKE;
Nico Huber756b6b32022-12-21 17:15:13 +00001085 }
Michał Żygowski5c9f5422021-06-16 15:13:54 +02001086 msg_pwarn("Unknown flash descriptor, assuming 500 series compatibility.\n");
1087 return CHIPSET_500_SERIES_TIGER_POINT;
Nico Huber1dc3d422017-06-17 00:09:31 +02001088 }
1089}
1090
Stefan Taunerb3850962011-12-24 00:00:32 +00001091/* len is the length of dump in bytes */
Nico Huberfa622942017-03-24 17:25:37 +01001092int read_ich_descriptors_from_dump(const uint32_t *const dump, const size_t len,
1093 enum ich_chipset *const cs, struct ich_descriptors *const desc)
Stefan Taunerb3850962011-12-24 00:00:32 +00001094{
Nico Huber519be662018-12-23 20:03:35 +01001095 ssize_t i, max_count;
1096 size_t pch_bug_offset = 0;
Stefan Taunerb3850962011-12-24 00:00:32 +00001097
1098 if (dump == NULL || desc == NULL)
1099 return ICH_RET_PARAM;
1100
1101 if (dump[0] != DESCRIPTOR_MODE_SIGNATURE) {
1102 if (dump[4] == DESCRIPTOR_MODE_SIGNATURE)
1103 pch_bug_offset = 4;
1104 else
1105 return ICH_RET_ERR;
1106 }
1107
1108 /* map */
Nico Huber9e14aed2017-03-28 17:08:46 +02001109 if (len < (4 + pch_bug_offset) * 4)
Stefan Taunerb3850962011-12-24 00:00:32 +00001110 return ICH_RET_OOB;
1111 desc->content.FLVALSIG = dump[0 + pch_bug_offset];
1112 desc->content.FLMAP0 = dump[1 + pch_bug_offset];
1113 desc->content.FLMAP1 = dump[2 + pch_bug_offset];
1114 desc->content.FLMAP2 = dump[3 + pch_bug_offset];
1115
1116 /* component */
Nico Huber9e14aed2017-03-28 17:08:46 +02001117 if (len < getFCBA(&desc->content) + 3 * 4)
Stefan Taunerb3850962011-12-24 00:00:32 +00001118 return ICH_RET_OOB;
1119 desc->component.FLCOMP = dump[(getFCBA(&desc->content) >> 2) + 0];
1120 desc->component.FLILL = dump[(getFCBA(&desc->content) >> 2) + 1];
1121 desc->component.FLPB = dump[(getFCBA(&desc->content) >> 2) + 2];
1122
Nico Huber8a03c902021-06-17 21:23:29 +02001123 /* upper map */
1124 desc->upper.FLUMAP1 = dump[(UPPER_MAP_OFFSET >> 2) + 0];
1125
1126 /* VTL is 8 bits long. Quote from the Ibex Peak SPI programming guide:
1127 * "Identifies the 1s based number of DWORDS contained in the VSCC
1128 * Table. Each SPI component entry in the table is 2 DWORDS long." So
1129 * the maximum of 255 gives us 127.5 SPI components(!?) 8 bytes each. A
1130 * check ensures that the maximum offset actually accessed is available.
1131 */
1132 if (len < getVTBA(&desc->upper) + (desc->upper.VTL / 2 * 8))
1133 return ICH_RET_OOB;
1134
1135 for (i = 0; i < desc->upper.VTL/2; i++) {
1136 desc->upper.vscc_table[i].JID = dump[(getVTBA(&desc->upper) >> 2) + i * 2 + 0];
1137 desc->upper.vscc_table[i].VSCC = dump[(getVTBA(&desc->upper) >> 2) + i * 2 + 1];
1138 }
1139
Nico Huber67d71792017-06-17 03:10:15 +02001140 if (*cs == CHIPSET_ICH_UNKNOWN) {
Nico Huberdb878fb2024-07-19 17:37:09 +02001141 *cs = guess_ich_chipset(&desc->content, &desc->upper);
Nico Huber67d71792017-06-17 03:10:15 +02001142 prettyprint_ich_chipset(*cs);
1143 }
Nico Huberfa622942017-03-24 17:25:37 +01001144
Stefan Taunerb3850962011-12-24 00:00:32 +00001145 /* region */
Nico Huberfa622942017-03-24 17:25:37 +01001146 const ssize_t nr = ich_number_of_regions(*cs, &desc->content);
Nico Huber519be662018-12-23 20:03:35 +01001147 if (nr < 0 || len < getFRBA(&desc->content) + (size_t)nr * 4)
Stefan Taunerb3850962011-12-24 00:00:32 +00001148 return ICH_RET_OOB;
Nico Huberfa622942017-03-24 17:25:37 +01001149 for (i = 0; i < nr; i++)
1150 desc->region.FLREGs[i] = dump[(getFRBA(&desc->content) >> 2) + i];
Stefan Taunerb3850962011-12-24 00:00:32 +00001151
1152 /* master */
Nico Huberfa622942017-03-24 17:25:37 +01001153 const ssize_t nm = ich_number_of_masters(*cs, &desc->content);
Nico Huber519be662018-12-23 20:03:35 +01001154 if (nm < 0 || len < getFMBA(&desc->content) + (size_t)nm * 4)
Stefan Taunerb3850962011-12-24 00:00:32 +00001155 return ICH_RET_OOB;
Nico Huberfa622942017-03-24 17:25:37 +01001156 for (i = 0; i < nm; i++)
1157 desc->master.FLMSTRs[i] = dump[(getFMBA(&desc->content) >> 2) + i];
Stefan Taunerb3850962011-12-24 00:00:32 +00001158
Nico Huber157b8182024-07-19 17:48:12 +02001159 if (has_classic_proc_straps(*cs)) {
1160 /* MCH/PROC (aka. North) straps */
1161 if (len < getFMSBA(&desc->content) + desc->content.MSL * 4)
1162 return ICH_RET_OOB;
Stefan Taunerb3850962011-12-24 00:00:32 +00001163
Nico Huber157b8182024-07-19 17:48:12 +02001164 /* limit the range to be written */
1165 max_count = MIN(sizeof(desc->north.STRPs) / 4, desc->content.MSL);
1166 for (i = 0; i < max_count; i++)
1167 desc->north.STRPs[i] = dump[(getFMSBA(&desc->content) >> 2) + i];
1168 }
Stefan Taunerb3850962011-12-24 00:00:32 +00001169
1170 /* ICH/PCH (aka. South) straps */
1171 if (len < getFISBA(&desc->content) + desc->content.ISL * 4)
1172 return ICH_RET_OOB;
1173
1174 /* limit the range to be written */
Nico Huber519be662018-12-23 20:03:35 +01001175 max_count = MIN(sizeof(desc->south.STRPs) / 4, desc->content.ISL);
Stefan Taunera1a14ec2012-08-13 08:45:13 +00001176 for (i = 0; i < max_count; i++)
1177 desc->south.STRPs[i] = dump[(getFISBA(&desc->content) >> 2) + i];
Stefan Taunerb3850962011-12-24 00:00:32 +00001178
1179 return ICH_RET_OK;
1180}
1181
Nico Huberad186312016-05-02 15:15:29 +02001182#ifndef ICH_DESCRIPTORS_FROM_DUMP_ONLY
Stefan Taunerb3850962011-12-24 00:00:32 +00001183
Stefan Taunerd0c5dc22011-10-20 12:57:14 +00001184/** Returns the integer representation of the component density with index
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001185\em idx in bytes or -1 if the correct size can not be determined. */
1186int getFCBA_component_density(enum ich_chipset cs, const struct ich_descriptors *desc, uint8_t idx)
Stefan Taunerd0c5dc22011-10-20 12:57:14 +00001187{
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001188 if (idx > 1) {
Stefan Taunera1a14ec2012-08-13 08:45:13 +00001189 msg_perr("Only ICH SPI component index 0 or 1 are supported yet.\n");
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001190 return -1;
Stefan Taunerd0c5dc22011-10-20 12:57:14 +00001191 }
Nico Huberdfd06472024-07-14 23:45:05 +02001192 if (cs == CHIPSET_ICH_UNKNOWN) {
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001193 msg_pwarn("Density encoding is unknown on this chipset.\n");
1194 return -1;
Stefan Taunerd0c5dc22011-10-20 12:57:14 +00001195 }
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001196
Nico Huberdfd06472024-07-14 23:45:05 +02001197 if (desc->content.NC == 0 && idx > 0)
1198 return 0;
1199
1200 const unsigned int max_idx = cs < CHIPSET_HAS_NEW_COMPONENT_DENSITY ? 5 : 7;
1201 const unsigned int size_idx = get_density_index(cs, desc, idx);
1202
1203 if (size_idx > max_idx) {
Tai-Hong Wu60dead42015-01-05 23:00:14 +00001204 msg_perr("Density of ICH SPI component with index %d is invalid.\n"
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001205 "Encoded density is 0x%x while maximum allowed is 0x%x.\n",
Nico Huberdfd06472024-07-14 23:45:05 +02001206 idx, size_idx, max_idx);
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001207 return -1;
1208 }
1209
Nico Huberdfd06472024-07-14 23:45:05 +02001210 return 1 << (19 + size_idx);
Stefan Taunerd0c5dc22011-10-20 12:57:14 +00001211}
1212
Nico Huber8d494992017-06-19 12:18:33 +02001213/* Only used by ichspi.c */
1214#if CONFIG_INTERNAL == 1 && (defined(__i386__) || defined(__x86_64__))
Nico Huberd54e4f42017-03-23 23:45:47 +01001215static uint32_t read_descriptor_reg(enum ich_chipset cs, uint8_t section, uint16_t offset, void *spibar)
Stefan Tauner1e146392011-09-15 23:52:55 +00001216{
1217 uint32_t control = 0;
1218 control |= (section << FDOC_FDSS_OFF) & FDOC_FDSS;
1219 control |= (offset << FDOC_FDSI_OFF) & FDOC_FDSI;
Nico Huberb2ad9fd2024-07-14 23:18:53 +02001220
1221 if (cs >= SPI_ENGINE_PCH100) {
Nico Huberd54e4f42017-03-23 23:45:47 +01001222 mmio_le_writel(control, spibar + PCH100_REG_FDOC);
1223 return mmio_le_readl(spibar + PCH100_REG_FDOD);
Nico Huberb2ad9fd2024-07-14 23:18:53 +02001224 } else {
Nico Huberd54e4f42017-03-23 23:45:47 +01001225 mmio_le_writel(control, spibar + ICH9_REG_FDOC);
1226 return mmio_le_readl(spibar + ICH9_REG_FDOD);
1227 }
Stefan Tauner1e146392011-09-15 23:52:55 +00001228}
1229
Nico Huberd54e4f42017-03-23 23:45:47 +01001230int read_ich_descriptors_via_fdo(enum ich_chipset cs, void *spibar, struct ich_descriptors *desc)
Stefan Tauner1e146392011-09-15 23:52:55 +00001231{
Nico Huber519be662018-12-23 20:03:35 +01001232 ssize_t i;
Stefan Tauner1e146392011-09-15 23:52:55 +00001233 struct ich_desc_region *r = &desc->region;
1234
1235 /* Test if bit-fields are working as expected.
1236 * FIXME: Replace this with dynamic bitfield fixup
1237 */
1238 for (i = 0; i < 4; i++)
1239 desc->region.FLREGs[i] = 0x5A << (i * 8);
Nico Huberfa622942017-03-24 17:25:37 +01001240 if (r->old_reg[0].base != 0x005A || r->old_reg[0].limit != 0x0000 ||
1241 r->old_reg[1].base != 0x1A00 || r->old_reg[1].limit != 0x0000 ||
1242 r->old_reg[2].base != 0x0000 || r->old_reg[2].limit != 0x005A ||
1243 r->old_reg[3].base != 0x0000 || r->old_reg[3].limit != 0x1A00) {
Stefan Tauner1e146392011-09-15 23:52:55 +00001244 msg_pdbg("The combination of compiler and CPU architecture used"
1245 "does not lay out bit-fields as expected, sorry.\n");
Nico Huberfa622942017-03-24 17:25:37 +01001246 msg_pspew("r->old_reg[0].base = 0x%04X (0x005A)\n", r->old_reg[0].base);
1247 msg_pspew("r->old_reg[0].limit = 0x%04X (0x0000)\n", r->old_reg[0].limit);
1248 msg_pspew("r->old_reg[1].base = 0x%04X (0x1A00)\n", r->old_reg[1].base);
1249 msg_pspew("r->old_reg[1].limit = 0x%04X (0x0000)\n", r->old_reg[1].limit);
1250 msg_pspew("r->old_reg[2].base = 0x%04X (0x0000)\n", r->old_reg[2].base);
1251 msg_pspew("r->old_reg[2].limit = 0x%04X (0x005A)\n", r->old_reg[2].limit);
1252 msg_pspew("r->old_reg[3].base = 0x%04X (0x0000)\n", r->old_reg[3].base);
1253 msg_pspew("r->old_reg[3].limit = 0x%04X (0x1A00)\n", r->old_reg[3].limit);
Stefan Tauner1e146392011-09-15 23:52:55 +00001254 return ICH_RET_ERR;
1255 }
1256
Stefan Taunera1a14ec2012-08-13 08:45:13 +00001257 msg_pdbg2("Reading flash descriptors mapped by the chipset via FDOC/FDOD...");
Stefan Tauner1e146392011-09-15 23:52:55 +00001258 /* content section */
Nico Huberd54e4f42017-03-23 23:45:47 +01001259 desc->content.FLVALSIG = read_descriptor_reg(cs, 0, 0, spibar);
1260 desc->content.FLMAP0 = read_descriptor_reg(cs, 0, 1, spibar);
1261 desc->content.FLMAP1 = read_descriptor_reg(cs, 0, 2, spibar);
1262 desc->content.FLMAP2 = read_descriptor_reg(cs, 0, 3, spibar);
Stefan Tauner1e146392011-09-15 23:52:55 +00001263
1264 /* component section */
Nico Huberd54e4f42017-03-23 23:45:47 +01001265 desc->component.FLCOMP = read_descriptor_reg(cs, 1, 0, spibar);
1266 desc->component.FLILL = read_descriptor_reg(cs, 1, 1, spibar);
1267 desc->component.FLPB = read_descriptor_reg(cs, 1, 2, spibar);
Stefan Tauner1e146392011-09-15 23:52:55 +00001268
1269 /* region section */
Nico Huberfa622942017-03-24 17:25:37 +01001270 const ssize_t nr = ich_number_of_regions(cs, &desc->content);
1271 if (nr < 0) {
Stefan Tauner1e146392011-09-15 23:52:55 +00001272 msg_pdbg2("%s: number of regions too high (%d) - failed\n",
Nico Huberfa622942017-03-24 17:25:37 +01001273 __func__, desc->content.NR + 1);
Stefan Tauner1e146392011-09-15 23:52:55 +00001274 return ICH_RET_ERR;
1275 }
Nico Huberfa622942017-03-24 17:25:37 +01001276 for (i = 0; i < nr; i++)
Nico Huberd54e4f42017-03-23 23:45:47 +01001277 desc->region.FLREGs[i] = read_descriptor_reg(cs, 2, i, spibar);
Stefan Tauner1e146392011-09-15 23:52:55 +00001278
1279 /* master section */
Nico Huberfa622942017-03-24 17:25:37 +01001280 const ssize_t nm = ich_number_of_masters(cs, &desc->content);
1281 if (nm < 0) {
1282 msg_pdbg2("%s: number of masters too high (%d) - failed\n",
1283 __func__, desc->content.NM + 1);
1284 return ICH_RET_ERR;
1285 }
1286 for (i = 0; i < nm; i++)
1287 desc->master.FLMSTRs[i] = read_descriptor_reg(cs, 3, i, spibar);
Stefan Tauner1e146392011-09-15 23:52:55 +00001288
1289 /* Accessing the strap section via FDOC/D is only possible on ICH8 and
1290 * reading the upper map is impossible on all chipsets, so don't bother.
1291 */
1292
1293 msg_pdbg2(" done.\n");
1294 return ICH_RET_OK;
1295}
Nico Huber8d494992017-06-19 12:18:33 +02001296#endif
Nico Huber305f4172013-06-14 11:55:26 +02001297
1298/**
1299 * @brief Read a layout from the dump of an Intel ICH descriptor.
1300 *
1301 * @param layout Pointer where to store the layout.
1302 * @param dump The descriptor dump to read from.
1303 * @param len The length of the descriptor dump.
1304 *
1305 * @return 0 on success,
Nico Huber70461a92019-06-15 14:56:19 +02001306 * 1 if the descriptor couldn't be parsed,
1307 * 2 when out of memory.
Nico Huber305f4172013-06-14 11:55:26 +02001308 */
Nico Huber5bd990c2019-06-16 19:46:46 +02001309int layout_from_ich_descriptors(
Nico Huberc3b02dc2023-08-12 01:13:45 +02001310 struct flashprog_layout **const layout,
Nico Huber5bd990c2019-06-16 19:46:46 +02001311 const void *const dump, const size_t len)
Nico Huber305f4172013-06-14 11:55:26 +02001312{
Nico Huberfa622942017-03-24 17:25:37 +01001313 static const char *const regions[] = {
David Hendricksa5216362017-08-08 20:02:22 -07001314 "fd", "bios", "me", "gbe", "pd", "reg5", "bios2", "reg7", "ec", "reg9", "ie",
1315 "10gbe", "reg12", "reg13", "reg14", "reg15"
Nico Huberfa622942017-03-24 17:25:37 +01001316 };
Nico Huber305f4172013-06-14 11:55:26 +02001317
1318 struct ich_descriptors desc;
Nico Huberfa622942017-03-24 17:25:37 +01001319 enum ich_chipset cs = CHIPSET_ICH_UNKNOWN;
1320 if (read_ich_descriptors_from_dump(dump, len, &cs, &desc))
Nico Huber305f4172013-06-14 11:55:26 +02001321 return 1;
1322
Nico Huberc3b02dc2023-08-12 01:13:45 +02001323 if (flashprog_layout_new(layout))
Nico Huber5bd990c2019-06-16 19:46:46 +02001324 return 2;
Nico Huber305f4172013-06-14 11:55:26 +02001325
Nico Huber92e0b622019-06-15 15:55:11 +02001326 ssize_t i;
Nico Huber519be662018-12-23 20:03:35 +01001327 const ssize_t nr = MIN(ich_number_of_regions(cs, &desc.content), (ssize_t)ARRAY_SIZE(regions));
Nico Huber92e0b622019-06-15 15:55:11 +02001328 for (i = 0; i < nr; ++i) {
Nico Huber305f4172013-06-14 11:55:26 +02001329 const chipoff_t base = ICH_FREG_BASE(desc.region.FLREGs[i]);
Nico Huber0bb3f712017-03-29 16:44:33 +02001330 const chipoff_t limit = ICH_FREG_LIMIT(desc.region.FLREGs[i]);
Nico Huber305f4172013-06-14 11:55:26 +02001331 if (limit <= base)
1332 continue;
Nico Huberc3b02dc2023-08-12 01:13:45 +02001333 if (flashprog_layout_add_region(*layout, base, limit, regions[i])) {
1334 flashprog_layout_release(*layout);
Nico Huber5bd990c2019-06-16 19:46:46 +02001335 *layout = NULL;
Nico Huber70461a92019-06-15 14:56:19 +02001336 return 2;
Nico Huber5bd990c2019-06-16 19:46:46 +02001337 }
Nico Huber305f4172013-06-14 11:55:26 +02001338 }
Nico Huber305f4172013-06-14 11:55:26 +02001339 return 0;
1340}
1341
Nico Huberad186312016-05-02 15:15:29 +02001342#endif /* ICH_DESCRIPTORS_FROM_DUMP_ONLY */