Show
Ignore:
Timestamp:
07/01/08 01:45:22 (5 months ago)
Author:
stepan
Message:

First attempt to clean up SPI probing and create a common
construct: the flash bus.

At some point the flash bus will be part of struct flashchip.

Pardon me for pushing this in, but I think it is important to beware of further
decay and it will improve things for other developers in the short run.

Carl-Daniel, I will consider your suggestions in another patch. I want to keep
things from getting too much for now. The patch includes Rudolf's VIA SPI
changes though.

Signed-off-by: Stefan Reinauer <stepan@…>
Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@…>

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/util/flashrom/chipset_enable.c

    r3398 r3401  
    3636#include "flash.h" 
    3737 
     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 
     45flashbus_t flashbus = BUS_TYPE_LPC; 
     46void *spibar = NULL; 
     47 
     48 
    3849static int enable_flash_ali_m1533(struct pci_dev *dev, const char *name) 
    3950{ 
     
    125136         * Set bit 2: BIOSCS# Write Enable (1=enable, 0=disable). 
    126137         */ 
    127         new = old | 0x2c4; 
     138        new = old | 0x02c4; 
    128139 
    129140        if (new == old) 
     
    186197} 
    187198 
    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 
    189203 
    190204static int enable_flash_vt8237s_spi(struct pci_dev *dev, const char *name) { 
     
    193207        mmio_base = (pci_read_long(dev, 0xbc)) << 8; 
    194208        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, 
    196210                                fd_mem, mmio_base); 
    197211 
    198         if (ich_spibar == MAP_FAILED) { 
     212        if (spibar == MAP_FAILED) { 
    199213                perror("Can't mmap memory using " MEM_DEV); 
    200214                exit(1); 
    201215        } 
    202216 
    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 
     224static int enable_flash_ich_dc_spi(struct pci_dev *dev, const char *name, int ich_generation) 
     225{ 
     226        int ret, i; 
    210227        uint8_t old, new, bbs, buc; 
     228        uint16_t spibar_offset; 
    211229        uint32_t tmp, gcs; 
    212230        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; 
    219238        printf_debug("\nRoot Complex Register Block address = 0x%x\n", tmp); 
     239 
     240        /* Map RCBA to virtual memory */ 
    220241        rcrb = mmap(0, 0x4000, PROT_READ | PROT_WRITE, MAP_SHARED, fd_mem, (off_t)tmp); 
    221242        if (rcrb == MAP_FAILED) { 
     
    223244                exit(1); 
    224245        } 
    225         printf_debug("GCS address = 0x%x\n", tmp + 0x3410); 
     246 
    226247        gcs = *(volatile uint32_t *)(rcrb + 0x3410); 
    227248        printf_debug("GCS = 0x%x: ", gcs); 
     
    229250                     (gcs & 0x1) ? "en" : "dis"); 
    230251        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]); 
    235253 
    236254        buc = *(volatile uint8_t *)(rcrb + 0x3414); 
    237255        printf_debug("Top Swap : %s\n", (buc & 1)?"enabled (A16 inverted)":"not enabled"); 
    238256 
     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 
    239283        /* 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 Address 
    243         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)); 
    250294                for (i=0; i < 8; i++) { 
    251295                        int offs; 
    252296                        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)); 
    261305                for (i=0; i < 4; i++) { 
    262306                        int offs; 
    263307                        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); 
    265309                } 
    266310                printf_debug("\n"); 
    267                 if ( (*(uint16_t *)ich_spibar) & (1 << 15)) { 
     311                if ( (*(uint16_t *)spibar) & (1 << 15)) { 
    268312                        printf("WARNING: SPI Configuration Lockdown activated.\n"); 
    269313                } 
     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; 
    270324        } 
    271325 
     
    278332        case 2: 
    279333                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"); 
    281336                break; 
    282337        default: 
     
    284339                break; 
    285340        } 
    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} 
    292344 
    293345static int enable_flash_ich7(struct pci_dev *dev, const char *name) 
    294346{ 
    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} 
    301349 
    302350static int enable_flash_ich8(struct pci_dev *dev, const char *name) 
    303351{ 
    304         ich9_detected = 1; 
    305         return enable_flash_ich_dc_spi(dev, name, 0x3020); 
     352        return enable_flash_ich_dc_spi(dev, name, 8); 
    306353} 
    307354 
    308355static int enable_flash_ich9(struct pci_dev *dev, const char *name) 
    309356{ 
    310         ich9_detected = 1; 
    311         return enable_flash_ich_dc_spi(dev, name, 0x3800); 
     357        return enable_flash_ich_dc_spi(dev, name, 9); 
    312358} 
    313359