Li-Ta Lo | 1a4f070 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * flash rom utility: enable flash writes |
| 3 | * |
| 4 | * Copyright (C) 2000-2004 ??? |
| 5 | * Copyright (C) 2005 coresystems GmbH <stepan@openbios.org> |
Stefan Reinauer | e918a3a | 2006-09-06 15:48:48 +0000 | [diff] [blame] | 6 | * Copyright (C) 2006 Uwe Hermann <uwe@hermann-uwe.de> |
Li-Ta Lo | 1a4f070 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License |
| 10 | * version 2 |
| 11 | * |
| 12 | */ |
| 13 | |
Li-Ta Lo | 115bd05 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 14 | #include <stdio.h> |
| 15 | #include <pci/pci.h> |
| 16 | #include <stdlib.h> |
Li-Ta Lo | 1a4f070 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 17 | #include <stdint.h> |
| 18 | #include <string.h> |
Adam Kaufman | 4f9cf13 | 2007-02-06 19:47:50 +0000 | [diff] [blame] | 19 | #if defined (__sun) && (defined(__i386) || defined(__amd64)) |
| 20 | #include <strings.h> |
| 21 | #include <sys/sysi86.h> |
| 22 | #include <sys/psw.h> |
| 23 | #include <asm/sunddi.h> |
| 24 | #endif |
| 25 | #include "flash.h" |
Li-Ta Lo | 1a4f070 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 26 | #include "lbtable.h" |
| 27 | #include "debug.h" |
Li-Ta Lo | 115bd05 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 28 | |
Stefan Reinauer | 1f64c13 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 29 | // We keep this for the others. |
| 30 | static struct pci_access *pacc; |
| 31 | |
Li-Ta Lo | fbf43ac | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 32 | static int enable_flash_sis630(struct pci_dev *dev, char *name) |
Li-Ta Lo | 115bd05 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 33 | { |
| 34 | char b; |
| 35 | |
Li-Ta Lo | 115bd05 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 36 | /* Enable 0xFFF8000~0xFFFF0000 decoding on SiS 540/630 */ |
| 37 | outl(0x80000840, 0x0cf8); |
| 38 | b = inb(0x0cfc) | 0x0b; |
| 39 | outb(b, 0xcfc); |
| 40 | /* Flash write enable on SiS 540/630 */ |
| 41 | outl(0x80000845, 0x0cf8); |
| 42 | b = inb(0x0cfd) | 0x40; |
| 43 | outb(b, 0xcfd); |
| 44 | |
| 45 | /* The same thing on SiS 950 SuperIO side */ |
| 46 | outb(0x87, 0x2e); |
| 47 | outb(0x01, 0x2e); |
| 48 | outb(0x55, 0x2e); |
| 49 | outb(0x55, 0x2e); |
| 50 | |
| 51 | if (inb(0x2f) != 0x87) { |
| 52 | outb(0x87, 0x4e); |
| 53 | outb(0x01, 0x4e); |
| 54 | outb(0x55, 0x4e); |
| 55 | outb(0xaa, 0x4e); |
| 56 | if (inb(0x4f) != 0x87) { |
| 57 | printf("Can not access SiS 950\n"); |
| 58 | return -1; |
| 59 | } |
| 60 | outb(0x24, 0x4e); |
| 61 | b = inb(0x4f) | 0xfc; |
| 62 | outb(0x24, 0x4e); |
| 63 | outb(b, 0x4f); |
| 64 | outb(0x02, 0x4e); |
Li-Ta Lo | fbf43ac | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 65 | outb(0x02, 0x4f); |
Li-Ta Lo | 115bd05 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | outb(0x24, 0x2e); |
| 69 | printf("2f is %#x\n", inb(0x2f)); |
| 70 | b = inb(0x2f) | 0xfc; |
| 71 | outb(0x24, 0x2e); |
| 72 | outb(b, 0x2f); |
| 73 | |
| 74 | outb(0x02, 0x2e); |
| 75 | outb(0x02, 0x2f); |
| 76 | |
| 77 | return 0; |
| 78 | } |
| 79 | |
Uwe Hermann | c65113c | 2006-11-07 11:16:21 +0000 | [diff] [blame] | 80 | /* Datasheet: |
| 81 | * - Name: 82371AB PCI-TO-ISA / IDE XCELERATOR (PIIX4) |
| 82 | * - URL: http://www.intel.com/design/intarch/datashts/290562.htm |
| 83 | * - PDF: http://www.intel.com/design/intarch/datashts/29056201.pdf |
| 84 | * - Order Number: 290562-001 |
| 85 | */ |
Uwe Hermann | bdb50fe | 2006-11-05 18:26:08 +0000 | [diff] [blame] | 86 | static int enable_flash_piix4(struct pci_dev *dev, char *name) |
| 87 | { |
| 88 | uint16_t old, new; |
| 89 | uint16_t xbcs = 0x4e; /* X-Bus Chip Select register. */ |
| 90 | |
| 91 | old = pci_read_word(dev, xbcs); |
| 92 | |
| 93 | /* Set bit 9: 1-Meg Extended BIOS Enable (PCI master accesses to |
| 94 | FFF00000-FFF7FFFF are forwarded to ISA). |
| 95 | Set bit 7: Extended BIOS Enable (PCI master accesses to |
| 96 | FFF80000-FFFDFFFF are forwarded to ISA). |
| 97 | Set bit 6: Lower BIOS Enable (PCI master, or ISA master accesses to |
Uwe Hermann | c65113c | 2006-11-07 11:16:21 +0000 | [diff] [blame] | 98 | the lower 64-Kbyte BIOS block (E0000-EFFFF) at the top |
Uwe Hermann | bdb50fe | 2006-11-05 18:26:08 +0000 | [diff] [blame] | 99 | of 1 Mbyte, or the aliases at the top of 4 Gbyte |
Uwe Hermann | c65113c | 2006-11-07 11:16:21 +0000 | [diff] [blame] | 100 | (FFFE0000-FFFEFFFF) result in the generation of BIOSCS#. |
| 101 | Note: Accesses to FFFF0000-FFFFFFFF are always forwarded to ISA. |
| 102 | Set bit 2: BIOSCS# Write Enable (1=enable, 0=disable). */ |
Uwe Hermann | bdb50fe | 2006-11-05 18:26:08 +0000 | [diff] [blame] | 103 | new = old | 0x2c4; |
| 104 | |
| 105 | if (new == old) |
| 106 | return 0; |
| 107 | |
| 108 | pci_write_word(dev, xbcs, new); |
| 109 | |
| 110 | if (pci_read_word(dev, xbcs) != new) { |
| 111 | printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", xbcs, new, name); |
| 112 | return -1; |
| 113 | } |
| 114 | return 0; |
| 115 | } |
| 116 | |
Stefan Reinauer | 1f64c13 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 117 | static int enable_flash_ich(struct pci_dev *dev, char *name, int bios_cntl) |
Ronald G. Minnich | a26c8ef | 2004-09-28 20:09:06 +0000 | [diff] [blame] | 118 | { |
| 119 | /* register 4e.b gets or'ed with one */ |
Li-Ta Lo | 1a4f070 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 120 | uint8_t old, new; |
Stefan Reinauer | e918a3a | 2006-09-06 15:48:48 +0000 | [diff] [blame] | 121 | |
Ronald G. Minnich | a26c8ef | 2004-09-28 20:09:06 +0000 | [diff] [blame] | 122 | /* if it fails, it fails. There are so many variations of broken mobos |
| 123 | * that it is hard to argue that we should quit at this point. |
| 124 | */ |
| 125 | |
Stefan Reinauer | e918a3a | 2006-09-06 15:48:48 +0000 | [diff] [blame] | 126 | /* Note: the ICH0-ICH5 BIOS_CNTL register is actually 16 bit wide, but |
| 127 | * just treating it as 8 bit wide seems to work fine in practice. |
| 128 | */ |
| 129 | |
| 130 | /* see ie. page 375 of "Intel ICH7 External Design Specification" |
| 131 | * http://download.intel.com/design/chipsets/datashts/30701302.pdf |
| 132 | */ |
| 133 | |
Stefan Reinauer | 1f64c13 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 134 | old = pci_read_byte(dev, bios_cntl); |
Ronald G. Minnich | a26c8ef | 2004-09-28 20:09:06 +0000 | [diff] [blame] | 135 | |
| 136 | new = old | 1; |
| 137 | |
| 138 | if (new == old) |
| 139 | return 0; |
| 140 | |
Stefan Reinauer | 1f64c13 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 141 | pci_write_byte(dev, bios_cntl, new); |
Ronald G. Minnich | a26c8ef | 2004-09-28 20:09:06 +0000 | [diff] [blame] | 142 | |
Stefan Reinauer | 1f64c13 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 143 | if (pci_read_byte(dev, bios_cntl) != new) { |
Ronald G. Minnich | a26c8ef | 2004-09-28 20:09:06 +0000 | [diff] [blame] | 144 | printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", |
Stefan Reinauer | 1f64c13 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 145 | bios_cntl, new, name); |
Ronald G. Minnich | a26c8ef | 2004-09-28 20:09:06 +0000 | [diff] [blame] | 146 | return -1; |
| 147 | } |
| 148 | return 0; |
| 149 | } |
| 150 | |
Stefan Reinauer | e918a3a | 2006-09-06 15:48:48 +0000 | [diff] [blame] | 151 | static int enable_flash_ich_4e(struct pci_dev *dev, char *name) |
Stefan Reinauer | 1f64c13 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 152 | { |
Stefan Reinauer | e918a3a | 2006-09-06 15:48:48 +0000 | [diff] [blame] | 153 | return enable_flash_ich(dev, name, 0x4e); |
Stefan Reinauer | 1f64c13 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 154 | } |
| 155 | |
Stefan Reinauer | e918a3a | 2006-09-06 15:48:48 +0000 | [diff] [blame] | 156 | static int enable_flash_ich_dc(struct pci_dev *dev, char *name) |
Stefan Reinauer | 1f64c13 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 157 | { |
Stefan Reinauer | e918a3a | 2006-09-06 15:48:48 +0000 | [diff] [blame] | 158 | return enable_flash_ich(dev, name, 0xdc); |
Stefan Reinauer | 1f64c13 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 159 | } |
| 160 | |
Luc Verhaegen | 47ce57a | 2007-03-02 22:16:38 +0000 | [diff] [blame] | 161 | static int enable_flash_vt823x(struct pci_dev *dev, char *name) |
Li-Ta Lo | 115bd05 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 162 | { |
Li-Ta Lo | 1a4f070 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 163 | uint8_t val; |
Luc Verhaegen | 47ce57a | 2007-03-02 22:16:38 +0000 | [diff] [blame] | 164 | int ret = 0; |
Li-Ta Lo | fbf43ac | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 165 | |
Luc Verhaegen | 47ce57a | 2007-03-02 22:16:38 +0000 | [diff] [blame] | 166 | /* ROM Write enable */ |
Li-Ta Lo | 115bd05 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 167 | val = pci_read_byte(dev, 0x40); |
| 168 | val |= 0x10; |
| 169 | pci_write_byte(dev, 0x40, val); |
| 170 | |
| 171 | if (pci_read_byte(dev, 0x40) != val) { |
Luc Verhaegen | 47ce57a | 2007-03-02 22:16:38 +0000 | [diff] [blame] | 172 | printf("Warning: Failed to enable ROM Write on %s\n", name); |
| 173 | ret = -1; |
Li-Ta Lo | 115bd05 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 174 | } |
Luc Verhaegen | 47ce57a | 2007-03-02 22:16:38 +0000 | [diff] [blame] | 175 | |
| 176 | if (dev->device_id == 0x3177) { /* VT8235 */ |
| 177 | if (!iopl(3)) { /* enable full IO access */ |
| 178 | unsigned int base; |
| 179 | |
| 180 | /* GPIO12-15 -> output */ |
| 181 | val = pci_read_byte(dev, 0xE4); |
| 182 | val |= 0x38; |
| 183 | pci_write_byte(dev, 0xE4, val); |
| 184 | |
| 185 | /* Get Power Management IO address. */ |
| 186 | base = pci_read_word(dev, 0x88) & 0xFF80; |
| 187 | |
| 188 | /* enable GPIO15 which is connected to write protect. */ |
| 189 | val = inb(base + 0x4d); |
| 190 | val |= 0xFF; |
| 191 | outb(val, base + 0x4d); |
| 192 | |
| 193 | val = inb(base + 0x4E); |
| 194 | val |= 0x0F; |
| 195 | outb(val, base + 0x4E); |
| 196 | } else { |
| 197 | printf("Warning; Failed to disable Write Protect" |
| 198 | " on %s (iopl failed)\n", name); |
| 199 | return -1; |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | return ret; |
Li-Ta Lo | 115bd05 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | static int enable_flash_cs5530(struct pci_dev *dev, char *name) |
| 207 | { |
Li-Ta Lo | 1a4f070 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 208 | uint8_t new; |
Li-Ta Lo | fbf43ac | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 209 | |
Li-Ta Lo | 115bd05 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 210 | pci_write_byte(dev, 0x52, 0xee); |
| 211 | |
| 212 | new = pci_read_byte(dev, 0x52); |
| 213 | |
| 214 | if (new != 0xee) { |
Li-Ta Lo | 39daaac | 2004-03-27 00:18:15 +0000 | [diff] [blame] | 215 | printf("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n", |
| 216 | 0x52, new, name); |
Li-Ta Lo | 115bd05 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 217 | return -1; |
| 218 | } |
Li-Ta Lo | 1a4f070 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 219 | |
| 220 | new = pci_read_byte(dev, 0x5b) | 0x20; |
| 221 | pci_write_byte(dev, 0x5b, new); |
| 222 | |
Li-Ta Lo | 115bd05 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 223 | return 0; |
| 224 | } |
| 225 | |
Li-Ta Lo | 1a4f070 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 226 | |
Li-Ta Lo | 115bd05 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 227 | static int enable_flash_sc1100(struct pci_dev *dev, char *name) |
| 228 | { |
Li-Ta Lo | 1a4f070 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 229 | uint8_t new; |
Li-Ta Lo | fbf43ac | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 230 | |
Li-Ta Lo | 115bd05 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 231 | pci_write_byte(dev, 0x52, 0xee); |
| 232 | |
| 233 | new = pci_read_byte(dev, 0x52); |
| 234 | |
| 235 | if (new != 0xee) { |
Li-Ta Lo | 39daaac | 2004-03-27 00:18:15 +0000 | [diff] [blame] | 236 | printf("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n", |
| 237 | 0x52, new, name); |
Li-Ta Lo | 115bd05 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 238 | return -1; |
| 239 | } |
| 240 | return 0; |
| 241 | } |
| 242 | |
| 243 | static int enable_flash_sis5595(struct pci_dev *dev, char *name) |
| 244 | { |
Li-Ta Lo | 1a4f070 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 245 | uint8_t new, newer; |
Li-Ta Lo | fbf43ac | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 246 | |
Li-Ta Lo | 115bd05 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 247 | new = pci_read_byte(dev, 0x45); |
| 248 | |
| 249 | /* clear bit 5 */ |
Li-Ta Lo | fbf43ac | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 250 | new &= (~0x20); |
Li-Ta Lo | 115bd05 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 251 | /* set bit 2 */ |
| 252 | new |= 0x4; |
| 253 | |
| 254 | pci_write_byte(dev, 0x45, new); |
| 255 | |
| 256 | newer = pci_read_byte(dev, 0x45); |
| 257 | if (newer != new) { |
Li-Ta Lo | 39daaac | 2004-03-27 00:18:15 +0000 | [diff] [blame] | 258 | printf("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n", |
| 259 | 0x45, new, name); |
Li-Ta Lo | 115bd05 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 260 | printf("Stuck at 0x%x\n", newer); |
| 261 | return -1; |
| 262 | } |
| 263 | return 0; |
| 264 | } |
| 265 | |
Li-Ta Lo | fbf43ac | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 266 | static int enable_flash_amd8111(struct pci_dev *dev, char *name) |
| 267 | { |
Li-Ta Lo | 115bd05 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 268 | /* register 4e.b gets or'ed with one */ |
Li-Ta Lo | 1a4f070 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 269 | uint8_t old, new; |
Li-Ta Lo | 115bd05 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 270 | /* if it fails, it fails. There are so many variations of broken mobos |
| 271 | * that it is hard to argue that we should quit at this point. |
| 272 | */ |
| 273 | |
Li-Ta Lo | c48822a | 2004-12-07 17:19:04 +0000 | [diff] [blame] | 274 | /* enable decoding at 0xffb00000 to 0xffffffff */ |
Li-Ta Lo | 115bd05 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 275 | old = pci_read_byte(dev, 0x43); |
Li-Ta Lo | c48822a | 2004-12-07 17:19:04 +0000 | [diff] [blame] | 276 | new = old | 0xC0; |
Li-Ta Lo | 115bd05 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 277 | if (new != old) { |
| 278 | pci_write_byte(dev, 0x43, new); |
| 279 | if (pci_read_byte(dev, 0x43) != new) { |
Li-Ta Lo | 39daaac | 2004-03-27 00:18:15 +0000 | [diff] [blame] | 280 | printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", |
| 281 | 0x43, new, name); |
Li-Ta Lo | 115bd05 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 282 | } |
| 283 | } |
| 284 | |
Li-Ta Lo | fbf43ac | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 285 | old = pci_read_byte(dev, 0x40); |
Li-Ta Lo | 115bd05 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 286 | new = old | 0x01; |
| 287 | if (new == old) |
| 288 | return 0; |
| 289 | pci_write_byte(dev, 0x40, new); |
| 290 | |
| 291 | if (pci_read_byte(dev, 0x40) != new) { |
Li-Ta Lo | 39daaac | 2004-03-27 00:18:15 +0000 | [diff] [blame] | 292 | printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", |
| 293 | 0x40, new, name); |
Li-Ta Lo | 115bd05 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 294 | return -1; |
| 295 | } |
| 296 | return 0; |
| 297 | } |
| 298 | |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 299 | //By yhlu |
| 300 | static int enable_flash_ck804(struct pci_dev *dev, char *name) |
| 301 | { |
| 302 | /* register 4e.b gets or'ed with one */ |
Li-Ta Lo | 1a4f070 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 303 | uint8_t old, new; |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 304 | /* if it fails, it fails. There are so many variations of broken mobos |
| 305 | * that it is hard to argue that we should quit at this point. |
| 306 | */ |
| 307 | |
| 308 | //dump_pci_device(dev); |
| 309 | |
| 310 | old = pci_read_byte(dev, 0x88); |
| 311 | new = old | 0xc0; |
| 312 | if (new != old) { |
| 313 | pci_write_byte(dev, 0x88, new); |
| 314 | if (pci_read_byte(dev, 0x88) != new) { |
| 315 | printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", |
| 316 | 0x88, new, name); |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | old = pci_read_byte(dev, 0x6d); |
| 321 | new = old | 0x01; |
| 322 | if (new == old) |
| 323 | return 0; |
| 324 | pci_write_byte(dev, 0x6d, new); |
| 325 | |
| 326 | if (pci_read_byte(dev, 0x6d) != new) { |
| 327 | printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", |
| 328 | 0x6d, new, name); |
| 329 | return -1; |
| 330 | } |
| 331 | return 0; |
| 332 | } |
| 333 | |
Stefan Reinauer | 1f64c13 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 334 | static int enable_flash_sb400(struct pci_dev *dev, char *name) |
| 335 | { |
| 336 | uint8_t tmp; |
| 337 | |
| 338 | struct pci_filter f; |
| 339 | struct pci_dev *smbusdev; |
| 340 | |
Stefan Reinauer | 1f64c13 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 341 | /* then look for the smbus device */ |
| 342 | pci_filter_init((struct pci_access *) 0, &f); |
| 343 | f.vendor = 0x1002; |
| 344 | f.device = 0x4372; |
| 345 | |
| 346 | for (smbusdev = pacc->devices; smbusdev; smbusdev = smbusdev->next) { |
| 347 | if (pci_filter_match(&f, smbusdev)) { |
| 348 | break; |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | if(!smbusdev) { |
| 353 | perror("smbus device not found. aborting\n"); |
| 354 | exit(1); |
| 355 | } |
| 356 | |
| 357 | // enable some smbus stuff |
| 358 | tmp=pci_read_byte(smbusdev, 0x79); |
| 359 | tmp|=0x01; |
| 360 | pci_write_byte(smbusdev, 0x79, tmp); |
| 361 | |
| 362 | // change southbridge |
| 363 | tmp=pci_read_byte(dev, 0x48); |
| 364 | tmp|=0x21; |
| 365 | pci_write_byte(dev, 0x48, tmp); |
| 366 | |
| 367 | // now become a bit silly. |
| 368 | tmp=inb(0xc6f); |
| 369 | outb(tmp,0xeb); |
| 370 | outb(tmp, 0xeb); |
| 371 | tmp|=0x40; |
| 372 | outb(tmp, 0xc6f); |
| 373 | outb(tmp, 0xeb); |
| 374 | outb(tmp, 0xeb); |
| 375 | |
| 376 | return 0; |
| 377 | } |
| 378 | |
Yinghai Lu | 298f898 | 2007-01-22 20:21:17 +0000 | [diff] [blame] | 379 | //By yhlu |
| 380 | static int enable_flash_mcp55(struct pci_dev *dev, char *name) |
| 381 | { |
| 382 | /* register 4e.b gets or'ed with one */ |
| 383 | unsigned char old, new, byte; |
| 384 | unsigned short word; |
| 385 | |
| 386 | /* if it fails, it fails. There are so many variations of broken mobos |
| 387 | * that it is hard to argue that we should quit at this point. |
| 388 | */ |
| 389 | |
| 390 | //dump_pci_device(dev); |
| 391 | |
| 392 | /* Set the 4MB enable bit bit */ |
| 393 | byte = pci_read_byte(dev, 0x88); |
| 394 | byte |= 0xff; //256K |
| 395 | pci_write_byte(dev, 0x88, byte); |
| 396 | byte = pci_read_byte(dev, 0x8c); |
| 397 | byte |= 0xff; //1M |
| 398 | pci_write_byte(dev, 0x8c, byte); |
| 399 | word = pci_read_word(dev, 0x90); |
| 400 | word |= 0x7fff; //15M |
| 401 | pci_write_word(dev, 0x90, word); |
| 402 | |
| 403 | old = pci_read_byte(dev, 0x6d); |
| 404 | new = old | 0x01; |
| 405 | if (new == old) |
| 406 | return 0; |
| 407 | pci_write_byte(dev, 0x6d, new); |
| 408 | |
| 409 | if (pci_read_byte(dev, 0x6d) != new) { |
| 410 | printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", |
| 411 | 0x6d, new, name); |
| 412 | return -1; |
| 413 | } |
| 414 | |
| 415 | return 0; |
| 416 | |
| 417 | } |
| 418 | |
Li-Ta Lo | 115bd05 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 419 | typedef struct penable { |
Li-Ta Lo | fbf43ac | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 420 | unsigned short vendor, device; |
Li-Ta Lo | 115bd05 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 421 | char *name; |
Li-Ta Lo | fbf43ac | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 422 | int (*doit) (struct pci_dev * dev, char *name); |
Li-Ta Lo | 115bd05 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 423 | } FLASH_ENABLE; |
| 424 | |
| 425 | static FLASH_ENABLE enables[] = { |
Stefan Reinauer | e918a3a | 2006-09-06 15:48:48 +0000 | [diff] [blame] | 426 | {0x1039, 0x0630, "SIS630", enable_flash_sis630}, |
Uwe Hermann | bdb50fe | 2006-11-05 18:26:08 +0000 | [diff] [blame] | 427 | {0x8086, 0x7110, "PIIX4/PIIX4E/PIIX4M", enable_flash_piix4}, |
Stefan Reinauer | e918a3a | 2006-09-06 15:48:48 +0000 | [diff] [blame] | 428 | {0x8086, 0x2410, "ICH", enable_flash_ich_4e}, |
| 429 | {0x8086, 0x2420, "ICH0", enable_flash_ich_4e}, |
| 430 | {0x8086, 0x2440, "ICH2", enable_flash_ich_4e}, |
| 431 | {0x8086, 0x244c, "ICH2-M", enable_flash_ich_4e}, |
| 432 | {0x8086, 0x2480, "ICH3-S", enable_flash_ich_4e}, |
| 433 | {0x8086, 0x248c, "ICH3-M", enable_flash_ich_4e}, |
| 434 | {0x8086, 0x24c0, "ICH4/ICH4-L", enable_flash_ich_4e}, |
| 435 | {0x8086, 0x24cc, "ICH4-M", enable_flash_ich_4e}, |
| 436 | {0x8086, 0x24d0, "ICH5/ICH5R", enable_flash_ich_4e}, |
| 437 | {0x8086, 0x2640, "ICH6/ICH6R", enable_flash_ich_dc}, |
| 438 | {0x8086, 0x2641, "ICH6-M", enable_flash_ich_dc}, |
Uwe Hermann | 0d9d0ba | 2007-03-31 19:48:38 +0000 | [diff] [blame^] | 439 | {0x8086, 0x27b0, "ICH7DH", enable_flash_ich_dc}, |
Stefan Reinauer | e918a3a | 2006-09-06 15:48:48 +0000 | [diff] [blame] | 440 | {0x8086, 0x27b8, "ICH7/ICH7R", enable_flash_ich_dc}, |
| 441 | {0x8086, 0x27b9, "ICH7M", enable_flash_ich_dc}, |
| 442 | {0x8086, 0x27bd, "ICH7MDH", enable_flash_ich_dc}, |
| 443 | {0x8086, 0x2810, "ICH8/ICH8R", enable_flash_ich_dc}, |
| 444 | {0x8086, 0x2812, "ICH8DH", enable_flash_ich_dc}, |
| 445 | {0x8086, 0x2814, "ICH8DO", enable_flash_ich_dc}, |
Luc Verhaegen | 47ce57a | 2007-03-02 22:16:38 +0000 | [diff] [blame] | 446 | {0x1106, 0x8231, "VT8231", enable_flash_vt823x}, |
| 447 | {0x1106, 0x3177, "VT8235", enable_flash_vt823x}, |
| 448 | {0x1106, 0x3227, "VT8237", enable_flash_vt823x}, |
Stefan Reinauer | 10fd79a | 2006-11-07 10:22:20 +0000 | [diff] [blame] | 449 | {0x1106, 0x0686, "VT82C686", enable_flash_amd8111}, |
Li-Ta Lo | fbf43ac | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 450 | {0x1078, 0x0100, "CS5530", enable_flash_cs5530}, |
| 451 | {0x100b, 0x0510, "SC1100", enable_flash_sc1100}, |
Li-Ta Lo | 115bd05 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 452 | {0x1039, 0x0008, "SIS5595", enable_flash_sis5595}, |
| 453 | {0x1022, 0x7468, "AMD8111", enable_flash_amd8111}, |
Stefan Reinauer | 1f64c13 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 454 | // this fallthrough looks broken. |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 455 | {0x10de, 0x0050, "NVIDIA CK804", enable_flash_ck804}, // LPC |
| 456 | {0x10de, 0x0051, "NVIDIA CK804", enable_flash_ck804}, // Pro |
| 457 | {0x10de, 0x00d3, "NVIDIA CK804", enable_flash_ck804}, // Slave, should not be here, to fix known bug for A01. |
Stefan Reinauer | 5ed51d1 | 2006-10-14 21:04:49 +0000 | [diff] [blame] | 458 | |
| 459 | {0x10de, 0x0260, "NVidia MCP51", enable_flash_ck804}, |
| 460 | {0x10de, 0x0261, "NVidia MCP51", enable_flash_ck804}, |
| 461 | {0x10de, 0x0262, "NVidia MCP51", enable_flash_ck804}, |
| 462 | {0x10de, 0x0263, "NVidia MCP51", enable_flash_ck804}, |
| 463 | |
Ward Vandewege | 811f5c1 | 2007-02-28 21:50:15 +0000 | [diff] [blame] | 464 | {0x10de, 0x0360, "NVIDIA MCP55", enable_flash_mcp55}, // Gigabyte m57sli-s4 |
Ed Swierk | 681d788 | 2007-03-06 23:49:49 +0000 | [diff] [blame] | 465 | {0x10de, 0x0361, "NVIDIA MCP55", enable_flash_mcp55}, // LPC |
| 466 | {0x10de, 0x0362, "NVIDIA MCP55", enable_flash_mcp55}, // LPC |
| 467 | {0x10de, 0x0363, "NVIDIA MCP55", enable_flash_mcp55}, // LPC |
Yinghai Lu | 298f898 | 2007-01-22 20:21:17 +0000 | [diff] [blame] | 468 | {0x10de, 0x0364, "NVIDIA MCP55", enable_flash_mcp55}, // LPC |
Ed Swierk | 681d788 | 2007-03-06 23:49:49 +0000 | [diff] [blame] | 469 | {0x10de, 0x0365, "NVIDIA MCP55", enable_flash_mcp55}, // LPC |
| 470 | {0x10de, 0x0366, "NVIDIA MCP55", enable_flash_mcp55}, // LPC |
Yinghai Lu | 298f898 | 2007-01-22 20:21:17 +0000 | [diff] [blame] | 471 | {0x10de, 0x0367, "NVIDIA MCP55", enable_flash_mcp55}, // Pro |
| 472 | |
Stefan Reinauer | 1f64c13 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 473 | {0x1002, 0x4377, "ATI SB400", enable_flash_sb400}, // ATI Technologies Inc IXP SB400 PCI-ISA Bridge (rev 80) |
Li-Ta Lo | 115bd05 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 474 | }; |
Li-Ta Lo | fbf43ac | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 475 | |
Li-Ta Lo | 1a4f070 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 476 | static int mbenable_island_aruma(void) |
| 477 | { |
Stefan Reinauer | 1f64c13 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 478 | #define EFIR 0x2e /* Extended function index register, either 0x2e or 0x4e */ |
| 479 | #define EFDR EFIR + 1 /* Extended function data register, one plus the index reg. */ |
Li-Ta Lo | 1a4f070 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 480 | char b; |
Stefan Reinauer | 1f64c13 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 481 | |
| 482 | /* Disable the flash write protect. The flash write protect is |
| 483 | * connected to the WinBond w83627hf GPIO 24. |
| 484 | */ |
Li-Ta Lo | 1a4f070 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 485 | |
Li-Ta Lo | 1a4f070 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 486 | printf("Disabling mainboard flash write protection.\n"); |
| 487 | |
| 488 | outb(0x87, EFIR); // sequence to unlock extended functions |
| 489 | outb(0x87, EFIR); |
| 490 | |
| 491 | outb(0x20, EFIR); // SIO device ID register |
| 492 | b = inb(EFDR); |
| 493 | printf_debug("W83627HF device ID = 0x%x\n",b); |
| 494 | |
| 495 | if (b != 0x52) { |
| 496 | perror("Incorrect device ID, aborting write protect disable\n"); |
| 497 | exit(1); |
| 498 | } |
| 499 | |
| 500 | outb(0x2b, EFIR); // GPIO multiplexed pin reg. |
| 501 | b = inb(EFDR) | 0x10; |
| 502 | outb(0x2b, EFIR); |
| 503 | outb(b, EFDR); // select GPIO 24 instead of WDTO |
| 504 | |
| 505 | outb(0x7, EFIR); // logical device select |
| 506 | outb(0x8, EFDR); // point to device 8, GPIO port 2 |
| 507 | |
| 508 | outb(0x30, EFIR); // logic device activation control |
| 509 | outb(0x1, EFDR); // activate |
| 510 | |
| 511 | outb(0xf0, EFIR); // GPIO 20-27 I/O selection register |
| 512 | b = inb(EFDR) & ~0x10; |
| 513 | outb(0xf0, EFIR); |
| 514 | outb(b, EFDR); // set GPIO 24 as an output |
| 515 | |
| 516 | outb(0xf1, EFIR); // GPIO 20-27 data register |
| 517 | b = inb(EFDR) | 0x10; |
| 518 | outb(0xf1, EFIR); |
| 519 | outb(b, EFDR); // set GPIO 24 |
| 520 | |
| 521 | outb(0xaa, EFIR); // command to exit extended functions |
| 522 | |
| 523 | return 0; |
| 524 | } |
| 525 | |
| 526 | typedef struct mbenable { |
| 527 | char *vendor, *part; |
| 528 | int (*doit)(void); |
| 529 | } MAINBOARD_ENABLE; |
| 530 | |
| 531 | static MAINBOARD_ENABLE mbenables[] = { |
| 532 | { "ISLAND", "ARUMA", mbenable_island_aruma }, |
| 533 | }; |
| 534 | |
Li-Ta Lo | 115bd05 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 535 | int enable_flash_write() |
| 536 | { |
| 537 | int i; |
Li-Ta Lo | 115bd05 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 538 | struct pci_dev *dev = 0; |
| 539 | FLASH_ENABLE *enable = 0; |
| 540 | |
Adam Kaufman | 4f9cf13 | 2007-02-06 19:47:50 +0000 | [diff] [blame] | 541 | /* get io privilege access PCI configuration space */ |
| 542 | #if defined (__sun) && (defined(__i386) || defined(__amd64)) |
| 543 | if (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) != 0){ |
| 544 | #else |
| 545 | if (iopl(3) != 0) { |
| 546 | #endif |
| 547 | perror("Can not set io privilege"); |
| 548 | exit(1); |
| 549 | } |
| 550 | |
| 551 | |
| 552 | /* Initialize PCI access */ |
Li-Ta Lo | fbf43ac | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 553 | pacc = pci_alloc(); /* Get the pci_access structure */ |
Li-Ta Lo | 115bd05 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 554 | /* Set all options you want -- here we stick with the defaults */ |
Li-Ta Lo | fbf43ac | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 555 | pci_init(pacc); /* Initialize the PCI library */ |
| 556 | pci_scan_bus(pacc); /* We want to get the list of devices */ |
Li-Ta Lo | 115bd05 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 557 | |
Li-Ta Lo | 1a4f070 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 558 | |
| 559 | /* First look whether we have to do something for this |
| 560 | * motherboard. |
| 561 | */ |
| 562 | for (i = 0; i < sizeof(mbenables) / sizeof(mbenables[0]); i++) { |
| 563 | if(lb_vendor && !strcmp(mbenables[i].vendor, lb_vendor) && |
| 564 | lb_part && !strcmp(mbenables[i].part, lb_part)) { |
| 565 | mbenables[i].doit(); |
| 566 | break; |
| 567 | } |
| 568 | } |
| 569 | |
Li-Ta Lo | 115bd05 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 570 | /* now let's try to find the chipset we have ... */ |
Li-Ta Lo | fbf43ac | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 571 | for (i = 0; i < sizeof(enables) / sizeof(enables[0]) && (!dev); |
| 572 | i++) { |
Li-Ta Lo | 115bd05 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 573 | struct pci_filter f; |
| 574 | struct pci_dev *z; |
| 575 | /* the first param is unused. */ |
| 576 | pci_filter_init((struct pci_access *) 0, &f); |
| 577 | f.vendor = enables[i].vendor; |
| 578 | f.device = enables[i].device; |
Li-Ta Lo | fbf43ac | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 579 | for (z = pacc->devices; z; z = z->next) |
Li-Ta Lo | 115bd05 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 580 | if (pci_filter_match(&f, z)) { |
| 581 | enable = &enables[i]; |
| 582 | dev = z; |
| 583 | } |
| 584 | } |
| 585 | |
Stefan Reinauer | 051427c | 2006-08-25 19:21:42 +0000 | [diff] [blame] | 586 | if (!enable) { |
| 587 | printf("Warning: Unknown system. Flash detection " |
| 588 | "will most likely fail.\n"); |
| 589 | return 1; |
Li-Ta Lo | 115bd05 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 590 | } |
Stefan Reinauer | 051427c | 2006-08-25 19:21:42 +0000 | [diff] [blame] | 591 | |
| 592 | /* now do the deed. */ |
| 593 | printf("Enabling flash write on %s...", enable->name); |
| 594 | if (enable->doit(dev, enable->name) == 0) |
| 595 | printf("OK\n"); |
Li-Ta Lo | 115bd05 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 596 | return 0; |
| 597 | } |