blob: 00af1e87daf8a5045a18060375d23ac21be052e7 [file] [log] [blame]
stepan927d4e22007-04-04 22:45:58 +00001/*
uweb25f1ea2007-08-29 17:52:32 +00002 * This file is part of the flashrom project.
stepan927d4e22007-04-04 22:45:58 +00003 *
uweb25f1ea2007-08-29 17:52:32 +00004 * Copyright (C) 2005-2007 coresystems GmbH <stepan@coresystems.de>
5 * Copyright (C) 2006 Uwe Hermann <uwe@hermann-uwe.de>
hailfinger755073f2008-02-09 02:03:06 +00006 * Copyright (C) 2007-2008 Luc Verhaegen <libv@skynet.be>
wardfbe9c652007-09-27 14:29:57 +00007 * Copyright (C) 2007 Carl-Daniel Hailfinger
stepan927d4e22007-04-04 22:45:58 +00008 *
uweb25f1ea2007-08-29 17:52:32 +00009 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2 of the License.
stepan927d4e22007-04-04 22:45:58 +000012 *
uweb25f1ea2007-08-29 17:52:32 +000013 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
stepan927d4e22007-04-04 22:45:58 +000021 */
22
23/*
24 * Contains the board specific flash enables.
25 */
26
27#include <stdio.h>
28#include <pci/pci.h>
29#include <stdint.h>
30#include <string.h>
stepanf778f522008-02-20 11:11:18 +000031#include <fcntl.h>
stepan927d4e22007-04-04 22:45:58 +000032#include "flash.h"
stepan927d4e22007-04-04 22:45:58 +000033
stuge04909772007-05-04 04:47:04 +000034/*
uwebe4477b2007-08-23 16:08:21 +000035 * Helper functions for many Winbond Super I/Os of the W836xx range.
stuge04909772007-05-04 04:47:04 +000036 */
stuge04909772007-05-04 04:47:04 +000037/* Enter extended functions */
stugeaa35d392009-01-26 02:34:51 +000038void w836xx_ext_enter(uint16_t port)
uwe23438a02007-05-03 10:09:23 +000039{
hailfingere1f062f2008-05-22 13:22:45 +000040 OUTB(0x87, port);
41 OUTB(0x87, port);
stuge04909772007-05-04 04:47:04 +000042}
uwe23438a02007-05-03 10:09:23 +000043
stuge04909772007-05-04 04:47:04 +000044/* Leave extended functions */
stugeaa35d392009-01-26 02:34:51 +000045void w836xx_ext_leave(uint16_t port)
stuge04909772007-05-04 04:47:04 +000046{
hailfingere1f062f2008-05-22 13:22:45 +000047 OUTB(0xAA, port);
stuge04909772007-05-04 04:47:04 +000048}
uwe23438a02007-05-03 10:09:23 +000049
uwebe4477b2007-08-23 16:08:21 +000050/* General functions for reading/writing Winbond Super I/Os. */
stugeaa35d392009-01-26 02:34:51 +000051unsigned char wbsio_read(uint16_t index, uint8_t reg)
stuge04909772007-05-04 04:47:04 +000052{
hailfingere1f062f2008-05-22 13:22:45 +000053 OUTB(reg, index);
54 return INB(index + 1);
stuge04909772007-05-04 04:47:04 +000055}
uwe23438a02007-05-03 10:09:23 +000056
stugeaa35d392009-01-26 02:34:51 +000057void wbsio_write(uint16_t index, uint8_t reg, uint8_t data)
stuge04909772007-05-04 04:47:04 +000058{
hailfingere1f062f2008-05-22 13:22:45 +000059 OUTB(reg, index);
60 OUTB(data, index + 1);
stuge04909772007-05-04 04:47:04 +000061}
uwe23438a02007-05-03 10:09:23 +000062
stugeaa35d392009-01-26 02:34:51 +000063void wbsio_mask(uint16_t index, uint8_t reg, uint8_t data, uint8_t mask)
stuge04909772007-05-04 04:47:04 +000064{
rminnich6079a1c2007-10-12 21:22:40 +000065 uint8_t tmp;
uwe23438a02007-05-03 10:09:23 +000066
hailfingere1f062f2008-05-22 13:22:45 +000067 OUTB(reg, index);
68 tmp = INB(index + 1) & ~mask;
69 OUTB(tmp | (data & mask), index + 1);
uwe23438a02007-05-03 10:09:23 +000070}
71
uwebe4477b2007-08-23 16:08:21 +000072/**
73 * Winbond W83627HF: Raise GPIO24.
stuge04909772007-05-04 04:47:04 +000074 *
75 * Suited for:
uwebe4477b2007-08-23 16:08:21 +000076 * - Agami Aruma
77 * - IWILL DK8-HTX
stepan927d4e22007-04-04 22:45:58 +000078 */
rminnich6079a1c2007-10-12 21:22:40 +000079static int w83627hf_gpio24_raise(uint16_t index, const char *name)
stepan927d4e22007-04-04 22:45:58 +000080{
rminnich6079a1c2007-10-12 21:22:40 +000081 w836xx_ext_enter(index);
stepan927d4e22007-04-04 22:45:58 +000082
uwe6ed6d952007-12-04 21:49:06 +000083 /* Is this the W83627HF? */
84 if (wbsio_read(index, 0x20) != 0x52) { /* Super I/O device ID reg. */
stuge04909772007-05-04 04:47:04 +000085 fprintf(stderr, "\nERROR: %s: W83627HF: Wrong ID: 0x%02X.\n",
rminnich6079a1c2007-10-12 21:22:40 +000086 name, wbsio_read(index, 0x20));
87 w836xx_ext_leave(index);
stepan927d4e22007-04-04 22:45:58 +000088 return -1;
89 }
90
stuge04909772007-05-04 04:47:04 +000091 /* PIN89S: WDTO/GP24 multiplex -> GPIO24 */
rminnich6079a1c2007-10-12 21:22:40 +000092 wbsio_mask(index, 0x2B, 0x10, 0x10);
stepan927d4e22007-04-04 22:45:58 +000093
uwe6ed6d952007-12-04 21:49:06 +000094 /* Select logical device 8: GPIO port 2 */
95 wbsio_write(index, 0x07, 0x08);
stepan927d4e22007-04-04 22:45:58 +000096
rminnich6079a1c2007-10-12 21:22:40 +000097 wbsio_mask(index, 0x30, 0x01, 0x01); /* Activate logical device. */
rminnich6079a1c2007-10-12 21:22:40 +000098 wbsio_mask(index, 0xF0, 0x00, 0x10); /* GPIO24 -> output */
rminnich6079a1c2007-10-12 21:22:40 +000099 wbsio_mask(index, 0xF2, 0x00, 0x10); /* Clear GPIO24 inversion */
rminnich6079a1c2007-10-12 21:22:40 +0000100 wbsio_mask(index, 0xF1, 0x10, 0x10); /* Raise GPIO24 */
stuge04909772007-05-04 04:47:04 +0000101
rminnich6079a1c2007-10-12 21:22:40 +0000102 w836xx_ext_leave(index);
stepan927d4e22007-04-04 22:45:58 +0000103
104 return 0;
105}
106
rminnich6079a1c2007-10-12 21:22:40 +0000107static int w83627hf_gpio24_raise_2e(const char *name)
108{
uwe6ed6d952007-12-04 21:49:06 +0000109 /* TODO: Typo? Shouldn't this be 0x2e? */
rminnich6079a1c2007-10-12 21:22:40 +0000110 return w83627hf_gpio24_raise(0x2d, name);
111}
112
113/**
114 * Winbond W83627THF: GPIO 4, bit 4
115 *
116 * Suited for:
stugea1efa0e2008-07-21 17:48:40 +0000117 * - MSI K8T Neo2-F
rminnich6079a1c2007-10-12 21:22:40 +0000118 * - MSI K8N-NEO3
119 */
120static int w83627thf_gpio4_4_raise(uint16_t index, const char *name)
121{
122 w836xx_ext_enter(index);
uwe6ed6d952007-12-04 21:49:06 +0000123
124 /* Is this the W83627THF? */
125 if (wbsio_read(index, 0x20) != 0x82) { /* Super I/O device ID reg. */
rminnich6079a1c2007-10-12 21:22:40 +0000126 fprintf(stderr, "\nERROR: %s: W83627THF: Wrong ID: 0x%02X.\n",
127 name, wbsio_read(index, 0x20));
128 w836xx_ext_leave(index);
129 return -1;
130 }
131
132 /* PINxxxxS: GPIO4/bit 4 multiplex -> GPIOXXX */
133
uwe6ed6d952007-12-04 21:49:06 +0000134 wbsio_write(index, 0x07, 0x09); /* Select LDN 9: GPIO port 4 */
135 wbsio_mask(index, 0x30, 0x02, 0x02); /* Activate logical device. */
136 wbsio_mask(index, 0xF4, 0x00, 0x10); /* GPIO4 bit 4 -> output */
137 wbsio_mask(index, 0xF6, 0x00, 0x10); /* Clear GPIO4 bit 4 inversion */
138 wbsio_mask(index, 0xF5, 0x10, 0x10); /* Raise GPIO4 bit 4 */
rminnich6079a1c2007-10-12 21:22:40 +0000139
140 w836xx_ext_leave(index);
141
142 return 0;
143}
144
stugea1efa0e2008-07-21 17:48:40 +0000145static int w83627thf_gpio4_4_raise_2e(const char *name)
146{
147 return w83627thf_gpio4_4_raise(0x2e, name);
148}
149
rminnich6079a1c2007-10-12 21:22:40 +0000150static int w83627thf_gpio4_4_raise_4e(const char *name)
151{
uwe6ed6d952007-12-04 21:49:06 +0000152 return w83627thf_gpio4_4_raise(0x4e, name);
rminnich6079a1c2007-10-12 21:22:40 +0000153}
uwe6ed6d952007-12-04 21:49:06 +0000154
uwebe4477b2007-08-23 16:08:21 +0000155/**
stepan927d4e22007-04-04 22:45:58 +0000156 * Suited for VIAs EPIA M and MII, and maybe other CLE266 based EPIAs.
157 *
stepan1037f6f2008-01-18 15:33:10 +0000158 * We don't need to do this when using coreboot, GPIO15 is never lowered there.
stepan927d4e22007-04-04 22:45:58 +0000159 */
stuge04909772007-05-04 04:47:04 +0000160static int board_via_epia_m(const char *name)
stepan927d4e22007-04-04 22:45:58 +0000161{
uwef6641642007-05-09 10:17:44 +0000162 struct pci_dev *dev;
uwe6ed6d952007-12-04 21:49:06 +0000163 uint16_t base;
uwef6641642007-05-09 10:17:44 +0000164 uint8_t val;
stepan927d4e22007-04-04 22:45:58 +0000165
uwef6641642007-05-09 10:17:44 +0000166 dev = pci_dev_find(0x1106, 0x3177); /* VT8235 ISA bridge */
167 if (!dev) {
uwefd2d0fe2007-10-17 23:55:15 +0000168 fprintf(stderr, "\nERROR: VT8235 ISA bridge not found.\n");
uwef6641642007-05-09 10:17:44 +0000169 return -1;
170 }
stepan927d4e22007-04-04 22:45:58 +0000171
uwef6641642007-05-09 10:17:44 +0000172 /* GPIO12-15 -> output */
173 val = pci_read_byte(dev, 0xE4);
174 val |= 0x10;
175 pci_write_byte(dev, 0xE4, val);
stepan927d4e22007-04-04 22:45:58 +0000176
uwef6641642007-05-09 10:17:44 +0000177 /* Get Power Management IO address. */
178 base = pci_read_word(dev, 0x88) & 0xFF80;
stepan927d4e22007-04-04 22:45:58 +0000179
uwe6ed6d952007-12-04 21:49:06 +0000180 /* Enable GPIO15 which is connected to write protect. */
hailfingere1f062f2008-05-22 13:22:45 +0000181 val = INB(base + 0x4D);
uwef6641642007-05-09 10:17:44 +0000182 val |= 0x80;
hailfingere1f062f2008-05-22 13:22:45 +0000183 OUTB(val, base + 0x4D);
stepan927d4e22007-04-04 22:45:58 +0000184
uwef6641642007-05-09 10:17:44 +0000185 return 0;
stepan927d4e22007-04-04 22:45:58 +0000186}
187
uwebe4477b2007-08-23 16:08:21 +0000188/**
uwe1d7c23d2007-07-04 17:51:49 +0000189 * Suited for:
uwebe4477b2007-08-23 16:08:21 +0000190 * - ASUS A7V8X-MX SE and A7V400-MX: AMD K7 + VIA KM400A + VT8235
191 * - Tyan Tomcat K7M: AMD Geode NX + VIA KM400 + VT8237.
stepan927d4e22007-04-04 22:45:58 +0000192 */
stuge04909772007-05-04 04:47:04 +0000193static int board_asus_a7v8x_mx(const char *name)
stepan927d4e22007-04-04 22:45:58 +0000194{
uwef6641642007-05-09 10:17:44 +0000195 struct pci_dev *dev;
196 uint8_t val;
stepan927d4e22007-04-04 22:45:58 +0000197
uwef6641642007-05-09 10:17:44 +0000198 dev = pci_dev_find(0x1106, 0x3177); /* VT8235 ISA bridge */
uwe1d7c23d2007-07-04 17:51:49 +0000199 if (!dev)
200 dev = pci_dev_find(0x1106, 0x3227); /* VT8237 ISA bridge */
uwef6641642007-05-09 10:17:44 +0000201 if (!dev) {
uwe1d7c23d2007-07-04 17:51:49 +0000202 fprintf(stderr, "\nERROR: VT823x ISA bridge not found.\n");
uwef6641642007-05-09 10:17:44 +0000203 return -1;
204 }
stepan927d4e22007-04-04 22:45:58 +0000205
uwe6ed6d952007-12-04 21:49:06 +0000206 /* This bit is marked reserved actually. */
uwef6641642007-05-09 10:17:44 +0000207 val = pci_read_byte(dev, 0x59);
208 val &= 0x7F;
209 pci_write_byte(dev, 0x59, val);
stepan927d4e22007-04-04 22:45:58 +0000210
uwe6ed6d952007-12-04 21:49:06 +0000211 /* Raise ROM MEMW# line on Winbond W83697 Super I/O. */
rminnich6079a1c2007-10-12 21:22:40 +0000212 w836xx_ext_enter(0x2E);
stuge04909772007-05-04 04:47:04 +0000213
uwe6ed6d952007-12-04 21:49:06 +0000214 if (!(wbsio_read(0x2E, 0x24) & 0x02)) /* Flash ROM enabled? */
215 wbsio_mask(0x2E, 0x24, 0x08, 0x08); /* Enable MEMW#. */
stuge04909772007-05-04 04:47:04 +0000216
rminnich6079a1c2007-10-12 21:22:40 +0000217 w836xx_ext_leave(0x2E);
stepan927d4e22007-04-04 22:45:58 +0000218
uwef6641642007-05-09 10:17:44 +0000219 return 0;
stepan927d4e22007-04-04 22:45:58 +0000220}
221
uwebe4477b2007-08-23 16:08:21 +0000222/**
hailfinger755073f2008-02-09 02:03:06 +0000223 * Suited for VIAs EPIA SP.
224 */
225static int board_via_epia_sp(const char *name)
226{
227 struct pci_dev *dev;
228 uint8_t val;
229
230 dev = pci_dev_find(0x1106, 0x3227); /* VT8237R ISA bridge */
231 if (!dev) {
232 fprintf(stderr, "\nERROR: VT8237R ISA bridge not found.\n");
233 return -1;
234 }
235
236 /* All memory cycles, not just ROM ones, go to LPC */
237 val = pci_read_byte(dev, 0x59);
238 val &= ~0x80;
239 pci_write_byte(dev, 0x59, val);
240
241 return 0;
242}
243
244/**
uwe691ddb62007-05-20 16:16:13 +0000245 * Suited for ASUS P5A.
246 *
247 * This is rather nasty code, but there's no way to do this cleanly.
248 * We're basically talking to some unknown device on SMBus, my guess
249 * is that it is the Winbond W83781D that lives near the DIP BIOS.
250 */
uwe691ddb62007-05-20 16:16:13 +0000251static int board_asus_p5a(const char *name)
252{
253 uint8_t tmp;
254 int i;
255
256#define ASUSP5A_LOOP 5000
257
hailfingere1f062f2008-05-22 13:22:45 +0000258 OUTB(0x00, 0xE807);
259 OUTB(0xEF, 0xE803);
uwe691ddb62007-05-20 16:16:13 +0000260
hailfingere1f062f2008-05-22 13:22:45 +0000261 OUTB(0xFF, 0xE800);
uwe691ddb62007-05-20 16:16:13 +0000262
263 for (i = 0; i < ASUSP5A_LOOP; i++) {
hailfingere1f062f2008-05-22 13:22:45 +0000264 OUTB(0xE1, 0xFF);
265 if (INB(0xE800) & 0x04)
uwe691ddb62007-05-20 16:16:13 +0000266 break;
267 }
268
269 if (i == ASUSP5A_LOOP) {
270 printf("%s: Unable to contact device.\n", name);
271 return -1;
272 }
273
hailfingere1f062f2008-05-22 13:22:45 +0000274 OUTB(0x20, 0xE801);
275 OUTB(0x20, 0xE1);
uwe691ddb62007-05-20 16:16:13 +0000276
hailfingere1f062f2008-05-22 13:22:45 +0000277 OUTB(0xFF, 0xE802);
uwe691ddb62007-05-20 16:16:13 +0000278
279 for (i = 0; i < ASUSP5A_LOOP; i++) {
hailfingere1f062f2008-05-22 13:22:45 +0000280 tmp = INB(0xE800);
uwe691ddb62007-05-20 16:16:13 +0000281 if (tmp & 0x70)
282 break;
283 }
284
285 if ((i == ASUSP5A_LOOP) || !(tmp & 0x10)) {
286 printf("%s: failed to read device.\n", name);
287 return -1;
288 }
289
hailfingere1f062f2008-05-22 13:22:45 +0000290 tmp = INB(0xE804);
uwe691ddb62007-05-20 16:16:13 +0000291 tmp &= ~0x02;
292
hailfingere1f062f2008-05-22 13:22:45 +0000293 OUTB(0x00, 0xE807);
294 OUTB(0xEE, 0xE803);
uwe691ddb62007-05-20 16:16:13 +0000295
hailfingere1f062f2008-05-22 13:22:45 +0000296 OUTB(tmp, 0xE804);
uwe691ddb62007-05-20 16:16:13 +0000297
hailfingere1f062f2008-05-22 13:22:45 +0000298 OUTB(0xFF, 0xE800);
299 OUTB(0xE1, 0xFF);
uwe691ddb62007-05-20 16:16:13 +0000300
hailfingere1f062f2008-05-22 13:22:45 +0000301 OUTB(0x20, 0xE801);
302 OUTB(0x20, 0xE1);
uwe691ddb62007-05-20 16:16:13 +0000303
hailfingere1f062f2008-05-22 13:22:45 +0000304 OUTB(0xFF, 0xE802);
uwe691ddb62007-05-20 16:16:13 +0000305
306 for (i = 0; i < ASUSP5A_LOOP; i++) {
hailfingere1f062f2008-05-22 13:22:45 +0000307 tmp = INB(0xE800);
uwe691ddb62007-05-20 16:16:13 +0000308 if (tmp & 0x70)
309 break;
310 }
311
312 if ((i == ASUSP5A_LOOP) || !(tmp & 0x10)) {
313 printf("%s: failed to write to device.\n", name);
314 return -1;
315 }
316
317 return 0;
318}
319
stepan60b4d872007-06-05 12:51:52 +0000320static int board_ibm_x3455(const char *name)
321{
322 uint8_t byte;
323
uwefcce12f2007-06-05 15:02:18 +0000324 /* Set GPIO lines in the Broadcom HT-1000 southbridge. */
hailfingere1f062f2008-05-22 13:22:45 +0000325 OUTB(0x45, 0xcd6);
326 byte = INB(0xcd7);
327 OUTB(byte | 0x20, 0xcd7);
stepan60b4d872007-06-05 12:51:52 +0000328
329 return 0;
330}
331
stuge5666bb42009-03-30 13:20:01 +0000332static int board_hp_dl145_g3_enable(const char *name)
333{
334 uint8_t byte;
335
336 /* Set GPIO lines in the Broadcom HT-1000 southbridge. */
337 OUTB(0x44, 0xcd6); /* GPIO 0 reg from PM regs */
338 byte = INB(0xcd7);
339 /* Set GPIO 2 and 5 high, connected to flash WP# and TBL# pins. */
340 OUTB(byte | 0x24, 0xcd7);
341
342 return 0;
343}
344
uwe0b88fc32007-08-11 16:59:11 +0000345/**
346 * Suited for EPoX EP-BX3, and maybe some other Intel 440BX based boards.
347 */
348static int board_epox_ep_bx3(const char *name)
349{
350 uint8_t tmp;
351
352 /* Raise GPIO22. */
hailfingere1f062f2008-05-22 13:22:45 +0000353 tmp = INB(0x4036);
354 OUTB(tmp, 0xEB);
uwe0b88fc32007-08-11 16:59:11 +0000355
356 tmp |= 0x40;
357
hailfingere1f062f2008-05-22 13:22:45 +0000358 OUTB(tmp, 0x4036);
359 OUTB(tmp, 0xEB);
uwe0b88fc32007-08-11 16:59:11 +0000360
361 return 0;
362}
363
uwebe4477b2007-08-23 16:08:21 +0000364/**
uwe6ed6d952007-12-04 21:49:06 +0000365 * Suited for Acorp 6A815EPD.
uwe8dcc9b02007-12-02 19:03:23 +0000366 */
367static int board_acorp_6a815epd(const char *name)
368{
369 struct pci_dev *dev;
370 uint16_t port;
371 uint8_t val;
372
uwefa98ca12008-10-18 21:14:13 +0000373 dev = pci_dev_find(0x8086, 0x2440); /* Intel ICH2 LPC */
uwe8dcc9b02007-12-02 19:03:23 +0000374 if (!dev) {
375 fprintf(stderr, "\nERROR: ICH2 LPC bridge not found.\n");
376 return -1;
377 }
378
379 /* Use GPIOBASE register to find where the GPIO is mapped. */
uwe6ed6d952007-12-04 21:49:06 +0000380 port = (pci_read_word(dev, 0x58) & 0xFFC0) + 0xE;
uwe8dcc9b02007-12-02 19:03:23 +0000381
hailfingere1f062f2008-05-22 13:22:45 +0000382 val = INB(port);
uwefa98ca12008-10-18 21:14:13 +0000383 val |= 0x80; /* Top Block Lock -- pin 8 of PLCC32 */
384 val |= 0x40; /* Lower Blocks Lock -- pin 7 of PLCC32 */
hailfingere1f062f2008-05-22 13:22:45 +0000385 OUTB(val, port);
uwe8dcc9b02007-12-02 19:03:23 +0000386
387 return 0;
388}
389
390/**
stepanf778f522008-02-20 11:11:18 +0000391 * Suited for Artec Group DBE61 and DBE62.
392 */
393static int board_artecgroup_dbe6x(const char *name)
394{
395#define DBE6x_MSR_DIVIL_BALL_OPTS 0x51400015
396#define DBE6x_PRI_BOOT_LOC_SHIFT (2)
397#define DBE6x_BOOT_OP_LATCHED_SHIFT (8)
398#define DBE6x_SEC_BOOT_LOC_SHIFT (10)
399#define DBE6x_PRI_BOOT_LOC (3 << DBE6x_PRI_BOOT_LOC_SHIFT)
400#define DBE6x_BOOT_OP_LATCHED (3 << DBE6x_BOOT_OP_LATCHED_SHIFT)
401#define DBE6x_SEC_BOOT_LOC (3 << DBE6x_SEC_BOOT_LOC_SHIFT)
402#define DBE6x_BOOT_LOC_FLASH (2)
403#define DBE6x_BOOT_LOC_FWHUB (3)
404
405 unsigned long msr[2];
406 int msr_fd;
407 unsigned long boot_loc;
408
409 msr_fd = open("/dev/cpu/0/msr", O_RDWR);
410 if (msr_fd == -1) {
411 perror("open /dev/cpu/0/msr");
412 return -1;
413 }
414
415 if (lseek(msr_fd, DBE6x_MSR_DIVIL_BALL_OPTS, SEEK_SET) == -1) {
416 perror("lseek");
417 close(msr_fd);
418 return -1;
419 }
420
uwefa98ca12008-10-18 21:14:13 +0000421 if (read(msr_fd, (void *)msr, 8) != 8) {
stepanf778f522008-02-20 11:11:18 +0000422 perror("read");
423 close(msr_fd);
424 return -1;
425 }
426
427 if ((msr[0] & (DBE6x_BOOT_OP_LATCHED)) ==
428 (DBE6x_BOOT_LOC_FWHUB << DBE6x_BOOT_OP_LATCHED_SHIFT))
429 boot_loc = DBE6x_BOOT_LOC_FWHUB;
430 else
431 boot_loc = DBE6x_BOOT_LOC_FLASH;
432
433 msr[0] &= ~(DBE6x_PRI_BOOT_LOC | DBE6x_SEC_BOOT_LOC);
434 msr[0] |= ((boot_loc << DBE6x_PRI_BOOT_LOC_SHIFT) |
uwefa98ca12008-10-18 21:14:13 +0000435 (boot_loc << DBE6x_SEC_BOOT_LOC_SHIFT));
stepanf778f522008-02-20 11:11:18 +0000436
437 if (lseek(msr_fd, DBE6x_MSR_DIVIL_BALL_OPTS, SEEK_SET) == -1) {
438 perror("lseek");
439 close(msr_fd);
440 return -1;
441 }
442
uwefa98ca12008-10-18 21:14:13 +0000443 if (write(msr_fd, (void *)msr, 8) != 8) {
stepanf778f522008-02-20 11:11:18 +0000444 perror("write");
445 close(msr_fd);
446 return -1;
447 }
448
449 close(msr_fd);
450 return 0;
451}
452
uwecc6ecc52008-05-22 21:19:38 +0000453/**
454 * Set the specified GPIO on the specified ICHx southbridge to high.
455 *
456 * @param name The name of this board.
457 * @param ich_vendor PCI vendor ID of the specified ICHx southbridge.
458 * @param ich_device PCI device ID of the specified ICHx southbridge.
459 * @param gpiobase_reg GPIOBASE register offset in the LPC bridge.
460 * @param gp_lvl Offset of GP_LVL register in I/O space, relative to GPIOBASE.
461 * @param gp_lvl_bitmask GP_LVL bitmask (set GPIO bits to 1, all others to 0).
462 * @param gpio_bit The bit (GPIO) which shall be set to high.
463 * @return If the write-enable was successful return 0, otherwise return -1.
464 */
465static int ich_gpio_raise(const char *name, uint16_t ich_vendor,
466 uint16_t ich_device, uint8_t gpiobase_reg,
467 uint8_t gp_lvl, uint32_t gp_lvl_bitmask,
468 unsigned int gpio_bit)
469{
470 struct pci_dev *dev;
471 uint16_t gpiobar;
472 uint32_t reg32;
473
uwefa98ca12008-10-18 21:14:13 +0000474 dev = pci_dev_find(ich_vendor, ich_device); /* Intel ICHx LPC */
uwecc6ecc52008-05-22 21:19:38 +0000475 if (!dev) {
476 fprintf(stderr, "\nERROR: ICHx LPC dev %4x:%4x not found.\n",
477 ich_vendor, ich_device);
478 return -1;
479 }
480
481 /* Use GPIOBASE register to find the I/O space for GPIO. */
482 gpiobar = pci_read_word(dev, gpiobase_reg) & gp_lvl_bitmask;
483
484 /* Set specified GPIO to high. */
485 reg32 = INL(gpiobar + gp_lvl);
486 reg32 |= (1 << gpio_bit);
487 OUTL(reg32, gpiobar + gp_lvl);
488
489 return 0;
490}
491
492/**
493 * Suited for ASUS P4B266.
494 */
495static int ich2_gpio22_raise(const char *name)
496{
497 return ich_gpio_raise(name, 0x8086, 0x2440, 0x58, 0x0c, 0xffc0, 22);
498}
499
stuge81664dd2009-02-02 22:55:26 +0000500/**
501 * Suited for MSI MS-7046.
502 */
503static int ich6_gpio19_raise(const char *name)
504{
505 return ich_gpio_raise(name, 0x8086, 0x2640, 0x48, 0x0c, 0xffc0, 19);
506}
507
stepanb8361b92008-03-17 22:59:40 +0000508static int board_kontron_986lcd_m(const char *name)
509{
510 struct pci_dev *dev;
511 uint16_t gpiobar;
512 uint32_t val;
513
514#define ICH7_GPIO_LVL2 0x38
515
uwefa98ca12008-10-18 21:14:13 +0000516 dev = pci_dev_find(0x8086, 0x27b8); /* Intel ICH7 LPC */
stepanb8361b92008-03-17 22:59:40 +0000517 if (!dev) {
518 // This will never happen on this board
519 fprintf(stderr, "\nERROR: ICH7 LPC bridge not found.\n");
520 return -1;
521 }
522
523 /* Use GPIOBASE register to find where the GPIO is mapped. */
524 gpiobar = pci_read_word(dev, 0x48) & 0xfffc;
525
hailfingere1f062f2008-05-22 13:22:45 +0000526 val = INL(gpiobar + ICH7_GPIO_LVL2); /* GP_LVL2 */
stepanb8361b92008-03-17 22:59:40 +0000527 printf_debug("\nGPIOBAR=0x%04x GP_LVL: 0x%08x\n", gpiobar, val);
528
529 /* bit 2 (0x04) = 0 #TBL --> bootblock locking = 1
530 * bit 2 (0x04) = 1 #TBL --> bootblock locking = 0
531 * bit 3 (0x08) = 0 #WP --> block locking = 1
532 * bit 3 (0x08) = 1 #WP --> block locking = 0
533 *
534 * To enable full block locking, you would do:
535 * val &= ~ ((1 << 2) | (1 << 3));
536 */
537 val |= (1 << 2) | (1 << 3);
538
hailfingere1f062f2008-05-22 13:22:45 +0000539 OUTL(val, gpiobar + ICH7_GPIO_LVL2);
stepanb8361b92008-03-17 22:59:40 +0000540
541 return 0;
542}
543
stepanf778f522008-02-20 11:11:18 +0000544/**
stuge79186d72008-06-11 02:22:42 +0000545 * Suited for:
546 * - BioStar P4M80-M4: Intel P4 + VIA P4M800 + VT8237
stuge8b8c2432008-06-13 01:39:45 +0000547 * - GIGABYTE GA-7VT600: AMD K7 + VIA KT600 + VT8237
stuge79186d72008-06-11 02:22:42 +0000548 */
549static int board_biostar_p4m80_m4(const char *name)
550{
551 /* enter IT87xx conf mode */
552 OUTB(0x87, 0x2e);
553 OUTB(0x01, 0x2e);
554 OUTB(0x55, 0x2e);
555 OUTB(0x55, 0x2e);
556
557 /* select right flash chip */
558 wbsio_mask(0x2e, 0x22, 0x80, 0x80);
559
560 /* bit 3: flash chip write enable
561 * bit 7: map flash chip at 1MB-128K (why though? ignoring this.)
562 */
563 wbsio_mask(0x2e, 0x24, 0x04, 0x04);
564
565 /* exit IT87xx conf mode */
566 wbsio_write(0x2, 0x2e, 0x2);
567
568 return 0;
569}
570
571/**
uwe53dd3c42008-08-19 21:51:39 +0000572 * Winbond W83697HF Super I/O + VIA VT8235 southbridge
573 *
574 * Suited for:
575 * - MSI KT4V and KT4V-L: AMD K7 + VIA KT400 + VT8235
576 * - MSI KT3 Ultra2: AMD K7 + VIA KT333 + VT8235
577 */
578static int board_msi_kt4v(const char *name)
579{
580 struct pci_dev *dev;
581 uint8_t val;
582 uint32_t val2;
583 uint16_t port;
584
585 dev = pci_dev_find(0x1106, 0x3177); /* VT8235 ISA bridge */
586 if (!dev) {
587 fprintf(stderr, "\nERROR: VT823x ISA bridge not found.\n");
588 return -1;
589 }
590
591 val = pci_read_byte(dev, 0x59);
592 val &= 0x0c;
593 pci_write_byte(dev, 0x59, val);
594
595 /* We need the I/O Base Address for this board's flash enable. */
596 port = pci_read_word(dev, 0x88) & 0xff80;
597
598 /* Starting at 'I/O Base + 0x4c' is the GPO Port Output Value.
599 * We must assert GPO12 for our enable, which is in 0x4d.
600 */
601 val2 = INB(port + 0x4d);
602 val2 |= 0x10;
603 OUTB(val2, port + 0x4d);
604
605 /* Raise ROM MEMW# line on Winbond W83697 Super I/O. */
606 w836xx_ext_enter(0x2e);
607 if (!(wbsio_read(0x2e, 0x24) & 0x02)) { /* Flash ROM enabled? */
608 /* Enable MEMW# and set ROM size select to max. (4M). */
609 wbsio_mask(0x2e, 0x24, 0x28, 0x28);
610 }
611 w836xx_ext_leave(0x2e);
612
613 return 0;
614}
615
616/**
uwebe4477b2007-08-23 16:08:21 +0000617 * We use 2 sets of IDs here, you're free to choose which is which. This
618 * is to provide a very high degree of certainty when matching a board on
619 * the basis of subsystem/card IDs. As not every vendor handles
620 * subsystem/card IDs in a sane manner.
stepan927d4e22007-04-04 22:45:58 +0000621 *
uwebe4477b2007-08-23 16:08:21 +0000622 * Keep the second set NULLed if it should be ignored.
stepanf778f522008-02-20 11:11:18 +0000623 *
624 * Keep the subsystem IDs NULLed if they don't identify the board fully.
stepan927d4e22007-04-04 22:45:58 +0000625 */
stepan927d4e22007-04-04 22:45:58 +0000626struct board_pciid_enable {
uwe6ed6d952007-12-04 21:49:06 +0000627 /* Any device, but make it sensible, like the ISA bridge. */
uwef6641642007-05-09 10:17:44 +0000628 uint16_t first_vendor;
629 uint16_t first_device;
630 uint16_t first_card_vendor;
631 uint16_t first_card_device;
stepan927d4e22007-04-04 22:45:58 +0000632
uwef6641642007-05-09 10:17:44 +0000633 /* Any device, but make it sensible, like
uwe6ed6d952007-12-04 21:49:06 +0000634 * the host bridge. May be NULL.
stepan927d4e22007-04-04 22:45:58 +0000635 */
uwef6641642007-05-09 10:17:44 +0000636 uint16_t second_vendor;
637 uint16_t second_device;
638 uint16_t second_card_vendor;
639 uint16_t second_card_device;
stepan927d4e22007-04-04 22:45:58 +0000640
stepan1037f6f2008-01-18 15:33:10 +0000641 /* The vendor / part name from the coreboot table. */
uwe6ed6d952007-12-04 21:49:06 +0000642 const char *lb_vendor;
643 const char *lb_part;
stepan927d4e22007-04-04 22:45:58 +0000644
uwe6ed6d952007-12-04 21:49:06 +0000645 const char *name;
uwef6641642007-05-09 10:17:44 +0000646 int (*enable) (const char *name);
stepan927d4e22007-04-04 22:45:58 +0000647};
648
649struct board_pciid_enable board_pciid_enables[] = {
hailfinger321a1a62009-01-15 00:48:24 +0000650 {
651 .first_vendor = 0x1106,
652 .first_device = 0x0571,
653 .first_card_vendor = 0x1462,
654 .first_card_device = 0x7120,
655 .second_vendor = 0x0000,
656 .second_device = 0x0000,
657 .second_card_vendor = 0x0000,
658 .second_card_device = 0x0000,
659 .lb_vendor = "msi",
660 .lb_part = "kt4v",
661 .name = "MSI KT4V",
662 .enable = board_msi_kt4v,
663 },
664 {
665 .first_vendor = 0x8086,
666 .first_device = 0x1a30,
667 .first_card_vendor = 0x1043,
668 .first_card_device = 0x8070,
669 .second_vendor = 0x8086,
670 .second_device = 0x244b,
671 .second_card_vendor = 0x1043,
672 .second_card_device = 0x8028,
673 .lb_vendor = NULL,
674 .lb_part = NULL,
675 .name = "ASUS P4B266",
676 .enable = ich2_gpio22_raise,
677 },
678 {
679 .first_vendor = 0x10de,
680 .first_device = 0x0360,
681 .first_card_vendor = 0x0000,
682 .first_card_device = 0x0000,
683 .second_vendor = 0x0000,
684 .second_device = 0x0000,
685 .second_card_vendor = 0x0000,
686 .second_card_device = 0x0000,
687 .lb_vendor = "gigabyte",
688 .lb_part = "m57sli",
689 .name = "GIGABYTE GA-M57SLI-S4",
690 .enable = it87xx_probe_spi_flash,
691 },
692 {
693 .first_vendor = 0x10de,
694 .first_device = 0x03e0,
695 .first_card_vendor = 0x0000,
696 .first_card_device = 0x0000,
697 .second_vendor = 0x0000,
698 .second_device = 0x0000,
699 .second_card_vendor = 0x0000,
700 .second_card_device = 0x0000,
701 .lb_vendor = "gigabyte",
702 .lb_part = "m61p",
703 .name = "GIGABYTE GA-M61P-S3",
704 .enable = it87xx_probe_spi_flash,
705 },
706 {
707 .first_vendor = 0x1002,
708 .first_device = 0x4398,
709 .first_card_vendor = 0x1458,
710 .first_card_device = 0x5004,
711 .second_vendor = 0x1002,
712 .second_device = 0x4385,
713 .second_card_vendor = 0x1458,
714 .second_card_device = 0x4385,
715 .lb_vendor = NULL,
716 .lb_part = NULL,
717 .name = "GIGABYTE GA-MA78G-DS3H",
718 .enable = it87xx_probe_spi_flash,
719 },
720 {
721 .first_vendor = 0x1039,
722 .first_device = 0x0761,
723 .first_card_vendor = 0x0000,
724 .first_card_device = 0x0000,
725 .second_vendor = 0x0000,
726 .second_device = 0x0000,
727 .second_card_vendor = 0x0000,
728 .second_card_device = 0x0000,
729 .lb_vendor = "gigabyte",
730 .lb_part = "2761gxdk",
731 .name = "GIGABYTE GA-2761GXDK",
732 .enable = it87xx_probe_spi_flash,
733 },
734 {
735 .first_vendor = 0x1022,
736 .first_device = 0x7468,
737 .first_card_vendor = 0x0000,
738 .first_card_device = 0x0000,
739 .second_vendor = 0x0000,
740 .second_device = 0x0000,
741 .second_card_vendor = 0x0000,
742 .second_card_device = 0x0000,
743 .lb_vendor = "iwill",
744 .lb_part = "dk8_htx",
745 .name = "IWILL DK8-HTX",
746 .enable = w83627hf_gpio24_raise_2e,
747 },
748 {
749 .first_vendor = 0x10de,
750 .first_device = 0x005e,
751 .first_card_vendor = 0x0000,
752 .first_card_device = 0x0000,
753 .second_vendor = 0x0000,
754 .second_device = 0x0000,
755 .second_card_vendor = 0x0000,
756 .second_card_device = 0x0000,
757 .lb_vendor = "msi",
758 .lb_part = "k8n-neo3",
759 .name = "MSI K8N Neo3",
760 .enable = w83627thf_gpio4_4_raise_4e,
761 },
762 {
763 .first_vendor = 0x1022,
764 .first_device = 0x746B,
765 .first_card_vendor = 0x1022,
766 .first_card_device = 0x36C0,
767 .second_vendor = 0x0000,
768 .second_device = 0x0000,
769 .second_card_vendor = 0x0000,
770 .second_card_device = 0x0000,
771 .lb_vendor = "AGAMI",
772 .lb_part = "ARUMA",
773 .name = "agami Aruma",
774 .enable = w83627hf_gpio24_raise_2e,
775 },
776 {
777 .first_vendor = 0x1106,
778 .first_device = 0x3177,
779 .first_card_vendor = 0x1106,
780 .first_card_device = 0xAA01,
781 .second_vendor = 0x1106,
782 .second_device = 0x3123,
783 .second_card_vendor = 0x1106,
784 .second_card_device = 0xAA01,
785 .lb_vendor = NULL,
786 .lb_part = NULL,
787 .name = "VIA EPIA M/MII/...",
788 .enable = board_via_epia_m,
789 },
790 {
791 .first_vendor = 0x1106,
792 .first_device = 0x3177,
793 .first_card_vendor = 0x1043,
794 .first_card_device = 0x80A1,
795 .second_vendor = 0x1106,
796 .second_device = 0x3205,
797 .second_card_vendor = 0x1043,
798 .second_card_device = 0x8118,
799 .lb_vendor = NULL,
800 .lb_part = NULL,
801 .name = "ASUS A7V8-MX SE",
802 .enable = board_asus_a7v8x_mx,
803 },
804 {
805 .first_vendor = 0x1106,
806 .first_device = 0x3227,
807 .first_card_vendor = 0x1106,
808 .first_card_device = 0xAA01,
809 .second_vendor = 0x1106,
810 .second_device = 0x0259,
811 .second_card_vendor = 0x1106,
812 .second_card_device = 0xAA01,
813 .lb_vendor = NULL,
814 .lb_part = NULL,
815 .name = "VIA EPIA SP",
816 .enable = board_via_epia_sp,
817 },
818 {
819 .first_vendor = 0x1106,
820 .first_device = 0x0314,
821 .first_card_vendor = 0x1106,
822 .first_card_device = 0xaa08,
823 .second_vendor = 0x1106,
824 .second_device = 0x3227,
825 .second_card_vendor = 0x1106,
826 .second_card_device = 0xAA08,
827 .lb_vendor = NULL,
828 .lb_part = NULL,
829 .name = "VIA EPIA-CN",
830 .enable = board_via_epia_sp,
831 },
832 {
833 .first_vendor = 0x8086,
834 .first_device = 0x1076,
835 .first_card_vendor = 0x8086,
836 .first_card_device = 0x1176,
837 .second_vendor = 0x1106,
838 .second_device = 0x3059,
839 .second_card_vendor = 0x10f1,
840 .second_card_device = 0x2498,
841 .lb_vendor = NULL,
842 .lb_part = NULL,
843 .name = "Tyan Tomcat K7M",
844 .enable = board_asus_a7v8x_mx,
845 },
846 {
847 .first_vendor = 0x10B9,
848 .first_device = 0x1541,
849 .first_card_vendor = 0x0000,
850 .first_card_device = 0x0000,
851 .second_vendor = 0x10B9,
852 .second_device = 0x1533,
853 .second_card_vendor = 0x0000,
854 .second_card_device = 0x0000,
855 .lb_vendor = "asus",
856 .lb_part = "p5a",
857 .name = "ASUS P5A",
858 .enable = board_asus_p5a,
859 },
860 {
861 .first_vendor = 0x1166,
862 .first_device = 0x0205,
863 .first_card_vendor = 0x1014,
864 .first_card_device = 0x0347,
865 .second_vendor = 0x0000,
866 .second_device = 0x0000,
867 .second_card_vendor = 0x0000,
868 .second_card_device = 0x0000,
869 .lb_vendor = "ibm",
870 .lb_part = "x3455",
871 .name = "IBM x3455",
872 .enable = board_ibm_x3455,
873 },
874 {
875 .first_vendor = 0x8086,
876 .first_device = 0x7110,
877 .first_card_vendor = 0x0000,
878 .first_card_device = 0x0000,
879 .second_vendor = 0x8086,
880 .second_device = 0x7190,
881 .second_card_vendor = 0x0000,
882 .second_card_device = 0x0000,
883 .lb_vendor = "epox",
884 .lb_part = "ep-bx3",
885 .name = "EPoX EP-BX3",
886 .enable = board_epox_ep_bx3,
887 },
888 {
889 .first_vendor = 0x8086,
890 .first_device = 0x1130,
891 .first_card_vendor = 0x0000,
892 .first_card_device = 0x0000,
893 .second_vendor = 0x105a,
894 .second_device = 0x0d30,
895 .second_card_vendor = 0x105a,
896 .second_card_device = 0x4d33,
897 .lb_vendor = "acorp",
898 .lb_part = "6a815epd",
899 .name = "Acorp 6A815EPD",
900 .enable = board_acorp_6a815epd,
901 },
902 {
903 .first_vendor = 0x1022,
904 .first_device = 0x2090,
905 .first_card_vendor = 0x0000,
906 .first_card_device = 0x0000,
907 .second_vendor = 0x1022,
908 .second_device = 0x2080,
909 .second_card_vendor = 0x0000,
910 .second_card_device = 0x0000,
911 .lb_vendor = "artecgroup",
912 .lb_part = "dbe61",
913 .name = "Artec Group DBE61",
914 .enable = board_artecgroup_dbe6x,
915 },
916 {
917 .first_vendor = 0x1022,
918 .first_device = 0x2090,
919 .first_card_vendor = 0x0000,
920 .first_card_device = 0x0000,
921 .second_vendor = 0x1022,
922 .second_device = 0x2080,
923 .second_card_vendor = 0x0000,
924 .second_card_device = 0x0000,
925 .lb_vendor = "artecgroup",
926 .lb_part = "dbe62",
927 .name = "Artec Group DBE62",
928 .enable = board_artecgroup_dbe6x,
929 },
uwef86e4cf2008-12-22 16:40:45 +0000930 /* Note: There are >= 2 version of the Kontron 986LCD-M/mITX! */
hailfinger321a1a62009-01-15 00:48:24 +0000931 {
932 .first_vendor = 0x8086,
933 .first_device = 0x27b8,
934 .first_card_vendor = 0x0000,
935 .first_card_device = 0x0000,
936 .second_vendor = 0x0000,
937 .second_device = 0x0000,
938 .second_card_vendor = 0x0000,
939 .second_card_device = 0x0000,
940 .lb_vendor = "kontron",
941 .lb_part = "986lcd-m",
942 .name = "Kontron 986LCD-M",
943 .enable = board_kontron_986lcd_m,
944 },
945 {
946 .first_vendor = 0x10ec,
947 .first_device = 0x8168,
948 .first_card_vendor = 0x10ec,
949 .first_card_device = 0x8168,
950 .second_vendor = 0x104c,
951 .second_device = 0x8023,
952 .second_card_vendor = 0x104c,
953 .second_card_device = 0x8019,
954 .lb_vendor = "kontron",
955 .lb_part = "986lcd-m",
956 .name = "Kontron 986LCD-M",
957 .enable = board_kontron_986lcd_m,
958 },
959 {
960 .first_vendor = 0x1106,
961 .first_device = 0x3149,
962 .first_card_vendor = 0x1565,
963 .first_card_device = 0x3206,
964 .second_vendor = 0x1106,
965 .second_device = 0x3344,
966 .second_card_vendor = 0x1565,
967 .second_card_device = 0x1202,
968 .lb_vendor = NULL,
969 .lb_part = NULL,
970 .name = "BioStar P4M80-M4",
971 .enable = board_biostar_p4m80_m4,
972 },
973 {
974 .first_vendor = 0x1106,
975 .first_device = 0x3227,
976 .first_card_vendor = 0x1458,
977 .first_card_device = 0x5001,
978 .second_vendor = 0x10ec,
979 .second_device = 0x8139,
980 .second_card_vendor = 0x1458,
981 .second_card_device = 0xe000,
982 .lb_vendor = NULL,
983 .lb_part = NULL,
984 .name = "GIGABYTE GA-7VT600",
985 .enable = board_biostar_p4m80_m4,
986 },
987 {
988 .first_vendor = 0x1106,
989 .first_device = 0x3149,
990 .first_card_vendor = 0x1462,
991 .first_card_device = 0x7094,
992 .second_vendor = 0x10ec,
993 .second_device = 0x8167,
994 .second_card_vendor = 0x1462,
995 .second_card_device = 0x094c,
996 .lb_vendor = NULL,
997 .lb_part = NULL,
998 .name = "MSI K8T Neo2",
999 .enable = w83627thf_gpio4_4_raise_2e,
1000 },
1001 {
stuge25cdcab2009-01-26 03:12:44 +00001002 .first_vendor = 0x1039,
1003 .first_device = 0x5513,
1004 .first_card_vendor = 0x8086,
1005 .first_card_device = 0xd61f,
1006 .second_vendor = 0x1039,
1007 .second_device = 0x6330,
1008 .second_card_vendor = 0x8086,
1009 .second_card_device = 0xd61f,
1010 .lb_vendor = NULL,
1011 .lb_part = NULL,
1012 .name = "Intel Desktop Board D201GLY",
1013 .enable = wbsio_check_for_spi,
1014 },
1015 {
stuge81664dd2009-02-02 22:55:26 +00001016 .first_vendor = 0x8086,
1017 .first_device = 0x2658,
1018 .first_card_vendor = 0x1462,
1019 .first_card_device = 0x7046,
1020 .second_vendor = 0x1106,
1021 .second_device = 0x3044,
1022 .second_card_vendor = 0x1462,
1023 .second_card_device = 0x046d,
1024 .lb_vendor = NULL,
1025 .lb_part = NULL,
1026 .name = "MSI MS-7046",
1027 .enable = ich6_gpio19_raise,
1028 },
1029 {
stuge5666bb42009-03-30 13:20:01 +00001030 .first_vendor = 0x1166,
1031 .first_device = 0x0223,
1032 .first_card_vendor = 0x103c,
1033 .first_card_device = 0x320d,
1034 .second_vendor = 0x102b,
1035 .second_device = 0x0522,
1036 .second_card_vendor = 0x103c,
1037 .second_card_device = 0x31fa,
1038 .lb_vendor = "hp",
1039 .lb_part = "dl145_g3",
1040 .name = "HP DL145 G3",
1041 .enable = board_hp_dl145_g3_enable,
1042 },
1043 {
hailfinger321a1a62009-01-15 00:48:24 +00001044 .first_vendor = 0,
1045 .first_device = 0,
1046 .first_card_vendor = 0,
1047 .first_card_device = 0,
1048 .second_vendor = 0,
1049 .second_device = 0,
1050 .second_card_vendor = 0,
1051 .second_card_device = 0,
1052 .lb_vendor = NULL,
1053 .lb_part = NULL,
1054 } /* Keep this */
stepan927d4e22007-04-04 22:45:58 +00001055};
1056
uwe16f99092008-03-12 11:54:51 +00001057void print_supported_boards(void)
1058{
1059 int i;
1060
1061 printf("\nSupported mainboards (this list is not exhaustive!):\n\n");
1062
uwe0d8153f2008-03-13 18:41:07 +00001063 for (i = 0; board_pciid_enables[i].name != NULL; i++) {
1064 if (board_pciid_enables[i].lb_vendor != NULL) {
1065 printf("%s (-m %s:%s)\n", board_pciid_enables[i].name,
1066 board_pciid_enables[i].lb_vendor,
1067 board_pciid_enables[i].lb_part);
1068 } else {
1069 printf("%s (autodetected)\n",
1070 board_pciid_enables[i].name);
1071 }
1072 }
uwe16f99092008-03-12 11:54:51 +00001073
1074 printf("\nSee also: http://coreboot.org/Flashrom\n");
1075}
1076
uwebe4477b2007-08-23 16:08:21 +00001077/**
stepan1037f6f2008-01-18 15:33:10 +00001078 * Match boards on coreboot table gathered vendor and part name.
uwebe4477b2007-08-23 16:08:21 +00001079 * Require main PCI IDs to match too as extra safety.
stepan927d4e22007-04-04 22:45:58 +00001080 */
uwefa98ca12008-10-18 21:14:13 +00001081static struct board_pciid_enable *board_match_coreboot_name(const char *vendor,
1082 const char *part)
stepan927d4e22007-04-04 22:45:58 +00001083{
uwef6641642007-05-09 10:17:44 +00001084 struct board_pciid_enable *board = board_pciid_enables;
stugeb9b411f2008-01-27 16:21:21 +00001085 struct board_pciid_enable *partmatch = NULL;
stepan927d4e22007-04-04 22:45:58 +00001086
uwef6641642007-05-09 10:17:44 +00001087 for (; board->name; board++) {
uwefa98ca12008-10-18 21:14:13 +00001088 if (vendor && (!board->lb_vendor
1089 || strcasecmp(board->lb_vendor, vendor)))
uwef6641642007-05-09 10:17:44 +00001090 continue;
stepan927d4e22007-04-04 22:45:58 +00001091
stuge0c1005b2008-07-02 00:47:30 +00001092 if (!board->lb_part || strcasecmp(board->lb_part, part))
uwef6641642007-05-09 10:17:44 +00001093 continue;
stepan927d4e22007-04-04 22:45:58 +00001094
uwef6641642007-05-09 10:17:44 +00001095 if (!pci_dev_find(board->first_vendor, board->first_device))
1096 continue;
stepan927d4e22007-04-04 22:45:58 +00001097
uwef6641642007-05-09 10:17:44 +00001098 if (board->second_vendor &&
uwefa98ca12008-10-18 21:14:13 +00001099 !pci_dev_find(board->second_vendor, board->second_device))
uwef6641642007-05-09 10:17:44 +00001100 continue;
stugeb9b411f2008-01-27 16:21:21 +00001101
1102 if (vendor)
1103 return board;
1104
1105 if (partmatch) {
1106 /* a second entry has a matching part name */
1107 printf("AMBIGUOUS BOARD NAME: %s\n", part);
1108 printf("At least vendors '%s' and '%s' match.\n",
uwefa98ca12008-10-18 21:14:13 +00001109 partmatch->lb_vendor, board->lb_vendor);
stugeb9b411f2008-01-27 16:21:21 +00001110 printf("Please use the full -m vendor:part syntax.\n");
1111 return NULL;
1112 }
1113 partmatch = board;
uwef6641642007-05-09 10:17:44 +00001114 }
uwe6ed6d952007-12-04 21:49:06 +00001115
stugeb9b411f2008-01-27 16:21:21 +00001116 if (partmatch)
1117 return partmatch;
1118
stugeb187f1f2008-07-02 00:59:29 +00001119 printf("\nUnknown vendor:board from coreboot table or -m option: %s:%s\n\n", vendor, part);
uwef6641642007-05-09 10:17:44 +00001120 return NULL;
stepan927d4e22007-04-04 22:45:58 +00001121}
1122
uwebe4477b2007-08-23 16:08:21 +00001123/**
1124 * Match boards on PCI IDs and subsystem IDs.
1125 * Second set of IDs can be main only or missing completely.
stepan927d4e22007-04-04 22:45:58 +00001126 */
1127static struct board_pciid_enable *board_match_pci_card_ids(void)
1128{
uwef6641642007-05-09 10:17:44 +00001129 struct board_pciid_enable *board = board_pciid_enables;
stepan927d4e22007-04-04 22:45:58 +00001130
uwef6641642007-05-09 10:17:44 +00001131 for (; board->name; board++) {
1132 if (!board->first_card_vendor || !board->first_card_device)
1133 continue;
stepan927d4e22007-04-04 22:45:58 +00001134
uwef6641642007-05-09 10:17:44 +00001135 if (!pci_card_find(board->first_vendor, board->first_device,
uwefa98ca12008-10-18 21:14:13 +00001136 board->first_card_vendor,
1137 board->first_card_device))
uwef6641642007-05-09 10:17:44 +00001138 continue;
stepan927d4e22007-04-04 22:45:58 +00001139
uwef6641642007-05-09 10:17:44 +00001140 if (board->second_vendor) {
1141 if (board->second_card_vendor) {
1142 if (!pci_card_find(board->second_vendor,
uwefa98ca12008-10-18 21:14:13 +00001143 board->second_device,
1144 board->second_card_vendor,
1145 board->second_card_device))
uwef6641642007-05-09 10:17:44 +00001146 continue;
1147 } else {
1148 if (!pci_dev_find(board->second_vendor,
uwefa98ca12008-10-18 21:14:13 +00001149 board->second_device))
uwef6641642007-05-09 10:17:44 +00001150 continue;
1151 }
1152 }
stepan927d4e22007-04-04 22:45:58 +00001153
uwef6641642007-05-09 10:17:44 +00001154 return board;
1155 }
stepan927d4e22007-04-04 22:45:58 +00001156
uwef6641642007-05-09 10:17:44 +00001157 return NULL;
stepan927d4e22007-04-04 22:45:58 +00001158}
1159
uwe6ed6d952007-12-04 21:49:06 +00001160int board_flash_enable(const char *vendor, const char *part)
stepan927d4e22007-04-04 22:45:58 +00001161{
uwef6641642007-05-09 10:17:44 +00001162 struct board_pciid_enable *board = NULL;
1163 int ret = 0;
stepan927d4e22007-04-04 22:45:58 +00001164
stugeb9b411f2008-01-27 16:21:21 +00001165 if (part)
stepan1037f6f2008-01-18 15:33:10 +00001166 board = board_match_coreboot_name(vendor, part);
stepan927d4e22007-04-04 22:45:58 +00001167
uwef6641642007-05-09 10:17:44 +00001168 if (!board)
1169 board = board_match_pci_card_ids();
stepan927d4e22007-04-04 22:45:58 +00001170
uwef6641642007-05-09 10:17:44 +00001171 if (board) {
uwe017911e2008-05-22 22:47:04 +00001172 printf("Found board \"%s\", enabling flash write... ",
uwefa98ca12008-10-18 21:14:13 +00001173 board->name);
stepan927d4e22007-04-04 22:45:58 +00001174
uwef6641642007-05-09 10:17:44 +00001175 ret = board->enable(board->name);
1176 if (ret)
uwefd2d0fe2007-10-17 23:55:15 +00001177 printf("FAILED!\n");
uwef6641642007-05-09 10:17:44 +00001178 else
1179 printf("OK.\n");
1180 }
stepan927d4e22007-04-04 22:45:58 +00001181
uwef6641642007-05-09 10:17:44 +00001182 return ret;
stepan927d4e22007-04-04 22:45:58 +00001183}