1*29175778SLew Glendenning /* 2*29175778SLew Glendenning * esb2rom.c 3*29175778SLew Glendenning * 4*29175778SLew Glendenning * Normal mappings of flash chips in physical memory 5*29175778SLew Glendenning * through the Intel ESB2 Southbridge. 6*29175778SLew Glendenning * 7*29175778SLew Glendenning * This was derived from ichxrom.c in May 2006 by 8*29175778SLew Glendenning * Lew Glendenning <lglendenning@lnxi.com> 9*29175778SLew Glendenning * 10*29175778SLew Glendenning * Eric Biederman, of course, was a major help in this effort. 11*29175778SLew Glendenning */ 12*29175778SLew Glendenning 13*29175778SLew Glendenning #include <linux/module.h> 14*29175778SLew Glendenning #include <linux/types.h> 15*29175778SLew Glendenning #include <linux/version.h> 16*29175778SLew Glendenning #include <linux/kernel.h> 17*29175778SLew Glendenning #include <linux/init.h> 18*29175778SLew Glendenning #include <asm/io.h> 19*29175778SLew Glendenning #include <linux/mtd/mtd.h> 20*29175778SLew Glendenning #include <linux/mtd/map.h> 21*29175778SLew Glendenning #include <linux/mtd/cfi.h> 22*29175778SLew Glendenning #include <linux/mtd/flashchip.h> 23*29175778SLew Glendenning #include <linux/pci.h> 24*29175778SLew Glendenning #include <linux/pci_ids.h> 25*29175778SLew Glendenning #include <linux/list.h> 26*29175778SLew Glendenning 27*29175778SLew Glendenning #define MOD_NAME KBUILD_BASENAME 28*29175778SLew Glendenning 29*29175778SLew Glendenning #define ADDRESS_NAME_LEN 18 30*29175778SLew Glendenning 31*29175778SLew Glendenning #define ROM_PROBE_STEP_SIZE (64*1024) /* 64KiB */ 32*29175778SLew Glendenning 33*29175778SLew Glendenning #define BIOS_CNTL 0xDC 34*29175778SLew Glendenning #define BIOS_LOCK_ENABLE 0x02 35*29175778SLew Glendenning #define BIOS_WRITE_ENABLE 0x01 36*29175778SLew Glendenning 37*29175778SLew Glendenning /* This became a 16-bit register, and EN2 has disappeared */ 38*29175778SLew Glendenning #define FWH_DEC_EN1 0xD8 39*29175778SLew Glendenning #define FWH_F8_EN 0x8000 40*29175778SLew Glendenning #define FWH_F0_EN 0x4000 41*29175778SLew Glendenning #define FWH_E8_EN 0x2000 42*29175778SLew Glendenning #define FWH_E0_EN 0x1000 43*29175778SLew Glendenning #define FWH_D8_EN 0x0800 44*29175778SLew Glendenning #define FWH_D0_EN 0x0400 45*29175778SLew Glendenning #define FWH_C8_EN 0x0200 46*29175778SLew Glendenning #define FWH_C0_EN 0x0100 47*29175778SLew Glendenning #define FWH_LEGACY_F_EN 0x0080 48*29175778SLew Glendenning #define FWH_LEGACY_E_EN 0x0040 49*29175778SLew Glendenning /* reserved 0x0020 and 0x0010 */ 50*29175778SLew Glendenning #define FWH_70_EN 0x0008 51*29175778SLew Glendenning #define FWH_60_EN 0x0004 52*29175778SLew Glendenning #define FWH_50_EN 0x0002 53*29175778SLew Glendenning #define FWH_40_EN 0x0001 54*29175778SLew Glendenning 55*29175778SLew Glendenning /* these are 32-bit values */ 56*29175778SLew Glendenning #define FWH_SEL1 0xD0 57*29175778SLew Glendenning #define FWH_SEL2 0xD4 58*29175778SLew Glendenning 59*29175778SLew Glendenning #define FWH_8MiB (FWH_F8_EN | FWH_F0_EN | FWH_E8_EN | FWH_E0_EN | \ 60*29175778SLew Glendenning FWH_D8_EN | FWH_D0_EN | FWH_C8_EN | FWH_C0_EN | \ 61*29175778SLew Glendenning FWH_70_EN | FWH_60_EN | FWH_50_EN | FWH_40_EN) 62*29175778SLew Glendenning 63*29175778SLew Glendenning #define FWH_7MiB (FWH_F8_EN | FWH_F0_EN | FWH_E8_EN | FWH_E0_EN | \ 64*29175778SLew Glendenning FWH_D8_EN | FWH_D0_EN | FWH_C8_EN | FWH_C0_EN | \ 65*29175778SLew Glendenning FWH_70_EN | FWH_60_EN | FWH_50_EN) 66*29175778SLew Glendenning 67*29175778SLew Glendenning #define FWH_6MiB (FWH_F8_EN | FWH_F0_EN | FWH_E8_EN | FWH_E0_EN | \ 68*29175778SLew Glendenning FWH_D8_EN | FWH_D0_EN | FWH_C8_EN | FWH_C0_EN | \ 69*29175778SLew Glendenning FWH_70_EN | FWH_60_EN) 70*29175778SLew Glendenning 71*29175778SLew Glendenning #define FWH_5MiB (FWH_F8_EN | FWH_F0_EN | FWH_E8_EN | FWH_E0_EN | \ 72*29175778SLew Glendenning FWH_D8_EN | FWH_D0_EN | FWH_C8_EN | FWH_C0_EN | \ 73*29175778SLew Glendenning FWH_70_EN) 74*29175778SLew Glendenning 75*29175778SLew Glendenning #define FWH_4MiB (FWH_F8_EN | FWH_F0_EN | FWH_E8_EN | FWH_E0_EN | \ 76*29175778SLew Glendenning FWH_D8_EN | FWH_D0_EN | FWH_C8_EN | FWH_C0_EN) 77*29175778SLew Glendenning 78*29175778SLew Glendenning #define FWH_3_5MiB (FWH_F8_EN | FWH_F0_EN | FWH_E8_EN | FWH_E0_EN | \ 79*29175778SLew Glendenning FWH_D8_EN | FWH_D0_EN | FWH_C8_EN) 80*29175778SLew Glendenning 81*29175778SLew Glendenning #define FWH_3MiB (FWH_F8_EN | FWH_F0_EN | FWH_E8_EN | FWH_E0_EN | \ 82*29175778SLew Glendenning FWH_D8_EN | FWH_D0_EN) 83*29175778SLew Glendenning 84*29175778SLew Glendenning #define FWH_2_5MiB (FWH_F8_EN | FWH_F0_EN | FWH_E8_EN | FWH_E0_EN | \ 85*29175778SLew Glendenning FWH_D8_EN) 86*29175778SLew Glendenning 87*29175778SLew Glendenning #define FWH_2MiB (FWH_F8_EN | FWH_F0_EN | FWH_E8_EN | FWH_E0_EN) 88*29175778SLew Glendenning 89*29175778SLew Glendenning #define FWH_1_5MiB (FWH_F8_EN | FWH_F0_EN | FWH_E8_EN) 90*29175778SLew Glendenning 91*29175778SLew Glendenning #define FWH_1MiB (FWH_F8_EN | FWH_F0_EN) 92*29175778SLew Glendenning 93*29175778SLew Glendenning #define FWH_0_5MiB (FWH_F8_EN) 94*29175778SLew Glendenning 95*29175778SLew Glendenning 96*29175778SLew Glendenning struct esb2rom_window { 97*29175778SLew Glendenning void __iomem* virt; 98*29175778SLew Glendenning unsigned long phys; 99*29175778SLew Glendenning unsigned long size; 100*29175778SLew Glendenning struct list_head maps; 101*29175778SLew Glendenning struct resource rsrc; 102*29175778SLew Glendenning struct pci_dev *pdev; 103*29175778SLew Glendenning }; 104*29175778SLew Glendenning 105*29175778SLew Glendenning struct esb2rom_map_info { 106*29175778SLew Glendenning struct list_head list; 107*29175778SLew Glendenning struct map_info map; 108*29175778SLew Glendenning struct mtd_info *mtd; 109*29175778SLew Glendenning struct resource rsrc; 110*29175778SLew Glendenning char map_name[sizeof(MOD_NAME) + 2 + ADDRESS_NAME_LEN]; 111*29175778SLew Glendenning }; 112*29175778SLew Glendenning 113*29175778SLew Glendenning static struct esb2rom_window esb2rom_window = { 114*29175778SLew Glendenning .maps = LIST_HEAD_INIT(esb2rom_window.maps), 115*29175778SLew Glendenning }; 116*29175778SLew Glendenning 117*29175778SLew Glendenning static void esb2rom_cleanup(struct esb2rom_window *window) 118*29175778SLew Glendenning { 119*29175778SLew Glendenning struct esb2rom_map_info *map, *scratch; 120*29175778SLew Glendenning u8 byte; 121*29175778SLew Glendenning 122*29175778SLew Glendenning /* Disable writes through the rom window */ 123*29175778SLew Glendenning pci_read_config_byte(window->pdev, BIOS_CNTL, &byte); 124*29175778SLew Glendenning pci_write_config_byte(window->pdev, BIOS_CNTL, 125*29175778SLew Glendenning byte & ~BIOS_WRITE_ENABLE); 126*29175778SLew Glendenning 127*29175778SLew Glendenning /* Free all of the mtd devices */ 128*29175778SLew Glendenning list_for_each_entry_safe(map, scratch, &window->maps, list) { 129*29175778SLew Glendenning if (map->rsrc.parent) 130*29175778SLew Glendenning release_resource(&map->rsrc); 131*29175778SLew Glendenning del_mtd_device(map->mtd); 132*29175778SLew Glendenning map_destroy(map->mtd); 133*29175778SLew Glendenning list_del(&map->list); 134*29175778SLew Glendenning kfree(map); 135*29175778SLew Glendenning } 136*29175778SLew Glendenning if (window->rsrc.parent) 137*29175778SLew Glendenning release_resource(&window->rsrc); 138*29175778SLew Glendenning if (window->virt) { 139*29175778SLew Glendenning iounmap(window->virt); 140*29175778SLew Glendenning window->virt = NULL; 141*29175778SLew Glendenning window->phys = 0; 142*29175778SLew Glendenning window->size = 0; 143*29175778SLew Glendenning window->pdev = NULL; 144*29175778SLew Glendenning } 145*29175778SLew Glendenning } 146*29175778SLew Glendenning 147*29175778SLew Glendenning static int __devinit esb2rom_init_one(struct pci_dev *pdev, 148*29175778SLew Glendenning const struct pci_device_id *ent) 149*29175778SLew Glendenning { 150*29175778SLew Glendenning static char *rom_probe_types[] = { "cfi_probe", "jedec_probe", NULL }; 151*29175778SLew Glendenning struct esb2rom_window *window = &esb2rom_window; 152*29175778SLew Glendenning struct esb2rom_map_info *map = NULL; 153*29175778SLew Glendenning unsigned long map_top; 154*29175778SLew Glendenning u8 byte; 155*29175778SLew Glendenning u16 word; 156*29175778SLew Glendenning 157*29175778SLew Glendenning /* For now I just handle the ecb2 and I assume there 158*29175778SLew Glendenning * are not a lot of resources up at the top of the address 159*29175778SLew Glendenning * space. It is possible to handle other devices in the 160*29175778SLew Glendenning * top 16MiB but it is very painful. Also since 161*29175778SLew Glendenning * you can only really attach a FWH to an ICHX there 162*29175778SLew Glendenning * a number of simplifications you can make. 163*29175778SLew Glendenning * 164*29175778SLew Glendenning * Also you can page firmware hubs if an 8MiB window isn't enough 165*29175778SLew Glendenning * but don't currently handle that case either. 166*29175778SLew Glendenning */ 167*29175778SLew Glendenning window->pdev = pdev; 168*29175778SLew Glendenning 169*29175778SLew Glendenning /* RLG: experiment 2. Force the window registers to the widest values */ 170*29175778SLew Glendenning 171*29175778SLew Glendenning /* 172*29175778SLew Glendenning pci_read_config_word(pdev, FWH_DEC_EN1, &word); 173*29175778SLew Glendenning printk(KERN_DEBUG "Original FWH_DEC_EN1 : %x\n", word); 174*29175778SLew Glendenning pci_write_config_byte(pdev, FWH_DEC_EN1, 0xff); 175*29175778SLew Glendenning pci_read_config_byte(pdev, FWH_DEC_EN1, &byte); 176*29175778SLew Glendenning printk(KERN_DEBUG "New FWH_DEC_EN1 : %x\n", byte); 177*29175778SLew Glendenning 178*29175778SLew Glendenning pci_read_config_byte(pdev, FWH_DEC_EN2, &byte); 179*29175778SLew Glendenning printk(KERN_DEBUG "Original FWH_DEC_EN2 : %x\n", byte); 180*29175778SLew Glendenning pci_write_config_byte(pdev, FWH_DEC_EN2, 0x0f); 181*29175778SLew Glendenning pci_read_config_byte(pdev, FWH_DEC_EN2, &byte); 182*29175778SLew Glendenning printk(KERN_DEBUG "New FWH_DEC_EN2 : %x\n", byte); 183*29175778SLew Glendenning */ 184*29175778SLew Glendenning 185*29175778SLew Glendenning /* Find a region continuous to the end of the ROM window */ 186*29175778SLew Glendenning window->phys = 0; 187*29175778SLew Glendenning pci_read_config_word(pdev, FWH_DEC_EN1, &word); 188*29175778SLew Glendenning printk(KERN_DEBUG "pci_read_config_byte : %x\n", word); 189*29175778SLew Glendenning 190*29175778SLew Glendenning if ((word & FWH_8MiB) == FWH_8MiB) 191*29175778SLew Glendenning window->phys = 0xff400000; 192*29175778SLew Glendenning else if ((word & FWH_7MiB) == FWH_7MiB) 193*29175778SLew Glendenning window->phys = 0xff500000; 194*29175778SLew Glendenning else if ((word & FWH_6MiB) == FWH_6MiB) 195*29175778SLew Glendenning window->phys = 0xff600000; 196*29175778SLew Glendenning else if ((word & FWH_5MiB) == FWH_5MiB) 197*29175778SLew Glendenning window->phys = 0xFF700000; 198*29175778SLew Glendenning else if ((word & FWH_4MiB) == FWH_4MiB) 199*29175778SLew Glendenning window->phys = 0xffc00000; 200*29175778SLew Glendenning else if ((word & FWH_3_5MiB) == FWH_3_5MiB) 201*29175778SLew Glendenning window->phys = 0xffc80000; 202*29175778SLew Glendenning else if ((word & FWH_3MiB) == FWH_3MiB) 203*29175778SLew Glendenning window->phys = 0xffd00000; 204*29175778SLew Glendenning else if ((word & FWH_2_5MiB) == FWH_2_5MiB) 205*29175778SLew Glendenning window->phys = 0xffd80000; 206*29175778SLew Glendenning else if ((word & FWH_2MiB) == FWH_2MiB) 207*29175778SLew Glendenning window->phys = 0xffe00000; 208*29175778SLew Glendenning else if ((word & FWH_1_5MiB) == FWH_1_5MiB) 209*29175778SLew Glendenning window->phys = 0xffe80000; 210*29175778SLew Glendenning else if ((word & FWH_1MiB) == FWH_1MiB) 211*29175778SLew Glendenning window->phys = 0xfff00000; 212*29175778SLew Glendenning else if ((word & FWH_0_5MiB) == FWH_0_5MiB) 213*29175778SLew Glendenning window->phys = 0xfff80000; 214*29175778SLew Glendenning 215*29175778SLew Glendenning /* reserved 0x0020 and 0x0010 */ 216*29175778SLew Glendenning window->phys -= 0x400000UL; 217*29175778SLew Glendenning window->size = (0xffffffffUL - window->phys) + 1UL; 218*29175778SLew Glendenning 219*29175778SLew Glendenning /* Enable writes through the rom window */ 220*29175778SLew Glendenning pci_read_config_byte(pdev, BIOS_CNTL, &byte); 221*29175778SLew Glendenning if (!(byte & BIOS_WRITE_ENABLE) && (byte & (BIOS_LOCK_ENABLE))) { 222*29175778SLew Glendenning /* The BIOS will generate an error if I enable 223*29175778SLew Glendenning * this device, so don't even try. 224*29175778SLew Glendenning */ 225*29175778SLew Glendenning printk(KERN_ERR MOD_NAME ": firmware access control, I can't enable writes\n"); 226*29175778SLew Glendenning goto out; 227*29175778SLew Glendenning } 228*29175778SLew Glendenning pci_write_config_byte(pdev, BIOS_CNTL, byte | BIOS_WRITE_ENABLE); 229*29175778SLew Glendenning 230*29175778SLew Glendenning /* 231*29175778SLew Glendenning * Try to reserve the window mem region. If this fails then 232*29175778SLew Glendenning * it is likely due to the window being "reseved" by the BIOS. 233*29175778SLew Glendenning */ 234*29175778SLew Glendenning window->rsrc.name = MOD_NAME; 235*29175778SLew Glendenning window->rsrc.start = window->phys; 236*29175778SLew Glendenning window->rsrc.end = window->phys + window->size - 1; 237*29175778SLew Glendenning window->rsrc.flags = IORESOURCE_MEM | IORESOURCE_BUSY; 238*29175778SLew Glendenning if (request_resource(&iomem_resource, &window->rsrc)) { 239*29175778SLew Glendenning window->rsrc.parent = NULL; 240*29175778SLew Glendenning printk(KERN_DEBUG MOD_NAME 241*29175778SLew Glendenning ": %s(): Unable to register resource" 242*29175778SLew Glendenning " 0x%.08llx-0x%.08llx - kernel bug?\n", 243*29175778SLew Glendenning __func__, 244*29175778SLew Glendenning (unsigned long long)window->rsrc.start, 245*29175778SLew Glendenning (unsigned long long)window->rsrc.end); 246*29175778SLew Glendenning } 247*29175778SLew Glendenning 248*29175778SLew Glendenning /* Map the firmware hub into my address space. */ 249*29175778SLew Glendenning window->virt = ioremap_nocache(window->phys, window->size); 250*29175778SLew Glendenning if (!window->virt) { 251*29175778SLew Glendenning printk(KERN_ERR MOD_NAME ": ioremap(%08lx, %08lx) failed\n", 252*29175778SLew Glendenning window->phys, window->size); 253*29175778SLew Glendenning goto out; 254*29175778SLew Glendenning } 255*29175778SLew Glendenning 256*29175778SLew Glendenning /* Get the first address to look for an rom chip at */ 257*29175778SLew Glendenning map_top = window->phys; 258*29175778SLew Glendenning if ((window->phys & 0x3fffff) != 0) { 259*29175778SLew Glendenning /* if not aligned on 4MiB, look 4MiB lower in address space */ 260*29175778SLew Glendenning map_top = window->phys + 0x400000; 261*29175778SLew Glendenning } 262*29175778SLew Glendenning #if 1 263*29175778SLew Glendenning /* The probe sequence run over the firmware hub lock 264*29175778SLew Glendenning * registers sets them to 0x7 (no access). 265*29175778SLew Glendenning * (Insane hardware design, but most copied Intel's.) 266*29175778SLew Glendenning * ==> Probe at most the last 4M of the address space. 267*29175778SLew Glendenning */ 268*29175778SLew Glendenning if (map_top < 0xffc00000) 269*29175778SLew Glendenning map_top = 0xffc00000; 270*29175778SLew Glendenning #endif 271*29175778SLew Glendenning /* Loop through and look for rom chips */ 272*29175778SLew Glendenning while ((map_top - 1) < 0xffffffffUL) { 273*29175778SLew Glendenning struct cfi_private *cfi; 274*29175778SLew Glendenning unsigned long offset; 275*29175778SLew Glendenning int i; 276*29175778SLew Glendenning 277*29175778SLew Glendenning if (!map) 278*29175778SLew Glendenning map = kmalloc(sizeof(*map), GFP_KERNEL); 279*29175778SLew Glendenning if (!map) { 280*29175778SLew Glendenning printk(KERN_ERR MOD_NAME ": kmalloc failed"); 281*29175778SLew Glendenning goto out; 282*29175778SLew Glendenning } 283*29175778SLew Glendenning memset(map, 0, sizeof(*map)); 284*29175778SLew Glendenning INIT_LIST_HEAD(&map->list); 285*29175778SLew Glendenning map->map.name = map->map_name; 286*29175778SLew Glendenning map->map.phys = map_top; 287*29175778SLew Glendenning offset = map_top - window->phys; 288*29175778SLew Glendenning map->map.virt = (void __iomem *) 289*29175778SLew Glendenning (((unsigned long)(window->virt)) + offset); 290*29175778SLew Glendenning map->map.size = 0xffffffffUL - map_top + 1UL; 291*29175778SLew Glendenning /* Set the name of the map to the address I am trying */ 292*29175778SLew Glendenning sprintf(map->map_name, "%s @%08lx", 293*29175778SLew Glendenning MOD_NAME, map->map.phys); 294*29175778SLew Glendenning 295*29175778SLew Glendenning /* Firmware hubs only use vpp when being programmed 296*29175778SLew Glendenning * in a factory setting. So in-place programming 297*29175778SLew Glendenning * needs to use a different method. 298*29175778SLew Glendenning */ 299*29175778SLew Glendenning for(map->map.bankwidth = 32; map->map.bankwidth; 300*29175778SLew Glendenning map->map.bankwidth >>= 1) { 301*29175778SLew Glendenning char **probe_type; 302*29175778SLew Glendenning /* Skip bankwidths that are not supported */ 303*29175778SLew Glendenning if (!map_bankwidth_supported(map->map.bankwidth)) 304*29175778SLew Glendenning continue; 305*29175778SLew Glendenning 306*29175778SLew Glendenning /* Setup the map methods */ 307*29175778SLew Glendenning simple_map_init(&map->map); 308*29175778SLew Glendenning 309*29175778SLew Glendenning /* Try all of the probe methods */ 310*29175778SLew Glendenning probe_type = rom_probe_types; 311*29175778SLew Glendenning for(; *probe_type; probe_type++) { 312*29175778SLew Glendenning map->mtd = do_map_probe(*probe_type, &map->map); 313*29175778SLew Glendenning if (map->mtd) 314*29175778SLew Glendenning goto found; 315*29175778SLew Glendenning } 316*29175778SLew Glendenning } 317*29175778SLew Glendenning map_top += ROM_PROBE_STEP_SIZE; 318*29175778SLew Glendenning continue; 319*29175778SLew Glendenning found: 320*29175778SLew Glendenning /* Trim the size if we are larger than the map */ 321*29175778SLew Glendenning if (map->mtd->size > map->map.size) { 322*29175778SLew Glendenning printk(KERN_WARNING MOD_NAME 323*29175778SLew Glendenning " rom(%u) larger than window(%lu). fixing...\n", 324*29175778SLew Glendenning map->mtd->size, map->map.size); 325*29175778SLew Glendenning map->mtd->size = map->map.size; 326*29175778SLew Glendenning } 327*29175778SLew Glendenning if (window->rsrc.parent) { 328*29175778SLew Glendenning /* 329*29175778SLew Glendenning * Registering the MTD device in iomem may not be possible 330*29175778SLew Glendenning * if there is a BIOS "reserved" and BUSY range. If this 331*29175778SLew Glendenning * fails then continue anyway. 332*29175778SLew Glendenning */ 333*29175778SLew Glendenning map->rsrc.name = map->map_name; 334*29175778SLew Glendenning map->rsrc.start = map->map.phys; 335*29175778SLew Glendenning map->rsrc.end = map->map.phys + map->mtd->size - 1; 336*29175778SLew Glendenning map->rsrc.flags = IORESOURCE_MEM | IORESOURCE_BUSY; 337*29175778SLew Glendenning if (request_resource(&window->rsrc, &map->rsrc)) { 338*29175778SLew Glendenning printk(KERN_ERR MOD_NAME 339*29175778SLew Glendenning ": cannot reserve MTD resource\n"); 340*29175778SLew Glendenning map->rsrc.parent = NULL; 341*29175778SLew Glendenning } 342*29175778SLew Glendenning } 343*29175778SLew Glendenning 344*29175778SLew Glendenning /* Make the whole region visible in the map */ 345*29175778SLew Glendenning map->map.virt = window->virt; 346*29175778SLew Glendenning map->map.phys = window->phys; 347*29175778SLew Glendenning cfi = map->map.fldrv_priv; 348*29175778SLew Glendenning for(i = 0; i < cfi->numchips; i++) 349*29175778SLew Glendenning cfi->chips[i].start += offset; 350*29175778SLew Glendenning 351*29175778SLew Glendenning /* Now that the mtd devices is complete claim and export it */ 352*29175778SLew Glendenning map->mtd->owner = THIS_MODULE; 353*29175778SLew Glendenning if (add_mtd_device(map->mtd)) { 354*29175778SLew Glendenning map_destroy(map->mtd); 355*29175778SLew Glendenning map->mtd = NULL; 356*29175778SLew Glendenning goto out; 357*29175778SLew Glendenning } 358*29175778SLew Glendenning 359*29175778SLew Glendenning /* Calculate the new value of map_top */ 360*29175778SLew Glendenning map_top += map->mtd->size; 361*29175778SLew Glendenning 362*29175778SLew Glendenning /* File away the map structure */ 363*29175778SLew Glendenning list_add(&map->list, &window->maps); 364*29175778SLew Glendenning map = NULL; 365*29175778SLew Glendenning } 366*29175778SLew Glendenning 367*29175778SLew Glendenning out: 368*29175778SLew Glendenning /* Free any left over map structures */ 369*29175778SLew Glendenning kfree(map); 370*29175778SLew Glendenning 371*29175778SLew Glendenning /* See if I have any map structures */ 372*29175778SLew Glendenning if (list_empty(&window->maps)) { 373*29175778SLew Glendenning esb2rom_cleanup(window); 374*29175778SLew Glendenning return -ENODEV; 375*29175778SLew Glendenning } 376*29175778SLew Glendenning return 0; 377*29175778SLew Glendenning } 378*29175778SLew Glendenning 379*29175778SLew Glendenning static void __devexit esb2rom_remove_one (struct pci_dev *pdev) 380*29175778SLew Glendenning { 381*29175778SLew Glendenning struct esb2rom_window *window = &esb2rom_window; 382*29175778SLew Glendenning esb2rom_cleanup(window); 383*29175778SLew Glendenning } 384*29175778SLew Glendenning 385*29175778SLew Glendenning static struct pci_device_id esb2rom_pci_tbl[] __devinitdata = { 386*29175778SLew Glendenning { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0, 387*29175778SLew Glendenning PCI_ANY_ID, PCI_ANY_ID, }, 388*29175778SLew Glendenning { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0, 389*29175778SLew Glendenning PCI_ANY_ID, PCI_ANY_ID, }, 390*29175778SLew Glendenning { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0, 391*29175778SLew Glendenning PCI_ANY_ID, PCI_ANY_ID, }, 392*29175778SLew Glendenning { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0, 393*29175778SLew Glendenning PCI_ANY_ID, PCI_ANY_ID, }, 394*29175778SLew Glendenning { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_1, 395*29175778SLew Glendenning PCI_ANY_ID, PCI_ANY_ID, }, 396*29175778SLew Glendenning { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB2_0, 397*29175778SLew Glendenning PCI_ANY_ID, PCI_ANY_ID, }, 398*29175778SLew Glendenning { 0, }, 399*29175778SLew Glendenning }; 400*29175778SLew Glendenning 401*29175778SLew Glendenning #if 0 402*29175778SLew Glendenning MODULE_DEVICE_TABLE(pci, esb2rom_pci_tbl); 403*29175778SLew Glendenning 404*29175778SLew Glendenning static struct pci_driver esb2rom_driver = { 405*29175778SLew Glendenning .name = MOD_NAME, 406*29175778SLew Glendenning .id_table = esb2rom_pci_tbl, 407*29175778SLew Glendenning .probe = esb2rom_init_one, 408*29175778SLew Glendenning .remove = esb2rom_remove_one, 409*29175778SLew Glendenning }; 410*29175778SLew Glendenning #endif 411*29175778SLew Glendenning 412*29175778SLew Glendenning static int __init init_esb2rom(void) 413*29175778SLew Glendenning { 414*29175778SLew Glendenning struct pci_dev *pdev; 415*29175778SLew Glendenning struct pci_device_id *id; 416*29175778SLew Glendenning int retVal; 417*29175778SLew Glendenning 418*29175778SLew Glendenning pdev = NULL; 419*29175778SLew Glendenning for (id = esb2rom_pci_tbl; id->vendor; id++) { 420*29175778SLew Glendenning printk(KERN_DEBUG "device id = %x\n", id->device); 421*29175778SLew Glendenning pdev = pci_find_device(id->vendor, id->device, NULL); 422*29175778SLew Glendenning if (pdev) { 423*29175778SLew Glendenning printk(KERN_DEBUG "matched device = %x\n", id->device); 424*29175778SLew Glendenning break; 425*29175778SLew Glendenning } 426*29175778SLew Glendenning } 427*29175778SLew Glendenning if (pdev) { 428*29175778SLew Glendenning printk(KERN_DEBUG "matched device id %x\n", id->device); 429*29175778SLew Glendenning retVal = esb2rom_init_one(pdev, &esb2rom_pci_tbl[0]); 430*29175778SLew Glendenning printk(KERN_DEBUG "retVal = %d\n", retVal); 431*29175778SLew Glendenning return retVal; 432*29175778SLew Glendenning } 433*29175778SLew Glendenning return -ENXIO; 434*29175778SLew Glendenning #if 0 435*29175778SLew Glendenning return pci_register_driver(&esb2rom_driver); 436*29175778SLew Glendenning #endif 437*29175778SLew Glendenning } 438*29175778SLew Glendenning 439*29175778SLew Glendenning static void __exit cleanup_esb2rom(void) 440*29175778SLew Glendenning { 441*29175778SLew Glendenning esb2rom_remove_one(esb2rom_window.pdev); 442*29175778SLew Glendenning } 443*29175778SLew Glendenning 444*29175778SLew Glendenning module_init(init_esb2rom); 445*29175778SLew Glendenning module_exit(cleanup_esb2rom); 446*29175778SLew Glendenning 447*29175778SLew Glendenning MODULE_LICENSE("GPL"); 448*29175778SLew Glendenning MODULE_AUTHOR("Lew Glendenning <lglendenning@lnxi.com>"); 449*29175778SLew Glendenning MODULE_DESCRIPTION("MTD map driver for BIOS chips on the ESB2 southbridge"); 450