Changeset 3401 for trunk/util/flashrom/chipset_enable.c
- Timestamp:
- 07/01/08 01:45:22 (5 months ago)
- Files:
-
- 1 modified
-
trunk/util/flashrom/chipset_enable.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/util/flashrom/chipset_enable.c
r3398 r3401 36 36 #include "flash.h" 37 37 38 /** 39 * flashrom defaults to LPC flash devices. If a known SPI controller is found 40 * and the SPI strappings are set, this will be overwritten by the probing code. 41 * 42 * Eventually, this will become an array when multiple flash support works. 43 */ 44 45 flashbus_t flashbus = BUS_TYPE_LPC; 46 void *spibar = NULL; 47 48 38 49 static int enable_flash_ali_m1533(struct pci_dev *dev, const char *name) 39 50 { … … 125 136 * Set bit 2: BIOSCS# Write Enable (1=enable, 0=disable). 126 137 */ 127 new = old | 0x 2c4;138 new = old | 0x02c4; 128 139 129 140 if (new == old) … … 186 197 } 187 198 188 void *ich_spibar = NULL; 199 #define ICH_STRAP_RSVD 0x00 200 #define ICH_STRAP_SPI 0x01 201 #define ICH_STRAP_PCI 0x02 202 #define ICH_STRAP_LPC 0x03 189 203 190 204 static int enable_flash_vt8237s_spi(struct pci_dev *dev, const char *name) { … … 193 207 mmio_base = (pci_read_long(dev, 0xbc)) << 8; 194 208 printf_debug("MMIO base at = 0x%x\n", mmio_base); 195 ich_spibar = mmap(NULL, 0x70, PROT_READ | PROT_WRITE, MAP_SHARED,209 spibar = mmap(NULL, 0x70, PROT_READ | PROT_WRITE, MAP_SHARED, 196 210 fd_mem, mmio_base); 197 211 198 if ( ich_spibar == MAP_FAILED) {212 if (spibar == MAP_FAILED) { 199 213 perror("Can't mmap memory using " MEM_DEV); 200 214 exit(1); 201 215 } 202 216 203 printf_debug("0x6c: 0x%04x (CLOCK/DEBUG)\n", *(uint16_t *)(ich_spibar + 0x6c)); 204 viaspi_detected = 1; 205 return 0; 206 } 207 208 static int enable_flash_ich_dc_spi(struct pci_dev *dev, const char *name, unsigned long spibar) 209 { 217 printf_debug("0x6c: 0x%04x (CLOCK/DEBUG)\n", *(uint16_t *)(spibar + 0x6c)); 218 219 flashbus = BUS_TYPE_VIA_SPI; 220 221 return 0; 222 } 223 224 static int enable_flash_ich_dc_spi(struct pci_dev *dev, const char *name, int ich_generation) 225 { 226 int ret, i; 210 227 uint8_t old, new, bbs, buc; 228 uint16_t spibar_offset; 211 229 uint32_t tmp, gcs; 212 230 void *rcrb; 213 214 /* Read the Root Complex Base Address Register (RCBA) */ 215 tmp = pci_read_long(dev, 0xf0); 216 217 /* Calculate the Root Complex Register Block address */ 218 tmp &= 0xffffc000; 231 static const char *straps_names[] = { "reserved", "SPI", "PCI", "LPC" }; 232 233 /* Enable Flash Writes */ 234 ret = enable_flash_ich_dc(dev, name); 235 236 /* Get physical address of Root Complex Register Block */ 237 tmp = pci_read_long(dev, 0xf0) & 0xffffc000; 219 238 printf_debug("\nRoot Complex Register Block address = 0x%x\n", tmp); 239 240 /* Map RCBA to virtual memory */ 220 241 rcrb = mmap(0, 0x4000, PROT_READ | PROT_WRITE, MAP_SHARED, fd_mem, (off_t)tmp); 221 242 if (rcrb == MAP_FAILED) { … … 223 244 exit(1); 224 245 } 225 printf_debug("GCS address = 0x%x\n", tmp + 0x3410); 246 226 247 gcs = *(volatile uint32_t *)(rcrb + 0x3410); 227 248 printf_debug("GCS = 0x%x: ", gcs); … … 229 250 (gcs & 0x1) ? "en" : "dis"); 230 251 bbs = (gcs >> 10) & 0x3; 231 printf_debug("BOOT BIOS Straps: 0x%x (%s)\n", bbs, 232 (bbs == 0x3) ? "LPC" : ((bbs == 0x2) ? "PCI" : "SPI")); 233 if (bbs >= 2) 234 ich7_detected = 0; 252 printf_debug("BOOT BIOS Straps: 0x%x (%s)\n", bbs, straps_names[bbs]); 235 253 236 254 buc = *(volatile uint8_t *)(rcrb + 0x3414); 237 255 printf_debug("Top Swap : %s\n", (buc & 1)?"enabled (A16 inverted)":"not enabled"); 238 256 257 /* It seems the ICH7 does not support SPI and LPC chips at the same 258 * time. At least not with our current code. So we prevent searching 259 * on ICH7 when the southbridge is strapped to LPC 260 */ 261 262 if (ich_generation == 7 && bbs == ICH_STRAP_LPC) { 263 /* No further SPI initialization required */ 264 return ret; 265 } 266 267 switch (ich_generation) { 268 case 7: 269 flashbus = BUS_TYPE_ICH7_SPI; 270 spibar_offset = 0x3020; 271 break; 272 case 8: 273 flashbus = BUS_TYPE_ICH9_SPI; 274 spibar_offset = 0x3020; 275 break; 276 case 9: 277 default: /* Future version might behave the same */ 278 flashbus = BUS_TYPE_ICH9_SPI; 279 spibar_offset = 0x3800; 280 break; 281 } 282 239 283 /* SPIBAR is at RCRB+0x3020 for ICH[78] and RCRB+0x3800 for ICH9. */ 240 printf_debug("SPIBAR = 0x%x + 0x%04x\n", tmp, (uint16_t)spibar);241 242 / / Assign Virtual Address243 ich_spibar = rcrb + spibar;244 245 if (ich7_detected) {246 int i;247 printf_debug("0x00: 0x%04x (SPIS)\n", *(uint16_t *)( ich_spibar + 0));248 printf_debug("0x02: 0x%04x (SPIC)\n", *(uint16_t *)( ich_spibar + 2));249 printf_debug("0x04: 0x%08x (SPIA)\n", *(uint32_t *)( ich_spibar + 4));284 printf_debug("SPIBAR = 0x%x + 0x%04x\n", tmp, spibar_offset); 285 286 /* Assign Virtual Address */ 287 spibar = rcrb + spibar_offset; 288 289 switch (flashbus) { 290 case BUS_TYPE_ICH7_SPI: 291 printf_debug("0x00: 0x%04x (SPIS)\n", *(uint16_t *)(spibar + 0)); 292 printf_debug("0x02: 0x%04x (SPIC)\n", *(uint16_t *)(spibar + 2)); 293 printf_debug("0x04: 0x%08x (SPIA)\n", *(uint32_t *)(spibar + 4)); 250 294 for (i=0; i < 8; i++) { 251 295 int offs; 252 296 offs = 8 + (i * 8); 253 printf_debug("0x%02x: 0x%08x (SPID%d)\n", offs, *(uint32_t *)( ich_spibar + offs), i);254 printf_debug("0x%02x: 0x%08x (SPID%d+4)\n", offs+4, *(uint32_t *)( ich_spibar + offs +4), i);255 } 256 printf_debug("0x50: 0x%08x (BBAR)\n", *(uint32_t *)( ich_spibar + 0x50));257 printf_debug("0x54: 0x%04x (PREOP)\n", *(uint16_t *)( ich_spibar + 0x54));258 printf_debug("0x56: 0x%04x (OPTYPE)\n", *(uint16_t *)( ich_spibar + 0x56));259 printf_debug("0x58: 0x%08x (OPMENU)\n", *(uint32_t *)( ich_spibar + 0x58));260 printf_debug("0x5c: 0x%08x (OPMENU+4)\n", *(uint32_t *)( ich_spibar + 0x5c));297 printf_debug("0x%02x: 0x%08x (SPID%d)\n", offs, *(uint32_t *)(spibar + offs), i); 298 printf_debug("0x%02x: 0x%08x (SPID%d+4)\n", offs+4, *(uint32_t *)(spibar + offs +4), i); 299 } 300 printf_debug("0x50: 0x%08x (BBAR)\n", *(uint32_t *)(spibar + 0x50)); 301 printf_debug("0x54: 0x%04x (PREOP)\n", *(uint16_t *)(spibar + 0x54)); 302 printf_debug("0x56: 0x%04x (OPTYPE)\n", *(uint16_t *)(spibar + 0x56)); 303 printf_debug("0x58: 0x%08x (OPMENU)\n", *(uint32_t *)(spibar + 0x58)); 304 printf_debug("0x5c: 0x%08x (OPMENU+4)\n", *(uint32_t *)(spibar + 0x5c)); 261 305 for (i=0; i < 4; i++) { 262 306 int offs; 263 307 offs = 0x60 + (i * 4); 264 printf_debug("0x%02x: 0x%08x (PBR%d)\n", offs, *(uint32_t *)( ich_spibar + offs), i);308 printf_debug("0x%02x: 0x%08x (PBR%d)\n", offs, *(uint32_t *)(spibar + offs), i); 265 309 } 266 310 printf_debug("\n"); 267 if ( (*(uint16_t *) ich_spibar) & (1 << 15)) {311 if ( (*(uint16_t *)spibar) & (1 << 15)) { 268 312 printf("WARNING: SPI Configuration Lockdown activated.\n"); 269 313 } 314 break; 315 case BUS_TYPE_ICH9_SPI: 316 /* TODO: Add dumping function for ICH8/ICH9, or drop the 317 * whole SPIBAR dumping from chipset_enable.c - There's 318 * inteltool for this task already. 319 */ 320 break; 321 default: 322 /* Nothing */ 323 break; 270 324 } 271 325 … … 278 332 case 2: 279 333 printf_debug("prefetching %sabled, caching %sabled, ", 280 (new & 0x2) ? "en" : "dis", (new & 0x1) ? "dis" : "en"); 334 (new & 0x2) ? "en" : "dis", 335 (new & 0x1) ? "dis" : "en"); 281 336 break; 282 337 default: … … 284 339 break; 285 340 } 286 return enable_flash_ich_dc(dev, name); 287 } 288 289 /* Flag for ICH7 SPI register block */ 290 int ich7_detected = 0; 291 int viaspi_detected = 0; 341 342 return ret; 343 } 292 344 293 345 static int enable_flash_ich7(struct pci_dev *dev, const char *name) 294 346 { 295 ich7_detected = 1; 296 return enable_flash_ich_dc_spi(dev, name, 0x3020); 297 } 298 299 /* Flag for ICH8/ICH9 SPI register block */ 300 int ich9_detected = 0; 347 return enable_flash_ich_dc_spi(dev, name, 7); 348 } 301 349 302 350 static int enable_flash_ich8(struct pci_dev *dev, const char *name) 303 351 { 304 ich9_detected = 1; 305 return enable_flash_ich_dc_spi(dev, name, 0x3020); 352 return enable_flash_ich_dc_spi(dev, name, 8); 306 353 } 307 354 308 355 static int enable_flash_ich9(struct pci_dev *dev, const char *name) 309 356 { 310 ich9_detected = 1; 311 return enable_flash_ich_dc_spi(dev, name, 0x3800); 357 return enable_flash_ich_dc_spi(dev, name, 9); 312 358 } 313 359
