source: trunk/chipset_enable.c

Last change on this file was 1656, checked in by stefanct, 3 months ago

Add support for Intel Lynx Point low-power and Wellsburg.

New IDs taken from Intel's patches for the Linux kernel.
Also, refine original Lynx Point naming etc.

Based on the chromiumos patch
Change-Id: I303a05baa80e4449e70d20adf78ebc7128b88d8e
Signed-off-by: Duncan Laurie <dlaurie@…>

Signed-off-by: Stefan Tauner <stefan.tauner@…>
Acked-by: Stefan Tauner <stefan.tauner@…>

File size: 53.1 KB
Line 
1/*
2 * This file is part of the flashrom project.
3 *
4 * Copyright (C) 2000 Silicon Integrated System Corporation
5 * Copyright (C) 2005-2009 coresystems GmbH
6 * Copyright (C) 2006 Uwe Hermann <uwe@hermann-uwe.de>
7 * Copyright (C) 2007,2008,2009 Carl-Daniel Hailfinger
8 * Copyright (C) 2009 Kontron Modular Computers GmbH
9 * Copyright (C) 2011, 2012 Stefan Tauner
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 2 of the License.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
23 */
24
25/*
26 * Contains the chipset specific flash enables.
27 */
28
29#define _LARGEFILE64_SOURCE
30
31#include <stdlib.h>
32#include <string.h>
33#include <unistd.h>
34#include <inttypes.h>
35#include <errno.h>
36#include "flash.h"
37#include "programmer.h"
38#include "hwaccess.h"
39
40#define NOT_DONE_YET 1
41
42#if defined(__i386__) || defined(__x86_64__)
43
44static int enable_flash_ali_m1533(struct pci_dev *dev, const char *name)
45{
46        uint8_t tmp;
47
48        /*
49         * ROM Write enable, 0xFFFC0000-0xFFFDFFFF and
50         * 0xFFFE0000-0xFFFFFFFF ROM select enable.
51         */
52        tmp = pci_read_byte(dev, 0x47);
53        tmp |= 0x46;
54        rpci_write_byte(dev, 0x47, tmp);
55
56        return 0;
57}
58
59static int enable_flash_rdc_r8610(struct pci_dev *dev, const char *name)
60{
61        uint8_t tmp;
62
63        /* enable ROMCS for writes */
64        tmp = pci_read_byte(dev, 0x43);
65        tmp |= 0x80;
66        pci_write_byte(dev, 0x43, tmp);
67
68        /* read the bootstrapping register */
69        tmp = pci_read_byte(dev, 0x40) & 0x3;
70        switch (tmp) {
71        case 3:
72                internal_buses_supported = BUS_FWH;
73                break;
74        case 2:
75                internal_buses_supported = BUS_LPC;
76                break;
77        default:
78                internal_buses_supported = BUS_PARALLEL;
79                break;
80        }
81
82        return 0;
83}
84
85static int enable_flash_sis85c496(struct pci_dev *dev, const char *name)
86{
87        uint8_t tmp;
88
89        tmp = pci_read_byte(dev, 0xd0);
90        tmp |= 0xf8;
91        rpci_write_byte(dev, 0xd0, tmp);
92
93        return 0;
94}
95
96static int enable_flash_sis_mapping(struct pci_dev *dev, const char *name)
97{
98        #define SIS_MAPREG 0x40
99        uint8_t new, newer;
100
101        /* Extended BIOS enable = 1, Lower BIOS Enable = 1 */
102        /* This is 0xFFF8000~0xFFFF0000 decoding on SiS 540/630. */
103        new = pci_read_byte(dev, SIS_MAPREG);
104        new &= (~0x04); /* No idea why we clear bit 2. */
105        new |= 0xb; /* 0x3 for some chipsets, bit 7 seems to be don't care. */
106        rpci_write_byte(dev, SIS_MAPREG, new);
107        newer = pci_read_byte(dev, SIS_MAPREG);
108        if (newer != new) { /* FIXME: share this with other code? */
109                msg_pinfo("Setting register 0x%x to 0x%02x on %s failed (WARNING ONLY).\n",
110                          SIS_MAPREG, new, name);
111                msg_pinfo("Stuck at 0x%02x.\n", newer);
112                return -1;
113        }
114        return 0;
115}
116
117static struct pci_dev *find_southbridge(uint16_t vendor, const char *name)
118{
119        struct pci_dev *sbdev;
120
121        sbdev = pci_dev_find_vendorclass(vendor, 0x0601);
122        if (!sbdev)
123                sbdev = pci_dev_find_vendorclass(vendor, 0x0680);
124        if (!sbdev)
125                sbdev = pci_dev_find_vendorclass(vendor, 0x0000);
126        if (!sbdev)
127                msg_perr("No southbridge found for %s!\n", name);
128        if (sbdev)
129                msg_pdbg("Found southbridge %04x:%04x at %02x:%02x:%01x\n",
130                         sbdev->vendor_id, sbdev->device_id,
131                         sbdev->bus, sbdev->dev, sbdev->func);
132        return sbdev;
133}
134
135static int enable_flash_sis501(struct pci_dev *dev, const char *name)
136{
137        uint8_t tmp;
138        int ret = 0;
139        struct pci_dev *sbdev;
140
141        sbdev = find_southbridge(dev->vendor_id, name);
142        if (!sbdev)
143                return -1;
144
145        ret = enable_flash_sis_mapping(sbdev, name);
146
147        tmp = sio_read(0x22, 0x80);
148        tmp &= (~0x20);
149        tmp |= 0x4;
150        sio_write(0x22, 0x80, tmp);
151
152        tmp = sio_read(0x22, 0x70);
153        tmp &= (~0x20);
154        tmp |= 0x4;
155        sio_write(0x22, 0x70, tmp);
156       
157        return ret;
158}
159
160static int enable_flash_sis5511(struct pci_dev *dev, const char *name)
161{
162        uint8_t tmp;
163        int ret = 0;
164        struct pci_dev *sbdev;
165
166        sbdev = find_southbridge(dev->vendor_id, name);
167        if (!sbdev)
168                return -1;
169
170        ret = enable_flash_sis_mapping(sbdev, name);
171
172        tmp = sio_read(0x22, 0x50);
173        tmp &= (~0x20);
174        tmp |= 0x4;
175        sio_write(0x22, 0x50, tmp);
176
177        return ret;
178}
179
180static int enable_flash_sis5x0(struct pci_dev *dev, const char *name, uint8_t dis_mask, uint8_t en_mask)
181{
182        #define SIS_REG 0x45
183        uint8_t new, newer;
184        int ret = 0;
185        struct pci_dev *sbdev;
186
187        sbdev = find_southbridge(dev->vendor_id, name);
188        if (!sbdev)
189                return -1;
190
191        ret = enable_flash_sis_mapping(sbdev, name);
192
193        new = pci_read_byte(sbdev, SIS_REG);
194        new &= (~dis_mask);
195        new |= en_mask;
196        rpci_write_byte(sbdev, SIS_REG, new);
197        newer = pci_read_byte(sbdev, SIS_REG);
198        if (newer != new) { /* FIXME: share this with other code? */
199                msg_pinfo("Setting register 0x%x to 0x%02x on %s failed (WARNING ONLY).\n", SIS_REG, new, name);
200                msg_pinfo("Stuck at 0x%02x\n", newer);
201                ret = -1;
202        }
203
204        return ret;
205}
206
207static int enable_flash_sis530(struct pci_dev *dev, const char *name)
208{
209        return enable_flash_sis5x0(dev, name, 0x20, 0x04);
210}
211
212static int enable_flash_sis540(struct pci_dev *dev, const char *name)
213{
214        return enable_flash_sis5x0(dev, name, 0x80, 0x40);
215}
216
217/* Datasheet:
218 *   - Name: 82371AB PCI-TO-ISA / IDE XCELERATOR (PIIX4)
219 *   - URL: http://www.intel.com/design/intarch/datashts/290562.htm
220 *   - PDF: http://www.intel.com/design/intarch/datashts/29056201.pdf
221 *   - Order Number: 290562-001
222 */
223static int enable_flash_piix4(struct pci_dev *dev, const char *name)
224{
225        uint16_t old, new;
226        uint16_t xbcs = 0x4e;   /* X-Bus Chip Select register. */
227
228        internal_buses_supported = BUS_PARALLEL;
229
230        old = pci_read_word(dev, xbcs);
231
232        /* Set bit 9: 1-Meg Extended BIOS Enable (PCI master accesses to
233         *            FFF00000-FFF7FFFF are forwarded to ISA).
234         *            Note: This bit is reserved on PIIX/PIIX3/MPIIX.
235         * Set bit 7: Extended BIOS Enable (PCI master accesses to
236         *            FFF80000-FFFDFFFF are forwarded to ISA).
237         * Set bit 6: Lower BIOS Enable (PCI master, or ISA master accesses to
238         *            the lower 64-Kbyte BIOS block (E0000-EFFFF) at the top
239         *            of 1 Mbyte, or the aliases at the top of 4 Gbyte
240         *            (FFFE0000-FFFEFFFF) result in the generation of BIOSCS#.
241         * Note: Accesses to FFFF0000-FFFFFFFF are always forwarded to ISA.
242         * Set bit 2: BIOSCS# Write Enable (1=enable, 0=disable).
243         */
244        if (dev->device_id == 0x122e || dev->device_id == 0x7000
245            || dev->device_id == 0x1234)
246                new = old | 0x00c4; /* PIIX/PIIX3/MPIIX: Bit 9 is reserved. */
247        else
248                new = old | 0x02c4;
249
250        if (new == old)
251                return 0;
252
253        rpci_write_word(dev, xbcs, new);
254
255        if (pci_read_word(dev, xbcs) != new) { /* FIXME: share this with other code? */
256                msg_pinfo("Setting register 0x%04x to 0x%04x on %s failed (WARNING ONLY).\n", xbcs, new, name);
257                return -1;
258        }
259
260        return 0;
261}
262
263/*
264 * See ie. page 375 of "Intel I/O Controller Hub 7 (ICH7) Family Datasheet"
265 * http://download.intel.com/design/chipsets/datashts/30701303.pdf
266 */
267static int enable_flash_ich(struct pci_dev *dev, const char *name, uint8_t bios_cntl)
268{
269        uint8_t old, new, wanted;
270
271        /*
272         * Note: the ICH0-ICH5 BIOS_CNTL register is actually 16 bit wide, in Tunnel Creek it is even 32b, but
273         * just treating it as 8 bit wide seems to work fine in practice.
274         */
275        wanted = old = pci_read_byte(dev, bios_cntl);
276
277        /*
278         * Quote from the 6 Series datasheet (Document Number: 324645-004):
279         * "Bit 5: SMM BIOS Write Protect Disable (SMM_BWP)
280         * 1 = BIOS region SMM protection is enabled.
281         * The BIOS Region is not writable unless all processors are in SMM."
282         * In earlier chipsets this bit is reserved.
283         *
284         * Try to unset it in any case.
285         * It won't hurt and makes sense in some cases according to Stefan Reinauer.
286         */
287        wanted &= ~(1 << 5);
288
289        /* Set BIOS Write Enable */
290        wanted |= (1 << 0);
291
292        /* Only write the register if it's necessary */
293        if (wanted != old) {
294                rpci_write_byte(dev, bios_cntl, wanted);
295                new = pci_read_byte(dev, bios_cntl);
296        } else
297                new = old;
298
299        msg_pdbg("\nBIOS_CNTL = 0x%02x: ", new);
300        msg_pdbg("BIOS Lock Enable: %sabled, ", (new & (1 << 1)) ? "en" : "dis");
301        msg_pdbg("BIOS Write Enable: %sabled\n", (new & (1 << 0)) ? "en" : "dis");
302        if (new & (1 << 5))
303                msg_pwarn("Warning: BIOS region SMM protection is enabled!\n");
304
305
306        if (new != wanted)
307                msg_pwarn("Warning: Setting Bios Control at 0x%x from 0x%02x to 0x%02x on %s failed.\n"
308                          "New value is 0x%02x.\n", bios_cntl, old, wanted, name, new);
309
310        /* Return an error if we could not set the write enable */
311        if (!(new & (1 << 0)))
312                return -1;
313
314        return 0;
315}
316
317static int enable_flash_ich_4e(struct pci_dev *dev, const char *name)
318{
319        /*
320         * Note: ICH5 has registers similar to FWH_SEL1, FWH_SEL2 and
321         * FWH_DEC_EN1, but they are called FB_SEL1, FB_SEL2, FB_DEC_EN1 and
322         * FB_DEC_EN2.
323         */
324        internal_buses_supported = BUS_FWH;
325        return enable_flash_ich(dev, name, 0x4e);
326}
327
328static int enable_flash_ich_dc(struct pci_dev *dev, const char *name)
329{
330        uint32_t fwh_conf;
331        int i, tmp;
332        char *idsel = NULL;
333        int max_decode_fwh_idsel = 0, max_decode_fwh_decode = 0;
334        int contiguous = 1;
335
336        idsel = extract_programmer_param("fwh_idsel");
337        if (idsel && strlen(idsel)) {
338                uint64_t fwh_idsel_old, fwh_idsel;
339                errno = 0;
340                /* Base 16, nothing else makes sense. */
341                fwh_idsel = (uint64_t)strtoull(idsel, NULL, 16);
342                if (errno) {
343                        msg_perr("Error: fwh_idsel= specified, but value could "
344                                 "not be converted.\n");
345                        goto idsel_garbage_out;
346                }
347                if (fwh_idsel & 0xffff000000000000ULL) {
348                        msg_perr("Error: fwh_idsel= specified, but value had "
349                                 "unused bits set.\n");
350                        goto idsel_garbage_out;
351                }
352                fwh_idsel_old = pci_read_long(dev, 0xd0);
353                fwh_idsel_old <<= 16;
354                fwh_idsel_old |= pci_read_word(dev, 0xd4);
355                msg_pdbg("\nSetting IDSEL from 0x%012" PRIx64 " to "
356                         "0x%012" PRIx64 " for top 16 MB.", fwh_idsel_old,
357                         fwh_idsel);
358                rpci_write_long(dev, 0xd0, (fwh_idsel >> 16) & 0xffffffff);
359                rpci_write_word(dev, 0xd4, fwh_idsel & 0xffff);
360                /* FIXME: Decode settings are not changed. */
361        } else if (idsel) {
362                msg_perr("Error: fwh_idsel= specified, but no value given.\n");
363idsel_garbage_out:
364                free(idsel);
365                return ERROR_FATAL;
366        }
367        free(idsel);
368
369        /* Ignore all legacy ranges below 1 MB.
370         * We currently only support flashing the chip which responds to
371         * IDSEL=0. To support IDSEL!=0, flashbase and decode size calculations
372         * have to be adjusted.
373         */
374        /* FWH_SEL1 */
375        fwh_conf = pci_read_long(dev, 0xd0);
376        for (i = 7; i >= 0; i--) {
377                tmp = (fwh_conf >> (i * 4)) & 0xf;
378                msg_pdbg("\n0x%08x/0x%08x FWH IDSEL: 0x%x",
379                         (0x1ff8 + i) * 0x80000,
380                         (0x1ff0 + i) * 0x80000,
381                         tmp);
382                if ((tmp == 0) && contiguous) {
383                        max_decode_fwh_idsel = (8 - i) * 0x80000;
384                } else {
385                        contiguous = 0;
386                }
387        }
388        /* FWH_SEL2 */
389        fwh_conf = pci_read_word(dev, 0xd4);
390        for (i = 3; i >= 0; i--) {
391                tmp = (fwh_conf >> (i * 4)) & 0xf;
392                msg_pdbg("\n0x%08x/0x%08x FWH IDSEL: 0x%x",
393                         (0xff4 + i) * 0x100000,
394                         (0xff0 + i) * 0x100000,
395                         tmp);
396                if ((tmp == 0) && contiguous) {
397                        max_decode_fwh_idsel = (8 - i) * 0x100000;
398                } else {
399                        contiguous = 0;
400                }
401        }
402        contiguous = 1;
403        /* FWH_DEC_EN1 */
404        fwh_conf = pci_read_word(dev, 0xd8);
405        for (i = 7; i >= 0; i--) {
406                tmp = (fwh_conf >> (i + 0x8)) & 0x1;
407                msg_pdbg("\n0x%08x/0x%08x FWH decode %sabled",
408                         (0x1ff8 + i) * 0x80000,
409                         (0x1ff0 + i) * 0x80000,
410                         tmp ? "en" : "dis");
411                if ((tmp == 1) && contiguous) {
412                        max_decode_fwh_decode = (8 - i) * 0x80000;
413                } else {
414                        contiguous = 0;
415                }
416        }
417        for (i = 3; i >= 0; i--) {
418                tmp = (fwh_conf >> i) & 0x1;
419                msg_pdbg("\n0x%08x/0x%08x FWH decode %sabled",
420                         (0xff4 + i) * 0x100000,
421                         (0xff0 + i) * 0x100000,
422                         tmp ? "en" : "dis");
423                if ((tmp == 1) && contiguous) {
424                        max_decode_fwh_decode = (8 - i) * 0x100000;
425                } else {
426                        contiguous = 0;
427                }
428        }
429        max_rom_decode.fwh = min(max_decode_fwh_idsel, max_decode_fwh_decode);
430        msg_pdbg("\nMaximum FWH chip size: 0x%x bytes", max_rom_decode.fwh);
431
432        /* If we're called by enable_flash_ich_dc_spi, it will override
433         * internal_buses_supported anyway.
434         */
435        internal_buses_supported = BUS_FWH;
436        return enable_flash_ich(dev, name, 0xdc);
437}
438
439static int enable_flash_poulsbo(struct pci_dev *dev, const char *name)
440{
441        uint16_t old, new;
442        int err;
443
444        if ((err = enable_flash_ich(dev, name, 0xd8)) != 0)
445                return err;
446
447        old = pci_read_byte(dev, 0xd9);
448        msg_pdbg("BIOS Prefetch Enable: %sabled, ",
449                 (old & 1) ? "en" : "dis");
450        new = old & ~1;
451
452        if (new != old)
453                rpci_write_byte(dev, 0xd9, new);
454
455        internal_buses_supported = BUS_FWH;
456        return 0;
457}
458
459static int enable_flash_tunnelcreek(struct pci_dev *dev, const char *name)
460{
461        uint16_t old, new;
462        uint32_t tmp, bnt;
463        void *rcrb;
464        int ret;
465
466        /* Enable Flash Writes */
467        ret = enable_flash_ich(dev, name, 0xd8);
468        if (ret == ERROR_FATAL)
469                return ret;
470
471        /* Make sure BIOS prefetch mechanism is disabled */
472        old = pci_read_byte(dev, 0xd9);
473        msg_pdbg("BIOS Prefetch Enable: %sabled, ", (old & 1) ? "en" : "dis");
474        new = old & ~1;
475        if (new != old)
476                rpci_write_byte(dev, 0xd9, new);
477
478        /* Get physical address of Root Complex Register Block */
479        tmp = pci_read_long(dev, 0xf0) & 0xffffc000;
480        msg_pdbg("\nRoot Complex Register Block address = 0x%x\n", tmp);
481
482        /* Map RCBA to virtual memory */
483        rcrb = physmap("ICH RCRB", tmp, 0x4000);
484
485        /* Test Boot BIOS Strap Status */
486        bnt = mmio_readl(rcrb + 0x3410);
487        if (bnt & 0x02) {
488                /* If strapped to LPC, no SPI initialization is required */
489                internal_buses_supported = BUS_FWH;
490                return 0;
491        }
492
493        /* This adds BUS_SPI */
494        if (ich_init_spi(dev, tmp, rcrb, 7) != 0) {
495                if (!ret)
496                        ret = ERROR_NONFATAL;
497        }
498
499        return ret;
500}
501
502static int enable_flash_ich_dc_spi(struct pci_dev *dev, const char *name,
503                                   enum ich_chipset ich_generation)
504{
505        int ret, ret_spi;
506        uint8_t bbs, buc;
507        uint32_t tmp, gcs;
508        void *rcrb;
509        const char *const *straps_names;
510
511        static const char *const straps_names_EP80579[] = { "SPI", "reserved", "reserved", "LPC" };
512        static const char *const straps_names_ich7_nm10[] = { "reserved", "SPI", "PCI", "LPC" };
513        static const char *const straps_names_ich8910[] = { "SPI", "SPI", "PCI", "LPC" };
514        static const char *const straps_names_pch567[] = { "LPC", "reserved", "PCI", "SPI" };
515        static const char *const straps_names_pch8[] = { "LPC", "reserved", "reserved", "SPI" };
516        static const char *const straps_names_pch8_lp[] = { "SPI", "LPC", "unknown", "unknown" };
517        static const char *const straps_names_unknown[] = { "unknown", "unknown", "unknown", "unknown" };
518
519        switch (ich_generation) {
520        case CHIPSET_ICH7:
521                /* EP80579 may need further changes, but this is the least
522                 * intrusive way to get correct BOOT Strap printing without
523                 * changing the rest of its code path). */
524                if (strcmp(name, "EP80579") == 0)
525                        straps_names = straps_names_EP80579;
526                else
527                        straps_names = straps_names_ich7_nm10;
528                break;
529        case CHIPSET_ICH8:
530        case CHIPSET_ICH9:
531        case CHIPSET_ICH10:
532                straps_names = straps_names_ich8910;
533                break;
534        case CHIPSET_5_SERIES_IBEX_PEAK:
535        case CHIPSET_6_SERIES_COUGAR_POINT:
536        case CHIPSET_7_SERIES_PANTHER_POINT:
537                straps_names = straps_names_pch567;
538                break;
539        case CHIPSET_8_SERIES_LYNX_POINT:
540                straps_names = straps_names_pch8;
541                break;
542        case CHIPSET_8_SERIES_LYNX_POINT_LP:
543                straps_names = straps_names_pch8_lp;
544                break;
545        case CHIPSET_8_SERIES_WELLSBURG: // FIXME: check datasheet
546                straps_names = straps_names_unknown;
547                break;
548        default:
549                msg_gerr("%s: unknown ICH generation. Please report!\n",
550                         __func__);
551                straps_names = straps_names_unknown;
552                break;
553        }
554
555        /* Enable Flash Writes */
556        ret = enable_flash_ich_dc(dev, name);
557        if (ret == ERROR_FATAL)
558                return ret;
559
560        /* Get physical address of Root Complex Register Block */
561        tmp = pci_read_long(dev, 0xf0) & 0xffffc000;
562        msg_pdbg("Root Complex Register Block address = 0x%x\n", tmp);
563
564        /* Map RCBA to virtual memory */
565        rcrb = physmap("ICH RCRB", tmp, 0x4000);
566
567        gcs = mmio_readl(rcrb + 0x3410);
568        msg_pdbg("GCS = 0x%x: ", gcs);
569        msg_pdbg("BIOS Interface Lock-Down: %sabled, ",
570                 (gcs & 0x1) ? "en" : "dis");
571
572        switch (ich_generation) {
573        case CHIPSET_8_SERIES_LYNX_POINT_LP:
574        case CHIPSET_8_SERIES_WELLSBURG: // FIXME: check datasheet
575                /* Lynx Point LP uses a single bit for GCS */
576                bbs = (gcs >> 10) & 0x1;
577                break;
578        default:
579                /* Older chipsets use two bits for GCS */
580                bbs = (gcs >> 10) & 0x3;
581                break;
582        }
583        msg_pdbg("Boot BIOS Straps: 0x%x (%s)\n", bbs, straps_names[bbs]);
584
585        buc = mmio_readb(rcrb + 0x3414);
586        msg_pdbg("Top Swap : %s\n",
587                 (buc & 1) ? "enabled (A16 inverted)" : "not enabled");
588
589        /* It seems the ICH7 does not support SPI and LPC chips at the same
590         * time. At least not with our current code. So we prevent searching
591         * on ICH7 when the southbridge is strapped to LPC
592         */
593        internal_buses_supported = BUS_FWH;
594        if (ich_generation == CHIPSET_ICH7) {
595                if (bbs == 0x03) {
596                        /* If strapped to LPC, no further SPI initialization is
597                         * required. */
598                        return ret;
599                } else {
600                        /* Disable LPC/FWH if strapped to PCI or SPI */
601                        internal_buses_supported = BUS_NONE;
602                }
603        }
604
605        /* This adds BUS_SPI */
606        ret_spi = ich_init_spi(dev, tmp, rcrb, ich_generation);
607        if (ret_spi == ERROR_FATAL)
608                return ret_spi;
609       
610        if (ret || ret_spi)
611                ret = ERROR_NONFATAL;
612
613        return ret;
614}
615
616static int enable_flash_ich7(struct pci_dev *dev, const char *name)
617{
618        return enable_flash_ich_dc_spi(dev, name, CHIPSET_ICH7);
619}
620
621static int enable_flash_ich8(struct pci_dev *dev, const char *name)
622{
623        return enable_flash_ich_dc_spi(dev, name, CHIPSET_ICH8);
624}
625
626static int enable_flash_ich9(struct pci_dev *dev, const char *name)
627{
628        return enable_flash_ich_dc_spi(dev, name, CHIPSET_ICH9);
629}
630
631static int enable_flash_ich10(struct pci_dev *dev, const char *name)
632{
633        return enable_flash_ich_dc_spi(dev, name, CHIPSET_ICH10);
634}
635
636/* Ibex Peak aka. 5 series & 3400 series */
637static int enable_flash_pch5(struct pci_dev *dev, const char *name)
638{
639        return enable_flash_ich_dc_spi(dev, name, CHIPSET_5_SERIES_IBEX_PEAK);
640}
641
642/* Cougar Point aka. 6 series & c200 series */
643static int enable_flash_pch6(struct pci_dev *dev, const char *name)
644{
645        return enable_flash_ich_dc_spi(dev, name, CHIPSET_6_SERIES_COUGAR_POINT);
646}
647
648/* Panther Point aka. 7 series */
649static int enable_flash_pch7(struct pci_dev *dev, const char *name)
650{
651        return enable_flash_ich_dc_spi(dev, name, CHIPSET_7_SERIES_PANTHER_POINT);
652}
653
654/* Lynx Point aka. 8 series */
655static int enable_flash_pch8(struct pci_dev *dev, const char *name)
656{
657        return enable_flash_ich_dc_spi(dev, name, CHIPSET_8_SERIES_LYNX_POINT);
658}
659
660/* Lynx Point aka. 8 series low-power */
661static int enable_flash_pch8_lp(struct pci_dev *dev, const char *name)
662{
663        return enable_flash_ich_dc_spi(dev, name, CHIPSET_8_SERIES_LYNX_POINT_LP);
664}
665
666/* Wellsburg (for Haswell-EP Xeons) */
667static int enable_flash_pch8_wb(struct pci_dev *dev, const char *name)
668{
669        return enable_flash_ich_dc_spi(dev, name, CHIPSET_8_SERIES_WELLSBURG);
670}
671
672static int via_no_byte_merge(struct pci_dev *dev, const char *name)
673{
674        uint8_t val;
675
676        val = pci_read_byte(dev, 0x71);
677        if (val & 0x40) {
678                msg_pdbg("Disabling byte merging\n");
679                val &= ~0x40;
680                rpci_write_byte(dev, 0x71, val);
681        }
682        return NOT_DONE_YET;    /* need to find south bridge, too */
683}
684
685static int enable_flash_vt823x(struct pci_dev *dev, const char *name)
686{
687        uint8_t val;
688
689        /* Enable ROM decode range (1MB) FFC00000 - FFFFFFFF. */
690        rpci_write_byte(dev, 0x41, 0x7f);
691
692        /* ROM write enable */
693        val = pci_read_byte(dev, 0x40);
694        val |= 0x10;
695        rpci_write_byte(dev, 0x40, val);
696
697        if (pci_read_byte(dev, 0x40) != val) {
698                msg_pwarn("\nWarning: Failed to enable flash write on \"%s\"\n", name);
699                return -1;
700        }
701
702        if (dev->device_id == 0x3227) { /* VT8237/VT8237R */
703                /* All memory cycles, not just ROM ones, go to LPC. */
704                val = pci_read_byte(dev, 0x59);
705                val &= ~0x80;
706                rpci_write_byte(dev, 0x59, val);
707        }
708
709        return 0;
710}
711
712static int enable_flash_vt_vx(struct pci_dev *dev, const char *name)
713{
714        struct pci_dev *south_north = pci_dev_find(0x1106, 0xa353);
715        if (south_north == NULL) {
716                msg_perr("Could not find South-North Module Interface Control device!\n");
717                return ERROR_FATAL;
718        }
719
720        msg_pdbg("Strapped to ");
721        if ((pci_read_byte(south_north, 0x56) & 0x01) == 0) {
722                msg_pdbg("LPC.\n");
723                return enable_flash_vt823x(dev, name);
724        }
725        msg_pdbg("SPI.\n");
726
727        uint32_t mmio_base;
728        void *mmio_base_physmapped;
729        uint32_t spi_cntl;
730        #define SPI_CNTL_LEN 0x08
731        uint32_t spi0_mm_base = 0;
732        switch(dev->device_id) {
733                case 0x8353: /* VX800/VX820 */
734                        spi0_mm_base = pci_read_long(dev, 0xbc) << 8;
735                        break;
736                case 0x8409: /* VX855/VX875 */
737                case 0x8410: /* VX900 */
738                        mmio_base = pci_read_long(dev, 0xbc) << 8;
739                        mmio_base_physmapped = physmap("VIA VX MMIO register", mmio_base, SPI_CNTL_LEN);
740                        if (mmio_base_physmapped == ERROR_PTR) {
741                                physunmap(mmio_base_physmapped, SPI_CNTL_LEN);
742                                return ERROR_FATAL;
743                        }
744
745                        /* Offset 0 - Bit 0 holds SPI Bus0 Enable Bit. */
746                        spi_cntl = mmio_readl(mmio_base_physmapped) + 0x00;
747                        if ((spi_cntl & 0x01) == 0) {
748                                msg_pdbg ("SPI Bus0 disabled!\n");
749                                physunmap(mmio_base_physmapped, SPI_CNTL_LEN);
750                                return ERROR_FATAL;
751                        }
752                        /* Offset 1-3 has  SPI Bus Memory Map Base Address: */
753                        spi0_mm_base = spi_cntl & 0xFFFFFF00;
754
755                        /* Offset 4 - Bit 0 holds SPI Bus1 Enable Bit. */
756                        spi_cntl = mmio_readl(mmio_base_physmapped) + 0x04;
757                        if ((spi_cntl & 0x01) == 1)
758                                msg_pdbg2("SPI Bus1 is enabled too.\n");
759
760                        physunmap(mmio_base_physmapped, SPI_CNTL_LEN);
761                        break;
762                default:
763                        msg_perr("%s: Unsupported chipset %x:%x!\n", __func__, dev->vendor_id, dev->device_id);
764                        return ERROR_FATAL;
765        }
766
767        return via_init_spi(dev, spi0_mm_base);
768}
769
770static int enable_flash_vt8237s_spi(struct pci_dev *dev, const char *name)
771{
772        return via_init_spi(dev, pci_read_long(dev, 0xbc) << 8);
773}
774
775static int enable_flash_cs5530(struct pci_dev *dev, const char *name)
776{
777        uint8_t reg8;
778
779#define DECODE_CONTROL_REG2             0x5b    /* F0 index 0x5b */
780#define ROM_AT_LOGIC_CONTROL_REG        0x52    /* F0 index 0x52 */
781#define CS5530_RESET_CONTROL_REG        0x44    /* F0 index 0x44 */
782#define CS5530_USB_SHADOW_REG           0x43    /* F0 index 0x43 */
783
784#define LOWER_ROM_ADDRESS_RANGE         (1 << 0)
785#define ROM_WRITE_ENABLE                (1 << 1)
786#define UPPER_ROM_ADDRESS_RANGE         (1 << 2)
787#define BIOS_ROM_POSITIVE_DECODE        (1 << 5)
788#define CS5530_ISA_MASTER               (1 << 7)
789#define CS5530_ENABLE_SA2320            (1 << 2)
790#define CS5530_ENABLE_SA20              (1 << 6)
791
792        internal_buses_supported = BUS_PARALLEL;
793        /* Decode 0x000E0000-0x000FFFFF (128 kB), not just 64 kB, and
794         * decode 0xFF000000-0xFFFFFFFF (16 MB), not just 256 kB.
795         * FIXME: Should we really touch the low mapping below 1 MB? Flashrom
796         * ignores that region completely.
797         * Make the configured ROM areas writable.
798         */
799        reg8 = pci_read_byte(dev, ROM_AT_LOGIC_CONTROL_REG);
800        reg8 |= LOWER_ROM_ADDRESS_RANGE;
801        reg8 |= UPPER_ROM_ADDRESS_RANGE;
802        reg8 |= ROM_WRITE_ENABLE;
803        rpci_write_byte(dev, ROM_AT_LOGIC_CONTROL_REG, reg8);
804
805        /* Set positive decode on ROM. */
806        reg8 = pci_read_byte(dev, DECODE_CONTROL_REG2);
807        reg8 |= BIOS_ROM_POSITIVE_DECODE;
808        rpci_write_byte(dev, DECODE_CONTROL_REG2, reg8);
809
810        reg8 = pci_read_byte(dev, CS5530_RESET_CONTROL_REG);
811        if (reg8 & CS5530_ISA_MASTER) {
812                /* We have A0-A23 available. */
813                max_rom_decode.parallel = 16 * 1024 * 1024;
814        } else {
815                reg8 = pci_read_byte(dev, CS5530_USB_SHADOW_REG);
816                if (reg8 & CS5530_ENABLE_SA2320) {
817                        /* We have A0-19, A20-A23 available. */
818                        max_rom_decode.parallel = 16 * 1024 * 1024;
819                } else if (reg8 & CS5530_ENABLE_SA20) {
820                        /* We have A0-19, A20 available. */
821                        max_rom_decode.parallel = 2 * 1024 * 1024;
822                } else {
823                        /* A20 and above are not active. */
824                        max_rom_decode.parallel = 1024 * 1024;
825                }
826        }
827
828        return 0;
829}
830
831/*
832 * Geode systems write protect the BIOS via RCONFs (cache settings similar
833 * to MTRRs). To unlock, change MSR 0x1808 top byte to 0x22.
834 *
835 * Geode systems also write protect the NOR flash chip itself via MSR_NORF_CTL.
836 * To enable write to NOR Boot flash for the benefit of systems that have such
837 * a setup, raise MSR 0x51400018 WE_CS3 (write enable Boot Flash Chip Select).
838 */
839static int enable_flash_cs5536(struct pci_dev *dev, const char *name)
840{
841#define MSR_RCONF_DEFAULT       0x1808
842#define MSR_NORF_CTL            0x51400018
843
844        msr_t msr;
845
846        /* Geode only has a single core */
847        if (setup_cpu_msr(0))
848                return -1;
849
850        msr = rdmsr(MSR_RCONF_DEFAULT);
851        if ((msr.hi >> 24) != 0x22) {
852                msr.hi &= 0xfbffffff;
853                wrmsr(MSR_RCONF_DEFAULT, msr);
854        }
855
856        msr = rdmsr(MSR_NORF_CTL);
857        /* Raise WE_CS3 bit. */
858        msr.lo |= 0x08;
859        wrmsr(MSR_NORF_CTL, msr);
860
861        cleanup_cpu_msr();
862
863#undef MSR_RCONF_DEFAULT
864#undef MSR_NORF_CTL
865        return 0;
866}
867
868static int enable_flash_sc1100(struct pci_dev *dev, const char *name)
869{
870        #define SC_REG 0x52
871        uint8_t new;
872
873        rpci_write_byte(dev, SC_REG, 0xee);
874
875        new = pci_read_byte(dev, SC_REG);
876
877        if (new != 0xee) { /* FIXME: share this with other code? */
878                msg_pinfo("Setting register 0x%x to 0x%02x on %s failed (WARNING ONLY).\n", SC_REG, new, name);
879                return -1;
880        }
881
882        return 0;
883}
884
885/* Works for AMD-8111, VIA VT82C586A/B, VIA VT82C686A/B. */
886static int enable_flash_amd8111(struct pci_dev *dev, const char *name)
887{
888        #define AMD_MAPREG 0x43
889        #define AMD_ENREG 0x40
890        uint8_t old, new;
891
892        /* Enable decoding at 0xffb00000 to 0xffffffff. */
893        old = pci_read_byte(dev, AMD_MAPREG);
894        new = old | 0xC0;
895        if (new != old) {
896                rpci_write_byte(dev, AMD_MAPREG, new);
897                if (pci_read_byte(dev, AMD_MAPREG) != new) {
898                        msg_pinfo("Setting register 0x%x to 0x%02x on %s failed (WARNING ONLY).\n",
899                                  AMD_MAPREG, new, name);
900                }
901        }
902
903        /* Enable 'ROM write' bit. */
904        old = pci_read_byte(dev, AMD_ENREG);
905        new = old | 0x01;
906        if (new == old)
907                return 0;
908        rpci_write_byte(dev, AMD_ENREG, new);
909
910        if (pci_read_byte(dev, AMD_ENREG) != new) {
911                msg_pinfo("Setting register 0x%x to 0x%02x on %s failed (WARNING ONLY).\n",
912                          AMD_ENREG, new, name);
913                return -1;
914        }
915
916        return 0;
917}
918
919static int enable_flash_sb600(struct pci_dev *dev, const char *name)
920{
921        uint32_t prot;
922        uint8_t reg;
923        int ret;
924
925        /* Clear ROM protect 0-3. */
926        for (reg = 0x50; reg < 0x60; reg += 4) {
927                prot = pci_read_long(dev, reg);
928                /* No protection flags for this region?*/
929                if ((prot & 0x3) == 0)
930                        continue;
931                msg_pinfo("SB600 %s%sprotected from 0x%08x to 0x%08x\n",
932                          (prot & 0x1) ? "write " : "",
933                          (prot & 0x2) ? "read " : "",
934                          (prot & 0xfffff800),
935                          (prot & 0xfffff800) + (((prot & 0x7fc) << 8) | 0x3ff));
936                prot &= 0xfffffffc;
937                rpci_write_byte(dev, reg, prot);
938                prot = pci_read_long(dev, reg);
939                if (prot & 0x3)
940                        msg_perr("SB600 %s%sunprotect failed from 0x%08x to 0x%08x\n",
941                                 (prot & 0x1) ? "write " : "",
942                                 (prot & 0x2) ? "read " : "",
943                                 (prot & 0xfffff800),
944                                 (prot & 0xfffff800) + (((prot & 0x7fc) << 8) | 0x3ff));
945        }
946
947        internal_buses_supported = BUS_LPC | BUS_FWH;
948
949        ret = sb600_probe_spi(dev);
950
951        /* Read ROM strap override register. */
952        OUTB(0x8f, 0xcd6);
953        reg = INB(0xcd7);
954        reg &= 0x0e;
955        msg_pdbg("ROM strap override is %sactive", (reg & 0x02) ? "" : "not ");
956        if (reg & 0x02) {
957                switch ((reg & 0x0c) >> 2) {
958                case 0x00:
959                        msg_pdbg(": LPC");
960                        break;
961                case 0x01:
962                        msg_pdbg(": PCI");
963                        break;
964                case 0x02:
965                        msg_pdbg(": FWH");
966                        break;
967                case 0x03:
968                        msg_pdbg(": SPI");
969                        break;
970                }
971        }
972        msg_pdbg("\n");
973
974        /* Force enable SPI ROM in SB600 PM register.
975         * If we enable SPI ROM here, we have to disable it after we leave.
976         * But how can we know which ROM we are going to handle? So we have
977         * to trade off. We only access LPC ROM if we boot via LPC ROM. And
978         * only SPI ROM if we boot via SPI ROM. If you want to access SPI on
979         * boards with LPC straps, you have to use the code below.
980         */
981        /*
982        OUTB(0x8f, 0xcd6);
983        OUTB(0x0e, 0xcd7);
984        */
985
986        return ret;
987}
988
989/* sets bit 0 in 0x6d */
990static int enable_flash_nvidia_common(struct pci_dev *dev, const char *name)
991{
992        uint8_t old, new;
993
994        old = pci_read_byte(dev, 0x6d);
995        new = old | 0x01;
996        if (new == old)
997                return 0;
998
999        rpci_write_byte(dev, 0x6d, new);
1000        if (pci_read_byte(dev, 0x6d) != new) {
1001                msg_pinfo("Setting register 0x6d to 0x%02x on %s failed.\n", new, name);
1002                return 1;
1003        }
1004        return 0;
1005}
1006
1007static int enable_flash_nvidia_nforce2(struct pci_dev *dev, const char *name)
1008{
1009        rpci_write_byte(dev, 0x92, 0);
1010        if (enable_flash_nvidia_common(dev, name))
1011                return ERROR_NONFATAL;
1012        else
1013                return 0;
1014}
1015
1016static int enable_flash_ck804(struct pci_dev *dev, const char *name)
1017{
1018        uint32_t segctrl;
1019        uint8_t reg, old, new;
1020        unsigned int err = 0;
1021
1022        /* 0x8A is special: it is a single byte and only one nibble is touched. */
1023        reg = 0x8A;
1024        segctrl = pci_read_byte(dev, reg);
1025        if ((segctrl & 0x3) != 0x0) {
1026                if ((segctrl & 0xC) != 0x0) {
1027                        msg_pinfo("Can not unlock existing protection in register 0x%02x.\n", reg);
1028                        err++;
1029                } else {
1030                        msg_pdbg("Unlocking protection in register 0x%02x... ", reg);
1031                        rpci_write_byte(dev, reg, segctrl & 0xF0);
1032
1033                        segctrl = pci_read_byte(dev, reg);
1034                        if ((segctrl & 0x3) != 0x0) {
1035                                msg_pinfo("Could not unlock protection in register 0x%02x (new value: 0x%x).\n",
1036                                          reg, segctrl);
1037                                err++;
1038                        } else
1039                                msg_pdbg("OK\n");
1040                }
1041        }
1042
1043        for (reg = 0x8C; reg <= 0x94; reg += 4) {
1044                segctrl = pci_read_long(dev, reg);
1045                if ((segctrl & 0x33333333) == 0x00000000) {
1046                        /* reads and writes are unlocked */
1047                        continue;
1048                }
1049                if ((segctrl & 0xCCCCCCCC) != 0x00000000) {
1050                        msg_pinfo("Can not unlock existing protection in register 0x%02x.\n", reg);
1051                        err++;
1052                        continue;
1053                }
1054                msg_pdbg("Unlocking protection in register 0x%02x... ", reg);
1055                rpci_write_long(dev, reg, 0x00000000);
1056
1057                segctrl = pci_read_long(dev, reg);
1058                if ((segctrl & 0x33333333) != 0x00000000) {
1059                        msg_pinfo("Could not unlock protection in register 0x%02x (new value: 0x%08x).\n",
1060                                  reg, segctrl);
1061                        err++;
1062                } else
1063                        msg_pdbg("OK\n");
1064        }
1065
1066        if (err > 0) {
1067                msg_pinfo("%d locks could not be disabled, disabling writes (reads may also fail).\n", err);
1068                programmer_may_write = 0;
1069        }
1070
1071        reg = 0x88;
1072        old = pci_read_byte(dev, reg);
1073        new = old | 0xC0;
1074        if (new != old) {
1075                rpci_write_byte(dev, reg, new);
1076                if (pci_read_byte(dev, reg) != new) { /* FIXME: share this with other code? */
1077                        msg_pinfo("Setting register 0x%02x to 0x%02x on %s failed.\n", reg, new, name);
1078                        err++;
1079                }
1080        }
1081
1082        if (enable_flash_nvidia_common(dev, name))
1083                err++;
1084
1085        if (err > 0)
1086                return ERROR_NONFATAL;
1087        else
1088                return 0;
1089}
1090
1091static int enable_flash_osb4(struct pci_dev *dev, const char *name)
1092{
1093        uint8_t tmp;
1094
1095        internal_buses_supported = BUS_PARALLEL;
1096
1097        tmp = INB(0xc06);
1098        tmp |= 0x1;
1099        OUTB(tmp, 0xc06);
1100
1101        tmp = INB(0xc6f);
1102        tmp |= 0x40;
1103        OUTB(tmp, 0xc6f);
1104
1105        return 0;
1106}
1107
1108/* ATI Technologies Inc IXP SB400 PCI-ISA Bridge (rev 80) */
1109static int enable_flash_sb400(struct pci_dev *dev, const char *name)
1110{
1111        uint8_t tmp;
1112        struct pci_dev *smbusdev;
1113
1114        /* Look for the SMBus device. */
1115        smbusdev = pci_dev_find(0x1002, 0x4372);
1116
1117        if (!smbusdev) {
1118                msg_perr("ERROR: SMBus device not found. Aborting.\n");
1119                return ERROR_FATAL;
1120        }
1121
1122        /* Enable some SMBus stuff. */
1123        tmp = pci_read_byte(smbusdev, 0x79);
1124        tmp |= 0x01;
1125        rpci_write_byte(smbusdev, 0x79, tmp);
1126
1127        /* Change southbridge. */
1128        tmp = pci_read_byte(dev, 0x48);
1129        tmp |= 0x21;
1130        rpci_write_byte(dev, 0x48, tmp);
1131
1132        /* Now become a bit silly. */
1133        tmp = INB(0xc6f);
1134        OUTB(tmp, 0xeb);
1135        OUTB(tmp, 0xeb);
1136        tmp |= 0x40;
1137        OUTB(tmp, 0xc6f);
1138        OUTB(tmp, 0xeb);
1139        OUTB(tmp, 0xeb);
1140
1141        return 0;
1142}
1143
1144static int enable_flash_mcp55(struct pci_dev *dev, const char *name)
1145{
1146        uint8_t val;
1147        uint16_t wordval;
1148
1149        /* Set the 0-16 MB enable bits. */
1150        val = pci_read_byte(dev, 0x88);
1151        val |= 0xff;            /* 256K */
1152        rpci_write_byte(dev, 0x88, val);
1153        val = pci_read_byte(dev, 0x8c);
1154        val |= 0xff;            /* 1M */
1155        rpci_write_byte(dev, 0x8c, val);
1156        wordval = pci_read_word(dev, 0x90);
1157        wordval |= 0x7fff;      /* 16M */
1158        rpci_write_word(dev, 0x90, wordval);
1159
1160        if (enable_flash_nvidia_common(dev, name))
1161                return ERROR_NONFATAL;
1162        else
1163                return 0;
1164}
1165
1166/*
1167 * The MCP6x/MCP7x code is based on cleanroom reverse engineering.
1168 * It is assumed that LPC chips need the MCP55 code and SPI chips need the
1169 * code provided in enable_flash_mcp6x_7x_common.
1170 */
1171static int enable_flash_mcp6x_7x(struct pci_dev *dev, const char *name)
1172{
1173        int ret = 0, want_spi = 0;
1174        uint8_t val;
1175
1176        msg_pinfo("This chipset is not really supported yet. Guesswork...\n");
1177
1178        /* dev is the ISA bridge. No idea what the stuff below does. */
1179        val = pci_read_byte(dev, 0x8a);
1180        msg_pdbg("ISA/LPC bridge reg 0x8a contents: 0x%02x, bit 6 is %i, bit 5 "
1181                 "is %i\n", val, (val >> 6) & 0x1, (val >> 5) & 0x1);
1182
1183        switch ((val >> 5) & 0x3) {
1184        case 0x0:
1185                ret = enable_flash_mcp55(dev, name);
1186                internal_buses_supported = BUS_LPC;
1187                msg_pdbg("Flash bus type is LPC\n");
1188                break;
1189        case 0x2:
1190                want_spi = 1;
1191                /* SPI is added in mcp6x_spi_init if it works.
1192                 * Do we really want to disable LPC in this case?
1193                 */
1194                internal_buses_supported = BUS_NONE;
1195                msg_pdbg("Flash bus type is SPI\n");
1196                msg_pinfo("SPI on this chipset is WIP. Please report any "
1197                          "success or failure by mailing us the verbose "
1198                          "output to flashrom@flashrom.org, thanks!\n");
1199                break;
1200        default:
1201                /* Should not happen. */
1202                internal_buses_supported = BUS_NONE;
1203                msg_pdbg("Flash bus type is unknown (none)\n");
1204                msg_pinfo("Something went wrong with bus type detection.\n");
1205                goto out_msg;
1206                break;
1207        }
1208
1209        /* Force enable SPI and disable LPC? Not a good idea. */
1210#if 0
1211        val |= (1 << 6);
1212        val &= ~(1 << 5);
1213        rpci_write_byte(dev, 0x8a, val);
1214#endif
1215
1216        if (mcp6x_spi_init(want_spi))
1217                ret = 1;
1218
1219out_msg:
1220        msg_pinfo("Please send the output of \"flashrom -V\" to "
1221                  "flashrom@flashrom.org with\n"
1222                  "your board name: flashrom -V as the subject to help us "
1223                  "finish support for your\n"
1224                  "chipset. Thanks.\n");
1225
1226        return ret;
1227}
1228
1229static int enable_flash_ht1000(struct pci_dev *dev, const char *name)
1230{
1231        uint8_t val;
1232
1233        /* Set the 4MB enable bit. */
1234        val = pci_read_byte(dev, 0x41);
1235        val |= 0x0e;
1236        rpci_write_byte(dev, 0x41, val);
1237
1238        val = pci_read_byte(dev, 0x43);
1239        val |= (1 << 4);
1240        rpci_write_byte(dev, 0x43, val);
1241
1242        return 0;
1243}
1244
1245/*
1246 * Usually on the x86 architectures (and on other PC-like platforms like some
1247 * Alphas or Itanium) the system flash is mapped right below 4G. On the AMD
1248 * Elan SC520 only a small piece of the system flash is mapped there, but the
1249 * complete flash is mapped somewhere below 1G. The position can be determined
1250 * by the BOOTCS PAR register.
1251 */
1252static int get_flashbase_sc520(struct pci_dev *dev, const char *name)
1253{
1254        int i, bootcs_found = 0;
1255        uint32_t parx = 0;
1256        void *mmcr;
1257
1258        /* 1. Map MMCR */
1259        mmcr = physmap("Elan SC520 MMCR", 0xfffef000, getpagesize());
1260
1261        /* 2. Scan PAR0 (0x88) - PAR15 (0xc4) for
1262         *    BOOTCS region (PARx[31:29] = 100b)e
1263         */
1264        for (i = 0x88; i <= 0xc4; i += 4) {
1265                parx = mmio_readl(mmcr + i);
1266                if ((parx >> 29) == 4) {
1267                        bootcs_found = 1;
1268                        break; /* BOOTCS found */
1269                }
1270        }
1271
1272        /* 3. PARx[25] = 1b --> flashbase[29:16] = PARx[13:0]
1273         *    PARx[25] = 0b --> flashbase[29:12] = PARx[17:0]
1274         */
1275        if (bootcs_found) {
1276                if (parx & (1 << 25)) {
1277                        parx &= (1 << 14) - 1; /* Mask [13:0] */
1278                        flashbase = parx << 16;
1279                } else {
1280                        parx &= (1 << 18) - 1; /* Mask [17:0] */
1281                        flashbase = parx << 12;
1282                }
1283        } else {
1284                msg_pinfo("AMD Elan SC520 detected, but no BOOTCS. "
1285                          "Assuming flash at 4G.\n");
1286        }
1287
1288        /* 4. Clean up */
1289        physunmap(mmcr, getpagesize());
1290        return 0;
1291}
1292
1293#endif
1294
1295/* Please keep this list numerically sorted by vendor/device ID. */
1296const struct penable chipset_enables[] = {
1297#if defined(__i386__) || defined(__x86_64__)
1298        {0x1002, 0x4377, OK, "ATI", "SB400",            enable_flash_sb400},
1299        {0x1002, 0x438d, OK, "AMD", "SB600",            enable_flash_sb600},
1300        {0x1002, 0x439d, OK, "AMD", "SB7x0/SB8x0/SB9x0", enable_flash_sb600},
1301        {0x100b, 0x0510, NT, "AMD", "SC1100",           enable_flash_sc1100},
1302        {0x1022, 0x2080, OK, "AMD", "CS5536",           enable_flash_cs5536},
1303        {0x1022, 0x2090, OK, "AMD", "CS5536",           enable_flash_cs5536},
1304        {0x1022, 0x3000, OK, "AMD", "Elan SC520",       get_flashbase_sc520},
1305        {0x1022, 0x7440, OK, "AMD", "AMD-768",          enable_flash_amd8111},
1306        {0x1022, 0x7468, OK, "AMD", "AMD8111",          enable_flash_amd8111},
1307        {0x1022, 0x780e, OK, "AMD", "Hudson",           enable_flash_sb600},
1308        {0x1039, 0x0406, NT, "SiS", "501/5101/5501",    enable_flash_sis501},
1309        {0x1039, 0x0496, NT, "SiS", "85C496+497",       enable_flash_sis85c496},
1310        {0x1039, 0x0530, OK, "SiS", "530",              enable_flash_sis530},
1311        {0x1039, 0x0540, NT, "SiS", "540",              enable_flash_sis540},
1312        {0x1039, 0x0620, NT, "SiS", "620",              enable_flash_sis530},
1313        {0x1039, 0x0630, NT, "SiS", "630",              enable_flash_sis540},
1314        {0x1039, 0x0635, NT, "SiS", "635",              enable_flash_sis540},
1315        {0x1039, 0x0640, NT, "SiS", "640",              enable_flash_sis540},
1316        {0x1039, 0x0645, NT, "SiS", "645",              enable_flash_sis540},
1317        {0x1039, 0x0646, OK, "SiS", "645DX",            enable_flash_sis540},
1318        {0x1039, 0x0648, NT, "SiS", "648",              enable_flash_sis540},
1319        {0x1039, 0x0650, OK, "SiS", "650",              enable_flash_sis540},
1320        {0x1039, 0x0651, OK, "SiS", "651",              enable_flash_sis540},
1321        {0x1039, 0x0655, NT, "SiS", "655",              enable_flash_sis540},
1322        {0x1039, 0x0661, OK, "SiS", "661",              enable_flash_sis540},
1323        {0x1039, 0x0730, OK, "SiS", "730",              enable_flash_sis540},
1324        {0x1039, 0x0733, NT, "SiS", "733",              enable_flash_sis540},
1325        {0x1039, 0x0735, OK, "SiS", "735",              enable_flash_sis540},
1326        {0x1039, 0x0740, NT, "SiS", "740",              enable_flash_sis540},
1327        {0x1039, 0x0741, OK, "SiS", "741",              enable_flash_sis540},
1328        {0x1039, 0x0745, OK, "SiS", "745",              enable_flash_sis540},
1329        {0x1039, 0x0746, NT, "SiS", "746",              enable_flash_sis540},
1330        {0x1039, 0x0748, NT, "SiS", "748",              enable_flash_sis540},
1331        {0x1039, 0x0755, OK, "SiS", "755",              enable_flash_sis540},
1332        {0x1039, 0x5511, NT, "SiS", "5511",             enable_flash_sis5511},
1333        {0x1039, 0x5571, NT, "SiS", "5571",             enable_flash_sis530},
1334        {0x1039, 0x5591, NT, "SiS", "5591/5592",        enable_flash_sis530},
1335        {0x1039, 0x5596, NT, "SiS", "5596",             enable_flash_sis5511},
1336        {0x1039, 0x5597, NT, "SiS", "5597/5598/5581/5120", enable_flash_sis530},
1337        {0x1039, 0x5600, NT, "SiS", "600",              enable_flash_sis530},
1338        {0x1078, 0x0100, OK, "AMD", "CS5530(A)",        enable_flash_cs5530},
1339        {0x10b9, 0x1533, OK, "ALi", "M1533",            enable_flash_ali_m1533},
1340        {0x10de, 0x0030, OK, "NVIDIA", "nForce4/MCP4",  enable_flash_nvidia_nforce2},
1341        {0x10de, 0x0050, OK, "NVIDIA", "CK804",         enable_flash_ck804}, /* LPC */
1342        {0x10de, 0x0051, OK, "NVIDIA", "CK804",         enable_flash_ck804}, /* Pro */
1343        {0x10de, 0x0060, OK, "NVIDIA", "NForce2",       enable_flash_nvidia_nforce2},
1344        {0x10de, 0x00e0, OK, "NVIDIA", "NForce3",       enable_flash_nvidia_nforce2},
1345        /* Slave, should not be here, to fix known bug for A01. */
1346        {0x10de, 0x00d3, OK, "NVIDIA", "CK804",         enable_flash_ck804},
1347        {0x10de, 0x0260, OK, "NVIDIA", "MCP51",         enable_flash_ck804},
1348        {0x10de, 0x0261, NT, "NVIDIA", "MCP51",         enable_flash_ck804},
1349        {0x10de, 0x0262, NT, "NVIDIA", "MCP51",         enable_flash_ck804},
1350        {0x10de, 0x0263, NT, "NVIDIA", "MCP51",         enable_flash_ck804},
1351        {0x10de, 0x0360, OK, "NVIDIA", "MCP55",         enable_flash_mcp55}, /* M57SLI*/
1352        /* 10de:0361 is present in Tyan S2915 OEM systems, but not connected to
1353         * the flash chip. Instead, 10de:0364 is connected to the flash chip.
1354         * Until we have PCI device class matching or some fallback mechanism,
1355         * this is needed to get flashrom working on Tyan S2915 and maybe other
1356         * dual-MCP55 boards.
1357         */
1358#if 0
1359        {0x10de, 0x0361, NT, "NVIDIA", "MCP55",         enable_flash_mcp55}, /* LPC */
1360#endif
1361        {0x10de, 0x0362, OK, "NVIDIA", "MCP55",         enable_flash_mcp55}, /* LPC */
1362        {0x10de, 0x0363, OK, "NVIDIA", "MCP55",         enable_flash_mcp55}, /* LPC */
1363        {0x10de, 0x0364, OK, "NVIDIA", "MCP55",         enable_flash_mcp55}, /* LPC */
1364        {0x10de, 0x0365, OK, "NVIDIA", "MCP55",         enable_flash_mcp55}, /* LPC */
1365        {0x10de, 0x0366, OK, "NVIDIA", "MCP55",         enable_flash_mcp55}, /* LPC */
1366        {0x10de, 0x0367, OK, "NVIDIA", "MCP55",         enable_flash_mcp55}, /* Pro */
1367        {0x10de, 0x03e0, OK, "NVIDIA", "MCP61",         enable_flash_mcp6x_7x},
1368        {0x10de, 0x03e1, OK, "NVIDIA", "MCP61",         enable_flash_mcp6x_7x},
1369        {0x10de, 0x03e2, NT, "NVIDIA", "MCP61",         enable_flash_mcp6x_7x},
1370        {0x10de, 0x03e3, NT, "NVIDIA", "MCP61",         enable_flash_mcp6x_7x},
1371        {0x10de, 0x0440, NT, "NVIDIA", "MCP65",         enable_flash_mcp6x_7x},
1372        {0x10de, 0x0441, NT, "NVIDIA", "MCP65",         enable_flash_mcp6x_7x},
1373        {0x10de, 0x0442, NT, "NVIDIA", "MCP65",         enable_flash_mcp6x_7x},
1374        {0x10de, 0x0443, NT, "NVIDIA", "MCP65",         enable_flash_mcp6x_7x},
1375        {0x10de, 0x0548, OK, "NVIDIA", "MCP67",         enable_flash_mcp6x_7x},
1376        {0x10de, 0x075c, OK, "NVIDIA", "MCP78S",        enable_flash_mcp6x_7x},
1377        {0x10de, 0x075d, OK, "NVIDIA", "MCP78S",        enable_flash_mcp6x_7x},
1378        {0x10de, 0x07d7, OK, "NVIDIA", "MCP73",         enable_flash_mcp6x_7x},
1379        {0x10de, 0x0aac, OK, "NVIDIA", "MCP79",         enable_flash_mcp6x_7x},
1380        {0x10de, 0x0aad, NT, "NVIDIA", "MCP79",         enable_flash_mcp6x_7x},
1381        {0x10de, 0x0aae, NT, "NVIDIA", "MCP79",         enable_flash_mcp6x_7x},
1382        {0x10de, 0x0aaf, NT, "NVIDIA", "MCP79",         enable_flash_mcp6x_7x},
1383        /* VIA northbridges */
1384        {0x1106, 0x0585, NT, "VIA", "VT82C585VPX",      via_no_byte_merge},
1385        {0x1106, 0x0595, NT, "VIA", "VT82C595",         via_no_byte_merge},
1386        {0x1106, 0x0597, NT, "VIA", "VT82C597",         via_no_byte_merge},
1387        {0x1106, 0x0601, NT, "VIA", "VT8601/VT8601A",   via_no_byte_merge},
1388        {0x1106, 0x0691, OK, "VIA", "VT82C69x",         via_no_byte_merge},
1389        {0x1106, 0x8601, NT, "VIA", "VT8601T",          via_no_byte_merge},
1390        /* VIA southbridges */
1391        {0x1106, 0x0586, OK, "VIA", "VT82C586A/B",      enable_flash_amd8111},
1392        {0x1106, 0x0596, OK, "VIA", "VT82C596",         enable_flash_amd8111},
1393        {0x1106, 0x0686, OK, "VIA", "VT82C686A/B",      enable_flash_amd8111},
1394        {0x1106, 0x3074, OK, "VIA", "VT8233",           enable_flash_vt823x},
1395        {0x1106, 0x3147, OK, "VIA", "VT8233A",          enable_flash_vt823x},
1396        {0x1106, 0x3177, OK, "VIA", "VT8235",           enable_flash_vt823x},
1397        {0x1106, 0x3227, OK, "VIA", "VT8237(R)",        enable_flash_vt823x},
1398        {0x1106, 0x3337, OK, "VIA", "VT8237A",          enable_flash_vt823x},
1399        {0x1106, 0x3372, OK, "VIA", "VT8237S",          enable_flash_vt8237s_spi},
1400        {0x1106, 0x8231, NT, "VIA", "VT8231",           enable_flash_vt823x},
1401        {0x1106, 0x8324, OK, "VIA", "CX700",            enable_flash_vt823x},
1402        {0x1106, 0x8353, NT, "VIA", "VX800/VX820",      enable_flash_vt_vx},
1403        {0x1106, 0x8409, NT, "VIA", "VX855/VX875",      enable_flash_vt_vx},
1404        {0x1106, 0x8410, NT, "VIA", "VX900",            enable_flash_vt_vx},
1405        {0x1166, 0x0200, OK, "Broadcom", "OSB4",        enable_flash_osb4},
1406        {0x1166, 0x0205, OK, "Broadcom", "HT-1000",     enable_flash_ht1000},
1407        {0x17f3, 0x6030, OK, "RDC", "R8610/R3210",      enable_flash_rdc_r8610},
1408        {0x8086, 0x122e, OK, "Intel", "PIIX",           enable_flash_piix4},
1409        {0x8086, 0x1234, NT, "Intel", "MPIIX",          enable_flash_piix4},
1410        {0x8086, 0x1c44, OK, "Intel", "Z68",            enable_flash_pch6},
1411        {0x8086, 0x1c46, OK, "Intel", "P67",            enable_flash_pch6},
1412        {0x8086, 0x1c47, NT, "Intel", "UM67",           enable_flash_pch6},
1413        {0x8086, 0x1c49, NT, "Intel", "HM65",           enable_flash_pch6},
1414        {0x8086, 0x1c4a, OK, "Intel", "H67",            enable_flash_pch6},
1415        {0x8086, 0x1c4b, NT, "Intel", "HM67",           enable_flash_pch6},
1416        {0x8086, 0x1c4c, NT, "Intel", "Q65",            enable_flash_pch6},
1417        {0x8086, 0x1c4d, NT, "Intel", "QS67",           enable_flash_pch6},
1418        {0x8086, 0x1c4e, NT, "Intel", "Q67",            enable_flash_pch6},
1419        {0x8086, 0x1c4f, NT, "Intel", "QM67",           enable_flash_pch6},
1420        {0x8086, 0x1c50, NT, "Intel", "B65",            enable_flash_pch6},
1421        {0x8086, 0x1c52, NT, "Intel", "C202",           enable_flash_pch6},
1422        {0x8086, 0x1c54, NT, "Intel", "C204",           enable_flash_pch6},
1423        {0x8086, 0x1c56, NT, "Intel", "C206",           enable_flash_pch6},
1424        {0x8086, 0x1c5c, OK, "Intel", "H61",            enable_flash_pch6},
1425        {0x8086, 0x1d40, OK, "Intel", "X79",            enable_flash_pch6},
1426        {0x8086, 0x1d41, OK, "Intel", "X79",            enable_flash_pch6},
1427        {0x8086, 0x1e44, OK, "Intel", "Z77",            enable_flash_pch7},
1428        {0x8086, 0x1e46, NT, "Intel", "Z75",            enable_flash_pch7},
1429        {0x8086, 0x1e47, NT, "Intel", "Q77",            enable_flash_pch7},
1430        {0x8086, 0x1e48, NT, "Intel", "Q75",            enable_flash_pch7},
1431        {0x8086, 0x1e49, NT, "Intel", "B75",            enable_flash_pch7},
1432        {0x8086, 0x1e4a, NT, "Intel", "H77",            enable_flash_pch7},
1433        {0x8086, 0x1e53, NT, "Intel", "C216",           enable_flash_pch7},
1434        {0x8086, 0x1e55, OK, "Intel", "QM77",           enable_flash_pch7},
1435        {0x8086, 0x1e56, NT, "Intel", "QS77",           enable_flash_pch7},
1436        {0x8086, 0x1e57, NT, "Intel", "HM77",           enable_flash_pch7},
1437        {0x8086, 0x1e58, NT, "Intel", "UM77",           enable_flash_pch7},
1438        {0x8086, 0x1e59, NT, "Intel", "HM76",           enable_flash_pch7},
1439        {0x8086, 0x1e5d, NT, "Intel", "HM75",           enable_flash_pch7},
1440        {0x8086, 0x1e5e, NT, "Intel", "HM70",           enable_flash_pch7},
1441        {0x8086, 0x1e5f, NT, "Intel", "NM70",           enable_flash_pch7},
1442        {0x8086, 0x2310, NT, "Intel", "DH89xxCC",       enable_flash_pch7},
1443        {0x8086, 0x2410, OK, "Intel", "ICH",            enable_flash_ich_4e},
1444        {0x8086, 0x2420, OK, "Intel", "ICH0",           enable_flash_ich_4e},
1445        {0x8086, 0x2440, OK, "Intel", "ICH2",           enable_flash_ich_4e},
1446        {0x8086, 0x244c, OK, "Intel", "ICH2-M",         enable_flash_ich_4e},
1447        {0x8086, 0x2450, NT, "Intel", "C-ICH",          enable_flash_ich_4e},
1448        {0x8086, 0x2480, OK, "Intel", "ICH3-S",         enable_flash_ich_4e},
1449        {0x8086, 0x248c, OK, "Intel", "ICH3-M",         enable_flash_ich_4e},
1450        {0x8086, 0x24c0, OK, "Intel", "ICH4/ICH4-L",    enable_flash_ich_4e},
1451        {0x8086, 0x24cc, OK, "Intel", "ICH4-M",         enable_flash_ich_4e},
1452        {0x8086, 0x24d0, OK, "Intel", "ICH5/ICH5R",     enable_flash_ich_4e},
1453        {0x8086, 0x25a1, OK, "Intel", "6300ESB",        enable_flash_ich_4e},
1454        {0x8086, 0x2640, OK, "Intel", "ICH6/ICH6R",     enable_flash_ich_dc},
1455        {0x8086, 0x2641, OK, "Intel", "ICH6-M",         enable_flash_ich_dc},
1456        {0x8086, 0x2642, NT, "Intel", "ICH6W/ICH6RW",   enable_flash_ich_dc},
1457        {0x8086, 0x2670, OK, "Intel", "631xESB/632xESB/3100", enable_flash_ich_dc},
1458        {0x8086, 0x27b0, OK, "Intel", "ICH7DH",         enable_flash_ich7},
1459        {0x8086, 0x27b8, OK, "Intel", "ICH7/ICH7R",     enable_flash_ich7},
1460        {0x8086, 0x27b9, OK, "Intel", "ICH7M",          enable_flash_ich7},
1461        {0x8086, 0x27bc, OK, "Intel", "NM10",           enable_flash_ich7},
1462        {0x8086, 0x27bd, OK, "Intel", "ICH7MDH",        enable_flash_ich7},
1463        {0x8086, 0x2810, OK, "Intel", "ICH8/ICH8R",     enable_flash_ich8},
1464        {0x8086, 0x2811, OK, "Intel", "ICH8M-E",        enable_flash_ich8},
1465        {0x8086, 0x2812, OK, "Intel", "ICH8DH",         enable_flash_ich8},
1466        {0x8086, 0x2814, OK, "Intel", "ICH8DO",         enable_flash_ich8},
1467        {0x8086, 0x2815, OK, "Intel", "ICH8M",          enable_flash_ich8},
1468        {0x8086, 0x2910, OK, "Intel", "ICH9 Engineering Sample", enable_flash_ich9},
1469        {0x8086, 0x2912, OK, "Intel", "ICH9DH",         enable_flash_ich9},
1470        {0x8086, 0x2914, OK, "Intel", "ICH9DO",         enable_flash_ich9},
1471        {0x8086, 0x2916, OK, "Intel", "ICH9R",          enable_flash_ich9},
1472        {0x8086, 0x2917, OK, "Intel", "ICH9M-E",        enable_flash_ich9},
1473        {0x8086, 0x2918, OK, "Intel", "ICH9",           enable_flash_ich9},
1474        {0x8086, 0x2919, OK, "Intel", "ICH9M",          enable_flash_ich9},
1475        {0x8086, 0x3a10, NT, "Intel", "ICH10R Engineering Sample", enable_flash_ich10},
1476        {0x8086, 0x3a14, OK, "Intel", "ICH10DO",        enable_flash_ich10},
1477        {0x8086, 0x3a16, OK, "Intel", "ICH10R",         enable_flash_ich10},
1478        {0x8086, 0x3a18, OK, "Intel", "ICH10",          enable_flash_ich10},
1479        {0x8086, 0x3a1a, OK, "Intel", "ICH10D",         enable_flash_ich10},
1480        {0x8086, 0x3a1e, NT, "Intel", "ICH10 Engineering Sample", enable_flash_ich10},
1481        {0x8086, 0x3b00, NT, "Intel", "3400 Desktop",   enable_flash_pch5},
1482        {0x8086, 0x3b01, NT, "Intel", "3400 Mobile",    enable_flash_pch5},
1483        {0x8086, 0x3b02, NT, "Intel", "P55",            enable_flash_pch5},
1484        {0x8086, 0x3b03, NT, "Intel", "PM55",           enable_flash_pch5},
1485        {0x8086, 0x3b06, OK, "Intel", "H55",            enable_flash_pch5},
1486        {0x8086, 0x3b07, OK, "Intel", "QM57",           enable_flash_pch5},
1487        {0x8086, 0x3b08, NT, "Intel", "H57",            enable_flash_pch5},
1488        {0x8086, 0x3b09, NT, "Intel", "HM55",           enable_flash_pch5},
1489        {0x8086, 0x3b0a, NT, "Intel", "Q57",            enable_flash_pch5},
1490        {0x8086, 0x3b0b, NT, "Intel", "HM57",           enable_flash_pch5},
1491        {0x8086, 0x3b0d, NT, "Intel", "3400 Mobile SFF", enable_flash_pch5},
1492        {0x8086, 0x3b0e, NT, "Intel", "B55",            enable_flash_pch5},
1493        {0x8086, 0x3b0f, OK, "Intel", "QS57",           enable_flash_pch5},
1494        {0x8086, 0x3b12, NT, "Intel", "3400",           enable_flash_pch5},
1495        {0x8086, 0x3b14, OK, "Intel", "3420",           enable_flash_pch5},
1496        {0x8086, 0x3b16, NT, "Intel", "3450",           enable_flash_pch5},
1497        {0x8086, 0x3b1e, NT, "Intel", "B55",            enable_flash_pch5},
1498        {0x8086, 0x5031, OK, "Intel", "EP80579",        enable_flash_ich7},
1499        {0x8086, 0x7000, OK, "Intel", "PIIX3",          enable_flash_piix4},
1500        {0x8086, 0x7110, OK, "Intel", "PIIX4/4E/4M",    enable_flash_piix4},
1501        {0x8086, 0x7198, OK, "Intel", "440MX",          enable_flash_piix4},
1502        {0x8086, 0x8119, OK, "Intel", "SCH Poulsbo",    enable_flash_poulsbo},
1503        {0x8086, 0x8186, OK, "Intel", "Atom E6xx(T)/Tunnel Creek", enable_flash_tunnelcreek},
1504        {0x8086, 0x8c40, NT, "Intel", "Lynx Point",     enable_flash_pch8},
1505        {0x8086, 0x8c41, NT, "Intel", "Lynx Point Mobile Engineering Sample", enable_flash_pch8},
1506        {0x8086, 0x8c42, NT, "Intel", "Lynx Point Desktop Engineering Sample", enable_flash_pch8},
1507        {0x8086, 0x8c43, NT, "Intel", "Lynx Point",     enable_flash_pch8},
1508        {0x8086, 0x8c44, NT, "Intel", "Z87",            enable_flash_pch8},
1509        {0x8086, 0x8c45, NT, "Intel", "Lynx Point",     enable_flash_pch8},
1510        {0x8086, 0x8c46, NT, "Intel", "Z85",            enable_flash_pch8},
1511        {0x8086, 0x8c47, NT, "Intel", "Lynx Point",     enable_flash_pch8},
1512        {0x8086, 0x8c48, NT, "Intel", "Lynx Point",     enable_flash_pch8},
1513        {0x8086, 0x8c49, NT, "Intel", "HM86",           enable_flash_pch8},
1514        {0x8086, 0x8c4a, NT, "Intel", "H87",            enable_flash_pch8},
1515        {0x8086, 0x8c4b, NT, "Intel", "HM87",           enable_flash_pch8},
1516        {0x8086, 0x8c4c, NT, "Intel", "Q85",            enable_flash_pch8},
1517        {0x8086, 0x8c4d, NT, "Intel", "Lynx Point",     enable_flash_pch8},
1518        {0x8086, 0x8c4e, NT, "Intel", "Q87",            enable_flash_pch8},
1519        {0x8086, 0x8c4f, NT, "Intel", "QM87",           enable_flash_pch8},
1520        {0x8086, 0x8c50, NT, "Intel", "B85",            enable_flash_pch8},
1521        {0x8086, 0x8c51, NT, "Intel", "Lynx Point",     enable_flash_pch8},
1522        {0x8086, 0x8c52, NT, "Intel", "C222",           enable_flash_pch8},
1523        {0x8086, 0x8c53, NT, "Intel", "Lynx Point",     enable_flash_pch8},
1524        {0x8086, 0x8c54, NT, "Intel", "C224",           enable_flash_pch8},
1525        {0x8086, 0x8c55, NT, "Intel", "Lynx Point",     enable_flash_pch8},
1526        {0x8086, 0x8c56, NT, "Intel", "C226",           enable_flash_pch8},
1527        {0x8086, 0x8c57, NT, "Intel", "Lynx Point",     enable_flash_pch8},
1528        {0x8086, 0x8c58, NT, "Intel", "Lynx Point",     enable_flash_pch8},
1529        {0x8086, 0x8c59, NT, "Intel", "Lynx Point",     enable_flash_pch8},
1530        {0x8086, 0x8c5a, NT, "Intel", "Lynx Point",     enable_flash_pch8},
1531        {0x8086, 0x8c5b, NT, "Intel", "Lynx Point",     enable_flash_pch8},
1532        {0x8086, 0x8c5c, NT, "Intel", "H81",            enable_flash_pch8},
1533        {0x8086, 0x8c5d, NT, "Intel", "Lynx Point",     enable_flash_pch8},
1534        {0x8086, 0x8c5e, NT, "Intel", "Lynx Point",     enable_flash_pch8},
1535        {0x8086, 0x8c5f, NT, "Intel", "Lynx Point",     enable_flash_pch8},
1536        {0x8086, 0x9c41, NT, "Intel", "Lynx Point LP Engineering Sample", enable_flash_pch8_lp},
1537        {0x8086, 0x9c43, NT, "Intel", "Lynx Point LP Premium", enable_flash_pch8_lp},
1538        {0x8086, 0x9c45, NT, "Intel", "Lynx Point LP Mainstream", enable_flash_pch8_lp},
1539        {0x8086, 0x9c47, NT, "Intel", "Lynx Point LP Value", enable_flash_pch8_lp},
1540        {0x8086, 0x8d40, NT, "Intel", "Wellsburg",      enable_flash_pch8_wb},
1541        {0x8086, 0x8d41, NT, "Intel", "Wellsburg",      enable_flash_pch8_wb},
1542        {0x8086, 0x8d42, NT, "Intel", "Wellsburg",      enable_flash_pch8_wb},
1543        {0x8086, 0x8d43, NT, "Intel", "Wellsburg",      enable_flash_pch8_wb},
1544        {0x8086, 0x8d44, NT, "Intel", "Wellsburg",      enable_flash_pch8_wb},
1545        {0x8086, 0x8d45, NT, "Intel", "Wellsburg",      enable_flash_pch8_wb},
1546        {0x8086, 0x8d46, NT, "Intel", "Wellsburg",      enable_flash_pch8_wb},
1547        {0x8086, 0x8d47, NT, "Intel", "Wellsburg",      enable_flash_pch8_wb},
1548        {0x8086, 0x8d48, NT, "Intel", "Wellsburg",      enable_flash_pch8_wb},
1549        {0x8086, 0x8d49, NT, "Intel", "Wellsburg",      enable_flash_pch8_wb},
1550        {0x8086, 0x8d4a, NT, "Intel", "Wellsburg",      enable_flash_pch8_wb},
1551        {0x8086, 0x8d4b, NT, "Intel", "Wellsburg",      enable_flash_pch8_wb},
1552        {0x8086, 0x8d4c, NT, "Intel", "Wellsburg",      enable_flash_pch8_wb},
1553        {0x8086, 0x8d4d, NT, "Intel", "Wellsburg",      enable_flash_pch8_wb},
1554        {0x8086, 0x8d4e, NT, "Intel", "Wellsburg",      enable_flash_pch8_wb},
1555        {0x8086, 0x8d4f, NT, "Intel", "Wellsburg",      enable_flash_pch8_wb},
1556        {0x8086, 0x8d50, NT, "Intel", "Wellsburg",      enable_flash_pch8_wb},
1557        {0x8086, 0x8d51, NT, "Intel", "Wellsburg",      enable_flash_pch8_wb},
1558        {0x8086, 0x8d52, NT, "Intel", "Wellsburg",      enable_flash_pch8_wb},
1559        {0x8086, 0x8d53, NT, "Intel", "Wellsburg",      enable_flash_pch8_wb},
1560        {0x8086, 0x8d54, NT, "Intel", "Wellsburg",      enable_flash_pch8_wb},
1561        {0x8086, 0x8d55, NT, "Intel", "Wellsburg",      enable_flash_pch8_wb},
1562        {0x8086, 0x8d56, NT, "Intel", "Wellsburg",      enable_flash_pch8_wb},
1563        {0x8086, 0x8d57, NT, "Intel", "Wellsburg",      enable_flash_pch8_wb},
1564        {0x8086, 0x8d58, NT, "Intel", "Wellsburg",      enable_flash_pch8_wb},
1565        {0x8086, 0x8d59, NT, "Intel", "Wellsburg",      enable_flash_pch8_wb},
1566        {0x8086, 0x8d5a, NT, "Intel", "Wellsburg",      enable_flash_pch8_wb},
1567        {0x8086, 0x8d5b, NT, "Intel", "Wellsburg",      enable_flash_pch8_wb},
1568        {0x8086, 0x8d5c, NT, "Intel", "Wellsburg",      enable_flash_pch8_wb},
1569        {0x8086, 0x8d5d, NT, "Intel", "Wellsburg",      enable_flash_pch8_wb},
1570        {0x8086, 0x8d5e, NT, "Intel", "Wellsburg",      enable_flash_pch8_wb},
1571        {0x8086, 0x8d5f, NT, "Intel", "Wellsburg",      enable_flash_pch8_wb},
1572#endif
1573        {0},
1574};
1575
1576int chipset_flash_enable(void)
1577{
1578        struct pci_dev *dev = NULL;
1579        int ret = -2;           /* Nothing! */
1580        int i;
1581
1582        /* Now let's try to find the chipset we have... */
1583        for (i = 0; chipset_enables[i].vendor_name != NULL; i++) {
1584                dev = pci_dev_find(chipset_enables[i].vendor_id,
1585                                   chipset_enables[i].device_id);
1586                if (!dev)
1587                        continue;
1588                if (ret != -2) {
1589                        msg_pwarn("Warning: unexpected second chipset match: "
1590                                    "\"%s %s\"\n"
1591                                  "ignoring, please report lspci and board URL "
1592                                    "to flashrom@flashrom.org\n"
1593                                  "with \'CHIPSET: your board name\' in the "
1594                                    "subject line.\n",
1595                                chipset_enables[i].vendor_name,
1596                                        chipset_enables[i].device_name);
1597                        continue;
1598                }
1599                msg_pinfo("Found chipset \"%s %s\"",
1600                          chipset_enables[i].vendor_name,
1601                          chipset_enables[i].device_name);
1602                msg_pdbg(" with PCI ID %04x:%04x",
1603                         chipset_enables[i].vendor_id,
1604                         chipset_enables[i].device_id);
1605                msg_pinfo(". ");
1606
1607                if (chipset_enables[i].status == NT) {
1608                        msg_pinfo("\nThis chipset is marked as untested. If "
1609                                  "you are using an up-to-date version\nof "
1610                                  "flashrom *and* were (not) able to "
1611                                  "successfully update your firmware with it,\n"
1612                                  "then please email a report to "
1613                                  "flashrom@flashrom.org including a verbose "
1614                                  "(-V) log.\nThank you!\n");
1615                }
1616                msg_pinfo("Enabling flash write... ");
1617                ret = chipset_enables[i].doit(dev,
1618                                              chipset_enables[i].device_name);
1619                if (ret == NOT_DONE_YET) {
1620                        ret = -2;
1621                        msg_pinfo("OK - searching further chips.\n");
1622                } else if (ret < 0)
1623                        msg_pinfo("FAILED!\n");
1624                else if (ret == 0)
1625                        msg_pinfo("OK.\n");
1626                else if (ret == ERROR_NONFATAL)
1627                        msg_pinfo("PROBLEMS, continuing anyway\n");
1628                if (ret == ERROR_FATAL) {
1629                        msg_perr("FATAL ERROR!\n");
1630                        return ret;
1631                }
1632        }
1633
1634        return ret;
1635}
Note: See TracBrowser for help on using the repository browser.