blob: 4c18dfa39a48f3c5df97cd15c24bef63fff04146 [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.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
Stefan Tauner1e146392011-09-15 23:52:55 +000022#include "ich_descriptors.h"
Stefan Taunerb3850962011-12-24 00:00:32 +000023
Nico Huberad186312016-05-02 15:15:29 +020024#ifdef ICH_DESCRIPTORS_FROM_DUMP_ONLY
Stefan Taunerb3850962011-12-24 00:00:32 +000025#include <stdio.h>
Nico Huber305f4172013-06-14 11:55:26 +020026#include <string.h>
Stefan Taunerb3850962011-12-24 00:00:32 +000027#define print(t, ...) printf(__VA_ARGS__)
Nico Huberad186312016-05-02 15:15:29 +020028#endif
29
Stefan Taunerb3850962011-12-24 00:00:32 +000030#define DESCRIPTOR_MODE_SIGNATURE 0x0ff0a55a
31/* The upper map is located in the word before the 256B-long OEM section at the
32 * end of the 4kB-long flash descriptor.
33 */
34#define UPPER_MAP_OFFSET (4096 - 256 - 4)
35#define getVTBA(flumap) (((flumap)->FLUMAP1 << 4) & 0x00000ff0)
36
Nico Huberad186312016-05-02 15:15:29 +020037#include <string.h>
Stefan Tauner1e146392011-09-15 23:52:55 +000038#include "flash.h" /* for msg_* */
39#include "programmer.h"
40
Stefan Taunerb3850962011-12-24 00:00:32 +000041#ifndef min
Nico Huber305f4172013-06-14 11:55:26 +020042#define min(a, b) (((a) < (b)) ? (a) : (b))
Stefan Taunerb3850962011-12-24 00:00:32 +000043#endif
44
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +000045void prettyprint_ich_reg_vscc(uint32_t reg_val, int verbosity, bool print_vcl)
Stefan Tauner1e146392011-09-15 23:52:55 +000046{
47 print(verbosity, "BES=0x%x, ", (reg_val & VSCC_BES) >> VSCC_BES_OFF);
48 print(verbosity, "WG=%d, ", (reg_val & VSCC_WG) >> VSCC_WG_OFF);
49 print(verbosity, "WSR=%d, ", (reg_val & VSCC_WSR) >> VSCC_WSR_OFF);
50 print(verbosity, "WEWS=%d, ", (reg_val & VSCC_WEWS) >> VSCC_WEWS_OFF);
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +000051 print(verbosity, "EO=0x%x", (reg_val & VSCC_EO) >> VSCC_EO_OFF);
52 if (print_vcl)
53 print(verbosity, ", VCL=%d", (reg_val & VSCC_VCL) >> VSCC_VCL_OFF);
54 print(verbosity, "\n");
Stefan Tauner1e146392011-09-15 23:52:55 +000055}
56
57#define getFCBA(cont) (((cont)->FLMAP0 << 4) & 0x00000ff0)
58#define getFRBA(cont) (((cont)->FLMAP0 >> 12) & 0x00000ff0)
59#define getFMBA(cont) (((cont)->FLMAP1 << 4) & 0x00000ff0)
60#define getFISBA(cont) (((cont)->FLMAP1 >> 12) & 0x00000ff0)
61#define getFMSBA(cont) (((cont)->FLMAP2 << 4) & 0x00000ff0)
62
63void prettyprint_ich_descriptors(enum ich_chipset cs, const struct ich_descriptors *desc)
64{
65 prettyprint_ich_descriptor_content(&desc->content);
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +000066 prettyprint_ich_descriptor_component(cs, desc);
Stefan Tauner1e146392011-09-15 23:52:55 +000067 prettyprint_ich_descriptor_region(desc);
68 prettyprint_ich_descriptor_master(&desc->master);
Nico Huberad186312016-05-02 15:15:29 +020069#ifdef ICH_DESCRIPTORS_FROM_DUMP_ONLY
Stefan Taunerb3850962011-12-24 00:00:32 +000070 if (cs >= CHIPSET_ICH8) {
71 prettyprint_ich_descriptor_upper_map(&desc->upper);
72 prettyprint_ich_descriptor_straps(cs, desc);
73 }
Nico Huberad186312016-05-02 15:15:29 +020074#endif /* ICH_DESCRIPTORS_FROM_DUMP_ONLY */
Stefan Tauner1e146392011-09-15 23:52:55 +000075}
76
77void prettyprint_ich_descriptor_content(const struct ich_desc_content *cont)
78{
79 msg_pdbg2("=== Content Section ===\n");
80 msg_pdbg2("FLVALSIG 0x%08x\n", cont->FLVALSIG);
81 msg_pdbg2("FLMAP0 0x%08x\n", cont->FLMAP0);
82 msg_pdbg2("FLMAP1 0x%08x\n", cont->FLMAP1);
83 msg_pdbg2("FLMAP2 0x%08x\n", cont->FLMAP2);
84 msg_pdbg2("\n");
85
86 msg_pdbg2("--- Details ---\n");
Stefan Taunera1a14ec2012-08-13 08:45:13 +000087 msg_pdbg2("NR (Number of Regions): %5d\n", cont->NR + 1);
88 msg_pdbg2("FRBA (Flash Region Base Address): 0x%03x\n", getFRBA(cont));
89 msg_pdbg2("NC (Number of Components): %5d\n", cont->NC + 1);
90 msg_pdbg2("FCBA (Flash Component Base Address): 0x%03x\n", getFCBA(cont));
91 msg_pdbg2("ISL (ICH/PCH Strap Length): %5d\n", cont->ISL);
92 msg_pdbg2("FISBA/FPSBA (Flash ICH/PCH Strap Base Address): 0x%03x\n", getFISBA(cont));
93 msg_pdbg2("NM (Number of Masters): %5d\n", cont->NM + 1);
94 msg_pdbg2("FMBA (Flash Master Base Address): 0x%03x\n", getFMBA(cont));
95 msg_pdbg2("MSL/PSL (MCH/PROC Strap Length): %5d\n", cont->MSL);
96 msg_pdbg2("FMSBA (Flash MCH/PROC Strap Base Address): 0x%03x\n", getFMSBA(cont));
Stefan Tauner1e146392011-09-15 23:52:55 +000097 msg_pdbg2("\n");
98}
99
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000100static const char *pprint_density(enum ich_chipset cs, const struct ich_descriptors *desc, uint8_t idx)
101{
102 if (idx > 1) {
103 msg_perr("Only ICH SPI component index 0 or 1 are supported yet.\n");
104 return NULL;
105 }
106
107 if (desc->content.NC == 0 && idx > 0)
108 return "unused";
109
110 static const char * const size_str[] = {
111 "512 kB", /* 0000 */
112 "1 MB", /* 0001 */
113 "2 MB", /* 0010 */
114 "4 MB", /* 0011 */
115 "8 MB", /* 0100 */
116 "16 MB", /* 0101 */ /* Maximum up to Lynx Point (excl.) */
117 "32 MB", /* 0110 */
118 "64 MB", /* 0111 */
119 };
120
121 switch (cs) {
122 case CHIPSET_ICH8:
123 case CHIPSET_ICH9:
124 case CHIPSET_ICH10:
125 case CHIPSET_5_SERIES_IBEX_PEAK:
126 case CHIPSET_6_SERIES_COUGAR_POINT:
Tai-Hong Wu60dead42015-01-05 23:00:14 +0000127 case CHIPSET_7_SERIES_PANTHER_POINT:
128 case CHIPSET_BAYTRAIL: {
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000129 uint8_t size_enc;
130 if (idx == 0) {
Tai-Hong Wu60dead42015-01-05 23:00:14 +0000131 size_enc = desc->component.dens_old.comp1_density;
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000132 } else {
Tai-Hong Wu60dead42015-01-05 23:00:14 +0000133 size_enc = desc->component.dens_old.comp2_density;
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000134 }
135 if (size_enc > 5)
136 return "reserved";
137 return size_str[size_enc];
138 }
139 case CHIPSET_8_SERIES_LYNX_POINT:
140 case CHIPSET_8_SERIES_LYNX_POINT_LP:
Duncan Laurie823096e2014-08-20 15:39:38 +0000141 case CHIPSET_8_SERIES_WELLSBURG:
Nico Huber51205912017-03-17 17:59:54 +0100142 case CHIPSET_9_SERIES_WILDCAT_POINT:
143 case CHIPSET_9_SERIES_WILDCAT_POINT_LP: {
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000144 uint8_t size_enc;
145 if (idx == 0) {
Tai-Hong Wu60dead42015-01-05 23:00:14 +0000146 size_enc = desc->component.dens_new.comp1_density;
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000147 } else {
Tai-Hong Wu60dead42015-01-05 23:00:14 +0000148 size_enc = desc->component.dens_new.comp2_density;
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000149 }
150 if (size_enc > 7)
151 return "reserved";
152 return size_str[size_enc];
153 }
154 case CHIPSET_ICH_UNKNOWN:
155 default:
156 return "unknown";
157 }
158}
159
160static const char *pprint_freq(enum ich_chipset cs, uint8_t value)
Stefan Tauner1e146392011-09-15 23:52:55 +0000161{
162 static const char * const freq_str[8] = {
163 "20 MHz", /* 000 */
164 "33 MHz", /* 001 */
165 "reserved", /* 010 */
166 "reserved", /* 011 */
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000167 "50 MHz", /* 100 */ /* New since Ibex Peak */
Stefan Tauner1e146392011-09-15 23:52:55 +0000168 "reserved", /* 101 */
169 "reserved", /* 110 */
170 "reserved" /* 111 */
171 };
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000172
173 switch (cs) {
174 case CHIPSET_ICH8:
175 case CHIPSET_ICH9:
176 case CHIPSET_ICH10:
177 if (value > 1)
178 return "reserved";
179 case CHIPSET_5_SERIES_IBEX_PEAK:
180 case CHIPSET_6_SERIES_COUGAR_POINT:
181 case CHIPSET_7_SERIES_PANTHER_POINT:
182 case CHIPSET_8_SERIES_LYNX_POINT:
Duncan Laurie4095ed72014-08-20 15:39:32 +0000183 case CHIPSET_BAYTRAIL:
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000184 case CHIPSET_8_SERIES_LYNX_POINT_LP:
185 case CHIPSET_8_SERIES_WELLSBURG:
Duncan Laurie823096e2014-08-20 15:39:38 +0000186 case CHIPSET_9_SERIES_WILDCAT_POINT:
Nico Huber51205912017-03-17 17:59:54 +0100187 case CHIPSET_9_SERIES_WILDCAT_POINT_LP:
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000188 return freq_str[value];
189 case CHIPSET_ICH_UNKNOWN:
190 default:
191 return "unknown";
192 }
193}
194
195void prettyprint_ich_descriptor_component(enum ich_chipset cs, const struct ich_descriptors *desc)
196{
Stefan Tauner1e146392011-09-15 23:52:55 +0000197
198 msg_pdbg2("=== Component Section ===\n");
199 msg_pdbg2("FLCOMP 0x%08x\n", desc->component.FLCOMP);
200 msg_pdbg2("FLILL 0x%08x\n", desc->component.FLILL );
201 msg_pdbg2("\n");
202
203 msg_pdbg2("--- Details ---\n");
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000204 msg_pdbg2("Component 1 density: %s\n", pprint_density(cs, desc, 0));
Stefan Tauner1e146392011-09-15 23:52:55 +0000205 if (desc->content.NC)
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000206 msg_pdbg2("Component 2 density: %s\n", pprint_density(cs, desc, 1));
Stefan Tauner1e146392011-09-15 23:52:55 +0000207 else
208 msg_pdbg2("Component 2 is not used.\n");
Tai-Hong Wu60dead42015-01-05 23:00:14 +0000209 msg_pdbg2("Read Clock Frequency: %s\n", pprint_freq(cs, desc->component.modes.freq_read));
210 msg_pdbg2("Read ID and Status Clock Freq.: %s\n", pprint_freq(cs, desc->component.modes.freq_read_id));
211 msg_pdbg2("Write and Erase Clock Freq.: %s\n", pprint_freq(cs, desc->component.modes.freq_write));
212 msg_pdbg2("Fast Read is %ssupported.\n", desc->component.modes.fastread ? "" : "not ");
213 if (desc->component.modes.fastread)
Stefan Tauner1e146392011-09-15 23:52:55 +0000214 msg_pdbg2("Fast Read Clock Frequency: %s\n",
Tai-Hong Wu60dead42015-01-05 23:00:14 +0000215 pprint_freq(cs, desc->component.modes.freq_fastread));
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000216 if (cs > CHIPSET_6_SERIES_COUGAR_POINT)
217 msg_pdbg2("Dual Output Fast Read Support: %sabled\n",
Tai-Hong Wu60dead42015-01-05 23:00:14 +0000218 desc->component.modes.dual_output ? "dis" : "en");
Stefan Tauner1e146392011-09-15 23:52:55 +0000219 if (desc->component.FLILL == 0)
220 msg_pdbg2("No forbidden opcodes.\n");
221 else {
222 msg_pdbg2("Invalid instruction 0: 0x%02x\n",
223 desc->component.invalid_instr0);
224 msg_pdbg2("Invalid instruction 1: 0x%02x\n",
225 desc->component.invalid_instr1);
226 msg_pdbg2("Invalid instruction 2: 0x%02x\n",
227 desc->component.invalid_instr2);
228 msg_pdbg2("Invalid instruction 3: 0x%02x\n",
229 desc->component.invalid_instr3);
230 }
231 msg_pdbg2("\n");
232}
233
234static void pprint_freg(const struct ich_desc_region *reg, uint32_t i)
235{
236 static const char *const region_names[5] = {
237 "Descr.", "BIOS", "ME", "GbE", "Platf."
238 };
239 if (i >= 5) {
240 msg_pdbg2("%s: region index too high.\n", __func__);
241 return;
242 }
243 uint32_t base = ICH_FREG_BASE(reg->FLREGs[i]);
244 uint32_t limit = ICH_FREG_LIMIT(reg->FLREGs[i]);
245 msg_pdbg2("Region %d (%-6s) ", i, region_names[i]);
246 if (base > limit)
247 msg_pdbg2("is unused.\n");
248 else
Nico Huber0bb3f712017-03-29 16:44:33 +0200249 msg_pdbg2("0x%08x - 0x%08x\n", base, limit);
Stefan Tauner1e146392011-09-15 23:52:55 +0000250}
251
252void prettyprint_ich_descriptor_region(const struct ich_descriptors *desc)
253{
254 uint8_t i;
255 uint8_t nr = desc->content.NR + 1;
256 msg_pdbg2("=== Region Section ===\n");
Stefan Tauner2abab942012-04-27 20:41:23 +0000257 if (nr > 5) {
Stefan Tauner1e146392011-09-15 23:52:55 +0000258 msg_pdbg2("%s: number of regions too high (%d).\n", __func__,
259 nr);
260 return;
261 }
Stefan Tauner0554ca52013-07-25 22:54:25 +0000262 for (i = 0; i < 5; i++)
Stefan Tauner1e146392011-09-15 23:52:55 +0000263 msg_pdbg2("FLREG%d 0x%08x\n", i, desc->region.FLREGs[i]);
264 msg_pdbg2("\n");
265
266 msg_pdbg2("--- Details ---\n");
Stefan Tauner0554ca52013-07-25 22:54:25 +0000267 for (i = 0; i < 5; i++)
Stefan Tauner1e146392011-09-15 23:52:55 +0000268 pprint_freg(&desc->region, i);
269 msg_pdbg2("\n");
270}
271
272void prettyprint_ich_descriptor_master(const struct ich_desc_master *mstr)
273{
274 msg_pdbg2("=== Master Section ===\n");
275 msg_pdbg2("FLMSTR1 0x%08x\n", mstr->FLMSTR1);
276 msg_pdbg2("FLMSTR2 0x%08x\n", mstr->FLMSTR2);
277 msg_pdbg2("FLMSTR3 0x%08x\n", mstr->FLMSTR3);
278 msg_pdbg2("\n");
279
280 msg_pdbg2("--- Details ---\n");
281 msg_pdbg2(" Descr. BIOS ME GbE Platf.\n");
282 msg_pdbg2("BIOS %c%c %c%c %c%c %c%c %c%c\n",
283 (mstr->BIOS_descr_r) ?'r':' ', (mstr->BIOS_descr_w) ?'w':' ',
284 (mstr->BIOS_BIOS_r) ?'r':' ', (mstr->BIOS_BIOS_w) ?'w':' ',
285 (mstr->BIOS_ME_r) ?'r':' ', (mstr->BIOS_ME_w) ?'w':' ',
286 (mstr->BIOS_GbE_r) ?'r':' ', (mstr->BIOS_GbE_w) ?'w':' ',
287 (mstr->BIOS_plat_r) ?'r':' ', (mstr->BIOS_plat_w) ?'w':' ');
288 msg_pdbg2("ME %c%c %c%c %c%c %c%c %c%c\n",
289 (mstr->ME_descr_r) ?'r':' ', (mstr->ME_descr_w) ?'w':' ',
290 (mstr->ME_BIOS_r) ?'r':' ', (mstr->ME_BIOS_w) ?'w':' ',
291 (mstr->ME_ME_r) ?'r':' ', (mstr->ME_ME_w) ?'w':' ',
292 (mstr->ME_GbE_r) ?'r':' ', (mstr->ME_GbE_w) ?'w':' ',
293 (mstr->ME_plat_r) ?'r':' ', (mstr->ME_plat_w) ?'w':' ');
294 msg_pdbg2("GbE %c%c %c%c %c%c %c%c %c%c\n",
295 (mstr->GbE_descr_r) ?'r':' ', (mstr->GbE_descr_w) ?'w':' ',
296 (mstr->GbE_BIOS_r) ?'r':' ', (mstr->GbE_BIOS_w) ?'w':' ',
297 (mstr->GbE_ME_r) ?'r':' ', (mstr->GbE_ME_w) ?'w':' ',
298 (mstr->GbE_GbE_r) ?'r':' ', (mstr->GbE_GbE_w) ?'w':' ',
299 (mstr->GbE_plat_r) ?'r':' ', (mstr->GbE_plat_w) ?'w':' ');
300 msg_pdbg2("\n");
301}
302
Stefan Taunerb3850962011-12-24 00:00:32 +0000303void prettyprint_ich_descriptor_straps_ich8(const struct ich_descriptors *desc)
304{
305 static const char * const str_GPIO12[4] = {
306 "GPIO12",
307 "LAN PHY Power Control Function (Native Output)",
308 "GLAN_DOCK# (Native Input)",
309 "invalid configuration",
310 };
311
312 msg_pdbg2("--- MCH details ---\n");
313 msg_pdbg2("ME B is %sabled.\n", desc->north.ich8.MDB ? "dis" : "en");
314 msg_pdbg2("\n");
315
316 msg_pdbg2("--- ICH details ---\n");
317 msg_pdbg2("ME SMBus Address 1: 0x%02x\n", desc->south.ich8.ASD);
318 msg_pdbg2("ME SMBus Address 2: 0x%02x\n", desc->south.ich8.ASD2);
319 msg_pdbg2("ME SMBus Controller is connected to the %s.\n",
320 desc->south.ich8.MESM2SEL ? "SMLink pins" : "SMBus pins");
321 msg_pdbg2("SPI CS1 is used for %s.\n",
322 desc->south.ich8.SPICS1_LANPHYPC_SEL ?
323 "LAN PHY Power Control Function" :
324 "SPI Chip Select");
325 msg_pdbg2("GPIO12 is used as %s.\n",
326 str_GPIO12[desc->south.ich8.GPIO12_SEL]);
327 msg_pdbg2("PCIe Port 6 is used for %s.\n",
328 desc->south.ich8.GLAN_PCIE_SEL ? "integrated LAN" : "PCI Express");
329 msg_pdbg2("%sn BMC Mode: "
330 "Intel AMT SMBus Controller 1 is connected to %s.\n",
331 desc->south.ich8.BMCMODE ? "I" : "Not i",
332 desc->south.ich8.BMCMODE ? "SMLink" : "SMBus");
333 msg_pdbg2("TCO is in %s Mode.\n",
334 desc->south.ich8.TCOMODE ? "Advanced TCO" : "Legacy/Compatible");
335 msg_pdbg2("ME A is %sabled.\n",
336 desc->south.ich8.ME_DISABLE ? "dis" : "en");
337 msg_pdbg2("\n");
338}
339
340static void prettyprint_ich_descriptor_straps_56_pciecs(uint8_t conf, uint8_t off)
341{
342 msg_pdbg2("PCI Express Port Configuration Strap %d: ", off+1);
343
344 off *= 4;
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000345 switch (conf){
Stefan Taunerb3850962011-12-24 00:00:32 +0000346 case 0:
347 msg_pdbg2("4x1 Ports %d-%d (x1)", 1+off, 4+off);
348 break;
349 case 1:
350 msg_pdbg2("1x2, 2x1 Port %d (x2), Port %d (disabled), "
351 "Ports %d, %d (x1)", 1+off, 2+off, 3+off, 4+off);
352 break;
353 case 2:
354 msg_pdbg2("2x2 Port %d (x2), Port %d (x2), Ports "
355 "%d, %d (disabled)", 1+off, 3+off, 2+off, 4+off);
356 break;
357 case 3:
358 msg_pdbg2("1x4 Port %d (x4), Ports %d-%d (disabled)",
359 1+off, 2+off, 4+off);
360 break;
361 }
362 msg_pdbg2("\n");
363}
364
365void prettyprint_ich_descriptor_pchstraps45678_56(const struct ich_desc_south_strap *s)
366{
367 /* PCHSTRP4 */
368 msg_pdbg2("Intel PHY is %s.\n",
369 (s->ibex.PHYCON == 2) ? "connected" :
370 (s->ibex.PHYCON == 0) ? "disconnected" : "reserved");
371 msg_pdbg2("GbE MAC SMBus address is %sabled.\n",
372 s->ibex.GBEMAC_SMBUS_ADDR_EN ? "en" : "dis");
373 msg_pdbg2("GbE MAC SMBus address: 0x%02x\n",
374 s->ibex.GBEMAC_SMBUS_ADDR);
375 msg_pdbg2("GbE PHY SMBus address: 0x%02x\n",
376 s->ibex.GBEPHY_SMBUS_ADDR);
377
378 /* PCHSTRP5 */
379 /* PCHSTRP6 */
380 /* PCHSTRP7 */
381 msg_pdbg2("Intel ME SMBus Subsystem Vendor ID: 0x%04x\n",
382 s->ibex.MESMA2UDID_VENDOR);
383 msg_pdbg2("Intel ME SMBus Subsystem Device ID: 0x%04x\n",
384 s->ibex.MESMA2UDID_VENDOR);
385
386 /* PCHSTRP8 */
387}
388
389void prettyprint_ich_descriptor_pchstraps111213_56(const struct ich_desc_south_strap *s)
390{
391 /* PCHSTRP11 */
392 msg_pdbg2("SMLink1 GP Address is %sabled.\n",
393 s->ibex.SML1GPAEN ? "en" : "dis");
394 msg_pdbg2("SMLink1 controller General Purpose Target address: 0x%02x\n",
395 s->ibex.SML1GPA);
396 msg_pdbg2("SMLink1 I2C Target address is %sabled.\n",
397 s->ibex.SML1I2CAEN ? "en" : "dis");
398 msg_pdbg2("SMLink1 I2C Target address: 0x%02x\n",
399 s->ibex.SML1I2CA);
400
401 /* PCHSTRP12 */
402 /* PCHSTRP13 */
403}
404
405void prettyprint_ich_descriptor_straps_ibex(const struct ich_desc_south_strap *s)
406{
Stefan Tauner67d163d2013-01-15 17:37:48 +0000407 static const uint8_t dec_t209min[4] = {
Stefan Taunerb3850962011-12-24 00:00:32 +0000408 100,
409 50,
410 5,
411 1
412 };
413
414 msg_pdbg2("--- PCH ---\n");
415
416 /* PCHSTRP0 */
417 msg_pdbg2("Chipset configuration Softstrap 2: %d\n", s->ibex.cs_ss2);
418 msg_pdbg2("Intel ME SMBus Select is %sabled.\n",
419 s->ibex.SMB_EN ? "en" : "dis");
420 msg_pdbg2("SMLink0 segment is %sabled.\n",
421 s->ibex.SML0_EN ? "en" : "dis");
422 msg_pdbg2("SMLink1 segment is %sabled.\n",
423 s->ibex.SML1_EN ? "en" : "dis");
424 msg_pdbg2("SMLink1 Frequency: %s\n",
425 (s->ibex.SML1FRQ == 1) ? "100 kHz" : "reserved");
426 msg_pdbg2("Intel ME SMBus Frequency: %s\n",
427 (s->ibex.SMB0FRQ == 1) ? "100 kHz" : "reserved");
428 msg_pdbg2("SMLink0 Frequency: %s\n",
429 (s->ibex.SML0FRQ == 1) ? "100 kHz" : "reserved");
430 msg_pdbg2("GPIO12 is used as %s.\n", s->ibex.LANPHYPC_GP12_SEL ?
431 "LAN_PHY_PWR_CTRL" : "general purpose output");
432 msg_pdbg2("Chipset configuration Softstrap 1: %d\n", s->ibex.cs_ss1);
433 msg_pdbg2("DMI RequesterID Checks are %sabled.\n",
434 s->ibex.DMI_REQID_DIS ? "en" : "dis");
435 msg_pdbg2("BIOS Boot-Block size (BBBS): %d kB.\n",
436 1 << (6 + s->ibex.BBBS));
437
438 /* PCHSTRP1 */
439 msg_pdbg2("Chipset configuration Softstrap 3: 0x%x\n", s->ibex.cs_ss3);
440
441 /* PCHSTRP2 */
442 msg_pdbg2("ME SMBus ASD address is %sabled.\n",
443 s->ibex.MESMASDEN ? "en" : "dis");
444 msg_pdbg2("ME SMBus Controller ASD Target address: 0x%02x\n",
445 s->ibex.MESMASDA);
446 msg_pdbg2("ME SMBus I2C address is %sabled.\n",
447 s->ibex.MESMI2CEN ? "en" : "dis");
448 msg_pdbg2("ME SMBus I2C target address: 0x%02x\n",
449 s->ibex.MESMI2CA);
450
451 /* PCHSTRP3 */
452 prettyprint_ich_descriptor_pchstraps45678_56(s);
453 /* PCHSTRP9 */
454 prettyprint_ich_descriptor_straps_56_pciecs(s->ibex.PCIEPCS1, 0);
455 prettyprint_ich_descriptor_straps_56_pciecs(s->ibex.PCIEPCS1, 1);
456 msg_pdbg2("PCIe Lane Reversal 1: PCIe Lanes 0-3 are %sreserved.\n",
457 s->ibex.PCIELR1 ? "" : "not ");
458 msg_pdbg2("PCIe Lane Reversal 2: PCIe Lanes 4-7 are %sreserved.\n",
459 s->ibex.PCIELR2 ? "" : "not ");
460 msg_pdbg2("DMI Lane Reversal: DMI Lanes 0-3 are %sreserved.\n",
461 s->ibex.DMILR ? "" : "not ");
462 msg_pdbg2("Default PHY PCIe Port is %d.\n", s->ibex.PHY_PCIEPORTSEL+1);
463 msg_pdbg2("Integrated MAC/PHY communication over PCIe is %sabled.\n",
464 s->ibex.PHY_PCIE_EN ? "en" : "dis");
465
466 /* PCHSTRP10 */
467 msg_pdbg2("Management Engine will boot from %sflash.\n",
468 s->ibex.ME_BOOT_FLASH ? "" : "ROM, then ");
469 msg_pdbg2("Chipset configuration Softstrap 5: %d\n", s->ibex.cs_ss5);
470 msg_pdbg2("Virtualization Engine Enable 1 is %sabled.\n",
471 s->ibex.VE_EN ? "en" : "dis");
472 msg_pdbg2("ME Memory-attached Debug Display Device is %sabled.\n",
473 s->ibex.MMDDE ? "en" : "dis");
474 msg_pdbg2("ME Memory-attached Debug Display Device address: 0x%02x\n",
475 s->ibex.MMADDR);
476 msg_pdbg2("Chipset configuration Softstrap 7: %d\n", s->ibex.cs_ss7);
477 msg_pdbg2("Integrated Clocking Configuration is %d.\n",
478 (s->ibex.ICC_SEL == 7) ? 0 : s->ibex.ICC_SEL);
479 msg_pdbg2("PCH Signal CL_RST1# does %sassert when Intel ME performs a "
480 "reset.\n", s->ibex.MER_CL1 ? "" : "not ");
481
482 prettyprint_ich_descriptor_pchstraps111213_56(s);
483
484 /* PCHSTRP14 */
485 msg_pdbg2("Virtualization Engine Enable 2 is %sabled.\n",
486 s->ibex.VE_EN2 ? "en" : "dis");
487 msg_pdbg2("Virtualization Engine will boot from %sflash.\n",
488 s->ibex.VE_BOOT_FLASH ? "" : "ROM, then ");
489 msg_pdbg2("Braidwood SSD functionality is %sabled.\n",
490 s->ibex.BW_SSD ? "en" : "dis");
491 msg_pdbg2("Braidwood NVMHCI functionality is %sabled.\n",
492 s->ibex.NVMHCI_EN ? "en" : "dis");
493
494 /* PCHSTRP15 */
495 msg_pdbg2("Chipset configuration Softstrap 6: %d\n", s->ibex.cs_ss6);
496 msg_pdbg2("Integrated wired LAN Solution is %sabled.\n",
497 s->ibex.IWL_EN ? "en" : "dis");
498 msg_pdbg2("t209 min Timing: %d ms\n",
499 dec_t209min[s->ibex.t209min]);
500 msg_pdbg2("\n");
501}
502
503void prettyprint_ich_descriptor_straps_cougar(const struct ich_desc_south_strap *s)
504{
505 msg_pdbg2("--- PCH ---\n");
506
507 /* PCHSTRP0 */
508 msg_pdbg2("Chipset configuration Softstrap 1: %d\n", s->cougar.cs_ss1);
509 msg_pdbg2("Intel ME SMBus Select is %sabled.\n",
510 s->ibex.SMB_EN ? "en" : "dis");
511 msg_pdbg2("SMLink0 segment is %sabled.\n",
512 s->ibex.SML0_EN ? "en" : "dis");
513 msg_pdbg2("SMLink1 segment is %sabled.\n",
514 s->ibex.SML1_EN ? "en" : "dis");
515 msg_pdbg2("SMLink1 Frequency: %s\n",
516 (s->ibex.SML1FRQ == 1) ? "100 kHz" : "reserved");
517 msg_pdbg2("Intel ME SMBus Frequency: %s\n",
518 (s->ibex.SMB0FRQ == 1) ? "100 kHz" : "reserved");
519 msg_pdbg2("SMLink0 Frequency: %s\n",
520 (s->ibex.SML0FRQ == 1) ? "100 kHz" : "reserved");
521 msg_pdbg2("GPIO12 is used as %s.\n", s->ibex.LANPHYPC_GP12_SEL ?
522 "LAN_PHY_PWR_CTRL" : "general purpose output");
523 msg_pdbg2("LinkSec is %sabled.\n",
524 s->cougar.LINKSEC_DIS ? "en" : "dis");
525 msg_pdbg2("DMI RequesterID Checks are %sabled.\n",
526 s->ibex.DMI_REQID_DIS ? "en" : "dis");
527 msg_pdbg2("BIOS Boot-Block size (BBBS): %d kB.\n",
528 1 << (6 + s->ibex.BBBS));
529
530 /* PCHSTRP1 */
531 msg_pdbg2("Chipset configuration Softstrap 3: 0x%x\n", s->ibex.cs_ss3);
532 msg_pdbg2("Chipset configuration Softstrap 2: 0x%x\n", s->ibex.cs_ss2);
533
534 /* PCHSTRP2 */
535 msg_pdbg2("ME SMBus ASD address is %sabled.\n",
536 s->ibex.MESMASDEN ? "en" : "dis");
537 msg_pdbg2("ME SMBus Controller ASD Target address: 0x%02x\n",
538 s->ibex.MESMASDA);
539 msg_pdbg2("ME SMBus MCTP Address is %sabled.\n",
540 s->cougar.MESMMCTPAEN ? "en" : "dis");
541 msg_pdbg2("ME SMBus MCTP target address: 0x%02x\n",
542 s->cougar.MESMMCTPA);
543 msg_pdbg2("ME SMBus I2C address is %sabled.\n",
544 s->ibex.MESMI2CEN ? "en" : "dis");
545 msg_pdbg2("ME SMBus I2C target address: 0x%02x\n",
546 s->ibex.MESMI2CA);
547
548 /* PCHSTRP3 */
549 prettyprint_ich_descriptor_pchstraps45678_56(s);
550 /* PCHSTRP9 */
551 prettyprint_ich_descriptor_straps_56_pciecs(s->ibex.PCIEPCS1, 0);
552 prettyprint_ich_descriptor_straps_56_pciecs(s->ibex.PCIEPCS1, 1);
553 msg_pdbg2("PCIe Lane Reversal 1: PCIe Lanes 0-3 are %sreserved.\n",
554 s->ibex.PCIELR1 ? "" : "not ");
555 msg_pdbg2("PCIe Lane Reversal 2: PCIe Lanes 4-7 are %sreserved.\n",
556 s->ibex.PCIELR2 ? "" : "not ");
557 msg_pdbg2("DMI Lane Reversal: DMI Lanes 0-3 are %sreserved.\n",
558 s->ibex.DMILR ? "" : "not ");
559 msg_pdbg2("ME Debug status writes over SMBUS are %sabled.\n",
560 s->cougar.MDSMBE_EN ? "en" : "dis");
561 msg_pdbg2("ME Debug SMBus Emergency Mode address: 0x%02x (raw)\n",
562 s->cougar.MDSMBE_ADD);
563 msg_pdbg2("Default PHY PCIe Port is %d.\n", s->ibex.PHY_PCIEPORTSEL+1);
564 msg_pdbg2("Integrated MAC/PHY communication over PCIe is %sabled.\n",
565 s->ibex.PHY_PCIE_EN ? "en" : "dis");
566 msg_pdbg2("PCIe ports Subtractive Decode Agent is %sabled.\n",
567 s->cougar.SUB_DECODE_EN ? "en" : "dis");
568 msg_pdbg2("GPIO74 is used as %s.\n", s->cougar.PCHHOT_SML1ALERT_SEL ?
569 "PCHHOT#" : "SML1ALERT#");
570
571 /* PCHSTRP10 */
572 msg_pdbg2("Management Engine will boot from %sflash.\n",
573 s->ibex.ME_BOOT_FLASH ? "" : "ROM, then ");
574
575 msg_pdbg2("ME Debug SMBus Emergency Mode is %sabled.\n",
576 s->cougar.MDSMBE_EN ? "en" : "dis");
577 msg_pdbg2("ME Debug SMBus Emergency Mode Address: 0x%02x\n",
578 s->cougar.MDSMBE_ADD);
579
580 msg_pdbg2("Integrated Clocking Configuration used: %d\n",
581 s->cougar.ICC_SEL);
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000582 msg_pdbg2("PCH Signal CL_RST1# does %sassert when Intel ME performs a reset.\n",
583 s->ibex.MER_CL1 ? "" : "not ");
Stefan Taunerb3850962011-12-24 00:00:32 +0000584 msg_pdbg2("ICC Profile is selected by %s.\n",
585 s->cougar.ICC_PRO_SEL ? "Softstraps" : "BIOS");
586 msg_pdbg2("Deep SX is %ssupported on the platform.\n",
587 s->cougar.Deep_SX_EN ? "not " : "");
588 msg_pdbg2("ME Debug LAN Emergency Mode is %sabled.\n",
589 s->cougar.ME_DBG_LAN ? "en" : "dis");
590
591 prettyprint_ich_descriptor_pchstraps111213_56(s);
592
593 /* PCHSTRP14 */
594 /* PCHSTRP15 */
595 msg_pdbg2("Chipset configuration Softstrap 6: %d\n", s->cougar.cs_ss6);
596 msg_pdbg2("Integrated wired LAN is %sabled.\n",
597 s->cougar.IWL_EN ? "en" : "dis");
598 msg_pdbg2("Chipset configuration Softstrap 5: %d\n", s->cougar.cs_ss5);
599 msg_pdbg2("SMLink1 provides temperature from %s.\n",
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000600 s->cougar.SMLINK1_THERM_SEL ? "PCH only" : "the CPU, PCH and DIMMs");
Stefan Taunerb3850962011-12-24 00:00:32 +0000601 msg_pdbg2("GPIO29 is used as %s.\n", s->cougar.SLP_LAN_GP29_SEL ?
602 "general purpose output" : "SLP_LAN#");
603
604 /* PCHSTRP16 */
605 /* PCHSTRP17 */
606 msg_pdbg2("Integrated Clock: %s Clock Mode\n",
607 s->cougar.ICML ? "Buffered Through" : "Full Integrated");
608 msg_pdbg2("\n");
609}
610
611void prettyprint_ich_descriptor_straps(enum ich_chipset cs, const struct ich_descriptors *desc)
612{
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000613 unsigned int i, max_count;
Stefan Taunerb3850962011-12-24 00:00:32 +0000614 msg_pdbg2("=== Softstraps ===\n");
615
Nico Huberd7c75522017-03-29 16:31:49 +0200616 max_count = min(ARRAY_SIZE(desc->north.STRPs), desc->content.MSL);
617 if (max_count < desc->content.MSL) {
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000618 msg_pdbg2("MSL (%u) is greater than the current maximum of %u entries.\n",
Nico Huberd7c75522017-03-29 16:31:49 +0200619 desc->content.MSL, max_count);
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000620 msg_pdbg2("Only the first %u entries will be printed.\n", max_count);
Nico Huberd7c75522017-03-29 16:31:49 +0200621 }
Stefan Taunerb3850962011-12-24 00:00:32 +0000622
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000623 msg_pdbg2("--- North/MCH/PROC (%d entries) ---\n", max_count);
624 for (i = 0; i < max_count; i++)
Stefan Taunerb3850962011-12-24 00:00:32 +0000625 msg_pdbg2("STRP%-2d = 0x%08x\n", i, desc->north.STRPs[i]);
626 msg_pdbg2("\n");
627
Nico Huberd7c75522017-03-29 16:31:49 +0200628 max_count = min(ARRAY_SIZE(desc->south.STRPs), desc->content.ISL);
629 if (max_count < desc->content.ISL) {
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000630 msg_pdbg2("ISL (%u) is greater than the current maximum of %u entries.\n",
631 desc->content.ISL, max_count);
632 msg_pdbg2("Only the first %u entries will be printed.\n", max_count);
Nico Huberd7c75522017-03-29 16:31:49 +0200633 }
Stefan Taunerb3850962011-12-24 00:00:32 +0000634
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000635 msg_pdbg2("--- South/ICH/PCH (%d entries) ---\n", max_count);
636 for (i = 0; i < max_count; i++)
Stefan Taunerb3850962011-12-24 00:00:32 +0000637 msg_pdbg2("STRP%-2d = 0x%08x\n", i, desc->south.STRPs[i]);
638 msg_pdbg2("\n");
639
640 switch (cs) {
641 case CHIPSET_ICH8:
642 if (sizeof(desc->north.ich8) / 4 != desc->content.MSL)
643 msg_pdbg2("Detailed North/MCH/PROC information is "
644 "probably not reliable, printing anyway.\n");
645 if (sizeof(desc->south.ich8) / 4 != desc->content.ISL)
646 msg_pdbg2("Detailed South/ICH/PCH information is "
647 "probably not reliable, printing anyway.\n");
648 prettyprint_ich_descriptor_straps_ich8(desc);
649 break;
650 case CHIPSET_5_SERIES_IBEX_PEAK:
651 /* PCH straps only. PROCSTRPs are unknown. */
652 if (sizeof(desc->south.ibex) / 4 != desc->content.ISL)
653 msg_pdbg2("Detailed South/ICH/PCH information is "
654 "probably not reliable, printing anyway.\n");
655 prettyprint_ich_descriptor_straps_ibex(&desc->south);
656 break;
657 case CHIPSET_6_SERIES_COUGAR_POINT:
658 /* PCH straps only. PROCSTRP0 is "reserved". */
659 if (sizeof(desc->south.cougar) / 4 != desc->content.ISL)
660 msg_pdbg2("Detailed South/ICH/PCH information is "
661 "probably not reliable, printing anyway.\n");
662 prettyprint_ich_descriptor_straps_cougar(&desc->south);
663 break;
664 case CHIPSET_ICH_UNKNOWN:
665 break;
666 default:
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000667 msg_pdbg2("The meaning of the descriptor straps are unknown yet.\n\n");
Stefan Taunerb3850962011-12-24 00:00:32 +0000668 break;
669 }
670}
671
672void prettyprint_rdid(uint32_t reg_val)
673{
674 uint8_t mid = reg_val & 0xFF;
675 uint16_t did = ((reg_val >> 16) & 0xFF) | (reg_val & 0xFF00);
676 msg_pdbg2("Manufacturer ID 0x%02x, Device ID 0x%04x\n", mid, did);
677}
678
679void prettyprint_ich_descriptor_upper_map(const struct ich_desc_upper_map *umap)
680{
681 int i;
682 msg_pdbg2("=== Upper Map Section ===\n");
683 msg_pdbg2("FLUMAP1 0x%08x\n", umap->FLUMAP1);
684 msg_pdbg2("\n");
685
686 msg_pdbg2("--- Details ---\n");
687 msg_pdbg2("VTL (length in DWORDS) = %d\n", umap->VTL);
688 msg_pdbg2("VTBA (base address) = 0x%6.6x\n", getVTBA(umap));
689 msg_pdbg2("\n");
690
691 msg_pdbg2("VSCC Table: %d entries\n", umap->VTL/2);
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000692 for (i = 0; i < umap->VTL/2; i++) {
Stefan Taunerb3850962011-12-24 00:00:32 +0000693 uint32_t jid = umap->vscc_table[i].JID;
694 uint32_t vscc = umap->vscc_table[i].VSCC;
695 msg_pdbg2(" JID%d = 0x%08x\n", i, jid);
696 msg_pdbg2(" VSCC%d = 0x%08x\n", i, vscc);
697 msg_pdbg2(" "); /* indention */
698 prettyprint_rdid(jid);
699 msg_pdbg2(" "); /* indention */
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000700 prettyprint_ich_reg_vscc(vscc, 0, false);
Stefan Taunerb3850962011-12-24 00:00:32 +0000701 }
702 msg_pdbg2("\n");
703}
704
Nico Huber1dc3d422017-06-17 00:09:31 +0200705/*
706 * Guesses a minimum chipset version based on the maximum number of
707 * soft straps per generation.
708 */
709static enum ich_chipset guess_ich_chipset_from_content(const struct ich_desc_content *const content)
710{
711 if (content->ICCRIBA == 0x00) {
712 if (content->MSL == 0 && content->ISL <= 2)
713 return CHIPSET_ICH8;
714 else if (content->ISL <= 2)
715 return CHIPSET_ICH9;
716 else if (content->ISL <= 10)
717 return CHIPSET_ICH10;
718 else if (content->ISL <= 16)
719 return CHIPSET_5_SERIES_IBEX_PEAK;
720 msg_pwarn("Peculiar firmware descriptor, assuming Ibex Peak compatibility.\n");
721 return CHIPSET_5_SERIES_IBEX_PEAK;
722 } else if (content->ICCRIBA < 0x31 && content->FMSBA < 0x30) {
723 if (content->MSL == 0 && content->ISL <= 17)
724 return CHIPSET_BAYTRAIL;
725 else if (content->MSL <= 1 && content->ISL <= 18)
726 return CHIPSET_6_SERIES_COUGAR_POINT;
727 else if (content->MSL <= 1 && content->ISL <= 21)
728 return CHIPSET_8_SERIES_LYNX_POINT;
729 msg_pwarn("Peculiar firmware descriptor, assuming Wildcat Point compatibility.\n");
730 return CHIPSET_9_SERIES_WILDCAT_POINT;
731 } else {
732 return CHIPSET_100_SERIES_SUNRISE_POINT;
733 }
734}
735
736/*
737 * As an additional measure, we check the read frequency like `ifdtool`.
738 * The frequency value 6 (17MHz) was reserved before Skylake and is the
739 * only valid value since. Skylake is currently the most important dis-
740 * tinction because of the dropped number of regions field (NR).
741 */
742enum ich_chipset guess_ich_chipset(const struct ich_desc_content *const content,
743 const struct ich_desc_component *const component)
744{
745 const enum ich_chipset guess = guess_ich_chipset_from_content(content);
746
747 if (component->modes.freq_read == 6) {
748 if (guess != CHIPSET_100_SERIES_SUNRISE_POINT)
749 msg_pwarn("\nThe firmware descriptor has the read frequency set to 17MHz. However,\n"
750 "it doesn't look like a Skylake/Sunrise Point compatible descriptor.\n"
751 "Please report this message, the output of `ich_descriptors_tool` for\n"
752 "your descriptor and the output of `lspci -nn` to flashrom@flashrom.org\n\n");
753 return CHIPSET_100_SERIES_SUNRISE_POINT;
754 } else {
755 if (guess == CHIPSET_100_SERIES_SUNRISE_POINT) {
756 msg_pwarn("\nThe firmware descriptor looks like a Skylake/Sunrise Point descriptor.\n"
757 "However, the read frequency isn't set to 17MHz (the only valid value).\n"
758 "Please report this message, the output of `ich_descriptors_tool` for\n"
759 "your descriptor and the output of `lspci -nn` to flashrom@flashrom.org\n\n");
760 return CHIPSET_9_SERIES_WILDCAT_POINT;
761 }
762 }
763
764 return guess;
765}
766
Stefan Taunerb3850962011-12-24 00:00:32 +0000767/* len is the length of dump in bytes */
768int read_ich_descriptors_from_dump(const uint32_t *dump, unsigned int len, struct ich_descriptors *desc)
769{
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000770 unsigned int i, max_count;
Stefan Taunerb3850962011-12-24 00:00:32 +0000771 uint8_t pch_bug_offset = 0;
772
773 if (dump == NULL || desc == NULL)
774 return ICH_RET_PARAM;
775
776 if (dump[0] != DESCRIPTOR_MODE_SIGNATURE) {
777 if (dump[4] == DESCRIPTOR_MODE_SIGNATURE)
778 pch_bug_offset = 4;
779 else
780 return ICH_RET_ERR;
781 }
782
783 /* map */
Nico Huber9e14aed2017-03-28 17:08:46 +0200784 if (len < (4 + pch_bug_offset) * 4)
Stefan Taunerb3850962011-12-24 00:00:32 +0000785 return ICH_RET_OOB;
786 desc->content.FLVALSIG = dump[0 + pch_bug_offset];
787 desc->content.FLMAP0 = dump[1 + pch_bug_offset];
788 desc->content.FLMAP1 = dump[2 + pch_bug_offset];
789 desc->content.FLMAP2 = dump[3 + pch_bug_offset];
790
791 /* component */
Nico Huber9e14aed2017-03-28 17:08:46 +0200792 if (len < getFCBA(&desc->content) + 3 * 4)
Stefan Taunerb3850962011-12-24 00:00:32 +0000793 return ICH_RET_OOB;
794 desc->component.FLCOMP = dump[(getFCBA(&desc->content) >> 2) + 0];
795 desc->component.FLILL = dump[(getFCBA(&desc->content) >> 2) + 1];
796 desc->component.FLPB = dump[(getFCBA(&desc->content) >> 2) + 2];
797
798 /* region */
Nico Huber9e14aed2017-03-28 17:08:46 +0200799 if (len < getFRBA(&desc->content) + 5 * 4)
Stefan Taunerb3850962011-12-24 00:00:32 +0000800 return ICH_RET_OOB;
801 desc->region.FLREGs[0] = dump[(getFRBA(&desc->content) >> 2) + 0];
802 desc->region.FLREGs[1] = dump[(getFRBA(&desc->content) >> 2) + 1];
803 desc->region.FLREGs[2] = dump[(getFRBA(&desc->content) >> 2) + 2];
804 desc->region.FLREGs[3] = dump[(getFRBA(&desc->content) >> 2) + 3];
805 desc->region.FLREGs[4] = dump[(getFRBA(&desc->content) >> 2) + 4];
806
807 /* master */
Nico Huber9e14aed2017-03-28 17:08:46 +0200808 if (len < getFMBA(&desc->content) + 3 * 4)
Stefan Taunerb3850962011-12-24 00:00:32 +0000809 return ICH_RET_OOB;
810 desc->master.FLMSTR1 = dump[(getFMBA(&desc->content) >> 2) + 0];
811 desc->master.FLMSTR2 = dump[(getFMBA(&desc->content) >> 2) + 1];
812 desc->master.FLMSTR3 = dump[(getFMBA(&desc->content) >> 2) + 2];
813
814 /* upper map */
815 desc->upper.FLUMAP1 = dump[(UPPER_MAP_OFFSET >> 2) + 0];
816
817 /* VTL is 8 bits long. Quote from the Ibex Peak SPI programming guide:
818 * "Identifies the 1s based number of DWORDS contained in the VSCC
819 * Table. Each SPI component entry in the table is 2 DWORDS long." So
820 * the maximum of 255 gives us 127.5 SPI components(!?) 8 bytes each. A
821 * check ensures that the maximum offset actually accessed is available.
822 */
Nico Huber9e14aed2017-03-28 17:08:46 +0200823 if (len < getVTBA(&desc->upper) + (desc->upper.VTL / 2 * 8))
Stefan Taunerb3850962011-12-24 00:00:32 +0000824 return ICH_RET_OOB;
825
826 for (i = 0; i < desc->upper.VTL/2; i++) {
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000827 desc->upper.vscc_table[i].JID = dump[(getVTBA(&desc->upper) >> 2) + i * 2 + 0];
828 desc->upper.vscc_table[i].VSCC = dump[(getVTBA(&desc->upper) >> 2) + i * 2 + 1];
Stefan Taunerb3850962011-12-24 00:00:32 +0000829 }
830
831 /* MCH/PROC (aka. North) straps */
832 if (len < getFMSBA(&desc->content) + desc->content.MSL * 4)
833 return ICH_RET_OOB;
834
835 /* limit the range to be written */
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000836 max_count = min(sizeof(desc->north.STRPs) / 4, desc->content.MSL);
837 for (i = 0; i < max_count; i++)
838 desc->north.STRPs[i] = dump[(getFMSBA(&desc->content) >> 2) + i];
Stefan Taunerb3850962011-12-24 00:00:32 +0000839
840 /* ICH/PCH (aka. South) straps */
841 if (len < getFISBA(&desc->content) + desc->content.ISL * 4)
842 return ICH_RET_OOB;
843
844 /* limit the range to be written */
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000845 max_count = min(sizeof(desc->south.STRPs) / 4, desc->content.ISL);
846 for (i = 0; i < max_count; i++)
847 desc->south.STRPs[i] = dump[(getFISBA(&desc->content) >> 2) + i];
Stefan Taunerb3850962011-12-24 00:00:32 +0000848
849 return ICH_RET_OK;
850}
851
Nico Huberad186312016-05-02 15:15:29 +0200852#ifndef ICH_DESCRIPTORS_FROM_DUMP_ONLY
Stefan Taunerb3850962011-12-24 00:00:32 +0000853
Stefan Taunerd0c5dc22011-10-20 12:57:14 +0000854/** Returns the integer representation of the component density with index
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000855\em idx in bytes or -1 if the correct size can not be determined. */
856int getFCBA_component_density(enum ich_chipset cs, const struct ich_descriptors *desc, uint8_t idx)
Stefan Taunerd0c5dc22011-10-20 12:57:14 +0000857{
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000858 if (idx > 1) {
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000859 msg_perr("Only ICH SPI component index 0 or 1 are supported yet.\n");
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000860 return -1;
Stefan Taunerd0c5dc22011-10-20 12:57:14 +0000861 }
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000862
863 if (desc->content.NC == 0 && idx > 0)
Stefan Taunerd0c5dc22011-10-20 12:57:14 +0000864 return 0;
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000865
866 uint8_t size_enc;
867 uint8_t size_max;
868
869 switch (cs) {
870 case CHIPSET_ICH8:
871 case CHIPSET_ICH9:
872 case CHIPSET_ICH10:
873 case CHIPSET_5_SERIES_IBEX_PEAK:
874 case CHIPSET_6_SERIES_COUGAR_POINT:
875 case CHIPSET_7_SERIES_PANTHER_POINT:
Tai-Hong Wu60dead42015-01-05 23:00:14 +0000876 case CHIPSET_BAYTRAIL:
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000877 if (idx == 0) {
Tai-Hong Wu60dead42015-01-05 23:00:14 +0000878 size_enc = desc->component.dens_old.comp1_density;
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000879 } else {
Tai-Hong Wu60dead42015-01-05 23:00:14 +0000880 size_enc = desc->component.dens_old.comp2_density;
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000881 }
882 size_max = 5;
883 break;
884 case CHIPSET_8_SERIES_LYNX_POINT:
885 case CHIPSET_8_SERIES_LYNX_POINT_LP:
886 case CHIPSET_8_SERIES_WELLSBURG:
Duncan Laurie823096e2014-08-20 15:39:38 +0000887 case CHIPSET_9_SERIES_WILDCAT_POINT:
Nico Huber51205912017-03-17 17:59:54 +0100888 case CHIPSET_9_SERIES_WILDCAT_POINT_LP:
Nico Huberd54e4f42017-03-23 23:45:47 +0100889 case CHIPSET_100_SERIES_SUNRISE_POINT:
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000890 if (idx == 0) {
Tai-Hong Wu60dead42015-01-05 23:00:14 +0000891 size_enc = desc->component.dens_new.comp1_density;
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000892 } else {
Tai-Hong Wu60dead42015-01-05 23:00:14 +0000893 size_enc = desc->component.dens_new.comp2_density;
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000894 }
895 size_max = 7;
896 break;
897 case CHIPSET_ICH_UNKNOWN:
898 default:
899 msg_pwarn("Density encoding is unknown on this chipset.\n");
900 return -1;
Stefan Taunerd0c5dc22011-10-20 12:57:14 +0000901 }
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000902
903 if (size_enc > size_max) {
Tai-Hong Wu60dead42015-01-05 23:00:14 +0000904 msg_perr("Density of ICH SPI component with index %d is invalid.\n"
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000905 "Encoded density is 0x%x while maximum allowed is 0x%x.\n",
906 idx, size_enc, size_max);
907 return -1;
908 }
909
Stefan Taunerd0c5dc22011-10-20 12:57:14 +0000910 return (1 << (19 + size_enc));
911}
912
Nico Huber8d494992017-06-19 12:18:33 +0200913/* Only used by ichspi.c */
914#if CONFIG_INTERNAL == 1 && (defined(__i386__) || defined(__x86_64__))
Nico Huberd54e4f42017-03-23 23:45:47 +0100915static uint32_t read_descriptor_reg(enum ich_chipset cs, uint8_t section, uint16_t offset, void *spibar)
Stefan Tauner1e146392011-09-15 23:52:55 +0000916{
917 uint32_t control = 0;
918 control |= (section << FDOC_FDSS_OFF) & FDOC_FDSS;
919 control |= (offset << FDOC_FDSI_OFF) & FDOC_FDSI;
Nico Huberd54e4f42017-03-23 23:45:47 +0100920 if (cs == CHIPSET_100_SERIES_SUNRISE_POINT) {
921 mmio_le_writel(control, spibar + PCH100_REG_FDOC);
922 return mmio_le_readl(spibar + PCH100_REG_FDOD);
923 } else {
924 mmio_le_writel(control, spibar + ICH9_REG_FDOC);
925 return mmio_le_readl(spibar + ICH9_REG_FDOD);
926 }
927
Stefan Tauner1e146392011-09-15 23:52:55 +0000928}
929
Nico Huberd54e4f42017-03-23 23:45:47 +0100930int read_ich_descriptors_via_fdo(enum ich_chipset cs, void *spibar, struct ich_descriptors *desc)
Stefan Tauner1e146392011-09-15 23:52:55 +0000931{
932 uint8_t i;
933 uint8_t nr;
934 struct ich_desc_region *r = &desc->region;
935
936 /* Test if bit-fields are working as expected.
937 * FIXME: Replace this with dynamic bitfield fixup
938 */
939 for (i = 0; i < 4; i++)
940 desc->region.FLREGs[i] = 0x5A << (i * 8);
941 if (r->reg0_base != 0x005A || r->reg0_limit != 0x0000 ||
942 r->reg1_base != 0x1A00 || r->reg1_limit != 0x0000 ||
943 r->reg2_base != 0x0000 || r->reg2_limit != 0x005A ||
944 r->reg3_base != 0x0000 || r->reg3_limit != 0x1A00) {
945 msg_pdbg("The combination of compiler and CPU architecture used"
946 "does not lay out bit-fields as expected, sorry.\n");
947 msg_pspew("r->reg0_base = 0x%04X (0x005A)\n", r->reg0_base);
948 msg_pspew("r->reg0_limit = 0x%04X (0x0000)\n", r->reg0_limit);
949 msg_pspew("r->reg1_base = 0x%04X (0x1A00)\n", r->reg1_base);
950 msg_pspew("r->reg1_limit = 0x%04X (0x0000)\n", r->reg1_limit);
951 msg_pspew("r->reg2_base = 0x%04X (0x0000)\n", r->reg2_base);
952 msg_pspew("r->reg2_limit = 0x%04X (0x005A)\n", r->reg2_limit);
953 msg_pspew("r->reg3_base = 0x%04X (0x0000)\n", r->reg3_base);
954 msg_pspew("r->reg3_limit = 0x%04X (0x1A00)\n", r->reg3_limit);
955 return ICH_RET_ERR;
956 }
957
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000958 msg_pdbg2("Reading flash descriptors mapped by the chipset via FDOC/FDOD...");
Stefan Tauner1e146392011-09-15 23:52:55 +0000959 /* content section */
Nico Huberd54e4f42017-03-23 23:45:47 +0100960 desc->content.FLVALSIG = read_descriptor_reg(cs, 0, 0, spibar);
961 desc->content.FLMAP0 = read_descriptor_reg(cs, 0, 1, spibar);
962 desc->content.FLMAP1 = read_descriptor_reg(cs, 0, 2, spibar);
963 desc->content.FLMAP2 = read_descriptor_reg(cs, 0, 3, spibar);
Stefan Tauner1e146392011-09-15 23:52:55 +0000964
965 /* component section */
Nico Huberd54e4f42017-03-23 23:45:47 +0100966 desc->component.FLCOMP = read_descriptor_reg(cs, 1, 0, spibar);
967 desc->component.FLILL = read_descriptor_reg(cs, 1, 1, spibar);
968 desc->component.FLPB = read_descriptor_reg(cs, 1, 2, spibar);
Stefan Tauner1e146392011-09-15 23:52:55 +0000969
970 /* region section */
971 nr = desc->content.NR + 1;
Stefan Tauner2abab942012-04-27 20:41:23 +0000972 if (nr > 5) {
Stefan Tauner1e146392011-09-15 23:52:55 +0000973 msg_pdbg2("%s: number of regions too high (%d) - failed\n",
974 __func__, nr);
975 return ICH_RET_ERR;
976 }
Stefan Tauner0554ca52013-07-25 22:54:25 +0000977 for (i = 0; i < 5; i++)
Nico Huberd54e4f42017-03-23 23:45:47 +0100978 desc->region.FLREGs[i] = read_descriptor_reg(cs, 2, i, spibar);
Stefan Tauner1e146392011-09-15 23:52:55 +0000979
980 /* master section */
Nico Huberd54e4f42017-03-23 23:45:47 +0100981 desc->master.FLMSTR1 = read_descriptor_reg(cs, 3, 0, spibar);
982 desc->master.FLMSTR2 = read_descriptor_reg(cs, 3, 1, spibar);
983 desc->master.FLMSTR3 = read_descriptor_reg(cs, 3, 2, spibar);
Stefan Tauner1e146392011-09-15 23:52:55 +0000984
985 /* Accessing the strap section via FDOC/D is only possible on ICH8 and
986 * reading the upper map is impossible on all chipsets, so don't bother.
987 */
988
989 msg_pdbg2(" done.\n");
990 return ICH_RET_OK;
991}
Nico Huber8d494992017-06-19 12:18:33 +0200992#endif
Nico Huber305f4172013-06-14 11:55:26 +0200993
994/**
995 * @brief Read a layout from the dump of an Intel ICH descriptor.
996 *
997 * @param layout Pointer where to store the layout.
998 * @param dump The descriptor dump to read from.
999 * @param len The length of the descriptor dump.
1000 *
1001 * @return 0 on success,
1002 * 1 if the descriptor couldn't be parsed.
1003 */
1004int layout_from_ich_descriptors(struct ich_layout *const layout, const void *const dump, const size_t len)
1005{
1006 static const char *regions[] = { "fd", "bios", "me", "gbe", "pd" };
1007
1008 struct ich_descriptors desc;
1009 if (read_ich_descriptors_from_dump(dump, len, &desc))
1010 return 1;
1011
1012 memset(layout, 0x00, sizeof(*layout));
1013
1014 size_t i, j;
1015 for (i = 0, j = 0; i < min(desc.content.NR + 1, ARRAY_SIZE(regions)); ++i) {
1016 const chipoff_t base = ICH_FREG_BASE(desc.region.FLREGs[i]);
Nico Huber0bb3f712017-03-29 16:44:33 +02001017 const chipoff_t limit = ICH_FREG_LIMIT(desc.region.FLREGs[i]);
Nico Huber305f4172013-06-14 11:55:26 +02001018 if (limit <= base)
1019 continue;
1020 layout->entries[j].start = base;
1021 layout->entries[j].end = limit;
1022 layout->entries[j].included = false;
1023 snprintf(layout->entries[j].name, sizeof(layout->entries[j].name), "%s", regions[i]);
1024 ++j;
1025 }
1026 layout->base.entries = layout->entries;
1027 layout->base.num_entries = j;
1028 return 0;
1029}
1030
Nico Huberad186312016-05-02 15:15:29 +02001031#endif /* ICH_DESCRIPTORS_FROM_DUMP_ONLY */