Changeset 3401
- Timestamp:
- 07/01/08 01:45:22 (3 months ago)
- Location:
- trunk/util/flashrom
- Files:
-
- 5 modified
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 -
trunk/util/flashrom/flash.h
r3399 r3401 371 371 int chipset_flash_enable(void); 372 372 void print_supported_chipsets(void); 373 extern int ich7_detected; 374 extern int viaspi_detected; 375 extern int ich9_detected; 376 extern void *ich_spibar; 373 374 typedef enum { 375 BUS_TYPE_LPC, 376 BUS_TYPE_ICH7_SPI, 377 BUS_TYPE_ICH9_SPI, 378 BUS_TYPE_IT87XX_SPI, 379 BUS_TYPE_VIA_SPI 380 } flashbus_t; 381 382 extern flashbus_t flashbus; 383 extern void *spibar; 377 384 378 385 /* Physical memory mapping device */ -
trunk/util/flashrom/ichspi.c
r3398 r3401 132 132 { 133 133 volatile uint32_t regval; 134 regval = *(volatile uint32_t *) ((uint8_t *) ich_spibar + X);134 regval = *(volatile uint32_t *) ((uint8_t *) spibar + X); 135 135 return regval; 136 136 } … … 139 139 { 140 140 volatile uint16_t regval; 141 regval = *(volatile uint16_t *) ((uint8_t *) ich_spibar + X);141 regval = *(volatile uint16_t *) ((uint8_t *) spibar + X); 142 142 return regval; 143 143 } 144 144 145 #define REGWRITE32(X,Y) (*(uint32_t *)((uint8_t *) ich_spibar+X)=Y)146 #define REGWRITE16(X,Y) (*(uint16_t *)((uint8_t *) ich_spibar+X)=Y)147 #define REGWRITE8(X,Y) (*(uint8_t *)((uint8_t *) ich_spibar+X)=Y)145 #define REGWRITE32(X,Y) (*(uint32_t *)((uint8_t *)spibar+X)=Y) 146 #define REGWRITE16(X,Y) (*(uint16_t *)((uint8_t *)spibar+X)=Y) 147 #define REGWRITE8(X,Y) (*(uint8_t *)((uint8_t *)spibar+X)=Y) 148 148 149 149 /* Common SPI functions */ … … 176 176 { 177 177 uint8_t a; 178 uint16_t temp16;179 uint32_t temp32;178 uint16_t preop, optype; 179 uint32_t opmenu[2]; 180 180 181 181 /* Program Prefix Opcodes */ 182 temp16= 0;182 preop = 0; 183 183 /* 0:7 Prefix Opcode 1 */ 184 temp16= (op->preop[0]);184 preop = (op->preop[0]); 185 185 /* 8:16 Prefix Opcode 2 */ 186 temp16 |= ((uint16_t) op->preop[1]) << 8; 187 if ((ich7_detected) || (viaspi_detected)) { 188 REGWRITE16(ICH7_REG_PREOP, temp16); 189 } else if (ich9_detected) { 190 REGWRITE16(ICH9_REG_PREOP, temp16); 191 } 192 186 preop |= ((uint16_t) op->preop[1]) << 8; 187 193 188 /* Program Opcode Types 0 - 7 */ 194 temp16= 0;189 optype = 0; 195 190 for (a = 0; a < 8; a++) { 196 temp16 |= ((uint16_t) op->opcode[a].spi_type) << (a * 2); 197 } 198 199 if ((ich7_detected) || (viaspi_detected)) { 200 REGWRITE16(ICH7_REG_OPTYPE, temp16); 201 } else if (ich9_detected) { 202 REGWRITE16(ICH9_REG_OPTYPE, temp16); 203 } 204 205 191 optype |= ((uint16_t) op->opcode[a].spi_type) << (a * 2); 192 } 193 206 194 /* Program Allowable Opcodes 0 - 3 */ 207 temp32= 0;195 opmenu[0] = 0; 208 196 for (a = 0; a < 4; a++) { 209 temp32 |= ((uint32_t) op->opcode[a].opcode) << (a * 8); 210 } 211 212 if ((ich7_detected) || (viaspi_detected)) { 213 REGWRITE32(ICH7_REG_OPMENU, temp32); 214 } else if (ich9_detected) { 215 REGWRITE32(ICH9_REG_OPMENU, temp32); 216 } 217 197 opmenu[0] |= ((uint32_t) op->opcode[a].opcode) << (a * 8); 198 } 218 199 219 200 /*Program Allowable Opcodes 4 - 7 */ 220 temp32= 0;201 opmenu[1] = 0; 221 202 for (a = 4; a < 8; a++) { 222 temp32 |= 223 ((uint32_t) op->opcode[a].opcode) << ((a - 4) * 8); 224 } 225 226 if ((ich7_detected) || (viaspi_detected)) { 227 REGWRITE32(ICH7_REG_OPMENU + 4, temp32); 228 } else if (ich9_detected) { 229 REGWRITE32(ICH9_REG_OPMENU + 4, temp32); 203 opmenu[1] |= ((uint32_t) op->opcode[a].opcode) << ((a - 4) * 8); 204 } 205 206 switch (flashbus) { 207 case BUS_TYPE_ICH7_SPI: 208 case BUS_TYPE_VIA_SPI: 209 REGWRITE16(ICH7_REG_PREOP, preop); 210 REGWRITE16(ICH7_REG_OPTYPE, optype); 211 REGWRITE32(ICH7_REG_OPMENU, opmenu[0]); 212 REGWRITE32(ICH7_REG_OPMENU + 4, opmenu[1]); 213 break; 214 case BUS_TYPE_ICH9_SPI: 215 REGWRITE16(ICH9_REG_PREOP, preop); 216 REGWRITE16(ICH9_REG_OPTYPE, optype); 217 REGWRITE32(ICH9_REG_OPMENU, opmenu[0]); 218 REGWRITE32(ICH9_REG_OPMENU + 4, opmenu[1]); 219 break; 220 default: 221 printf_debug("%s: unsupported chipset\n", __FUNCTION__); 222 return -1; 230 223 } 231 224 … … 341 334 { 342 335 int write_cmd = 0; 336 int timeout; 343 337 uint32_t temp32; 344 338 uint32_t a; … … 411 405 412 406 /*wait for cycle complete */ 413 while ((REGREAD32(ICH9_REG_SSFS) & SSFS_CDS) == 0) { 414 /*TODO; Do something that this can't lead into an endless loop. but some 415 * commands may cause this to be last more than 30 seconds */ 407 timeout = 1000 * 60; // 60s is a looong timeout. 408 while (((REGREAD32(ICH9_REG_SSFS) & SSFS_CDS) == 0) && --timeout) { 409 myusec_delay(1000); 410 } 411 if (!timeout) { 412 printf_debug("timeout\n"); 416 413 } 417 414 … … 439 436 uint8_t datalength, uint8_t * data) 440 437 { 441 if (ich7_detected) 438 switch (flashbus) { 439 case BUS_TYPE_VIA_SPI: 440 return ich7_run_opcode(nr, op, offset, datalength, data, 16); 441 case BUS_TYPE_ICH7_SPI: 442 442 return ich7_run_opcode(nr, op, offset, datalength, data, 64); 443 else if (viaspi_detected) 444 return ich7_run_opcode(nr, op, offset, datalength, data, 16); 445 else if (ich9_detected) 443 case BUS_TYPE_ICH9_SPI: 446 444 return ich9_run_opcode(nr, op, offset, datalength, data); 445 default: 446 printf_debug("%s: unsupported chipset\n", __FUNCTION__); 447 } 447 448 448 449 /* If we ever get here, something really weird happened */ … … 542 543 int maxdata = 64; 543 544 544 if ( viaspi_detected) {545 if (flashbus == BUS_TYPE_VIA_SPI) { 545 546 maxdata = 16; 546 547 } … … 573 574 } 574 575 575 if ( viaspi_detected) {576 if (flashbus == BUS_TYPE_VIA_SPI) { 576 577 maxdata = 16; 577 578 } -
trunk/util/flashrom/it87spi.c
r3344 r3401 4 4 * Copyright (C) 2007, 2008 Carl-Daniel Hailfinger 5 5 * Copyright (C) 2008 Ronald Hoogenboom <ronald@zonnet.nl> 6 * Copyright (C) 2008 coresystems GmbH 6 7 * 7 8 * This program is free software; you can redistribute it and/or modify … … 113 114 { 114 115 it8716f_flashport = find_ite_spi_flash_port(ITE_SUPERIO_PORT1); 116 115 117 if (!it8716f_flashport) 116 118 it8716f_flashport = find_ite_spi_flash_port(ITE_SUPERIO_PORT2); 119 120 if (it8716f_flashport) 121 flashbus = BUS_TYPE_IT87XX_SPI; 122 117 123 return (!it8716f_flashport); 118 124 } -
trunk/util/flashrom/spi.c
r3399 r3401 35 35 int spi_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr) 36 36 { 37 if (it8716f_flashport) 37 switch (flashbus) { 38 case BUS_TYPE_IT87XX_SPI: 38 39 return it8716f_spi_command(writecnt, readcnt, writearr, readarr); 39 else if ((ich7_detected) || (viaspi_detected)) 40 return ich_spi_command(writecnt, readcnt, writearr, readarr); 41 else if (ich9_detected) 42 return ich_spi_command(writecnt, readcnt, writearr, readarr); 43 printf_debug("%s called, but no SPI chipset detected\n", __FUNCTION__); 40 case BUS_TYPE_ICH7_SPI: 41 case BUS_TYPE_ICH9_SPI: 42 case BUS_TYPE_VIA_SPI: 43 return ich_spi_command(writecnt, readcnt, writearr, readarr); 44 default: 45 printf_debug("%s called, but no SPI chipset/strapping detected\n", __FUNCTION__); 46 } 44 47 return 1; 45 48 } … … 136 139 137 140 /* only some SPI chipsets support 4 bytes commands */ 138 if (!((ich7_detected) || (ich9_detected) || (viaspi_detected))) 139 return 0; 140 return probe_spi_rdid_generic(flash, 4); 141 switch (flashbus) { 142 case BUS_TYPE_ICH7_SPI: 143 case BUS_TYPE_ICH9_SPI: 144 case BUS_TYPE_VIA_SPI: 145 return probe_spi_rdid_generic(flash, 4); 146 default: 147 printf_debug("4b ID not supported on this SPI controller\n"); 148 } 149 150 return 0; 141 151 } 142 152 … … 317 327 void spi_page_program(int block, uint8_t *buf, uint8_t *bios) 318 328 { 319 if (it8716f_flashport) { 329 switch (flashbus) { 330 case BUS_TYPE_IT87XX_SPI: 320 331 it8716f_spi_page_program(block, buf, bios); 321 return; 322 } 323 printf_debug("%s called, but no SPI chipset detected\n", __FUNCTION__); 332 break; 333 case BUS_TYPE_ICH7_SPI: 334 case BUS_TYPE_ICH9_SPI: 335 printf_debug("%s called, but not implemented for ICH\n", __FUNCTION__); 336 break; 337 default: 338 printf_debug("%s called, but no SPI chipset/strapping detected\n", __FUNCTION__); 339 } 324 340 } 325 341 … … 376 392 int spi_chip_read(struct flashchip *flash, uint8_t *buf) 377 393 { 378 if (it8716f_flashport) 394 395 switch (flashbus) { 396 case BUS_TYPE_IT87XX_SPI: 379 397 return it8716f_spi_chip_read(flash, buf); 380 else if ((ich7_detected) || (viaspi_detected)) 398 case BUS_TYPE_ICH7_SPI: 399 case BUS_TYPE_ICH9_SPI: 400 case BUS_TYPE_VIA_SPI: 381 401 return ich_spi_read(flash, buf); 382 else if (ich9_detected) 383 return ich_spi_read(flash, buf); 384 printf_debug("%s called, but no SPI chipset detected\n", __FUNCTION__); 402 default: 403 printf_debug("%s called, but no SPI chipset/strapping detected\n", __FUNCTION__); 404 } 405 385 406 return 1; 386 407 } … … 388 409 int spi_chip_write(struct flashchip *flash, uint8_t *buf) 389 410 { 390 if (it8716f_flashport) 411 switch (flashbus) { 412 case BUS_TYPE_IT87XX_SPI: 391 413 return it8716f_spi_chip_write(flash, buf); 392 else if ((ich7_detected) || (viaspi_detected)) 414 case BUS_TYPE_ICH7_SPI: 415 case BUS_TYPE_ICH9_SPI: 416 case BUS_TYPE_VIA_SPI: 393 417 return ich_spi_write(flash, buf); 394 else if (ich9_detected) 395 return ich_spi_write(flash, buf); 396 printf_debug("%s called, but no SPI chipset detected\n", __FUNCTION__); 418 default: 419 printf_debug("%s called, but no SPI chipset/strapping detected\n", __FUNCTION__); 420 } 421 397 422 return 1; 398 423 }
