Ollie Lho | 184a404 | 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 | eb36647 | 2006-09-06 15:48:48 +0000 | [diff] [blame] | 6 | * Copyright (C) 2006 Uwe Hermann <uwe@hermann-uwe.de> |
Ollie Lho | 184a404 | 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 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 14 | #include <sys/io.h> |
| 15 | #include <stdio.h> |
| 16 | #include <pci/pci.h> |
| 17 | #include <stdlib.h> |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 18 | #include <stdint.h> |
| 19 | #include <string.h> |
| 20 | #include "lbtable.h" |
| 21 | #include "debug.h" |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 22 | |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 23 | // We keep this for the others. |
| 24 | static struct pci_access *pacc; |
| 25 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 26 | static int enable_flash_sis630(struct pci_dev *dev, char *name) |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 27 | { |
| 28 | char b; |
| 29 | |
| 30 | /* get io privilege access PCI configuration space */ |
| 31 | if (iopl(3) != 0) { |
| 32 | perror("Can not set io priviliage"); |
| 33 | exit(1); |
| 34 | } |
| 35 | |
| 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); |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 65 | outb(0x02, 0x4f); |
Ollie Lho | cbbf125 | 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 | |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 80 | static int enable_flash_ich(struct pci_dev *dev, char *name, int bios_cntl) |
Ronald G. Minnich | 6a96741 | 2004-09-28 20:09:06 +0000 | [diff] [blame] | 81 | { |
| 82 | /* register 4e.b gets or'ed with one */ |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 83 | uint8_t old, new; |
Stefan Reinauer | eb36647 | 2006-09-06 15:48:48 +0000 | [diff] [blame] | 84 | |
Ronald G. Minnich | 6a96741 | 2004-09-28 20:09:06 +0000 | [diff] [blame] | 85 | /* if it fails, it fails. There are so many variations of broken mobos |
| 86 | * that it is hard to argue that we should quit at this point. |
| 87 | */ |
| 88 | |
Stefan Reinauer | eb36647 | 2006-09-06 15:48:48 +0000 | [diff] [blame] | 89 | /* Note: the ICH0-ICH5 BIOS_CNTL register is actually 16 bit wide, but |
| 90 | * just treating it as 8 bit wide seems to work fine in practice. |
| 91 | */ |
| 92 | |
| 93 | /* see ie. page 375 of "Intel ICH7 External Design Specification" |
| 94 | * http://download.intel.com/design/chipsets/datashts/30701302.pdf |
| 95 | */ |
| 96 | |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 97 | old = pci_read_byte(dev, bios_cntl); |
Ronald G. Minnich | 6a96741 | 2004-09-28 20:09:06 +0000 | [diff] [blame] | 98 | |
| 99 | new = old | 1; |
| 100 | |
| 101 | if (new == old) |
| 102 | return 0; |
| 103 | |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 104 | pci_write_byte(dev, bios_cntl, new); |
Ronald G. Minnich | 6a96741 | 2004-09-28 20:09:06 +0000 | [diff] [blame] | 105 | |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 106 | if (pci_read_byte(dev, bios_cntl) != new) { |
Ronald G. Minnich | 6a96741 | 2004-09-28 20:09:06 +0000 | [diff] [blame] | 107 | printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 108 | bios_cntl, new, name); |
Ronald G. Minnich | 6a96741 | 2004-09-28 20:09:06 +0000 | [diff] [blame] | 109 | return -1; |
| 110 | } |
| 111 | return 0; |
| 112 | } |
| 113 | |
Stefan Reinauer | eb36647 | 2006-09-06 15:48:48 +0000 | [diff] [blame] | 114 | static int enable_flash_ich_4e(struct pci_dev *dev, char *name) |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 115 | { |
Stefan Reinauer | eb36647 | 2006-09-06 15:48:48 +0000 | [diff] [blame] | 116 | return enable_flash_ich(dev, name, 0x4e); |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 117 | } |
| 118 | |
Stefan Reinauer | eb36647 | 2006-09-06 15:48:48 +0000 | [diff] [blame] | 119 | static int enable_flash_ich_dc(struct pci_dev *dev, char *name) |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 120 | { |
Stefan Reinauer | eb36647 | 2006-09-06 15:48:48 +0000 | [diff] [blame] | 121 | return enable_flash_ich(dev, name, 0xdc); |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 122 | } |
| 123 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 124 | static int enable_flash_vt8235(struct pci_dev *dev, char *name) |
| 125 | { |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 126 | uint8_t old, new, val; |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 127 | unsigned int base; |
| 128 | int ok; |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 129 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 130 | /* get io privilege access PCI configuration space */ |
| 131 | if (iopl(3) != 0) { |
| 132 | perror("Can not set io priviliage"); |
| 133 | exit(1); |
| 134 | } |
| 135 | |
| 136 | old = pci_read_byte(dev, 0x40); |
| 137 | |
| 138 | new = old | 0x10; |
| 139 | |
| 140 | if (new == old) |
| 141 | return 0; |
| 142 | |
| 143 | ok = pci_write_byte(dev, 0x40, new); |
| 144 | if (ok != 0) { |
Ollie Lho | 8b8897a | 2004-03-27 00:18:15 +0000 | [diff] [blame] | 145 | printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", |
| 146 | old, new, name); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | /* enable GPIO15 which is connected to write protect. */ |
Ollie Lho | 8b8897a | 2004-03-27 00:18:15 +0000 | [diff] [blame] | 150 | base = ((pci_read_byte(dev, 0x88) & 0x80) | pci_read_byte(dev, 0x89) << 8); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 151 | val = inb(base + 0x4d); |
| 152 | val |= 0x80; |
| 153 | outb(val, base + 0x4d); |
| 154 | |
| 155 | if (ok != 0) { |
| 156 | return -1; |
| 157 | } else { |
| 158 | return 0; |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | static int enable_flash_vt8231(struct pci_dev *dev, char *name) |
| 163 | { |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 164 | uint8_t val; |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 165 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 166 | val = pci_read_byte(dev, 0x40); |
| 167 | val |= 0x10; |
| 168 | pci_write_byte(dev, 0x40, val); |
| 169 | |
| 170 | if (pci_read_byte(dev, 0x40) != val) { |
Ollie Lho | 8b8897a | 2004-03-27 00:18:15 +0000 | [diff] [blame] | 171 | printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", |
| 172 | 0x40, val, name); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 173 | return -1; |
| 174 | } |
| 175 | return 0; |
| 176 | } |
| 177 | |
| 178 | static int enable_flash_cs5530(struct pci_dev *dev, char *name) |
| 179 | { |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 180 | uint8_t new; |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 181 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 182 | pci_write_byte(dev, 0x52, 0xee); |
| 183 | |
| 184 | new = pci_read_byte(dev, 0x52); |
| 185 | |
| 186 | if (new != 0xee) { |
Ollie Lho | 8b8897a | 2004-03-27 00:18:15 +0000 | [diff] [blame] | 187 | printf("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n", |
| 188 | 0x52, new, name); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 189 | return -1; |
| 190 | } |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 191 | |
| 192 | new = pci_read_byte(dev, 0x5b) | 0x20; |
| 193 | pci_write_byte(dev, 0x5b, new); |
| 194 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 195 | return 0; |
| 196 | } |
| 197 | |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 198 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 199 | static int enable_flash_sc1100(struct pci_dev *dev, char *name) |
| 200 | { |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 201 | uint8_t new; |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 202 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 203 | pci_write_byte(dev, 0x52, 0xee); |
| 204 | |
| 205 | new = pci_read_byte(dev, 0x52); |
| 206 | |
| 207 | if (new != 0xee) { |
Ollie Lho | 8b8897a | 2004-03-27 00:18:15 +0000 | [diff] [blame] | 208 | printf("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n", |
| 209 | 0x52, new, name); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 210 | return -1; |
| 211 | } |
| 212 | return 0; |
| 213 | } |
| 214 | |
| 215 | static int enable_flash_sis5595(struct pci_dev *dev, char *name) |
| 216 | { |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 217 | uint8_t new, newer; |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 218 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 219 | new = pci_read_byte(dev, 0x45); |
| 220 | |
| 221 | /* clear bit 5 */ |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 222 | new &= (~0x20); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 223 | /* set bit 2 */ |
| 224 | new |= 0x4; |
| 225 | |
| 226 | pci_write_byte(dev, 0x45, new); |
| 227 | |
| 228 | newer = pci_read_byte(dev, 0x45); |
| 229 | if (newer != new) { |
Ollie Lho | 8b8897a | 2004-03-27 00:18:15 +0000 | [diff] [blame] | 230 | printf("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n", |
| 231 | 0x45, new, name); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 232 | printf("Stuck at 0x%x\n", newer); |
| 233 | return -1; |
| 234 | } |
| 235 | return 0; |
| 236 | } |
| 237 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 238 | static int enable_flash_amd8111(struct pci_dev *dev, char *name) |
| 239 | { |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 240 | /* register 4e.b gets or'ed with one */ |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 241 | uint8_t old, new; |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 242 | /* if it fails, it fails. There are so many variations of broken mobos |
| 243 | * that it is hard to argue that we should quit at this point. |
| 244 | */ |
| 245 | |
Ollie Lho | d11f361 | 2004-12-07 17:19:04 +0000 | [diff] [blame] | 246 | /* enable decoding at 0xffb00000 to 0xffffffff */ |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 247 | old = pci_read_byte(dev, 0x43); |
Ollie Lho | d11f361 | 2004-12-07 17:19:04 +0000 | [diff] [blame] | 248 | new = old | 0xC0; |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 249 | if (new != old) { |
| 250 | pci_write_byte(dev, 0x43, new); |
| 251 | if (pci_read_byte(dev, 0x43) != new) { |
Ollie Lho | 8b8897a | 2004-03-27 00:18:15 +0000 | [diff] [blame] | 252 | printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", |
| 253 | 0x43, new, name); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 254 | } |
| 255 | } |
| 256 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 257 | old = pci_read_byte(dev, 0x40); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 258 | new = old | 0x01; |
| 259 | if (new == old) |
| 260 | return 0; |
| 261 | pci_write_byte(dev, 0x40, new); |
| 262 | |
| 263 | if (pci_read_byte(dev, 0x40) != new) { |
Ollie Lho | 8b8897a | 2004-03-27 00:18:15 +0000 | [diff] [blame] | 264 | printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", |
| 265 | 0x40, new, name); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 266 | return -1; |
| 267 | } |
| 268 | return 0; |
| 269 | } |
| 270 | |
Yinghai Lu | 952dfce | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 271 | //By yhlu |
| 272 | static int enable_flash_ck804(struct pci_dev *dev, char *name) |
| 273 | { |
| 274 | /* register 4e.b gets or'ed with one */ |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 275 | uint8_t old, new; |
Yinghai Lu | 952dfce | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 276 | /* if it fails, it fails. There are so many variations of broken mobos |
| 277 | * that it is hard to argue that we should quit at this point. |
| 278 | */ |
| 279 | |
| 280 | //dump_pci_device(dev); |
| 281 | |
| 282 | old = pci_read_byte(dev, 0x88); |
| 283 | new = old | 0xc0; |
| 284 | if (new != old) { |
| 285 | pci_write_byte(dev, 0x88, new); |
| 286 | if (pci_read_byte(dev, 0x88) != new) { |
| 287 | printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", |
| 288 | 0x88, new, name); |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | old = pci_read_byte(dev, 0x6d); |
| 293 | new = old | 0x01; |
| 294 | if (new == old) |
| 295 | return 0; |
| 296 | pci_write_byte(dev, 0x6d, new); |
| 297 | |
| 298 | if (pci_read_byte(dev, 0x6d) != new) { |
| 299 | printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", |
| 300 | 0x6d, new, name); |
| 301 | return -1; |
| 302 | } |
| 303 | return 0; |
| 304 | } |
| 305 | |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 306 | static int enable_flash_sb400(struct pci_dev *dev, char *name) |
| 307 | { |
| 308 | uint8_t tmp; |
| 309 | |
| 310 | struct pci_filter f; |
| 311 | struct pci_dev *smbusdev; |
| 312 | |
| 313 | /* get io privilege access */ |
| 314 | if (iopl(3) != 0) { |
| 315 | perror("Can not set io priviliage"); |
| 316 | exit(1); |
| 317 | } |
| 318 | |
| 319 | /* then look for the smbus device */ |
| 320 | pci_filter_init((struct pci_access *) 0, &f); |
| 321 | f.vendor = 0x1002; |
| 322 | f.device = 0x4372; |
| 323 | |
| 324 | for (smbusdev = pacc->devices; smbusdev; smbusdev = smbusdev->next) { |
| 325 | if (pci_filter_match(&f, smbusdev)) { |
| 326 | break; |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | if(!smbusdev) { |
| 331 | perror("smbus device not found. aborting\n"); |
| 332 | exit(1); |
| 333 | } |
| 334 | |
| 335 | // enable some smbus stuff |
| 336 | tmp=pci_read_byte(smbusdev, 0x79); |
| 337 | tmp|=0x01; |
| 338 | pci_write_byte(smbusdev, 0x79, tmp); |
| 339 | |
| 340 | // change southbridge |
| 341 | tmp=pci_read_byte(dev, 0x48); |
| 342 | tmp|=0x21; |
| 343 | pci_write_byte(dev, 0x48, tmp); |
| 344 | |
| 345 | // now become a bit silly. |
| 346 | tmp=inb(0xc6f); |
| 347 | outb(tmp,0xeb); |
| 348 | outb(tmp, 0xeb); |
| 349 | tmp|=0x40; |
| 350 | outb(tmp, 0xc6f); |
| 351 | outb(tmp, 0xeb); |
| 352 | outb(tmp, 0xeb); |
| 353 | |
| 354 | return 0; |
| 355 | } |
| 356 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 357 | typedef struct penable { |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 358 | unsigned short vendor, device; |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 359 | char *name; |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 360 | int (*doit) (struct pci_dev * dev, char *name); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 361 | } FLASH_ENABLE; |
| 362 | |
| 363 | static FLASH_ENABLE enables[] = { |
Stefan Reinauer | eb36647 | 2006-09-06 15:48:48 +0000 | [diff] [blame] | 364 | {0x1039, 0x0630, "SIS630", enable_flash_sis630}, |
| 365 | {0x8086, 0x2410, "ICH", enable_flash_ich_4e}, |
| 366 | {0x8086, 0x2420, "ICH0", enable_flash_ich_4e}, |
| 367 | {0x8086, 0x2440, "ICH2", enable_flash_ich_4e}, |
| 368 | {0x8086, 0x244c, "ICH2-M", enable_flash_ich_4e}, |
| 369 | {0x8086, 0x2480, "ICH3-S", enable_flash_ich_4e}, |
| 370 | {0x8086, 0x248c, "ICH3-M", enable_flash_ich_4e}, |
| 371 | {0x8086, 0x24c0, "ICH4/ICH4-L", enable_flash_ich_4e}, |
| 372 | {0x8086, 0x24cc, "ICH4-M", enable_flash_ich_4e}, |
| 373 | {0x8086, 0x24d0, "ICH5/ICH5R", enable_flash_ich_4e}, |
| 374 | {0x8086, 0x2640, "ICH6/ICH6R", enable_flash_ich_dc}, |
| 375 | {0x8086, 0x2641, "ICH6-M", enable_flash_ich_dc}, |
| 376 | {0x8086, 0x27b8, "ICH7/ICH7R", enable_flash_ich_dc}, |
| 377 | {0x8086, 0x27b9, "ICH7M", enable_flash_ich_dc}, |
| 378 | {0x8086, 0x27bd, "ICH7MDH", enable_flash_ich_dc}, |
| 379 | {0x8086, 0x2810, "ICH8/ICH8R", enable_flash_ich_dc}, |
| 380 | {0x8086, 0x2812, "ICH8DH", enable_flash_ich_dc}, |
| 381 | {0x8086, 0x2814, "ICH8DO", enable_flash_ich_dc}, |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 382 | {0x1106, 0x8231, "VT8231", enable_flash_vt8231}, |
| 383 | {0x1106, 0x3177, "VT8235", enable_flash_vt8235}, |
Stefan Reinauer | 219b61e | 2006-10-14 21:04:49 +0000 | [diff] [blame^] | 384 | {0x1106, 0x3227, "VT8237", enable_flash_vt8231}, |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 385 | {0x1078, 0x0100, "CS5530", enable_flash_cs5530}, |
| 386 | {0x100b, 0x0510, "SC1100", enable_flash_sc1100}, |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 387 | {0x1039, 0x0008, "SIS5595", enable_flash_sis5595}, |
| 388 | {0x1022, 0x7468, "AMD8111", enable_flash_amd8111}, |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 389 | // this fallthrough looks broken. |
Yinghai Lu | 952dfce | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 390 | {0x10de, 0x0050, "NVIDIA CK804", enable_flash_ck804}, // LPC |
| 391 | {0x10de, 0x0051, "NVIDIA CK804", enable_flash_ck804}, // Pro |
| 392 | {0x10de, 0x00d3, "NVIDIA CK804", enable_flash_ck804}, // Slave, should not be here, to fix known bug for A01. |
Stefan Reinauer | 219b61e | 2006-10-14 21:04:49 +0000 | [diff] [blame^] | 393 | |
| 394 | {0x10de, 0x0260, "NVidia MCP51", enable_flash_ck804}, |
| 395 | {0x10de, 0x0261, "NVidia MCP51", enable_flash_ck804}, |
| 396 | {0x10de, 0x0262, "NVidia MCP51", enable_flash_ck804}, |
| 397 | {0x10de, 0x0263, "NVidia MCP51", enable_flash_ck804}, |
| 398 | |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 399 | {0x1002, 0x4377, "ATI SB400", enable_flash_sb400}, // ATI Technologies Inc IXP SB400 PCI-ISA Bridge (rev 80) |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 400 | }; |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 401 | |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 402 | static int mbenable_island_aruma(void) |
| 403 | { |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 404 | #define EFIR 0x2e /* Extended function index register, either 0x2e or 0x4e */ |
| 405 | #define EFDR EFIR + 1 /* Extended function data register, one plus the index reg. */ |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 406 | char b; |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 407 | |
| 408 | /* Disable the flash write protect. The flash write protect is |
| 409 | * connected to the WinBond w83627hf GPIO 24. |
| 410 | */ |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 411 | |
| 412 | /* get io privilege access winbond config space */ |
| 413 | if (iopl(3) != 0) { |
| 414 | perror("Can not set io priviliage"); |
| 415 | exit(1); |
| 416 | } |
| 417 | |
| 418 | printf("Disabling mainboard flash write protection.\n"); |
| 419 | |
| 420 | outb(0x87, EFIR); // sequence to unlock extended functions |
| 421 | outb(0x87, EFIR); |
| 422 | |
| 423 | outb(0x20, EFIR); // SIO device ID register |
| 424 | b = inb(EFDR); |
| 425 | printf_debug("W83627HF device ID = 0x%x\n",b); |
| 426 | |
| 427 | if (b != 0x52) { |
| 428 | perror("Incorrect device ID, aborting write protect disable\n"); |
| 429 | exit(1); |
| 430 | } |
| 431 | |
| 432 | outb(0x2b, EFIR); // GPIO multiplexed pin reg. |
| 433 | b = inb(EFDR) | 0x10; |
| 434 | outb(0x2b, EFIR); |
| 435 | outb(b, EFDR); // select GPIO 24 instead of WDTO |
| 436 | |
| 437 | outb(0x7, EFIR); // logical device select |
| 438 | outb(0x8, EFDR); // point to device 8, GPIO port 2 |
| 439 | |
| 440 | outb(0x30, EFIR); // logic device activation control |
| 441 | outb(0x1, EFDR); // activate |
| 442 | |
| 443 | outb(0xf0, EFIR); // GPIO 20-27 I/O selection register |
| 444 | b = inb(EFDR) & ~0x10; |
| 445 | outb(0xf0, EFIR); |
| 446 | outb(b, EFDR); // set GPIO 24 as an output |
| 447 | |
| 448 | outb(0xf1, EFIR); // GPIO 20-27 data register |
| 449 | b = inb(EFDR) | 0x10; |
| 450 | outb(0xf1, EFIR); |
| 451 | outb(b, EFDR); // set GPIO 24 |
| 452 | |
| 453 | outb(0xaa, EFIR); // command to exit extended functions |
| 454 | |
| 455 | return 0; |
| 456 | } |
| 457 | |
| 458 | typedef struct mbenable { |
| 459 | char *vendor, *part; |
| 460 | int (*doit)(void); |
| 461 | } MAINBOARD_ENABLE; |
| 462 | |
| 463 | static MAINBOARD_ENABLE mbenables[] = { |
| 464 | { "ISLAND", "ARUMA", mbenable_island_aruma }, |
| 465 | }; |
| 466 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 467 | int enable_flash_write() |
| 468 | { |
| 469 | int i; |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 470 | struct pci_dev *dev = 0; |
| 471 | FLASH_ENABLE *enable = 0; |
| 472 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 473 | pacc = pci_alloc(); /* Get the pci_access structure */ |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 474 | /* Set all options you want -- here we stick with the defaults */ |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 475 | pci_init(pacc); /* Initialize the PCI library */ |
| 476 | pci_scan_bus(pacc); /* We want to get the list of devices */ |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 477 | |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 478 | |
| 479 | /* First look whether we have to do something for this |
| 480 | * motherboard. |
| 481 | */ |
| 482 | for (i = 0; i < sizeof(mbenables) / sizeof(mbenables[0]); i++) { |
| 483 | if(lb_vendor && !strcmp(mbenables[i].vendor, lb_vendor) && |
| 484 | lb_part && !strcmp(mbenables[i].part, lb_part)) { |
| 485 | mbenables[i].doit(); |
| 486 | break; |
| 487 | } |
| 488 | } |
| 489 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 490 | /* now let's try to find the chipset we have ... */ |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 491 | for (i = 0; i < sizeof(enables) / sizeof(enables[0]) && (!dev); |
| 492 | i++) { |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 493 | struct pci_filter f; |
| 494 | struct pci_dev *z; |
| 495 | /* the first param is unused. */ |
| 496 | pci_filter_init((struct pci_access *) 0, &f); |
| 497 | f.vendor = enables[i].vendor; |
| 498 | f.device = enables[i].device; |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 499 | for (z = pacc->devices; z; z = z->next) |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 500 | if (pci_filter_match(&f, z)) { |
| 501 | enable = &enables[i]; |
| 502 | dev = z; |
| 503 | } |
| 504 | } |
| 505 | |
Stefan Reinauer | cbc55d0 | 2006-08-25 19:21:42 +0000 | [diff] [blame] | 506 | if (!enable) { |
| 507 | printf("Warning: Unknown system. Flash detection " |
| 508 | "will most likely fail.\n"); |
| 509 | return 1; |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 510 | } |
Stefan Reinauer | cbc55d0 | 2006-08-25 19:21:42 +0000 | [diff] [blame] | 511 | |
| 512 | /* now do the deed. */ |
| 513 | printf("Enabling flash write on %s...", enable->name); |
| 514 | if (enable->doit(dev, enable->name) == 0) |
| 515 | printf("OK\n"); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 516 | return 0; |
| 517 | } |