2 * flash rom utility: enable flash writes
4 * Copyright (C) 2000 Silicon Integrated System Corporation
5 * Copyright (C) 2005-2007 coresystems GmbH <stepan@coresystems.de>
6 * Copyright (C) 2006 Uwe Hermann <uwe@hermann-uwe.de>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
21 static int enable_flash_ali_m1533(struct pci_dev *dev, char *name)
25 /* ROM Write enable, 0xFFFC0000-0xFFFDFFFF and
26 0xFFFE0000-0xFFFFFFFF ROM select enable. */
27 tmp = pci_read_byte(dev, 0x47);
29 pci_write_byte(dev, 0x47, tmp);
34 static int enable_flash_sis630(struct pci_dev *dev, char *name)
38 /* Enable 0xFFF8000~0xFFFF0000 decoding on SiS 540/630 */
39 outl(0x80000840, 0x0cf8);
40 b = inb(0x0cfc) | 0x0b;
42 /* Flash write enable on SiS 540/630 */
43 outl(0x80000845, 0x0cf8);
44 b = inb(0x0cfd) | 0x40;
47 /* The same thing on SiS 950 SuperIO side */
53 if (inb(0x2f) != 0x87) {
58 if (inb(0x4f) != 0x87) {
59 printf("Can not access SiS 950\n");
71 printf("2f is %#x\n", inb(0x2f));
83 * - Name: 82371AB PCI-TO-ISA / IDE XCELERATOR (PIIX4)
84 * - URL: http://www.intel.com/design/intarch/datashts/290562.htm
85 * - PDF: http://www.intel.com/design/intarch/datashts/29056201.pdf
86 * - Order Number: 290562-001
88 static int enable_flash_piix4(struct pci_dev *dev, char *name)
91 uint16_t xbcs = 0x4e; /* X-Bus Chip Select register. */
93 old = pci_read_word(dev, xbcs);
95 /* Set bit 9: 1-Meg Extended BIOS Enable (PCI master accesses to
96 * FFF00000-FFF7FFFF are forwarded to ISA).
97 * Set bit 7: Extended BIOS Enable (PCI master accesses to
98 * FFF80000-FFFDFFFF are forwarded to ISA).
99 * Set bit 6: Lower BIOS Enable (PCI master, or ISA master accesses to
100 * the lower 64-Kbyte BIOS block (E0000-EFFFF) at the top
101 * of 1 Mbyte, or the aliases at the top of 4 Gbyte
102 * (FFFE0000-FFFEFFFF) result in the generation of BIOSCS#.
103 * Note: Accesses to FFFF0000-FFFFFFFF are always forwarded to ISA.
104 * Set bit 2: BIOSCS# Write Enable (1=enable, 0=disable).
111 pci_write_word(dev, xbcs, new);
113 if (pci_read_word(dev, xbcs) != new) {
114 printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", xbcs, new, name);
120 static int enable_flash_ich(struct pci_dev *dev, char *name, int bios_cntl)
122 /* register 4e.b gets or'ed with one */
125 /* if it fails, it fails. There are so many variations of broken mobos
126 * that it is hard to argue that we should quit at this point.
129 /* Note: the ICH0-ICH5 BIOS_CNTL register is actually 16 bit wide, but
130 * just treating it as 8 bit wide seems to work fine in practice.
133 /* see ie. page 375 of "Intel ICH7 External Design Specification"
134 * http://download.intel.com/design/chipsets/datashts/30701302.pdf
137 old = pci_read_byte(dev, bios_cntl);
144 pci_write_byte(dev, bios_cntl, new);
146 if (pci_read_byte(dev, bios_cntl) != new) {
147 printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", bios_cntl, new, name);
153 static int enable_flash_ich_4e(struct pci_dev *dev, char *name)
155 return enable_flash_ich(dev, name, 0x4e);
158 static int enable_flash_ich_dc(struct pci_dev *dev, char *name)
160 return enable_flash_ich(dev, name, 0xdc);
166 static int enable_flash_vt823x(struct pci_dev *dev, char *name)
170 /* ROM Write enable */
171 val = pci_read_byte(dev, 0x40);
173 pci_write_byte(dev, 0x40, val);
175 if (pci_read_byte(dev, 0x40) != val) {
176 printf("\nWARNING: Failed to enable ROM Write on \"%s\"\n",
184 static int enable_flash_cs5530(struct pci_dev *dev, char *name)
188 pci_write_byte(dev, 0x52, 0xee);
190 new = pci_read_byte(dev, 0x52);
193 printf("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x52, new, name);
197 new = pci_read_byte(dev, 0x5b) | 0x20;
198 pci_write_byte(dev, 0x5b, new);
203 static int enable_flash_sc1100(struct pci_dev *dev, char *name)
207 pci_write_byte(dev, 0x52, 0xee);
209 new = pci_read_byte(dev, 0x52);
212 printf("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x52, new, name);
218 static int enable_flash_sis5595(struct pci_dev *dev, char *name)
222 new = pci_read_byte(dev, 0x45);
229 pci_write_byte(dev, 0x45, new);
231 newer = pci_read_byte(dev, 0x45);
233 printf("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x45, new, name);
234 printf("Stuck at 0x%x\n", newer);
240 static int enable_flash_amd8111(struct pci_dev *dev, char *name)
242 /* register 4e.b gets or'ed with one */
245 /* if it fails, it fails. There are so many variations of broken mobos
246 * that it is hard to argue that we should quit at this point.
249 /* enable decoding at 0xffb00000 to 0xffffffff */
250 old = pci_read_byte(dev, 0x43);
253 pci_write_byte(dev, 0x43, new);
254 if (pci_read_byte(dev, 0x43) != new) {
255 printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x43, new, name);
259 old = pci_read_byte(dev, 0x40);
263 pci_write_byte(dev, 0x40, new);
265 if (pci_read_byte(dev, 0x40) != new) {
266 printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x40, new, name);
272 static int enable_flash_ck804(struct pci_dev *dev, char *name)
274 /* register 4e.b gets or'ed with one */
277 /* if it fails, it fails. There are so many variations of broken mobos
278 * that it is hard to argue that we should quit at this point.
281 /* dump_pci_device(dev); */
283 old = pci_read_byte(dev, 0x88);
286 pci_write_byte(dev, 0x88, new);
287 if (pci_read_byte(dev, 0x88) != new) {
288 printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x88, new, name);
292 old = pci_read_byte(dev, 0x6d);
296 pci_write_byte(dev, 0x6d, new);
298 if (pci_read_byte(dev, 0x6d) != new) {
299 printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x6d, new, name);
305 static int enable_flash_sb400(struct pci_dev *dev, char *name)
310 struct pci_dev *smbusdev;
312 /* then look for the smbus device */
313 pci_filter_init((struct pci_access *)0, &f);
317 for (smbusdev = pacc->devices; smbusdev; smbusdev = smbusdev->next) {
318 if (pci_filter_match(&f, smbusdev)) {
324 fprintf(stderr, "ERROR: SMBus device not found. aborting\n");
328 /* enable some smbus stuff */
329 tmp = pci_read_byte(smbusdev, 0x79);
331 pci_write_byte(smbusdev, 0x79, tmp);
333 /* change southbridge */
334 tmp = pci_read_byte(dev, 0x48);
336 pci_write_byte(dev, 0x48, tmp);
338 /* now become a bit silly. */
350 static int enable_flash_mcp55(struct pci_dev *dev, char *name)
352 /* register 4e.b gets or'ed with one */
353 unsigned char old, new, byte;
356 /* if it fails, it fails. There are so many variations of broken mobos
357 * that it is hard to argue that we should quit at this point.
360 /* dump_pci_device(dev); */
362 /* Set the 4MB enable bit bit */
363 byte = pci_read_byte(dev, 0x88);
364 byte |= 0xff; /* 256K */
365 pci_write_byte(dev, 0x88, byte);
366 byte = pci_read_byte(dev, 0x8c);
367 byte |= 0xff; /* 1M */
368 pci_write_byte(dev, 0x8c, byte);
369 word = pci_read_word(dev, 0x90);
370 word |= 0x7fff; /* 15M */
371 pci_write_word(dev, 0x90, word);
373 old = pci_read_byte(dev, 0x6d);
377 pci_write_byte(dev, 0x6d, new);
379 if (pci_read_byte(dev, 0x6d) != new) {
381 ("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
391 static int enable_flash_ht1000(struct pci_dev *dev, char *name)
395 /* Set the 4MB enable bit */
396 byte = pci_read_byte(dev, 0x41);
398 pci_write_byte(dev, 0x41, byte);
400 byte = pci_read_byte(dev, 0x43);
402 pci_write_byte(dev, 0x43, byte);
407 typedef struct penable {
408 unsigned short vendor, device;
410 int (*doit) (struct pci_dev * dev, char *name);
413 static FLASH_ENABLE enables[] = {
414 {0x1039, 0x0630, "SIS630", enable_flash_sis630},
415 {0x8086, 0x7110, "PIIX4/PIIX4E/PIIX4M", enable_flash_piix4},
416 {0x8086, 0x2410, "ICH", enable_flash_ich_4e},
417 {0x8086, 0x2420, "ICH0", enable_flash_ich_4e},
418 {0x8086, 0x2440, "ICH2", enable_flash_ich_4e},
419 {0x8086, 0x244c, "ICH2-M", enable_flash_ich_4e},
420 {0x8086, 0x2480, "ICH3-S", enable_flash_ich_4e},
421 {0x8086, 0x248c, "ICH3-M", enable_flash_ich_4e},
422 {0x8086, 0x24c0, "ICH4/ICH4-L", enable_flash_ich_4e},
423 {0x8086, 0x24cc, "ICH4-M", enable_flash_ich_4e},
424 {0x8086, 0x24d0, "ICH5/ICH5R", enable_flash_ich_4e},
425 {0x8086, 0x2640, "ICH6/ICH6R", enable_flash_ich_dc},
426 {0x8086, 0x2641, "ICH6-M", enable_flash_ich_dc},
427 {0x8086, 0x27b0, "ICH7DH", enable_flash_ich_dc},
428 {0x8086, 0x27b8, "ICH7/ICH7R", enable_flash_ich_dc},
429 {0x8086, 0x27b9, "ICH7M", enable_flash_ich_dc},
430 {0x8086, 0x27bd, "ICH7MDH", enable_flash_ich_dc},
431 {0x8086, 0x2810, "ICH8/ICH8R", enable_flash_ich_dc},
432 {0x8086, 0x2812, "ICH8DH", enable_flash_ich_dc},
433 {0x8086, 0x2814, "ICH8DO", enable_flash_ich_dc},
434 {0x1106, 0x8231, "VT8231", enable_flash_vt823x},
435 {0x1106, 0x3177, "VT8235", enable_flash_vt823x},
436 {0x1106, 0x3227, "VT8237", enable_flash_vt823x},
437 {0x1106, 0x8324, "CX700", enable_flash_vt823x},
438 {0x1106, 0x0686, "VT82C686", enable_flash_amd8111},
439 {0x1078, 0x0100, "CS5530", enable_flash_cs5530},
440 {0x100b, 0x0510, "SC1100", enable_flash_sc1100},
441 {0x1039, 0x0008, "SIS5595", enable_flash_sis5595},
442 {0x1022, 0x7468, "AMD8111", enable_flash_amd8111},
443 {0x10B9, 0x1533, "ALi M1533", enable_flash_ali_m1533},
444 /* this fallthrough looks broken. */
445 {0x10de, 0x0050, "NVIDIA CK804", enable_flash_ck804}, /* LPC */
446 {0x10de, 0x0051, "NVIDIA CK804", enable_flash_ck804}, /* Pro */
447 {0x10de, 0x00d3, "NVIDIA CK804", enable_flash_ck804}, /* Slave, should not be here, to fix known bug for A01. */
449 {0x10de, 0x0260, "NVidia MCP51", enable_flash_ck804},
450 {0x10de, 0x0261, "NVidia MCP51", enable_flash_ck804},
451 {0x10de, 0x0262, "NVidia MCP51", enable_flash_ck804},
452 {0x10de, 0x0263, "NVidia MCP51", enable_flash_ck804},
454 {0x10de, 0x0360, "NVIDIA MCP55", enable_flash_mcp55}, /* Gigabyte m57sli-s4 */
455 {0x10de, 0x0361, "NVIDIA MCP55", enable_flash_mcp55}, /* LPC */
456 {0x10de, 0x0362, "NVIDIA MCP55", enable_flash_mcp55}, /* LPC */
457 {0x10de, 0x0363, "NVIDIA MCP55", enable_flash_mcp55}, /* LPC */
458 {0x10de, 0x0364, "NVIDIA MCP55", enable_flash_mcp55}, /* LPC */
459 {0x10de, 0x0365, "NVIDIA MCP55", enable_flash_mcp55}, /* LPC */
460 {0x10de, 0x0366, "NVIDIA MCP55", enable_flash_mcp55}, /* LPC */
461 {0x10de, 0x0367, "NVIDIA MCP55", enable_flash_mcp55}, /* Pro */
463 {0x1002, 0x4377, "ATI SB400", enable_flash_sb400}, /* ATI Technologies Inc IXP SB400 PCI-ISA Bridge (rev 80) */
465 {0x1166, 0x0205, "BCM HT1000", enable_flash_ht1000},
471 int chipset_flash_enable(void)
473 struct pci_dev *dev = 0;
474 int ret = -2; /* nothing! */
477 /* now let's try to find the chipset we have ... */
478 for (i = 0; i < sizeof(enables) / sizeof(enables[0]); i++) {
479 dev = pci_dev_find(enables[i].vendor, enables[i].device);
485 printf("Found chipset \"%s\": Enabling flash write... ",
488 ret = enables[i].doit(dev, enables[i].name);