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 <stdio.h> |
| 15 | #include <pci/pci.h> |
| 16 | #include <stdlib.h> |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 17 | #include <stdint.h> |
| 18 | #include <string.h> |
Adam Kaufman | 064b1f2 | 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" |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 26 | #include "lbtable.h" |
| 27 | #include "debug.h" |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 28 | |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 29 | // We keep this for the others. |
| 30 | static struct pci_access *pacc; |
| 31 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 32 | static int enable_flash_sis630(struct pci_dev *dev, char *name) |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 33 | { |
| 34 | char b; |
| 35 | |
Ollie Lho | cbbf125 | 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); |
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 | |
Uwe Hermann | 987942d | 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 | ea2c66d | 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 | 987942d | 2006-11-07 11:16:21 +0000 | [diff] [blame] | 98 | the lower 64-Kbyte BIOS block (E0000-EFFFF) at the top |
Uwe Hermann | ea2c66d | 2006-11-05 18:26:08 +0000 | [diff] [blame] | 99 | of 1 Mbyte, or the aliases at the top of 4 Gbyte |
Uwe Hermann | 987942d | 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 | ea2c66d | 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 | 86de283 | 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 | 6a96741 | 2004-09-28 20:09:06 +0000 | [diff] [blame] | 118 | { |
| 119 | /* register 4e.b gets or'ed with one */ |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 120 | uint8_t old, new; |
Stefan Reinauer | eb36647 | 2006-09-06 15:48:48 +0000 | [diff] [blame] | 121 | |
Ronald G. Minnich | 6a96741 | 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 | eb36647 | 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 | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 134 | old = pci_read_byte(dev, bios_cntl); |
Ronald G. Minnich | 6a96741 | 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 | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 141 | pci_write_byte(dev, bios_cntl, new); |
Ronald G. Minnich | 6a96741 | 2004-09-28 20:09:06 +0000 | [diff] [blame] | 142 | |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 143 | if (pci_read_byte(dev, bios_cntl) != new) { |
Ronald G. Minnich | 6a96741 | 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 | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 145 | bios_cntl, new, name); |
Ronald G. Minnich | 6a96741 | 2004-09-28 20:09:06 +0000 | [diff] [blame] | 146 | return -1; |
| 147 | } |
| 148 | return 0; |
| 149 | } |
| 150 | |
Stefan Reinauer | eb36647 | 2006-09-06 15:48:48 +0000 | [diff] [blame] | 151 | static int enable_flash_ich_4e(struct pci_dev *dev, char *name) |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 152 | { |
Stefan Reinauer | eb36647 | 2006-09-06 15:48:48 +0000 | [diff] [blame] | 153 | return enable_flash_ich(dev, name, 0x4e); |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 154 | } |
| 155 | |
Stefan Reinauer | eb36647 | 2006-09-06 15:48:48 +0000 | [diff] [blame] | 156 | static int enable_flash_ich_dc(struct pci_dev *dev, char *name) |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 157 | { |
Stefan Reinauer | eb36647 | 2006-09-06 15:48:48 +0000 | [diff] [blame] | 158 | return enable_flash_ich(dev, name, 0xdc); |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 159 | } |
| 160 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 161 | static int enable_flash_vt8235(struct pci_dev *dev, char *name) |
| 162 | { |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 163 | uint8_t old, new, val; |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 164 | unsigned int base; |
| 165 | int ok; |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 166 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 167 | old = pci_read_byte(dev, 0x40); |
| 168 | |
| 169 | new = old | 0x10; |
| 170 | |
| 171 | if (new == old) |
| 172 | return 0; |
| 173 | |
| 174 | ok = pci_write_byte(dev, 0x40, new); |
| 175 | if (ok != 0) { |
Ollie Lho | 8b8897a | 2004-03-27 00:18:15 +0000 | [diff] [blame] | 176 | printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", |
| 177 | old, new, name); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | /* enable GPIO15 which is connected to write protect. */ |
Ollie Lho | 8b8897a | 2004-03-27 00:18:15 +0000 | [diff] [blame] | 181 | 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] | 182 | val = inb(base + 0x4d); |
| 183 | val |= 0x80; |
| 184 | outb(val, base + 0x4d); |
| 185 | |
| 186 | if (ok != 0) { |
| 187 | return -1; |
| 188 | } else { |
| 189 | return 0; |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | static int enable_flash_vt8231(struct pci_dev *dev, char *name) |
| 194 | { |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 195 | uint8_t val; |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 196 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 197 | val = pci_read_byte(dev, 0x40); |
| 198 | val |= 0x10; |
| 199 | pci_write_byte(dev, 0x40, val); |
| 200 | |
| 201 | if (pci_read_byte(dev, 0x40) != val) { |
Ollie Lho | 8b8897a | 2004-03-27 00:18:15 +0000 | [diff] [blame] | 202 | printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", |
| 203 | 0x40, val, name); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 204 | return -1; |
| 205 | } |
| 206 | return 0; |
| 207 | } |
| 208 | |
| 209 | static int enable_flash_cs5530(struct pci_dev *dev, char *name) |
| 210 | { |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 211 | uint8_t new; |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 212 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 213 | pci_write_byte(dev, 0x52, 0xee); |
| 214 | |
| 215 | new = pci_read_byte(dev, 0x52); |
| 216 | |
| 217 | if (new != 0xee) { |
Ollie Lho | 8b8897a | 2004-03-27 00:18:15 +0000 | [diff] [blame] | 218 | printf("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n", |
| 219 | 0x52, new, name); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 220 | return -1; |
| 221 | } |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 222 | |
| 223 | new = pci_read_byte(dev, 0x5b) | 0x20; |
| 224 | pci_write_byte(dev, 0x5b, new); |
| 225 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 226 | return 0; |
| 227 | } |
| 228 | |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 229 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 230 | static int enable_flash_sc1100(struct pci_dev *dev, char *name) |
| 231 | { |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 232 | uint8_t new; |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 233 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 234 | pci_write_byte(dev, 0x52, 0xee); |
| 235 | |
| 236 | new = pci_read_byte(dev, 0x52); |
| 237 | |
| 238 | if (new != 0xee) { |
Ollie Lho | 8b8897a | 2004-03-27 00:18:15 +0000 | [diff] [blame] | 239 | printf("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n", |
| 240 | 0x52, new, name); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 241 | return -1; |
| 242 | } |
| 243 | return 0; |
| 244 | } |
| 245 | |
| 246 | static int enable_flash_sis5595(struct pci_dev *dev, char *name) |
| 247 | { |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 248 | uint8_t new, newer; |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 249 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 250 | new = pci_read_byte(dev, 0x45); |
| 251 | |
| 252 | /* clear bit 5 */ |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 253 | new &= (~0x20); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 254 | /* set bit 2 */ |
| 255 | new |= 0x4; |
| 256 | |
| 257 | pci_write_byte(dev, 0x45, new); |
| 258 | |
| 259 | newer = pci_read_byte(dev, 0x45); |
| 260 | if (newer != new) { |
Ollie Lho | 8b8897a | 2004-03-27 00:18:15 +0000 | [diff] [blame] | 261 | printf("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n", |
| 262 | 0x45, new, name); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 263 | printf("Stuck at 0x%x\n", newer); |
| 264 | return -1; |
| 265 | } |
| 266 | return 0; |
| 267 | } |
| 268 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 269 | static int enable_flash_amd8111(struct pci_dev *dev, char *name) |
| 270 | { |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 271 | /* register 4e.b gets or'ed with one */ |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 272 | uint8_t old, new; |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 273 | /* if it fails, it fails. There are so many variations of broken mobos |
| 274 | * that it is hard to argue that we should quit at this point. |
| 275 | */ |
| 276 | |
Ollie Lho | d11f361 | 2004-12-07 17:19:04 +0000 | [diff] [blame] | 277 | /* enable decoding at 0xffb00000 to 0xffffffff */ |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 278 | old = pci_read_byte(dev, 0x43); |
Ollie Lho | d11f361 | 2004-12-07 17:19:04 +0000 | [diff] [blame] | 279 | new = old | 0xC0; |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 280 | if (new != old) { |
| 281 | pci_write_byte(dev, 0x43, new); |
| 282 | if (pci_read_byte(dev, 0x43) != new) { |
Ollie Lho | 8b8897a | 2004-03-27 00:18:15 +0000 | [diff] [blame] | 283 | printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", |
| 284 | 0x43, new, name); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 285 | } |
| 286 | } |
| 287 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 288 | old = pci_read_byte(dev, 0x40); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 289 | new = old | 0x01; |
| 290 | if (new == old) |
| 291 | return 0; |
| 292 | pci_write_byte(dev, 0x40, new); |
| 293 | |
| 294 | if (pci_read_byte(dev, 0x40) != new) { |
Ollie Lho | 8b8897a | 2004-03-27 00:18:15 +0000 | [diff] [blame] | 295 | printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", |
| 296 | 0x40, new, name); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 297 | return -1; |
| 298 | } |
| 299 | return 0; |
| 300 | } |
| 301 | |
Yinghai Lu | 952dfce | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 302 | //By yhlu |
| 303 | static int enable_flash_ck804(struct pci_dev *dev, char *name) |
| 304 | { |
| 305 | /* register 4e.b gets or'ed with one */ |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 306 | uint8_t old, new; |
Yinghai Lu | 952dfce | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 307 | /* if it fails, it fails. There are so many variations of broken mobos |
| 308 | * that it is hard to argue that we should quit at this point. |
| 309 | */ |
| 310 | |
| 311 | //dump_pci_device(dev); |
| 312 | |
| 313 | old = pci_read_byte(dev, 0x88); |
| 314 | new = old | 0xc0; |
| 315 | if (new != old) { |
| 316 | pci_write_byte(dev, 0x88, new); |
| 317 | if (pci_read_byte(dev, 0x88) != new) { |
| 318 | printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", |
| 319 | 0x88, new, name); |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | old = pci_read_byte(dev, 0x6d); |
| 324 | new = old | 0x01; |
| 325 | if (new == old) |
| 326 | return 0; |
| 327 | pci_write_byte(dev, 0x6d, new); |
| 328 | |
| 329 | if (pci_read_byte(dev, 0x6d) != new) { |
| 330 | printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", |
| 331 | 0x6d, new, name); |
| 332 | return -1; |
| 333 | } |
| 334 | return 0; |
| 335 | } |
| 336 | |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 337 | static int enable_flash_sb400(struct pci_dev *dev, char *name) |
| 338 | { |
| 339 | uint8_t tmp; |
| 340 | |
| 341 | struct pci_filter f; |
| 342 | struct pci_dev *smbusdev; |
| 343 | |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 344 | /* then look for the smbus device */ |
| 345 | pci_filter_init((struct pci_access *) 0, &f); |
| 346 | f.vendor = 0x1002; |
| 347 | f.device = 0x4372; |
| 348 | |
| 349 | for (smbusdev = pacc->devices; smbusdev; smbusdev = smbusdev->next) { |
| 350 | if (pci_filter_match(&f, smbusdev)) { |
| 351 | break; |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | if(!smbusdev) { |
| 356 | perror("smbus device not found. aborting\n"); |
| 357 | exit(1); |
| 358 | } |
| 359 | |
| 360 | // enable some smbus stuff |
| 361 | tmp=pci_read_byte(smbusdev, 0x79); |
| 362 | tmp|=0x01; |
| 363 | pci_write_byte(smbusdev, 0x79, tmp); |
| 364 | |
| 365 | // change southbridge |
| 366 | tmp=pci_read_byte(dev, 0x48); |
| 367 | tmp|=0x21; |
| 368 | pci_write_byte(dev, 0x48, tmp); |
| 369 | |
| 370 | // now become a bit silly. |
| 371 | tmp=inb(0xc6f); |
| 372 | outb(tmp,0xeb); |
| 373 | outb(tmp, 0xeb); |
| 374 | tmp|=0x40; |
| 375 | outb(tmp, 0xc6f); |
| 376 | outb(tmp, 0xeb); |
| 377 | outb(tmp, 0xeb); |
| 378 | |
| 379 | return 0; |
| 380 | } |
| 381 | |
Yinghai Lu | ca78297 | 2007-01-22 20:21:17 +0000 | [diff] [blame] | 382 | //By yhlu |
| 383 | static int enable_flash_mcp55(struct pci_dev *dev, char *name) |
| 384 | { |
| 385 | /* register 4e.b gets or'ed with one */ |
| 386 | unsigned char old, new, byte; |
| 387 | unsigned short word; |
| 388 | |
| 389 | /* if it fails, it fails. There are so many variations of broken mobos |
| 390 | * that it is hard to argue that we should quit at this point. |
| 391 | */ |
| 392 | |
| 393 | //dump_pci_device(dev); |
| 394 | |
| 395 | /* Set the 4MB enable bit bit */ |
| 396 | byte = pci_read_byte(dev, 0x88); |
| 397 | byte |= 0xff; //256K |
| 398 | pci_write_byte(dev, 0x88, byte); |
| 399 | byte = pci_read_byte(dev, 0x8c); |
| 400 | byte |= 0xff; //1M |
| 401 | pci_write_byte(dev, 0x8c, byte); |
| 402 | word = pci_read_word(dev, 0x90); |
| 403 | word |= 0x7fff; //15M |
| 404 | pci_write_word(dev, 0x90, word); |
| 405 | |
| 406 | old = pci_read_byte(dev, 0x6d); |
| 407 | new = old | 0x01; |
| 408 | if (new == old) |
| 409 | return 0; |
| 410 | pci_write_byte(dev, 0x6d, new); |
| 411 | |
| 412 | if (pci_read_byte(dev, 0x6d) != new) { |
| 413 | printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", |
| 414 | 0x6d, new, name); |
| 415 | return -1; |
| 416 | } |
| 417 | |
| 418 | return 0; |
| 419 | |
| 420 | } |
| 421 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 422 | typedef struct penable { |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 423 | unsigned short vendor, device; |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 424 | char *name; |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 425 | int (*doit) (struct pci_dev * dev, char *name); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 426 | } FLASH_ENABLE; |
| 427 | |
| 428 | static FLASH_ENABLE enables[] = { |
Stefan Reinauer | eb36647 | 2006-09-06 15:48:48 +0000 | [diff] [blame] | 429 | {0x1039, 0x0630, "SIS630", enable_flash_sis630}, |
Uwe Hermann | ea2c66d | 2006-11-05 18:26:08 +0000 | [diff] [blame] | 430 | {0x8086, 0x7110, "PIIX4/PIIX4E/PIIX4M", enable_flash_piix4}, |
Stefan Reinauer | eb36647 | 2006-09-06 15:48:48 +0000 | [diff] [blame] | 431 | {0x8086, 0x2410, "ICH", enable_flash_ich_4e}, |
| 432 | {0x8086, 0x2420, "ICH0", enable_flash_ich_4e}, |
| 433 | {0x8086, 0x2440, "ICH2", enable_flash_ich_4e}, |
| 434 | {0x8086, 0x244c, "ICH2-M", enable_flash_ich_4e}, |
| 435 | {0x8086, 0x2480, "ICH3-S", enable_flash_ich_4e}, |
| 436 | {0x8086, 0x248c, "ICH3-M", enable_flash_ich_4e}, |
| 437 | {0x8086, 0x24c0, "ICH4/ICH4-L", enable_flash_ich_4e}, |
| 438 | {0x8086, 0x24cc, "ICH4-M", enable_flash_ich_4e}, |
| 439 | {0x8086, 0x24d0, "ICH5/ICH5R", enable_flash_ich_4e}, |
| 440 | {0x8086, 0x2640, "ICH6/ICH6R", enable_flash_ich_dc}, |
| 441 | {0x8086, 0x2641, "ICH6-M", enable_flash_ich_dc}, |
| 442 | {0x8086, 0x27b8, "ICH7/ICH7R", enable_flash_ich_dc}, |
| 443 | {0x8086, 0x27b9, "ICH7M", enable_flash_ich_dc}, |
| 444 | {0x8086, 0x27bd, "ICH7MDH", enable_flash_ich_dc}, |
| 445 | {0x8086, 0x2810, "ICH8/ICH8R", enable_flash_ich_dc}, |
| 446 | {0x8086, 0x2812, "ICH8DH", enable_flash_ich_dc}, |
| 447 | {0x8086, 0x2814, "ICH8DO", enable_flash_ich_dc}, |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 448 | {0x1106, 0x8231, "VT8231", enable_flash_vt8231}, |
| 449 | {0x1106, 0x3177, "VT8235", enable_flash_vt8235}, |
Stefan Reinauer | 219b61e | 2006-10-14 21:04:49 +0000 | [diff] [blame] | 450 | {0x1106, 0x3227, "VT8237", enable_flash_vt8231}, |
Stefan Reinauer | c6b5f49 | 2006-11-07 10:22:20 +0000 | [diff] [blame] | 451 | {0x1106, 0x0686, "VT82C686", enable_flash_amd8111}, |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 452 | {0x1078, 0x0100, "CS5530", enable_flash_cs5530}, |
| 453 | {0x100b, 0x0510, "SC1100", enable_flash_sc1100}, |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 454 | {0x1039, 0x0008, "SIS5595", enable_flash_sis5595}, |
| 455 | {0x1022, 0x7468, "AMD8111", enable_flash_amd8111}, |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 456 | // this fallthrough looks broken. |
Yinghai Lu | 952dfce | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 457 | {0x10de, 0x0050, "NVIDIA CK804", enable_flash_ck804}, // LPC |
| 458 | {0x10de, 0x0051, "NVIDIA CK804", enable_flash_ck804}, // Pro |
| 459 | {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] | 460 | |
| 461 | {0x10de, 0x0260, "NVidia MCP51", enable_flash_ck804}, |
| 462 | {0x10de, 0x0261, "NVidia MCP51", enable_flash_ck804}, |
| 463 | {0x10de, 0x0262, "NVidia MCP51", enable_flash_ck804}, |
| 464 | {0x10de, 0x0263, "NVidia MCP51", enable_flash_ck804}, |
| 465 | |
Yinghai Lu | ca78297 | 2007-01-22 20:21:17 +0000 | [diff] [blame] | 466 | {0x10de, 0x0364, "NVIDIA MCP55", enable_flash_mcp55}, // LPC |
| 467 | {0x10de, 0x0367, "NVIDIA MCP55", enable_flash_mcp55}, // Pro |
| 468 | |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 469 | {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] | 470 | }; |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 471 | |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 472 | static int mbenable_island_aruma(void) |
| 473 | { |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 474 | #define EFIR 0x2e /* Extended function index register, either 0x2e or 0x4e */ |
| 475 | #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] | 476 | char b; |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 477 | |
| 478 | /* Disable the flash write protect. The flash write protect is |
| 479 | * connected to the WinBond w83627hf GPIO 24. |
| 480 | */ |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 481 | |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 482 | printf("Disabling mainboard flash write protection.\n"); |
| 483 | |
| 484 | outb(0x87, EFIR); // sequence to unlock extended functions |
| 485 | outb(0x87, EFIR); |
| 486 | |
| 487 | outb(0x20, EFIR); // SIO device ID register |
| 488 | b = inb(EFDR); |
| 489 | printf_debug("W83627HF device ID = 0x%x\n",b); |
| 490 | |
| 491 | if (b != 0x52) { |
| 492 | perror("Incorrect device ID, aborting write protect disable\n"); |
| 493 | exit(1); |
| 494 | } |
| 495 | |
| 496 | outb(0x2b, EFIR); // GPIO multiplexed pin reg. |
| 497 | b = inb(EFDR) | 0x10; |
| 498 | outb(0x2b, EFIR); |
| 499 | outb(b, EFDR); // select GPIO 24 instead of WDTO |
| 500 | |
| 501 | outb(0x7, EFIR); // logical device select |
| 502 | outb(0x8, EFDR); // point to device 8, GPIO port 2 |
| 503 | |
| 504 | outb(0x30, EFIR); // logic device activation control |
| 505 | outb(0x1, EFDR); // activate |
| 506 | |
| 507 | outb(0xf0, EFIR); // GPIO 20-27 I/O selection register |
| 508 | b = inb(EFDR) & ~0x10; |
| 509 | outb(0xf0, EFIR); |
| 510 | outb(b, EFDR); // set GPIO 24 as an output |
| 511 | |
| 512 | outb(0xf1, EFIR); // GPIO 20-27 data register |
| 513 | b = inb(EFDR) | 0x10; |
| 514 | outb(0xf1, EFIR); |
| 515 | outb(b, EFDR); // set GPIO 24 |
| 516 | |
| 517 | outb(0xaa, EFIR); // command to exit extended functions |
| 518 | |
| 519 | return 0; |
| 520 | } |
| 521 | |
| 522 | typedef struct mbenable { |
| 523 | char *vendor, *part; |
| 524 | int (*doit)(void); |
| 525 | } MAINBOARD_ENABLE; |
| 526 | |
| 527 | static MAINBOARD_ENABLE mbenables[] = { |
| 528 | { "ISLAND", "ARUMA", mbenable_island_aruma }, |
| 529 | }; |
| 530 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 531 | int enable_flash_write() |
| 532 | { |
| 533 | int i; |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 534 | struct pci_dev *dev = 0; |
| 535 | FLASH_ENABLE *enable = 0; |
| 536 | |
Adam Kaufman | 064b1f2 | 2007-02-06 19:47:50 +0000 | [diff] [blame] | 537 | /* get io privilege access PCI configuration space */ |
| 538 | #if defined (__sun) && (defined(__i386) || defined(__amd64)) |
| 539 | if (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) != 0){ |
| 540 | #else |
| 541 | if (iopl(3) != 0) { |
| 542 | #endif |
| 543 | perror("Can not set io privilege"); |
| 544 | exit(1); |
| 545 | } |
| 546 | |
| 547 | |
| 548 | /* Initialize PCI access */ |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 549 | pacc = pci_alloc(); /* Get the pci_access structure */ |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 550 | /* Set all options you want -- here we stick with the defaults */ |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 551 | pci_init(pacc); /* Initialize the PCI library */ |
| 552 | pci_scan_bus(pacc); /* We want to get the list of devices */ |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 553 | |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 554 | |
| 555 | /* First look whether we have to do something for this |
| 556 | * motherboard. |
| 557 | */ |
| 558 | for (i = 0; i < sizeof(mbenables) / sizeof(mbenables[0]); i++) { |
| 559 | if(lb_vendor && !strcmp(mbenables[i].vendor, lb_vendor) && |
| 560 | lb_part && !strcmp(mbenables[i].part, lb_part)) { |
| 561 | mbenables[i].doit(); |
| 562 | break; |
| 563 | } |
| 564 | } |
| 565 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 566 | /* now let's try to find the chipset we have ... */ |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 567 | for (i = 0; i < sizeof(enables) / sizeof(enables[0]) && (!dev); |
| 568 | i++) { |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 569 | struct pci_filter f; |
| 570 | struct pci_dev *z; |
| 571 | /* the first param is unused. */ |
| 572 | pci_filter_init((struct pci_access *) 0, &f); |
| 573 | f.vendor = enables[i].vendor; |
| 574 | f.device = enables[i].device; |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 575 | for (z = pacc->devices; z; z = z->next) |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 576 | if (pci_filter_match(&f, z)) { |
| 577 | enable = &enables[i]; |
| 578 | dev = z; |
| 579 | } |
| 580 | } |
| 581 | |
Stefan Reinauer | cbc55d0 | 2006-08-25 19:21:42 +0000 | [diff] [blame] | 582 | if (!enable) { |
| 583 | printf("Warning: Unknown system. Flash detection " |
| 584 | "will most likely fail.\n"); |
| 585 | return 1; |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 586 | } |
Stefan Reinauer | cbc55d0 | 2006-08-25 19:21:42 +0000 | [diff] [blame] | 587 | |
| 588 | /* now do the deed. */ |
| 589 | printf("Enabling flash write on %s...", enable->name); |
| 590 | if (enable->doit(dev, enable->name) == 0) |
| 591 | printf("OK\n"); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 592 | return 0; |
| 593 | } |