15a2c675cSTim Small /* 25a2c675cSTim Small * Intel 82443BX/GX (440BX/GX chipset) Memory Controller EDAC kernel 35a2c675cSTim Small * module (C) 2006 Tim Small 45a2c675cSTim Small * 55a2c675cSTim Small * This file may be distributed under the terms of the GNU General 65a2c675cSTim Small * Public License. 75a2c675cSTim Small * 85a2c675cSTim Small * Written by Tim Small <tim@buttersideup.com>, based on work by Linux 95a2c675cSTim Small * Networx, Thayne Harbaugh, Dan Hollis <goemon at anime dot net> and 105a2c675cSTim Small * others. 115a2c675cSTim Small * 125a2c675cSTim Small * 440GX fix by Jason Uhlenkott <juhlenko@akamai.com>. 135a2c675cSTim Small * 145a2c675cSTim Small * Written with reference to 82443BX Host Bridge Datasheet: 15631dd1a8SJustin P. Mattock * http://download.intel.com/design/chipsets/datashts/29063301.pdf 165a2c675cSTim Small * references to this document given in []. 175a2c675cSTim Small * 185a2c675cSTim Small * This module doesn't support the 440LX, but it may be possible to 195a2c675cSTim Small * make it do so (the 440LX's register definitions are different, but 205a2c675cSTim Small * not completely so - I haven't studied them in enough detail to know 215a2c675cSTim Small * how easy this would be). 225a2c675cSTim Small */ 235a2c675cSTim Small 245a2c675cSTim Small #include <linux/module.h> 255a2c675cSTim Small #include <linux/init.h> 265a2c675cSTim Small 275a2c675cSTim Small #include <linux/pci.h> 285a2c675cSTim Small #include <linux/pci_ids.h> 295a2c675cSTim Small 305a2c675cSTim Small 31c3c52bceSHitoshi Mitake #include <linux/edac.h> 3220bcb7a8SDouglas Thompson #include "edac_core.h" 335a2c675cSTim Small 345a2c675cSTim Small #define I82443_REVISION "0.1" 355a2c675cSTim Small 365a2c675cSTim Small #define EDAC_MOD_STR "i82443bxgx_edac" 375a2c675cSTim Small 385a2c675cSTim Small /* The 82443BX supports SDRAM, or EDO (EDO for mobile only), "Memory 395a2c675cSTim Small * Size: 8 MB to 512 MB (1GB with Registered DIMMs) with eight memory 405a2c675cSTim Small * rows" "The 82443BX supports multiple-bit error detection and 415a2c675cSTim Small * single-bit error correction when ECC mode is enabled and 425a2c675cSTim Small * single/multi-bit error detection when correction is disabled. 435a2c675cSTim Small * During writes to the DRAM, the 82443BX generates ECC for the data 445a2c675cSTim Small * on a QWord basis. Partial QWord writes require a read-modify-write 455a2c675cSTim Small * cycle when ECC is enabled." 465a2c675cSTim Small */ 475a2c675cSTim Small 485a2c675cSTim Small /* "Additionally, the 82443BX ensures that the data is corrected in 495a2c675cSTim Small * main memory so that accumulation of errors is prevented. Another 505a2c675cSTim Small * error within the same QWord would result in a double-bit error 515a2c675cSTim Small * which is unrecoverable. This is known as hardware scrubbing since 525a2c675cSTim Small * it requires no software intervention to correct the data in memory." 535a2c675cSTim Small */ 545a2c675cSTim Small 555a2c675cSTim Small /* [Also see page 100 (section 4.3), "DRAM Interface"] 565a2c675cSTim Small * [Also see page 112 (section 4.6.1.4), ECC] 575a2c675cSTim Small */ 585a2c675cSTim Small 595a2c675cSTim Small #define I82443BXGX_NR_CSROWS 8 605a2c675cSTim Small #define I82443BXGX_NR_CHANS 1 615a2c675cSTim Small #define I82443BXGX_NR_DIMMS 4 625a2c675cSTim Small 635a2c675cSTim Small /* 82443 PCI Device 0 */ 645a2c675cSTim Small #define I82443BXGX_NBXCFG 0x50 /* 32bit register starting at this PCI 655a2c675cSTim Small * config space offset */ 665a2c675cSTim Small #define I82443BXGX_NBXCFG_OFFSET_NON_ECCROW 24 /* Array of bits, zero if 675a2c675cSTim Small * row is non-ECC */ 685a2c675cSTim Small #define I82443BXGX_NBXCFG_OFFSET_DRAM_FREQ 12 /* 2 bits,00=100MHz,10=66 MHz */ 695a2c675cSTim Small 705a2c675cSTim Small #define I82443BXGX_NBXCFG_OFFSET_DRAM_INTEGRITY 7 /* 2 bits: */ 715a2c675cSTim Small #define I82443BXGX_NBXCFG_INTEGRITY_NONE 0x0 /* 00 = Non-ECC */ 725a2c675cSTim Small #define I82443BXGX_NBXCFG_INTEGRITY_EC 0x1 /* 01 = EC (only) */ 735a2c675cSTim Small #define I82443BXGX_NBXCFG_INTEGRITY_ECC 0x2 /* 10 = ECC */ 745a2c675cSTim Small #define I82443BXGX_NBXCFG_INTEGRITY_SCRUB 0x3 /* 11 = ECC + HW Scrub */ 755a2c675cSTim Small 765a2c675cSTim Small #define I82443BXGX_NBXCFG_OFFSET_ECC_DIAG_ENABLE 6 775a2c675cSTim Small 785a2c675cSTim Small /* 82443 PCI Device 0 */ 795a2c675cSTim Small #define I82443BXGX_EAP 0x80 /* 32bit register starting at this PCI 805a2c675cSTim Small * config space offset, Error Address 815a2c675cSTim Small * Pointer Register */ 825a2c675cSTim Small #define I82443BXGX_EAP_OFFSET_EAP 12 /* High 20 bits of error address */ 835a2c675cSTim Small #define I82443BXGX_EAP_OFFSET_MBE BIT(1) /* Err at EAP was multi-bit (W1TC) */ 845a2c675cSTim Small #define I82443BXGX_EAP_OFFSET_SBE BIT(0) /* Err at EAP was single-bit (W1TC) */ 855a2c675cSTim Small 865a2c675cSTim Small #define I82443BXGX_ERRCMD 0x90 /* 8bit register starting at this PCI 875a2c675cSTim Small * config space offset. */ 885a2c675cSTim Small #define I82443BXGX_ERRCMD_OFFSET_SERR_ON_MBE BIT(1) /* 1 = enable */ 895a2c675cSTim Small #define I82443BXGX_ERRCMD_OFFSET_SERR_ON_SBE BIT(0) /* 1 = enable */ 905a2c675cSTim Small 915a2c675cSTim Small #define I82443BXGX_ERRSTS 0x91 /* 16bit register starting at this PCI 925a2c675cSTim Small * config space offset. */ 935a2c675cSTim Small #define I82443BXGX_ERRSTS_OFFSET_MBFRE 5 /* 3 bits - first err row multibit */ 945a2c675cSTim Small #define I82443BXGX_ERRSTS_OFFSET_MEF BIT(4) /* 1 = MBE occurred */ 955a2c675cSTim Small #define I82443BXGX_ERRSTS_OFFSET_SBFRE 1 /* 3 bits - first err row singlebit */ 965a2c675cSTim Small #define I82443BXGX_ERRSTS_OFFSET_SEF BIT(0) /* 1 = SBE occurred */ 975a2c675cSTim Small 985a2c675cSTim Small #define I82443BXGX_DRAMC 0x57 /* 8bit register starting at this PCI 995a2c675cSTim Small * config space offset. */ 1005a2c675cSTim Small #define I82443BXGX_DRAMC_OFFSET_DT 3 /* 2 bits, DRAM Type */ 1015a2c675cSTim Small #define I82443BXGX_DRAMC_DRAM_IS_EDO 0 /* 00 = EDO */ 1025a2c675cSTim Small #define I82443BXGX_DRAMC_DRAM_IS_SDRAM 1 /* 01 = SDRAM */ 1035a2c675cSTim Small #define I82443BXGX_DRAMC_DRAM_IS_RSDRAM 2 /* 10 = Registered SDRAM */ 1045a2c675cSTim Small 1055a2c675cSTim Small #define I82443BXGX_DRB 0x60 /* 8x 8bit registers starting at this PCI 1065a2c675cSTim Small * config space offset. */ 1075a2c675cSTim Small 1085a2c675cSTim Small /* FIXME - don't poll when ECC disabled? */ 1095a2c675cSTim Small 1105a2c675cSTim Small struct i82443bxgx_edacmc_error_info { 1115a2c675cSTim Small u32 eap; 1125a2c675cSTim Small }; 1135a2c675cSTim Small 114456a2f95SDave Jiang static struct edac_pci_ctl_info *i82443bxgx_pci; 115456a2f95SDave Jiang 11653a2fe58SVladislav Bogdanov static struct pci_dev *mci_pdev; /* init dev: in case that AGP code has 11753a2fe58SVladislav Bogdanov * already registered driver 11853a2fe58SVladislav Bogdanov */ 11953a2fe58SVladislav Bogdanov 12053a2fe58SVladislav Bogdanov static int i82443bxgx_registered = 1; 12153a2fe58SVladislav Bogdanov 1225a2c675cSTim Small static void i82443bxgx_edacmc_get_error_info(struct mem_ctl_info *mci, 12311116601SDouglas Thompson struct i82443bxgx_edacmc_error_info 12411116601SDouglas Thompson *info) 1255a2c675cSTim Small { 1265a2c675cSTim Small struct pci_dev *pdev; 1275a2c675cSTim Small pdev = to_pci_dev(mci->dev); 1285a2c675cSTim Small pci_read_config_dword(pdev, I82443BXGX_EAP, &info->eap); 1295a2c675cSTim Small if (info->eap & I82443BXGX_EAP_OFFSET_SBE) 1305a2c675cSTim Small /* Clear error to allow next error to be reported [p.61] */ 1315a2c675cSTim Small pci_write_bits32(pdev, I82443BXGX_EAP, 1325a2c675cSTim Small I82443BXGX_EAP_OFFSET_SBE, 1335a2c675cSTim Small I82443BXGX_EAP_OFFSET_SBE); 1345a2c675cSTim Small 1355a2c675cSTim Small if (info->eap & I82443BXGX_EAP_OFFSET_MBE) 1365a2c675cSTim Small /* Clear error to allow next error to be reported [p.61] */ 1375a2c675cSTim Small pci_write_bits32(pdev, I82443BXGX_EAP, 1385a2c675cSTim Small I82443BXGX_EAP_OFFSET_MBE, 1395a2c675cSTim Small I82443BXGX_EAP_OFFSET_MBE); 1405a2c675cSTim Small } 1415a2c675cSTim Small 1425a2c675cSTim Small static int i82443bxgx_edacmc_process_error_info(struct mem_ctl_info *mci, 14311116601SDouglas Thompson struct 14411116601SDouglas Thompson i82443bxgx_edacmc_error_info 14511116601SDouglas Thompson *info, int handle_errors) 1465a2c675cSTim Small { 1475a2c675cSTim Small int error_found = 0; 1485a2c675cSTim Small u32 eapaddr, page, pageoffset; 1495a2c675cSTim Small 1505a2c675cSTim Small /* bits 30:12 hold the 4kb block in which the error occurred 1515a2c675cSTim Small * [p.61] */ 1525a2c675cSTim Small eapaddr = (info->eap & 0xfffff000); 1535a2c675cSTim Small page = eapaddr >> PAGE_SHIFT; 1545a2c675cSTim Small pageoffset = eapaddr - (page << PAGE_SHIFT); 1555a2c675cSTim Small 1565a2c675cSTim Small if (info->eap & I82443BXGX_EAP_OFFSET_SBE) { 1575a2c675cSTim Small error_found = 1; 1585a2c675cSTim Small if (handle_errors) 15940f562b1SMauro Carvalho Chehab edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 16040f562b1SMauro Carvalho Chehab page, pageoffset, 0, 16140f562b1SMauro Carvalho Chehab edac_mc_find_csrow_by_page(mci, page), 16240f562b1SMauro Carvalho Chehab 0, -1, mci->ctl_name, "", NULL); 1635a2c675cSTim Small } 1645a2c675cSTim Small 1655a2c675cSTim Small if (info->eap & I82443BXGX_EAP_OFFSET_MBE) { 1665a2c675cSTim Small error_found = 1; 1675a2c675cSTim Small if (handle_errors) 16840f562b1SMauro Carvalho Chehab edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, 16940f562b1SMauro Carvalho Chehab page, pageoffset, 0, 1705a2c675cSTim Small edac_mc_find_csrow_by_page(mci, page), 17140f562b1SMauro Carvalho Chehab 0, -1, mci->ctl_name, "", NULL); 1725a2c675cSTim Small } 1735a2c675cSTim Small 1745a2c675cSTim Small return error_found; 1755a2c675cSTim Small } 1765a2c675cSTim Small 1775a2c675cSTim Small static void i82443bxgx_edacmc_check(struct mem_ctl_info *mci) 1785a2c675cSTim Small { 1795a2c675cSTim Small struct i82443bxgx_edacmc_error_info info; 1805a2c675cSTim Small 18163ae96beSJoe Perches debugf1("MC%d: %s: %s()\n", mci->mc_idx, __FILE__, __func__); 1825a2c675cSTim Small i82443bxgx_edacmc_get_error_info(mci, &info); 1835a2c675cSTim Small i82443bxgx_edacmc_process_error_info(mci, &info, 1); 1845a2c675cSTim Small } 1855a2c675cSTim Small 1865a2c675cSTim Small static void i82443bxgx_init_csrows(struct mem_ctl_info *mci, 1875a2c675cSTim Small struct pci_dev *pdev, 1885a2c675cSTim Small enum edac_type edac_mode, 1895a2c675cSTim Small enum mem_type mtype) 1905a2c675cSTim Small { 1915a2c675cSTim Small struct csrow_info *csrow; 192084a4fccSMauro Carvalho Chehab struct dimm_info *dimm; 1935a2c675cSTim Small int index; 1945a2c675cSTim Small u8 drbar, dramc; 1955a2c675cSTim Small u32 row_base, row_high_limit, row_high_limit_last; 1965a2c675cSTim Small 1975a2c675cSTim Small pci_read_config_byte(pdev, I82443BXGX_DRAMC, &dramc); 1985a2c675cSTim Small row_high_limit_last = 0; 1995a2c675cSTim Small for (index = 0; index < mci->nr_csrows; index++) { 2005a2c675cSTim Small csrow = &mci->csrows[index]; 201084a4fccSMauro Carvalho Chehab dimm = csrow->channels[0].dimm; 202084a4fccSMauro Carvalho Chehab 2035a2c675cSTim Small pci_read_config_byte(pdev, I82443BXGX_DRB + index, &drbar); 20463ae96beSJoe Perches debugf1("MC%d: %s: %s() Row=%d DRB = %#0x\n", 20563ae96beSJoe Perches mci->mc_idx, __FILE__, __func__, index, drbar); 2065a2c675cSTim Small row_high_limit = ((u32) drbar << 23); 2075a2c675cSTim Small /* find the DRAM Chip Select Base address and mask */ 20863ae96beSJoe Perches debugf1("MC%d: %s: %s() Row=%d, " 20925985edcSLucas De Marchi "Boundary Address=%#0x, Last = %#0x\n", 21063ae96beSJoe Perches mci->mc_idx, __FILE__, __func__, index, row_high_limit, 2115a2c675cSTim Small row_high_limit_last); 2125a2c675cSTim Small 2135a2c675cSTim Small /* 440GX goes to 2GB, represented with a DRB of 0. */ 2145a2c675cSTim Small if (row_high_limit_last && !row_high_limit) 2155a2c675cSTim Small row_high_limit = 1UL << 31; 2165a2c675cSTim Small 2175a2c675cSTim Small /* This row is empty [p.49] */ 2185a2c675cSTim Small if (row_high_limit == row_high_limit_last) 2195a2c675cSTim Small continue; 2205a2c675cSTim Small row_base = row_high_limit_last; 2215a2c675cSTim Small csrow->first_page = row_base >> PAGE_SHIFT; 2225a2c675cSTim Small csrow->last_page = (row_high_limit >> PAGE_SHIFT) - 1; 223a895bf8bSMauro Carvalho Chehab dimm->nr_pages = csrow->last_page - csrow->first_page + 1; 2245a2c675cSTim Small /* EAP reports in 4kilobyte granularity [61] */ 225084a4fccSMauro Carvalho Chehab dimm->grain = 1 << 12; 226084a4fccSMauro Carvalho Chehab dimm->mtype = mtype; 2275a2c675cSTim Small /* I don't think 440BX can tell you device type? FIXME? */ 228084a4fccSMauro Carvalho Chehab dimm->dtype = DEV_UNKNOWN; 2295a2c675cSTim Small /* Mode is global to all rows on 440BX */ 230084a4fccSMauro Carvalho Chehab dimm->edac_mode = edac_mode; 2315a2c675cSTim Small row_high_limit_last = row_high_limit; 2325a2c675cSTim Small } 2335a2c675cSTim Small } 2345a2c675cSTim Small 2355a2c675cSTim Small static int i82443bxgx_edacmc_probe1(struct pci_dev *pdev, int dev_idx) 2365a2c675cSTim Small { 2375a2c675cSTim Small struct mem_ctl_info *mci; 23840f562b1SMauro Carvalho Chehab struct edac_mc_layer layers[2]; 2395a2c675cSTim Small u8 dramc; 2405a2c675cSTim Small u32 nbxcfg, ecc_mode; 2415a2c675cSTim Small enum mem_type mtype; 2425a2c675cSTim Small enum edac_type edac_mode; 2435a2c675cSTim Small 24463ae96beSJoe Perches debugf0("MC: %s: %s()\n", __FILE__, __func__); 2455a2c675cSTim Small 2465a2c675cSTim Small /* Something is really hosed if PCI config space reads from 247052dfb45SDouglas Thompson * the MC aren't working. 248052dfb45SDouglas Thompson */ 2495a2c675cSTim Small if (pci_read_config_dword(pdev, I82443BXGX_NBXCFG, &nbxcfg)) 2505a2c675cSTim Small return -EIO; 2515a2c675cSTim Small 25240f562b1SMauro Carvalho Chehab layers[0].type = EDAC_MC_LAYER_CHIP_SELECT; 25340f562b1SMauro Carvalho Chehab layers[0].size = I82443BXGX_NR_CSROWS; 25440f562b1SMauro Carvalho Chehab layers[0].is_virt_csrow = true; 25540f562b1SMauro Carvalho Chehab layers[1].type = EDAC_MC_LAYER_CHANNEL; 25640f562b1SMauro Carvalho Chehab layers[1].size = I82443BXGX_NR_CHANS; 25740f562b1SMauro Carvalho Chehab layers[1].is_virt_csrow = false; 258*ca0907b9SMauro Carvalho Chehab mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers, 0); 2595a2c675cSTim Small if (mci == NULL) 2605a2c675cSTim Small return -ENOMEM; 2615a2c675cSTim Small 26263ae96beSJoe Perches debugf0("MC: %s: %s(): mci = %p\n", __FILE__, __func__, mci); 2635a2c675cSTim Small mci->dev = &pdev->dev; 2645a2c675cSTim Small mci->mtype_cap = MEM_FLAG_EDO | MEM_FLAG_SDR | MEM_FLAG_RDR; 2655a2c675cSTim Small mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_EC | EDAC_FLAG_SECDED; 2665a2c675cSTim Small pci_read_config_byte(pdev, I82443BXGX_DRAMC, &dramc); 2675a2c675cSTim Small switch ((dramc >> I82443BXGX_DRAMC_OFFSET_DT) & (BIT(0) | BIT(1))) { 2685a2c675cSTim Small case I82443BXGX_DRAMC_DRAM_IS_EDO: 2695a2c675cSTim Small mtype = MEM_EDO; 2705a2c675cSTim Small break; 2715a2c675cSTim Small case I82443BXGX_DRAMC_DRAM_IS_SDRAM: 2725a2c675cSTim Small mtype = MEM_SDR; 2735a2c675cSTim Small break; 2745a2c675cSTim Small case I82443BXGX_DRAMC_DRAM_IS_RSDRAM: 2755a2c675cSTim Small mtype = MEM_RDR; 2765a2c675cSTim Small break; 2775a2c675cSTim Small default: 278052dfb45SDouglas Thompson debugf0("Unknown/reserved DRAM type value " 279052dfb45SDouglas Thompson "in DRAMC register!\n"); 2805a2c675cSTim Small mtype = -MEM_UNKNOWN; 2815a2c675cSTim Small } 2825a2c675cSTim Small 2835a2c675cSTim Small if ((mtype == MEM_SDR) || (mtype == MEM_RDR)) 2845a2c675cSTim Small mci->edac_cap = mci->edac_ctl_cap; 2855a2c675cSTim Small else 2865a2c675cSTim Small mci->edac_cap = EDAC_FLAG_NONE; 2875a2c675cSTim Small 2885a2c675cSTim Small mci->scrub_cap = SCRUB_FLAG_HW_SRC; 2895a2c675cSTim Small pci_read_config_dword(pdev, I82443BXGX_NBXCFG, &nbxcfg); 2905a2c675cSTim Small ecc_mode = ((nbxcfg >> I82443BXGX_NBXCFG_OFFSET_DRAM_INTEGRITY) & 2915a2c675cSTim Small (BIT(0) | BIT(1))); 2925a2c675cSTim Small 2935a2c675cSTim Small mci->scrub_mode = (ecc_mode == I82443BXGX_NBXCFG_INTEGRITY_SCRUB) 29411116601SDouglas Thompson ? SCRUB_HW_SRC : SCRUB_NONE; 2955a2c675cSTim Small 2965a2c675cSTim Small switch (ecc_mode) { 2975a2c675cSTim Small case I82443BXGX_NBXCFG_INTEGRITY_NONE: 2985a2c675cSTim Small edac_mode = EDAC_NONE; 2995a2c675cSTim Small break; 3005a2c675cSTim Small case I82443BXGX_NBXCFG_INTEGRITY_EC: 3015a2c675cSTim Small edac_mode = EDAC_EC; 3025a2c675cSTim Small break; 3035a2c675cSTim Small case I82443BXGX_NBXCFG_INTEGRITY_ECC: 3045a2c675cSTim Small case I82443BXGX_NBXCFG_INTEGRITY_SCRUB: 3055a2c675cSTim Small edac_mode = EDAC_SECDED; 3065a2c675cSTim Small break; 3075a2c675cSTim Small default: 308052dfb45SDouglas Thompson debugf0("%s(): Unknown/reserved ECC state " 309052dfb45SDouglas Thompson "in NBXCFG register!\n", __func__); 3105a2c675cSTim Small edac_mode = EDAC_UNKNOWN; 3115a2c675cSTim Small break; 3125a2c675cSTim Small } 3135a2c675cSTim Small 3145a2c675cSTim Small i82443bxgx_init_csrows(mci, pdev, edac_mode, mtype); 3155a2c675cSTim Small 3165a2c675cSTim Small /* Many BIOSes don't clear error flags on boot, so do this 31725985edcSLucas De Marchi * here, or we get "phantom" errors occurring at module-load 3185a2c675cSTim Small * time. */ 3195a2c675cSTim Small pci_write_bits32(pdev, I82443BXGX_EAP, 32011116601SDouglas Thompson (I82443BXGX_EAP_OFFSET_SBE | 32111116601SDouglas Thompson I82443BXGX_EAP_OFFSET_MBE), 32211116601SDouglas Thompson (I82443BXGX_EAP_OFFSET_SBE | 32311116601SDouglas Thompson I82443BXGX_EAP_OFFSET_MBE)); 3245a2c675cSTim Small 3255a2c675cSTim Small mci->mod_name = EDAC_MOD_STR; 3265a2c675cSTim Small mci->mod_ver = I82443_REVISION; 3275a2c675cSTim Small mci->ctl_name = "I82443BXGX"; 328c4192705SDave Jiang mci->dev_name = pci_name(pdev); 3295a2c675cSTim Small mci->edac_check = i82443bxgx_edacmc_check; 3305a2c675cSTim Small mci->ctl_page_to_phys = NULL; 3315a2c675cSTim Small 332b8f6f975SDoug Thompson if (edac_mc_add_mc(mci)) { 3335a2c675cSTim Small debugf3("%s(): failed edac_mc_add_mc()\n", __func__); 3345a2c675cSTim Small goto fail; 3355a2c675cSTim Small } 3365a2c675cSTim Small 337456a2f95SDave Jiang /* allocating generic PCI control info */ 338456a2f95SDave Jiang i82443bxgx_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR); 339456a2f95SDave Jiang if (!i82443bxgx_pci) { 340456a2f95SDave Jiang printk(KERN_WARNING 341456a2f95SDave Jiang "%s(): Unable to create PCI control\n", 342456a2f95SDave Jiang __func__); 343456a2f95SDave Jiang printk(KERN_WARNING 344456a2f95SDave Jiang "%s(): PCI error report via EDAC not setup\n", 345456a2f95SDave Jiang __func__); 346456a2f95SDave Jiang } 347456a2f95SDave Jiang 34863ae96beSJoe Perches debugf3("MC: %s: %s(): success\n", __FILE__, __func__); 3495a2c675cSTim Small return 0; 3505a2c675cSTim Small 3515a2c675cSTim Small fail: 3525a2c675cSTim Small edac_mc_free(mci); 3535a2c675cSTim Small return -ENODEV; 3545a2c675cSTim Small } 35511116601SDouglas Thompson 3565a2c675cSTim Small EXPORT_SYMBOL_GPL(i82443bxgx_edacmc_probe1); 3575a2c675cSTim Small 3585a2c675cSTim Small /* returns count (>= 0), or negative on error */ 3595a2c675cSTim Small static int __devinit i82443bxgx_edacmc_init_one(struct pci_dev *pdev, 3605a2c675cSTim Small const struct pci_device_id *ent) 3615a2c675cSTim Small { 36253a2fe58SVladislav Bogdanov int rc; 36353a2fe58SVladislav Bogdanov 36463ae96beSJoe Perches debugf0("MC: %s: %s()\n", __FILE__, __func__); 3655a2c675cSTim Small 366ee6583f6SRoman Fietze /* don't need to call pci_enable_device() */ 36753a2fe58SVladislav Bogdanov rc = i82443bxgx_edacmc_probe1(pdev, ent->driver_data); 36853a2fe58SVladislav Bogdanov 36953a2fe58SVladislav Bogdanov if (mci_pdev == NULL) 37053a2fe58SVladislav Bogdanov mci_pdev = pci_dev_get(pdev); 37153a2fe58SVladislav Bogdanov 37253a2fe58SVladislav Bogdanov return rc; 3735a2c675cSTim Small } 3745a2c675cSTim Small 3755a2c675cSTim Small static void __devexit i82443bxgx_edacmc_remove_one(struct pci_dev *pdev) 3765a2c675cSTim Small { 3775a2c675cSTim Small struct mem_ctl_info *mci; 3785a2c675cSTim Small 37963ae96beSJoe Perches debugf0("%s: %s()\n", __FILE__, __func__); 3805a2c675cSTim Small 381456a2f95SDave Jiang if (i82443bxgx_pci) 382456a2f95SDave Jiang edac_pci_release_generic_ctl(i82443bxgx_pci); 383456a2f95SDave Jiang 3845a2c675cSTim Small if ((mci = edac_mc_del_mc(&pdev->dev)) == NULL) 3855a2c675cSTim Small return; 3865a2c675cSTim Small 3875a2c675cSTim Small edac_mc_free(mci); 3885a2c675cSTim Small } 3895a2c675cSTim Small 39011116601SDouglas Thompson EXPORT_SYMBOL_GPL(i82443bxgx_edacmc_remove_one); 3915a2c675cSTim Small 39236c46f31SLionel Debroux static DEFINE_PCI_DEVICE_TABLE(i82443bxgx_pci_tbl) = { 3935a2c675cSTim Small {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_0)}, 3945a2c675cSTim Small {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_2)}, 3955a2c675cSTim Small {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0)}, 3965a2c675cSTim Small {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_2)}, 3975a2c675cSTim Small {0,} /* 0 terminated list. */ 3985a2c675cSTim Small }; 3995a2c675cSTim Small 4005a2c675cSTim Small MODULE_DEVICE_TABLE(pci, i82443bxgx_pci_tbl); 4015a2c675cSTim Small 4025a2c675cSTim Small static struct pci_driver i82443bxgx_edacmc_driver = { 4035a2c675cSTim Small .name = EDAC_MOD_STR, 4045a2c675cSTim Small .probe = i82443bxgx_edacmc_init_one, 4055a2c675cSTim Small .remove = __devexit_p(i82443bxgx_edacmc_remove_one), 4065a2c675cSTim Small .id_table = i82443bxgx_pci_tbl, 4075a2c675cSTim Small }; 4085a2c675cSTim Small 4095a2c675cSTim Small static int __init i82443bxgx_edacmc_init(void) 4105a2c675cSTim Small { 41153a2fe58SVladislav Bogdanov int pci_rc; 412c3c52bceSHitoshi Mitake /* Ensure that the OPSTATE is set correctly for POLL or NMI */ 413c3c52bceSHitoshi Mitake opstate_init(); 414c3c52bceSHitoshi Mitake 41553a2fe58SVladislav Bogdanov pci_rc = pci_register_driver(&i82443bxgx_edacmc_driver); 41653a2fe58SVladislav Bogdanov if (pci_rc < 0) 41753a2fe58SVladislav Bogdanov goto fail0; 41853a2fe58SVladislav Bogdanov 41953a2fe58SVladislav Bogdanov if (mci_pdev == NULL) { 42053a2fe58SVladislav Bogdanov const struct pci_device_id *id = &i82443bxgx_pci_tbl[0]; 42153a2fe58SVladislav Bogdanov int i = 0; 42253a2fe58SVladislav Bogdanov i82443bxgx_registered = 0; 42353a2fe58SVladislav Bogdanov 42453a2fe58SVladislav Bogdanov while (mci_pdev == NULL && id->vendor != 0) { 42553a2fe58SVladislav Bogdanov mci_pdev = pci_get_device(id->vendor, 42653a2fe58SVladislav Bogdanov id->device, NULL); 42753a2fe58SVladislav Bogdanov i++; 42853a2fe58SVladislav Bogdanov id = &i82443bxgx_pci_tbl[i]; 42953a2fe58SVladislav Bogdanov } 43053a2fe58SVladislav Bogdanov if (!mci_pdev) { 43153a2fe58SVladislav Bogdanov debugf0("i82443bxgx pci_get_device fail\n"); 43253a2fe58SVladislav Bogdanov pci_rc = -ENODEV; 43353a2fe58SVladislav Bogdanov goto fail1; 43453a2fe58SVladislav Bogdanov } 43553a2fe58SVladislav Bogdanov 43653a2fe58SVladislav Bogdanov pci_rc = i82443bxgx_edacmc_init_one(mci_pdev, i82443bxgx_pci_tbl); 43753a2fe58SVladislav Bogdanov 43853a2fe58SVladislav Bogdanov if (pci_rc < 0) { 43953a2fe58SVladislav Bogdanov debugf0("i82443bxgx init fail\n"); 44053a2fe58SVladislav Bogdanov pci_rc = -ENODEV; 44153a2fe58SVladislav Bogdanov goto fail1; 44253a2fe58SVladislav Bogdanov } 44353a2fe58SVladislav Bogdanov } 44453a2fe58SVladislav Bogdanov 44553a2fe58SVladislav Bogdanov return 0; 44653a2fe58SVladislav Bogdanov 44753a2fe58SVladislav Bogdanov fail1: 44853a2fe58SVladislav Bogdanov pci_unregister_driver(&i82443bxgx_edacmc_driver); 44953a2fe58SVladislav Bogdanov 45053a2fe58SVladislav Bogdanov fail0: 45153a2fe58SVladislav Bogdanov if (mci_pdev != NULL) 45253a2fe58SVladislav Bogdanov pci_dev_put(mci_pdev); 45353a2fe58SVladislav Bogdanov 45453a2fe58SVladislav Bogdanov return pci_rc; 4555a2c675cSTim Small } 4565a2c675cSTim Small 4575a2c675cSTim Small static void __exit i82443bxgx_edacmc_exit(void) 4585a2c675cSTim Small { 4595a2c675cSTim Small pci_unregister_driver(&i82443bxgx_edacmc_driver); 46053a2fe58SVladislav Bogdanov 46153a2fe58SVladislav Bogdanov if (!i82443bxgx_registered) 46253a2fe58SVladislav Bogdanov i82443bxgx_edacmc_remove_one(mci_pdev); 46353a2fe58SVladislav Bogdanov 46453a2fe58SVladislav Bogdanov if (mci_pdev) 46553a2fe58SVladislav Bogdanov pci_dev_put(mci_pdev); 4665a2c675cSTim Small } 4675a2c675cSTim Small 4685a2c675cSTim Small module_init(i82443bxgx_edacmc_init); 4695a2c675cSTim Small module_exit(i82443bxgx_edacmc_exit); 4705a2c675cSTim Small 4715a2c675cSTim Small MODULE_LICENSE("GPL"); 4725a2c675cSTim Small MODULE_AUTHOR("Tim Small <tim@buttersideup.com> - WPAD"); 4735a2c675cSTim Small MODULE_DESCRIPTION("EDAC MC support for Intel 82443BX/GX memory controllers"); 474c3c52bceSHitoshi Mitake 475c3c52bceSHitoshi Mitake module_param(edac_op_state, int, 0444); 476c3c52bceSHitoshi Mitake MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI"); 477