blob: 7e2521a40fcdaed5b98b35ca52285fdf7ec9c542 [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:
142 case CHIPSET_9_SERIES_WILDCAT_POINT: {
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000143 uint8_t size_enc;
144 if (idx == 0) {
Tai-Hong Wu60dead42015-01-05 23:00:14 +0000145 size_enc = desc->component.dens_new.comp1_density;
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000146 } else {
Tai-Hong Wu60dead42015-01-05 23:00:14 +0000147 size_enc = desc->component.dens_new.comp2_density;
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000148 }
149 if (size_enc > 7)
150 return "reserved";
151 return size_str[size_enc];
152 }
153 case CHIPSET_ICH_UNKNOWN:
154 default:
155 return "unknown";
156 }
157}
158
159static const char *pprint_freq(enum ich_chipset cs, uint8_t value)
Stefan Tauner1e146392011-09-15 23:52:55 +0000160{
161 static const char * const freq_str[8] = {
162 "20 MHz", /* 000 */
163 "33 MHz", /* 001 */
164 "reserved", /* 010 */
165 "reserved", /* 011 */
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000166 "50 MHz", /* 100 */ /* New since Ibex Peak */
Stefan Tauner1e146392011-09-15 23:52:55 +0000167 "reserved", /* 101 */
168 "reserved", /* 110 */
169 "reserved" /* 111 */
170 };
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000171
172 switch (cs) {
173 case CHIPSET_ICH8:
174 case CHIPSET_ICH9:
175 case CHIPSET_ICH10:
176 if (value > 1)
177 return "reserved";
178 case CHIPSET_5_SERIES_IBEX_PEAK:
179 case CHIPSET_6_SERIES_COUGAR_POINT:
180 case CHIPSET_7_SERIES_PANTHER_POINT:
181 case CHIPSET_8_SERIES_LYNX_POINT:
Duncan Laurie4095ed72014-08-20 15:39:32 +0000182 case CHIPSET_BAYTRAIL:
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000183 case CHIPSET_8_SERIES_LYNX_POINT_LP:
184 case CHIPSET_8_SERIES_WELLSBURG:
Duncan Laurie823096e2014-08-20 15:39:38 +0000185 case CHIPSET_9_SERIES_WILDCAT_POINT:
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000186 return freq_str[value];
187 case CHIPSET_ICH_UNKNOWN:
188 default:
189 return "unknown";
190 }
191}
192
193void prettyprint_ich_descriptor_component(enum ich_chipset cs, const struct ich_descriptors *desc)
194{
Stefan Tauner1e146392011-09-15 23:52:55 +0000195
196 msg_pdbg2("=== Component Section ===\n");
197 msg_pdbg2("FLCOMP 0x%08x\n", desc->component.FLCOMP);
198 msg_pdbg2("FLILL 0x%08x\n", desc->component.FLILL );
199 msg_pdbg2("\n");
200
201 msg_pdbg2("--- Details ---\n");
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000202 msg_pdbg2("Component 1 density: %s\n", pprint_density(cs, desc, 0));
Stefan Tauner1e146392011-09-15 23:52:55 +0000203 if (desc->content.NC)
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000204 msg_pdbg2("Component 2 density: %s\n", pprint_density(cs, desc, 1));
Stefan Tauner1e146392011-09-15 23:52:55 +0000205 else
206 msg_pdbg2("Component 2 is not used.\n");
Tai-Hong Wu60dead42015-01-05 23:00:14 +0000207 msg_pdbg2("Read Clock Frequency: %s\n", pprint_freq(cs, desc->component.modes.freq_read));
208 msg_pdbg2("Read ID and Status Clock Freq.: %s\n", pprint_freq(cs, desc->component.modes.freq_read_id));
209 msg_pdbg2("Write and Erase Clock Freq.: %s\n", pprint_freq(cs, desc->component.modes.freq_write));
210 msg_pdbg2("Fast Read is %ssupported.\n", desc->component.modes.fastread ? "" : "not ");
211 if (desc->component.modes.fastread)
Stefan Tauner1e146392011-09-15 23:52:55 +0000212 msg_pdbg2("Fast Read Clock Frequency: %s\n",
Tai-Hong Wu60dead42015-01-05 23:00:14 +0000213 pprint_freq(cs, desc->component.modes.freq_fastread));
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000214 if (cs > CHIPSET_6_SERIES_COUGAR_POINT)
215 msg_pdbg2("Dual Output Fast Read Support: %sabled\n",
Tai-Hong Wu60dead42015-01-05 23:00:14 +0000216 desc->component.modes.dual_output ? "dis" : "en");
Stefan Tauner1e146392011-09-15 23:52:55 +0000217 if (desc->component.FLILL == 0)
218 msg_pdbg2("No forbidden opcodes.\n");
219 else {
220 msg_pdbg2("Invalid instruction 0: 0x%02x\n",
221 desc->component.invalid_instr0);
222 msg_pdbg2("Invalid instruction 1: 0x%02x\n",
223 desc->component.invalid_instr1);
224 msg_pdbg2("Invalid instruction 2: 0x%02x\n",
225 desc->component.invalid_instr2);
226 msg_pdbg2("Invalid instruction 3: 0x%02x\n",
227 desc->component.invalid_instr3);
228 }
229 msg_pdbg2("\n");
230}
231
232static void pprint_freg(const struct ich_desc_region *reg, uint32_t i)
233{
234 static const char *const region_names[5] = {
235 "Descr.", "BIOS", "ME", "GbE", "Platf."
236 };
237 if (i >= 5) {
238 msg_pdbg2("%s: region index too high.\n", __func__);
239 return;
240 }
241 uint32_t base = ICH_FREG_BASE(reg->FLREGs[i]);
242 uint32_t limit = ICH_FREG_LIMIT(reg->FLREGs[i]);
243 msg_pdbg2("Region %d (%-6s) ", i, region_names[i]);
244 if (base > limit)
245 msg_pdbg2("is unused.\n");
246 else
247 msg_pdbg2("0x%08x - 0x%08x\n", base, limit | 0x0fff);
248}
249
250void prettyprint_ich_descriptor_region(const struct ich_descriptors *desc)
251{
252 uint8_t i;
253 uint8_t nr = desc->content.NR + 1;
254 msg_pdbg2("=== Region Section ===\n");
Stefan Tauner2abab942012-04-27 20:41:23 +0000255 if (nr > 5) {
Stefan Tauner1e146392011-09-15 23:52:55 +0000256 msg_pdbg2("%s: number of regions too high (%d).\n", __func__,
257 nr);
258 return;
259 }
Stefan Tauner0554ca52013-07-25 22:54:25 +0000260 for (i = 0; i < 5; i++)
Stefan Tauner1e146392011-09-15 23:52:55 +0000261 msg_pdbg2("FLREG%d 0x%08x\n", i, desc->region.FLREGs[i]);
262 msg_pdbg2("\n");
263
264 msg_pdbg2("--- Details ---\n");
Stefan Tauner0554ca52013-07-25 22:54:25 +0000265 for (i = 0; i < 5; i++)
Stefan Tauner1e146392011-09-15 23:52:55 +0000266 pprint_freg(&desc->region, i);
267 msg_pdbg2("\n");
268}
269
270void prettyprint_ich_descriptor_master(const struct ich_desc_master *mstr)
271{
272 msg_pdbg2("=== Master Section ===\n");
273 msg_pdbg2("FLMSTR1 0x%08x\n", mstr->FLMSTR1);
274 msg_pdbg2("FLMSTR2 0x%08x\n", mstr->FLMSTR2);
275 msg_pdbg2("FLMSTR3 0x%08x\n", mstr->FLMSTR3);
276 msg_pdbg2("\n");
277
278 msg_pdbg2("--- Details ---\n");
279 msg_pdbg2(" Descr. BIOS ME GbE Platf.\n");
280 msg_pdbg2("BIOS %c%c %c%c %c%c %c%c %c%c\n",
281 (mstr->BIOS_descr_r) ?'r':' ', (mstr->BIOS_descr_w) ?'w':' ',
282 (mstr->BIOS_BIOS_r) ?'r':' ', (mstr->BIOS_BIOS_w) ?'w':' ',
283 (mstr->BIOS_ME_r) ?'r':' ', (mstr->BIOS_ME_w) ?'w':' ',
284 (mstr->BIOS_GbE_r) ?'r':' ', (mstr->BIOS_GbE_w) ?'w':' ',
285 (mstr->BIOS_plat_r) ?'r':' ', (mstr->BIOS_plat_w) ?'w':' ');
286 msg_pdbg2("ME %c%c %c%c %c%c %c%c %c%c\n",
287 (mstr->ME_descr_r) ?'r':' ', (mstr->ME_descr_w) ?'w':' ',
288 (mstr->ME_BIOS_r) ?'r':' ', (mstr->ME_BIOS_w) ?'w':' ',
289 (mstr->ME_ME_r) ?'r':' ', (mstr->ME_ME_w) ?'w':' ',
290 (mstr->ME_GbE_r) ?'r':' ', (mstr->ME_GbE_w) ?'w':' ',
291 (mstr->ME_plat_r) ?'r':' ', (mstr->ME_plat_w) ?'w':' ');
292 msg_pdbg2("GbE %c%c %c%c %c%c %c%c %c%c\n",
293 (mstr->GbE_descr_r) ?'r':' ', (mstr->GbE_descr_w) ?'w':' ',
294 (mstr->GbE_BIOS_r) ?'r':' ', (mstr->GbE_BIOS_w) ?'w':' ',
295 (mstr->GbE_ME_r) ?'r':' ', (mstr->GbE_ME_w) ?'w':' ',
296 (mstr->GbE_GbE_r) ?'r':' ', (mstr->GbE_GbE_w) ?'w':' ',
297 (mstr->GbE_plat_r) ?'r':' ', (mstr->GbE_plat_w) ?'w':' ');
298 msg_pdbg2("\n");
299}
300
Stefan Taunerb3850962011-12-24 00:00:32 +0000301void prettyprint_ich_descriptor_straps_ich8(const struct ich_descriptors *desc)
302{
303 static const char * const str_GPIO12[4] = {
304 "GPIO12",
305 "LAN PHY Power Control Function (Native Output)",
306 "GLAN_DOCK# (Native Input)",
307 "invalid configuration",
308 };
309
310 msg_pdbg2("--- MCH details ---\n");
311 msg_pdbg2("ME B is %sabled.\n", desc->north.ich8.MDB ? "dis" : "en");
312 msg_pdbg2("\n");
313
314 msg_pdbg2("--- ICH details ---\n");
315 msg_pdbg2("ME SMBus Address 1: 0x%02x\n", desc->south.ich8.ASD);
316 msg_pdbg2("ME SMBus Address 2: 0x%02x\n", desc->south.ich8.ASD2);
317 msg_pdbg2("ME SMBus Controller is connected to the %s.\n",
318 desc->south.ich8.MESM2SEL ? "SMLink pins" : "SMBus pins");
319 msg_pdbg2("SPI CS1 is used for %s.\n",
320 desc->south.ich8.SPICS1_LANPHYPC_SEL ?
321 "LAN PHY Power Control Function" :
322 "SPI Chip Select");
323 msg_pdbg2("GPIO12 is used as %s.\n",
324 str_GPIO12[desc->south.ich8.GPIO12_SEL]);
325 msg_pdbg2("PCIe Port 6 is used for %s.\n",
326 desc->south.ich8.GLAN_PCIE_SEL ? "integrated LAN" : "PCI Express");
327 msg_pdbg2("%sn BMC Mode: "
328 "Intel AMT SMBus Controller 1 is connected to %s.\n",
329 desc->south.ich8.BMCMODE ? "I" : "Not i",
330 desc->south.ich8.BMCMODE ? "SMLink" : "SMBus");
331 msg_pdbg2("TCO is in %s Mode.\n",
332 desc->south.ich8.TCOMODE ? "Advanced TCO" : "Legacy/Compatible");
333 msg_pdbg2("ME A is %sabled.\n",
334 desc->south.ich8.ME_DISABLE ? "dis" : "en");
335 msg_pdbg2("\n");
336}
337
338static void prettyprint_ich_descriptor_straps_56_pciecs(uint8_t conf, uint8_t off)
339{
340 msg_pdbg2("PCI Express Port Configuration Strap %d: ", off+1);
341
342 off *= 4;
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000343 switch (conf){
Stefan Taunerb3850962011-12-24 00:00:32 +0000344 case 0:
345 msg_pdbg2("4x1 Ports %d-%d (x1)", 1+off, 4+off);
346 break;
347 case 1:
348 msg_pdbg2("1x2, 2x1 Port %d (x2), Port %d (disabled), "
349 "Ports %d, %d (x1)", 1+off, 2+off, 3+off, 4+off);
350 break;
351 case 2:
352 msg_pdbg2("2x2 Port %d (x2), Port %d (x2), Ports "
353 "%d, %d (disabled)", 1+off, 3+off, 2+off, 4+off);
354 break;
355 case 3:
356 msg_pdbg2("1x4 Port %d (x4), Ports %d-%d (disabled)",
357 1+off, 2+off, 4+off);
358 break;
359 }
360 msg_pdbg2("\n");
361}
362
363void prettyprint_ich_descriptor_pchstraps45678_56(const struct ich_desc_south_strap *s)
364{
365 /* PCHSTRP4 */
366 msg_pdbg2("Intel PHY is %s.\n",
367 (s->ibex.PHYCON == 2) ? "connected" :
368 (s->ibex.PHYCON == 0) ? "disconnected" : "reserved");
369 msg_pdbg2("GbE MAC SMBus address is %sabled.\n",
370 s->ibex.GBEMAC_SMBUS_ADDR_EN ? "en" : "dis");
371 msg_pdbg2("GbE MAC SMBus address: 0x%02x\n",
372 s->ibex.GBEMAC_SMBUS_ADDR);
373 msg_pdbg2("GbE PHY SMBus address: 0x%02x\n",
374 s->ibex.GBEPHY_SMBUS_ADDR);
375
376 /* PCHSTRP5 */
377 /* PCHSTRP6 */
378 /* PCHSTRP7 */
379 msg_pdbg2("Intel ME SMBus Subsystem Vendor ID: 0x%04x\n",
380 s->ibex.MESMA2UDID_VENDOR);
381 msg_pdbg2("Intel ME SMBus Subsystem Device ID: 0x%04x\n",
382 s->ibex.MESMA2UDID_VENDOR);
383
384 /* PCHSTRP8 */
385}
386
387void prettyprint_ich_descriptor_pchstraps111213_56(const struct ich_desc_south_strap *s)
388{
389 /* PCHSTRP11 */
390 msg_pdbg2("SMLink1 GP Address is %sabled.\n",
391 s->ibex.SML1GPAEN ? "en" : "dis");
392 msg_pdbg2("SMLink1 controller General Purpose Target address: 0x%02x\n",
393 s->ibex.SML1GPA);
394 msg_pdbg2("SMLink1 I2C Target address is %sabled.\n",
395 s->ibex.SML1I2CAEN ? "en" : "dis");
396 msg_pdbg2("SMLink1 I2C Target address: 0x%02x\n",
397 s->ibex.SML1I2CA);
398
399 /* PCHSTRP12 */
400 /* PCHSTRP13 */
401}
402
403void prettyprint_ich_descriptor_straps_ibex(const struct ich_desc_south_strap *s)
404{
Stefan Tauner67d163d2013-01-15 17:37:48 +0000405 static const uint8_t dec_t209min[4] = {
Stefan Taunerb3850962011-12-24 00:00:32 +0000406 100,
407 50,
408 5,
409 1
410 };
411
412 msg_pdbg2("--- PCH ---\n");
413
414 /* PCHSTRP0 */
415 msg_pdbg2("Chipset configuration Softstrap 2: %d\n", s->ibex.cs_ss2);
416 msg_pdbg2("Intel ME SMBus Select is %sabled.\n",
417 s->ibex.SMB_EN ? "en" : "dis");
418 msg_pdbg2("SMLink0 segment is %sabled.\n",
419 s->ibex.SML0_EN ? "en" : "dis");
420 msg_pdbg2("SMLink1 segment is %sabled.\n",
421 s->ibex.SML1_EN ? "en" : "dis");
422 msg_pdbg2("SMLink1 Frequency: %s\n",
423 (s->ibex.SML1FRQ == 1) ? "100 kHz" : "reserved");
424 msg_pdbg2("Intel ME SMBus Frequency: %s\n",
425 (s->ibex.SMB0FRQ == 1) ? "100 kHz" : "reserved");
426 msg_pdbg2("SMLink0 Frequency: %s\n",
427 (s->ibex.SML0FRQ == 1) ? "100 kHz" : "reserved");
428 msg_pdbg2("GPIO12 is used as %s.\n", s->ibex.LANPHYPC_GP12_SEL ?
429 "LAN_PHY_PWR_CTRL" : "general purpose output");
430 msg_pdbg2("Chipset configuration Softstrap 1: %d\n", s->ibex.cs_ss1);
431 msg_pdbg2("DMI RequesterID Checks are %sabled.\n",
432 s->ibex.DMI_REQID_DIS ? "en" : "dis");
433 msg_pdbg2("BIOS Boot-Block size (BBBS): %d kB.\n",
434 1 << (6 + s->ibex.BBBS));
435
436 /* PCHSTRP1 */
437 msg_pdbg2("Chipset configuration Softstrap 3: 0x%x\n", s->ibex.cs_ss3);
438
439 /* PCHSTRP2 */
440 msg_pdbg2("ME SMBus ASD address is %sabled.\n",
441 s->ibex.MESMASDEN ? "en" : "dis");
442 msg_pdbg2("ME SMBus Controller ASD Target address: 0x%02x\n",
443 s->ibex.MESMASDA);
444 msg_pdbg2("ME SMBus I2C address is %sabled.\n",
445 s->ibex.MESMI2CEN ? "en" : "dis");
446 msg_pdbg2("ME SMBus I2C target address: 0x%02x\n",
447 s->ibex.MESMI2CA);
448
449 /* PCHSTRP3 */
450 prettyprint_ich_descriptor_pchstraps45678_56(s);
451 /* PCHSTRP9 */
452 prettyprint_ich_descriptor_straps_56_pciecs(s->ibex.PCIEPCS1, 0);
453 prettyprint_ich_descriptor_straps_56_pciecs(s->ibex.PCIEPCS1, 1);
454 msg_pdbg2("PCIe Lane Reversal 1: PCIe Lanes 0-3 are %sreserved.\n",
455 s->ibex.PCIELR1 ? "" : "not ");
456 msg_pdbg2("PCIe Lane Reversal 2: PCIe Lanes 4-7 are %sreserved.\n",
457 s->ibex.PCIELR2 ? "" : "not ");
458 msg_pdbg2("DMI Lane Reversal: DMI Lanes 0-3 are %sreserved.\n",
459 s->ibex.DMILR ? "" : "not ");
460 msg_pdbg2("Default PHY PCIe Port is %d.\n", s->ibex.PHY_PCIEPORTSEL+1);
461 msg_pdbg2("Integrated MAC/PHY communication over PCIe is %sabled.\n",
462 s->ibex.PHY_PCIE_EN ? "en" : "dis");
463
464 /* PCHSTRP10 */
465 msg_pdbg2("Management Engine will boot from %sflash.\n",
466 s->ibex.ME_BOOT_FLASH ? "" : "ROM, then ");
467 msg_pdbg2("Chipset configuration Softstrap 5: %d\n", s->ibex.cs_ss5);
468 msg_pdbg2("Virtualization Engine Enable 1 is %sabled.\n",
469 s->ibex.VE_EN ? "en" : "dis");
470 msg_pdbg2("ME Memory-attached Debug Display Device is %sabled.\n",
471 s->ibex.MMDDE ? "en" : "dis");
472 msg_pdbg2("ME Memory-attached Debug Display Device address: 0x%02x\n",
473 s->ibex.MMADDR);
474 msg_pdbg2("Chipset configuration Softstrap 7: %d\n", s->ibex.cs_ss7);
475 msg_pdbg2("Integrated Clocking Configuration is %d.\n",
476 (s->ibex.ICC_SEL == 7) ? 0 : s->ibex.ICC_SEL);
477 msg_pdbg2("PCH Signal CL_RST1# does %sassert when Intel ME performs a "
478 "reset.\n", s->ibex.MER_CL1 ? "" : "not ");
479
480 prettyprint_ich_descriptor_pchstraps111213_56(s);
481
482 /* PCHSTRP14 */
483 msg_pdbg2("Virtualization Engine Enable 2 is %sabled.\n",
484 s->ibex.VE_EN2 ? "en" : "dis");
485 msg_pdbg2("Virtualization Engine will boot from %sflash.\n",
486 s->ibex.VE_BOOT_FLASH ? "" : "ROM, then ");
487 msg_pdbg2("Braidwood SSD functionality is %sabled.\n",
488 s->ibex.BW_SSD ? "en" : "dis");
489 msg_pdbg2("Braidwood NVMHCI functionality is %sabled.\n",
490 s->ibex.NVMHCI_EN ? "en" : "dis");
491
492 /* PCHSTRP15 */
493 msg_pdbg2("Chipset configuration Softstrap 6: %d\n", s->ibex.cs_ss6);
494 msg_pdbg2("Integrated wired LAN Solution is %sabled.\n",
495 s->ibex.IWL_EN ? "en" : "dis");
496 msg_pdbg2("t209 min Timing: %d ms\n",
497 dec_t209min[s->ibex.t209min]);
498 msg_pdbg2("\n");
499}
500
501void prettyprint_ich_descriptor_straps_cougar(const struct ich_desc_south_strap *s)
502{
503 msg_pdbg2("--- PCH ---\n");
504
505 /* PCHSTRP0 */
506 msg_pdbg2("Chipset configuration Softstrap 1: %d\n", s->cougar.cs_ss1);
507 msg_pdbg2("Intel ME SMBus Select is %sabled.\n",
508 s->ibex.SMB_EN ? "en" : "dis");
509 msg_pdbg2("SMLink0 segment is %sabled.\n",
510 s->ibex.SML0_EN ? "en" : "dis");
511 msg_pdbg2("SMLink1 segment is %sabled.\n",
512 s->ibex.SML1_EN ? "en" : "dis");
513 msg_pdbg2("SMLink1 Frequency: %s\n",
514 (s->ibex.SML1FRQ == 1) ? "100 kHz" : "reserved");
515 msg_pdbg2("Intel ME SMBus Frequency: %s\n",
516 (s->ibex.SMB0FRQ == 1) ? "100 kHz" : "reserved");
517 msg_pdbg2("SMLink0 Frequency: %s\n",
518 (s->ibex.SML0FRQ == 1) ? "100 kHz" : "reserved");
519 msg_pdbg2("GPIO12 is used as %s.\n", s->ibex.LANPHYPC_GP12_SEL ?
520 "LAN_PHY_PWR_CTRL" : "general purpose output");
521 msg_pdbg2("LinkSec is %sabled.\n",
522 s->cougar.LINKSEC_DIS ? "en" : "dis");
523 msg_pdbg2("DMI RequesterID Checks are %sabled.\n",
524 s->ibex.DMI_REQID_DIS ? "en" : "dis");
525 msg_pdbg2("BIOS Boot-Block size (BBBS): %d kB.\n",
526 1 << (6 + s->ibex.BBBS));
527
528 /* PCHSTRP1 */
529 msg_pdbg2("Chipset configuration Softstrap 3: 0x%x\n", s->ibex.cs_ss3);
530 msg_pdbg2("Chipset configuration Softstrap 2: 0x%x\n", s->ibex.cs_ss2);
531
532 /* PCHSTRP2 */
533 msg_pdbg2("ME SMBus ASD address is %sabled.\n",
534 s->ibex.MESMASDEN ? "en" : "dis");
535 msg_pdbg2("ME SMBus Controller ASD Target address: 0x%02x\n",
536 s->ibex.MESMASDA);
537 msg_pdbg2("ME SMBus MCTP Address is %sabled.\n",
538 s->cougar.MESMMCTPAEN ? "en" : "dis");
539 msg_pdbg2("ME SMBus MCTP target address: 0x%02x\n",
540 s->cougar.MESMMCTPA);
541 msg_pdbg2("ME SMBus I2C address is %sabled.\n",
542 s->ibex.MESMI2CEN ? "en" : "dis");
543 msg_pdbg2("ME SMBus I2C target address: 0x%02x\n",
544 s->ibex.MESMI2CA);
545
546 /* PCHSTRP3 */
547 prettyprint_ich_descriptor_pchstraps45678_56(s);
548 /* PCHSTRP9 */
549 prettyprint_ich_descriptor_straps_56_pciecs(s->ibex.PCIEPCS1, 0);
550 prettyprint_ich_descriptor_straps_56_pciecs(s->ibex.PCIEPCS1, 1);
551 msg_pdbg2("PCIe Lane Reversal 1: PCIe Lanes 0-3 are %sreserved.\n",
552 s->ibex.PCIELR1 ? "" : "not ");
553 msg_pdbg2("PCIe Lane Reversal 2: PCIe Lanes 4-7 are %sreserved.\n",
554 s->ibex.PCIELR2 ? "" : "not ");
555 msg_pdbg2("DMI Lane Reversal: DMI Lanes 0-3 are %sreserved.\n",
556 s->ibex.DMILR ? "" : "not ");
557 msg_pdbg2("ME Debug status writes over SMBUS are %sabled.\n",
558 s->cougar.MDSMBE_EN ? "en" : "dis");
559 msg_pdbg2("ME Debug SMBus Emergency Mode address: 0x%02x (raw)\n",
560 s->cougar.MDSMBE_ADD);
561 msg_pdbg2("Default PHY PCIe Port is %d.\n", s->ibex.PHY_PCIEPORTSEL+1);
562 msg_pdbg2("Integrated MAC/PHY communication over PCIe is %sabled.\n",
563 s->ibex.PHY_PCIE_EN ? "en" : "dis");
564 msg_pdbg2("PCIe ports Subtractive Decode Agent is %sabled.\n",
565 s->cougar.SUB_DECODE_EN ? "en" : "dis");
566 msg_pdbg2("GPIO74 is used as %s.\n", s->cougar.PCHHOT_SML1ALERT_SEL ?
567 "PCHHOT#" : "SML1ALERT#");
568
569 /* PCHSTRP10 */
570 msg_pdbg2("Management Engine will boot from %sflash.\n",
571 s->ibex.ME_BOOT_FLASH ? "" : "ROM, then ");
572
573 msg_pdbg2("ME Debug SMBus Emergency Mode is %sabled.\n",
574 s->cougar.MDSMBE_EN ? "en" : "dis");
575 msg_pdbg2("ME Debug SMBus Emergency Mode Address: 0x%02x\n",
576 s->cougar.MDSMBE_ADD);
577
578 msg_pdbg2("Integrated Clocking Configuration used: %d\n",
579 s->cougar.ICC_SEL);
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000580 msg_pdbg2("PCH Signal CL_RST1# does %sassert when Intel ME performs a reset.\n",
581 s->ibex.MER_CL1 ? "" : "not ");
Stefan Taunerb3850962011-12-24 00:00:32 +0000582 msg_pdbg2("ICC Profile is selected by %s.\n",
583 s->cougar.ICC_PRO_SEL ? "Softstraps" : "BIOS");
584 msg_pdbg2("Deep SX is %ssupported on the platform.\n",
585 s->cougar.Deep_SX_EN ? "not " : "");
586 msg_pdbg2("ME Debug LAN Emergency Mode is %sabled.\n",
587 s->cougar.ME_DBG_LAN ? "en" : "dis");
588
589 prettyprint_ich_descriptor_pchstraps111213_56(s);
590
591 /* PCHSTRP14 */
592 /* PCHSTRP15 */
593 msg_pdbg2("Chipset configuration Softstrap 6: %d\n", s->cougar.cs_ss6);
594 msg_pdbg2("Integrated wired LAN is %sabled.\n",
595 s->cougar.IWL_EN ? "en" : "dis");
596 msg_pdbg2("Chipset configuration Softstrap 5: %d\n", s->cougar.cs_ss5);
597 msg_pdbg2("SMLink1 provides temperature from %s.\n",
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000598 s->cougar.SMLINK1_THERM_SEL ? "PCH only" : "the CPU, PCH and DIMMs");
Stefan Taunerb3850962011-12-24 00:00:32 +0000599 msg_pdbg2("GPIO29 is used as %s.\n", s->cougar.SLP_LAN_GP29_SEL ?
600 "general purpose output" : "SLP_LAN#");
601
602 /* PCHSTRP16 */
603 /* PCHSTRP17 */
604 msg_pdbg2("Integrated Clock: %s Clock Mode\n",
605 s->cougar.ICML ? "Buffered Through" : "Full Integrated");
606 msg_pdbg2("\n");
607}
608
609void prettyprint_ich_descriptor_straps(enum ich_chipset cs, const struct ich_descriptors *desc)
610{
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000611 unsigned int i, max_count;
Stefan Taunerb3850962011-12-24 00:00:32 +0000612 msg_pdbg2("=== Softstraps ===\n");
613
Nico Huberd7c75522017-03-29 16:31:49 +0200614 max_count = min(ARRAY_SIZE(desc->north.STRPs), desc->content.MSL);
615 if (max_count < desc->content.MSL) {
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000616 msg_pdbg2("MSL (%u) is greater than the current maximum of %u entries.\n",
Nico Huberd7c75522017-03-29 16:31:49 +0200617 desc->content.MSL, max_count);
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000618 msg_pdbg2("Only the first %u entries will be printed.\n", max_count);
Nico Huberd7c75522017-03-29 16:31:49 +0200619 }
Stefan Taunerb3850962011-12-24 00:00:32 +0000620
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000621 msg_pdbg2("--- North/MCH/PROC (%d entries) ---\n", max_count);
622 for (i = 0; i < max_count; i++)
Stefan Taunerb3850962011-12-24 00:00:32 +0000623 msg_pdbg2("STRP%-2d = 0x%08x\n", i, desc->north.STRPs[i]);
624 msg_pdbg2("\n");
625
Nico Huberd7c75522017-03-29 16:31:49 +0200626 max_count = min(ARRAY_SIZE(desc->south.STRPs), desc->content.ISL);
627 if (max_count < desc->content.ISL) {
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000628 msg_pdbg2("ISL (%u) is greater than the current maximum of %u entries.\n",
629 desc->content.ISL, max_count);
630 msg_pdbg2("Only the first %u entries will be printed.\n", max_count);
Nico Huberd7c75522017-03-29 16:31:49 +0200631 }
Stefan Taunerb3850962011-12-24 00:00:32 +0000632
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000633 msg_pdbg2("--- South/ICH/PCH (%d entries) ---\n", max_count);
634 for (i = 0; i < max_count; i++)
Stefan Taunerb3850962011-12-24 00:00:32 +0000635 msg_pdbg2("STRP%-2d = 0x%08x\n", i, desc->south.STRPs[i]);
636 msg_pdbg2("\n");
637
638 switch (cs) {
639 case CHIPSET_ICH8:
640 if (sizeof(desc->north.ich8) / 4 != desc->content.MSL)
641 msg_pdbg2("Detailed North/MCH/PROC information is "
642 "probably not reliable, printing anyway.\n");
643 if (sizeof(desc->south.ich8) / 4 != desc->content.ISL)
644 msg_pdbg2("Detailed South/ICH/PCH information is "
645 "probably not reliable, printing anyway.\n");
646 prettyprint_ich_descriptor_straps_ich8(desc);
647 break;
648 case CHIPSET_5_SERIES_IBEX_PEAK:
649 /* PCH straps only. PROCSTRPs are unknown. */
650 if (sizeof(desc->south.ibex) / 4 != desc->content.ISL)
651 msg_pdbg2("Detailed South/ICH/PCH information is "
652 "probably not reliable, printing anyway.\n");
653 prettyprint_ich_descriptor_straps_ibex(&desc->south);
654 break;
655 case CHIPSET_6_SERIES_COUGAR_POINT:
656 /* PCH straps only. PROCSTRP0 is "reserved". */
657 if (sizeof(desc->south.cougar) / 4 != desc->content.ISL)
658 msg_pdbg2("Detailed South/ICH/PCH information is "
659 "probably not reliable, printing anyway.\n");
660 prettyprint_ich_descriptor_straps_cougar(&desc->south);
661 break;
662 case CHIPSET_ICH_UNKNOWN:
663 break;
664 default:
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000665 msg_pdbg2("The meaning of the descriptor straps are unknown yet.\n\n");
Stefan Taunerb3850962011-12-24 00:00:32 +0000666 break;
667 }
668}
669
670void prettyprint_rdid(uint32_t reg_val)
671{
672 uint8_t mid = reg_val & 0xFF;
673 uint16_t did = ((reg_val >> 16) & 0xFF) | (reg_val & 0xFF00);
674 msg_pdbg2("Manufacturer ID 0x%02x, Device ID 0x%04x\n", mid, did);
675}
676
677void prettyprint_ich_descriptor_upper_map(const struct ich_desc_upper_map *umap)
678{
679 int i;
680 msg_pdbg2("=== Upper Map Section ===\n");
681 msg_pdbg2("FLUMAP1 0x%08x\n", umap->FLUMAP1);
682 msg_pdbg2("\n");
683
684 msg_pdbg2("--- Details ---\n");
685 msg_pdbg2("VTL (length in DWORDS) = %d\n", umap->VTL);
686 msg_pdbg2("VTBA (base address) = 0x%6.6x\n", getVTBA(umap));
687 msg_pdbg2("\n");
688
689 msg_pdbg2("VSCC Table: %d entries\n", umap->VTL/2);
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000690 for (i = 0; i < umap->VTL/2; i++) {
Stefan Taunerb3850962011-12-24 00:00:32 +0000691 uint32_t jid = umap->vscc_table[i].JID;
692 uint32_t vscc = umap->vscc_table[i].VSCC;
693 msg_pdbg2(" JID%d = 0x%08x\n", i, jid);
694 msg_pdbg2(" VSCC%d = 0x%08x\n", i, vscc);
695 msg_pdbg2(" "); /* indention */
696 prettyprint_rdid(jid);
697 msg_pdbg2(" "); /* indention */
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000698 prettyprint_ich_reg_vscc(vscc, 0, false);
Stefan Taunerb3850962011-12-24 00:00:32 +0000699 }
700 msg_pdbg2("\n");
701}
702
703/* len is the length of dump in bytes */
704int read_ich_descriptors_from_dump(const uint32_t *dump, unsigned int len, struct ich_descriptors *desc)
705{
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000706 unsigned int i, max_count;
Stefan Taunerb3850962011-12-24 00:00:32 +0000707 uint8_t pch_bug_offset = 0;
708
709 if (dump == NULL || desc == NULL)
710 return ICH_RET_PARAM;
711
712 if (dump[0] != DESCRIPTOR_MODE_SIGNATURE) {
713 if (dump[4] == DESCRIPTOR_MODE_SIGNATURE)
714 pch_bug_offset = 4;
715 else
716 return ICH_RET_ERR;
717 }
718
719 /* map */
Nico Huber9e14aed2017-03-28 17:08:46 +0200720 if (len < (4 + pch_bug_offset) * 4)
Stefan Taunerb3850962011-12-24 00:00:32 +0000721 return ICH_RET_OOB;
722 desc->content.FLVALSIG = dump[0 + pch_bug_offset];
723 desc->content.FLMAP0 = dump[1 + pch_bug_offset];
724 desc->content.FLMAP1 = dump[2 + pch_bug_offset];
725 desc->content.FLMAP2 = dump[3 + pch_bug_offset];
726
727 /* component */
Nico Huber9e14aed2017-03-28 17:08:46 +0200728 if (len < getFCBA(&desc->content) + 3 * 4)
Stefan Taunerb3850962011-12-24 00:00:32 +0000729 return ICH_RET_OOB;
730 desc->component.FLCOMP = dump[(getFCBA(&desc->content) >> 2) + 0];
731 desc->component.FLILL = dump[(getFCBA(&desc->content) >> 2) + 1];
732 desc->component.FLPB = dump[(getFCBA(&desc->content) >> 2) + 2];
733
734 /* region */
Nico Huber9e14aed2017-03-28 17:08:46 +0200735 if (len < getFRBA(&desc->content) + 5 * 4)
Stefan Taunerb3850962011-12-24 00:00:32 +0000736 return ICH_RET_OOB;
737 desc->region.FLREGs[0] = dump[(getFRBA(&desc->content) >> 2) + 0];
738 desc->region.FLREGs[1] = dump[(getFRBA(&desc->content) >> 2) + 1];
739 desc->region.FLREGs[2] = dump[(getFRBA(&desc->content) >> 2) + 2];
740 desc->region.FLREGs[3] = dump[(getFRBA(&desc->content) >> 2) + 3];
741 desc->region.FLREGs[4] = dump[(getFRBA(&desc->content) >> 2) + 4];
742
743 /* master */
Nico Huber9e14aed2017-03-28 17:08:46 +0200744 if (len < getFMBA(&desc->content) + 3 * 4)
Stefan Taunerb3850962011-12-24 00:00:32 +0000745 return ICH_RET_OOB;
746 desc->master.FLMSTR1 = dump[(getFMBA(&desc->content) >> 2) + 0];
747 desc->master.FLMSTR2 = dump[(getFMBA(&desc->content) >> 2) + 1];
748 desc->master.FLMSTR3 = dump[(getFMBA(&desc->content) >> 2) + 2];
749
750 /* upper map */
751 desc->upper.FLUMAP1 = dump[(UPPER_MAP_OFFSET >> 2) + 0];
752
753 /* VTL is 8 bits long. Quote from the Ibex Peak SPI programming guide:
754 * "Identifies the 1s based number of DWORDS contained in the VSCC
755 * Table. Each SPI component entry in the table is 2 DWORDS long." So
756 * the maximum of 255 gives us 127.5 SPI components(!?) 8 bytes each. A
757 * check ensures that the maximum offset actually accessed is available.
758 */
Nico Huber9e14aed2017-03-28 17:08:46 +0200759 if (len < getVTBA(&desc->upper) + (desc->upper.VTL / 2 * 8))
Stefan Taunerb3850962011-12-24 00:00:32 +0000760 return ICH_RET_OOB;
761
762 for (i = 0; i < desc->upper.VTL/2; i++) {
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000763 desc->upper.vscc_table[i].JID = dump[(getVTBA(&desc->upper) >> 2) + i * 2 + 0];
764 desc->upper.vscc_table[i].VSCC = dump[(getVTBA(&desc->upper) >> 2) + i * 2 + 1];
Stefan Taunerb3850962011-12-24 00:00:32 +0000765 }
766
767 /* MCH/PROC (aka. North) straps */
768 if (len < getFMSBA(&desc->content) + desc->content.MSL * 4)
769 return ICH_RET_OOB;
770
771 /* limit the range to be written */
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000772 max_count = min(sizeof(desc->north.STRPs) / 4, desc->content.MSL);
773 for (i = 0; i < max_count; i++)
774 desc->north.STRPs[i] = dump[(getFMSBA(&desc->content) >> 2) + i];
Stefan Taunerb3850962011-12-24 00:00:32 +0000775
776 /* ICH/PCH (aka. South) straps */
777 if (len < getFISBA(&desc->content) + desc->content.ISL * 4)
778 return ICH_RET_OOB;
779
780 /* limit the range to be written */
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000781 max_count = min(sizeof(desc->south.STRPs) / 4, desc->content.ISL);
782 for (i = 0; i < max_count; i++)
783 desc->south.STRPs[i] = dump[(getFISBA(&desc->content) >> 2) + i];
Stefan Taunerb3850962011-12-24 00:00:32 +0000784
785 return ICH_RET_OK;
786}
787
Nico Huberad186312016-05-02 15:15:29 +0200788#ifndef ICH_DESCRIPTORS_FROM_DUMP_ONLY
Stefan Taunerb3850962011-12-24 00:00:32 +0000789
Stefan Taunerd0c5dc22011-10-20 12:57:14 +0000790/** Returns the integer representation of the component density with index
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000791\em idx in bytes or -1 if the correct size can not be determined. */
792int getFCBA_component_density(enum ich_chipset cs, const struct ich_descriptors *desc, uint8_t idx)
Stefan Taunerd0c5dc22011-10-20 12:57:14 +0000793{
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000794 if (idx > 1) {
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000795 msg_perr("Only ICH SPI component index 0 or 1 are supported yet.\n");
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000796 return -1;
Stefan Taunerd0c5dc22011-10-20 12:57:14 +0000797 }
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000798
799 if (desc->content.NC == 0 && idx > 0)
Stefan Taunerd0c5dc22011-10-20 12:57:14 +0000800 return 0;
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000801
802 uint8_t size_enc;
803 uint8_t size_max;
804
805 switch (cs) {
806 case CHIPSET_ICH8:
807 case CHIPSET_ICH9:
808 case CHIPSET_ICH10:
809 case CHIPSET_5_SERIES_IBEX_PEAK:
810 case CHIPSET_6_SERIES_COUGAR_POINT:
811 case CHIPSET_7_SERIES_PANTHER_POINT:
Tai-Hong Wu60dead42015-01-05 23:00:14 +0000812 case CHIPSET_BAYTRAIL:
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000813 if (idx == 0) {
Tai-Hong Wu60dead42015-01-05 23:00:14 +0000814 size_enc = desc->component.dens_old.comp1_density;
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000815 } else {
Tai-Hong Wu60dead42015-01-05 23:00:14 +0000816 size_enc = desc->component.dens_old.comp2_density;
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000817 }
818 size_max = 5;
819 break;
820 case CHIPSET_8_SERIES_LYNX_POINT:
821 case CHIPSET_8_SERIES_LYNX_POINT_LP:
822 case CHIPSET_8_SERIES_WELLSBURG:
Duncan Laurie823096e2014-08-20 15:39:38 +0000823 case CHIPSET_9_SERIES_WILDCAT_POINT:
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000824 if (idx == 0) {
Tai-Hong Wu60dead42015-01-05 23:00:14 +0000825 size_enc = desc->component.dens_new.comp1_density;
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000826 } else {
Tai-Hong Wu60dead42015-01-05 23:00:14 +0000827 size_enc = desc->component.dens_new.comp2_density;
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000828 }
829 size_max = 7;
830 break;
831 case CHIPSET_ICH_UNKNOWN:
832 default:
833 msg_pwarn("Density encoding is unknown on this chipset.\n");
834 return -1;
Stefan Taunerd0c5dc22011-10-20 12:57:14 +0000835 }
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000836
837 if (size_enc > size_max) {
Tai-Hong Wu60dead42015-01-05 23:00:14 +0000838 msg_perr("Density of ICH SPI component with index %d is invalid.\n"
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000839 "Encoded density is 0x%x while maximum allowed is 0x%x.\n",
840 idx, size_enc, size_max);
841 return -1;
842 }
843
Stefan Taunerd0c5dc22011-10-20 12:57:14 +0000844 return (1 << (19 + size_enc));
845}
846
Stefan Tauner1e146392011-09-15 23:52:55 +0000847static uint32_t read_descriptor_reg(uint8_t section, uint16_t offset, void *spibar)
848{
849 uint32_t control = 0;
850 control |= (section << FDOC_FDSS_OFF) & FDOC_FDSS;
851 control |= (offset << FDOC_FDSI_OFF) & FDOC_FDSI;
852 mmio_le_writel(control, spibar + ICH9_REG_FDOC);
853 return mmio_le_readl(spibar + ICH9_REG_FDOD);
854}
855
856int read_ich_descriptors_via_fdo(void *spibar, struct ich_descriptors *desc)
857{
858 uint8_t i;
859 uint8_t nr;
860 struct ich_desc_region *r = &desc->region;
861
862 /* Test if bit-fields are working as expected.
863 * FIXME: Replace this with dynamic bitfield fixup
864 */
865 for (i = 0; i < 4; i++)
866 desc->region.FLREGs[i] = 0x5A << (i * 8);
867 if (r->reg0_base != 0x005A || r->reg0_limit != 0x0000 ||
868 r->reg1_base != 0x1A00 || r->reg1_limit != 0x0000 ||
869 r->reg2_base != 0x0000 || r->reg2_limit != 0x005A ||
870 r->reg3_base != 0x0000 || r->reg3_limit != 0x1A00) {
871 msg_pdbg("The combination of compiler and CPU architecture used"
872 "does not lay out bit-fields as expected, sorry.\n");
873 msg_pspew("r->reg0_base = 0x%04X (0x005A)\n", r->reg0_base);
874 msg_pspew("r->reg0_limit = 0x%04X (0x0000)\n", r->reg0_limit);
875 msg_pspew("r->reg1_base = 0x%04X (0x1A00)\n", r->reg1_base);
876 msg_pspew("r->reg1_limit = 0x%04X (0x0000)\n", r->reg1_limit);
877 msg_pspew("r->reg2_base = 0x%04X (0x0000)\n", r->reg2_base);
878 msg_pspew("r->reg2_limit = 0x%04X (0x005A)\n", r->reg2_limit);
879 msg_pspew("r->reg3_base = 0x%04X (0x0000)\n", r->reg3_base);
880 msg_pspew("r->reg3_limit = 0x%04X (0x1A00)\n", r->reg3_limit);
881 return ICH_RET_ERR;
882 }
883
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000884 msg_pdbg2("Reading flash descriptors mapped by the chipset via FDOC/FDOD...");
Stefan Tauner1e146392011-09-15 23:52:55 +0000885 /* content section */
886 desc->content.FLVALSIG = read_descriptor_reg(0, 0, spibar);
887 desc->content.FLMAP0 = read_descriptor_reg(0, 1, spibar);
888 desc->content.FLMAP1 = read_descriptor_reg(0, 2, spibar);
889 desc->content.FLMAP2 = read_descriptor_reg(0, 3, spibar);
890
891 /* component section */
892 desc->component.FLCOMP = read_descriptor_reg(1, 0, spibar);
893 desc->component.FLILL = read_descriptor_reg(1, 1, spibar);
894 desc->component.FLPB = read_descriptor_reg(1, 2, spibar);
895
896 /* region section */
897 nr = desc->content.NR + 1;
Stefan Tauner2abab942012-04-27 20:41:23 +0000898 if (nr > 5) {
Stefan Tauner1e146392011-09-15 23:52:55 +0000899 msg_pdbg2("%s: number of regions too high (%d) - failed\n",
900 __func__, nr);
901 return ICH_RET_ERR;
902 }
Stefan Tauner0554ca52013-07-25 22:54:25 +0000903 for (i = 0; i < 5; i++)
Stefan Tauner1e146392011-09-15 23:52:55 +0000904 desc->region.FLREGs[i] = read_descriptor_reg(2, i, spibar);
905
906 /* master section */
907 desc->master.FLMSTR1 = read_descriptor_reg(3, 0, spibar);
908 desc->master.FLMSTR2 = read_descriptor_reg(3, 1, spibar);
909 desc->master.FLMSTR3 = read_descriptor_reg(3, 2, spibar);
910
911 /* Accessing the strap section via FDOC/D is only possible on ICH8 and
912 * reading the upper map is impossible on all chipsets, so don't bother.
913 */
914
915 msg_pdbg2(" done.\n");
916 return ICH_RET_OK;
917}
Nico Huber305f4172013-06-14 11:55:26 +0200918
919/**
920 * @brief Read a layout from the dump of an Intel ICH descriptor.
921 *
922 * @param layout Pointer where to store the layout.
923 * @param dump The descriptor dump to read from.
924 * @param len The length of the descriptor dump.
925 *
926 * @return 0 on success,
927 * 1 if the descriptor couldn't be parsed.
928 */
929int layout_from_ich_descriptors(struct ich_layout *const layout, const void *const dump, const size_t len)
930{
931 static const char *regions[] = { "fd", "bios", "me", "gbe", "pd" };
932
933 struct ich_descriptors desc;
934 if (read_ich_descriptors_from_dump(dump, len, &desc))
935 return 1;
936
937 memset(layout, 0x00, sizeof(*layout));
938
939 size_t i, j;
940 for (i = 0, j = 0; i < min(desc.content.NR + 1, ARRAY_SIZE(regions)); ++i) {
941 const chipoff_t base = ICH_FREG_BASE(desc.region.FLREGs[i]);
942 const chipoff_t limit = ICH_FREG_LIMIT(desc.region.FLREGs[i]) + 0xfff;
943 if (limit <= base)
944 continue;
945 layout->entries[j].start = base;
946 layout->entries[j].end = limit;
947 layout->entries[j].included = false;
948 snprintf(layout->entries[j].name, sizeof(layout->entries[j].name), "%s", regions[i]);
949 ++j;
950 }
951 layout->base.entries = layout->entries;
952 layout->base.num_entries = j;
953 return 0;
954}
955
Nico Huberad186312016-05-02 15:15:29 +0200956#endif /* ICH_DESCRIPTORS_FROM_DUMP_ONLY */