xref: /openbmc/linux/drivers/edac/i82443bxgx_edac.c (revision 25985edcedea6396277003854657b5f3cb31a628)
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)
15911116601SDouglas Thompson 			edac_mc_handle_ce(mci, page, pageoffset,
160052dfb45SDouglas Thompson 				/* 440BX/GX don't make syndrome information
161052dfb45SDouglas Thompson 				 * available */
162052dfb45SDouglas Thompson 				0, edac_mc_find_csrow_by_page(mci, page), 0,
1635a2c675cSTim Small 				mci->ctl_name);
1645a2c675cSTim Small 	}
1655a2c675cSTim Small 
1665a2c675cSTim Small 	if (info->eap & I82443BXGX_EAP_OFFSET_MBE) {
1675a2c675cSTim Small 		error_found = 1;
1685a2c675cSTim Small 		if (handle_errors)
16911116601SDouglas Thompson 			edac_mc_handle_ue(mci, page, pageoffset,
1705a2c675cSTim Small 					edac_mc_find_csrow_by_page(mci, page),
1715a2c675cSTim Small 					mci->ctl_name);
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;
1925a2c675cSTim Small 	int index;
1935a2c675cSTim Small 	u8 drbar, dramc;
1945a2c675cSTim Small 	u32 row_base, row_high_limit, row_high_limit_last;
1955a2c675cSTim Small 
1965a2c675cSTim Small 	pci_read_config_byte(pdev, I82443BXGX_DRAMC, &dramc);
1975a2c675cSTim Small 	row_high_limit_last = 0;
1985a2c675cSTim Small 	for (index = 0; index < mci->nr_csrows; index++) {
1995a2c675cSTim Small 		csrow = &mci->csrows[index];
2005a2c675cSTim Small 		pci_read_config_byte(pdev, I82443BXGX_DRB + index, &drbar);
20163ae96beSJoe Perches 		debugf1("MC%d: %s: %s() Row=%d DRB = %#0x\n",
20263ae96beSJoe Perches 			mci->mc_idx, __FILE__, __func__, index, drbar);
2035a2c675cSTim Small 		row_high_limit = ((u32) drbar << 23);
2045a2c675cSTim Small 		/* find the DRAM Chip Select Base address and mask */
20563ae96beSJoe Perches 		debugf1("MC%d: %s: %s() Row=%d, "
206*25985edcSLucas De Marchi 			"Boundary Address=%#0x, Last = %#0x\n",
20763ae96beSJoe Perches 			mci->mc_idx, __FILE__, __func__, index, row_high_limit,
2085a2c675cSTim Small 			row_high_limit_last);
2095a2c675cSTim Small 
2105a2c675cSTim Small 		/* 440GX goes to 2GB, represented with a DRB of 0. */
2115a2c675cSTim Small 		if (row_high_limit_last && !row_high_limit)
2125a2c675cSTim Small 			row_high_limit = 1UL << 31;
2135a2c675cSTim Small 
2145a2c675cSTim Small 		/* This row is empty [p.49] */
2155a2c675cSTim Small 		if (row_high_limit == row_high_limit_last)
2165a2c675cSTim Small 			continue;
2175a2c675cSTim Small 		row_base = row_high_limit_last;
2185a2c675cSTim Small 		csrow->first_page = row_base >> PAGE_SHIFT;
2195a2c675cSTim Small 		csrow->last_page = (row_high_limit >> PAGE_SHIFT) - 1;
2205a2c675cSTim Small 		csrow->nr_pages = csrow->last_page - csrow->first_page + 1;
2215a2c675cSTim Small 		/* EAP reports in 4kilobyte granularity [61] */
2225a2c675cSTim Small 		csrow->grain = 1 << 12;
2235a2c675cSTim Small 		csrow->mtype = mtype;
2245a2c675cSTim Small 		/* I don't think 440BX can tell you device type? FIXME? */
2255a2c675cSTim Small 		csrow->dtype = DEV_UNKNOWN;
2265a2c675cSTim Small 		/* Mode is global to all rows on 440BX */
2275a2c675cSTim Small 		csrow->edac_mode = edac_mode;
2285a2c675cSTim Small 		row_high_limit_last = row_high_limit;
2295a2c675cSTim Small 	}
2305a2c675cSTim Small }
2315a2c675cSTim Small 
2325a2c675cSTim Small static int i82443bxgx_edacmc_probe1(struct pci_dev *pdev, int dev_idx)
2335a2c675cSTim Small {
2345a2c675cSTim Small 	struct mem_ctl_info *mci;
2355a2c675cSTim Small 	u8 dramc;
2365a2c675cSTim Small 	u32 nbxcfg, ecc_mode;
2375a2c675cSTim Small 	enum mem_type mtype;
2385a2c675cSTim Small 	enum edac_type edac_mode;
2395a2c675cSTim Small 
24063ae96beSJoe Perches 	debugf0("MC: %s: %s()\n", __FILE__, __func__);
2415a2c675cSTim Small 
2425a2c675cSTim Small 	/* Something is really hosed if PCI config space reads from
243052dfb45SDouglas Thompson 	 * the MC aren't working.
244052dfb45SDouglas Thompson 	 */
2455a2c675cSTim Small 	if (pci_read_config_dword(pdev, I82443BXGX_NBXCFG, &nbxcfg))
2465a2c675cSTim Small 		return -EIO;
2475a2c675cSTim Small 
248b8f6f975SDoug Thompson 	mci = edac_mc_alloc(0, I82443BXGX_NR_CSROWS, I82443BXGX_NR_CHANS, 0);
2495a2c675cSTim Small 
2505a2c675cSTim Small 	if (mci == NULL)
2515a2c675cSTim Small 		return -ENOMEM;
2525a2c675cSTim Small 
25363ae96beSJoe Perches 	debugf0("MC: %s: %s(): mci = %p\n", __FILE__, __func__, mci);
2545a2c675cSTim Small 	mci->dev = &pdev->dev;
2555a2c675cSTim Small 	mci->mtype_cap = MEM_FLAG_EDO | MEM_FLAG_SDR | MEM_FLAG_RDR;
2565a2c675cSTim Small 	mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_EC | EDAC_FLAG_SECDED;
2575a2c675cSTim Small 	pci_read_config_byte(pdev, I82443BXGX_DRAMC, &dramc);
2585a2c675cSTim Small 	switch ((dramc >> I82443BXGX_DRAMC_OFFSET_DT) & (BIT(0) | BIT(1))) {
2595a2c675cSTim Small 	case I82443BXGX_DRAMC_DRAM_IS_EDO:
2605a2c675cSTim Small 		mtype = MEM_EDO;
2615a2c675cSTim Small 		break;
2625a2c675cSTim Small 	case I82443BXGX_DRAMC_DRAM_IS_SDRAM:
2635a2c675cSTim Small 		mtype = MEM_SDR;
2645a2c675cSTim Small 		break;
2655a2c675cSTim Small 	case I82443BXGX_DRAMC_DRAM_IS_RSDRAM:
2665a2c675cSTim Small 		mtype = MEM_RDR;
2675a2c675cSTim Small 		break;
2685a2c675cSTim Small 	default:
269052dfb45SDouglas Thompson 		debugf0("Unknown/reserved DRAM type value "
270052dfb45SDouglas Thompson 			"in DRAMC register!\n");
2715a2c675cSTim Small 		mtype = -MEM_UNKNOWN;
2725a2c675cSTim Small 	}
2735a2c675cSTim Small 
2745a2c675cSTim Small 	if ((mtype == MEM_SDR) || (mtype == MEM_RDR))
2755a2c675cSTim Small 		mci->edac_cap = mci->edac_ctl_cap;
2765a2c675cSTim Small 	else
2775a2c675cSTim Small 		mci->edac_cap = EDAC_FLAG_NONE;
2785a2c675cSTim Small 
2795a2c675cSTim Small 	mci->scrub_cap = SCRUB_FLAG_HW_SRC;
2805a2c675cSTim Small 	pci_read_config_dword(pdev, I82443BXGX_NBXCFG, &nbxcfg);
2815a2c675cSTim Small 	ecc_mode = ((nbxcfg >> I82443BXGX_NBXCFG_OFFSET_DRAM_INTEGRITY) &
2825a2c675cSTim Small 		(BIT(0) | BIT(1)));
2835a2c675cSTim Small 
2845a2c675cSTim Small 	mci->scrub_mode = (ecc_mode == I82443BXGX_NBXCFG_INTEGRITY_SCRUB)
28511116601SDouglas Thompson 		? SCRUB_HW_SRC : SCRUB_NONE;
2865a2c675cSTim Small 
2875a2c675cSTim Small 	switch (ecc_mode) {
2885a2c675cSTim Small 	case I82443BXGX_NBXCFG_INTEGRITY_NONE:
2895a2c675cSTim Small 		edac_mode = EDAC_NONE;
2905a2c675cSTim Small 		break;
2915a2c675cSTim Small 	case I82443BXGX_NBXCFG_INTEGRITY_EC:
2925a2c675cSTim Small 		edac_mode = EDAC_EC;
2935a2c675cSTim Small 		break;
2945a2c675cSTim Small 	case I82443BXGX_NBXCFG_INTEGRITY_ECC:
2955a2c675cSTim Small 	case I82443BXGX_NBXCFG_INTEGRITY_SCRUB:
2965a2c675cSTim Small 		edac_mode = EDAC_SECDED;
2975a2c675cSTim Small 		break;
2985a2c675cSTim Small 	default:
299052dfb45SDouglas Thompson 		debugf0("%s(): Unknown/reserved ECC state "
300052dfb45SDouglas Thompson 			"in NBXCFG register!\n", __func__);
3015a2c675cSTim Small 		edac_mode = EDAC_UNKNOWN;
3025a2c675cSTim Small 		break;
3035a2c675cSTim Small 	}
3045a2c675cSTim Small 
3055a2c675cSTim Small 	i82443bxgx_init_csrows(mci, pdev, edac_mode, mtype);
3065a2c675cSTim Small 
3075a2c675cSTim Small 	/* Many BIOSes don't clear error flags on boot, so do this
308*25985edcSLucas De Marchi 	 * here, or we get "phantom" errors occurring at module-load
3095a2c675cSTim Small 	 * time. */
3105a2c675cSTim Small 	pci_write_bits32(pdev, I82443BXGX_EAP,
31111116601SDouglas Thompson 			(I82443BXGX_EAP_OFFSET_SBE |
31211116601SDouglas Thompson 				I82443BXGX_EAP_OFFSET_MBE),
31311116601SDouglas Thompson 			(I82443BXGX_EAP_OFFSET_SBE |
31411116601SDouglas Thompson 				I82443BXGX_EAP_OFFSET_MBE));
3155a2c675cSTim Small 
3165a2c675cSTim Small 	mci->mod_name = EDAC_MOD_STR;
3175a2c675cSTim Small 	mci->mod_ver = I82443_REVISION;
3185a2c675cSTim Small 	mci->ctl_name = "I82443BXGX";
319c4192705SDave Jiang 	mci->dev_name = pci_name(pdev);
3205a2c675cSTim Small 	mci->edac_check = i82443bxgx_edacmc_check;
3215a2c675cSTim Small 	mci->ctl_page_to_phys = NULL;
3225a2c675cSTim Small 
323b8f6f975SDoug Thompson 	if (edac_mc_add_mc(mci)) {
3245a2c675cSTim Small 		debugf3("%s(): failed edac_mc_add_mc()\n", __func__);
3255a2c675cSTim Small 		goto fail;
3265a2c675cSTim Small 	}
3275a2c675cSTim Small 
328456a2f95SDave Jiang 	/* allocating generic PCI control info */
329456a2f95SDave Jiang 	i82443bxgx_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR);
330456a2f95SDave Jiang 	if (!i82443bxgx_pci) {
331456a2f95SDave Jiang 		printk(KERN_WARNING
332456a2f95SDave Jiang 			"%s(): Unable to create PCI control\n",
333456a2f95SDave Jiang 			__func__);
334456a2f95SDave Jiang 		printk(KERN_WARNING
335456a2f95SDave Jiang 			"%s(): PCI error report via EDAC not setup\n",
336456a2f95SDave Jiang 			__func__);
337456a2f95SDave Jiang 	}
338456a2f95SDave Jiang 
33963ae96beSJoe Perches 	debugf3("MC: %s: %s(): success\n", __FILE__, __func__);
3405a2c675cSTim Small 	return 0;
3415a2c675cSTim Small 
3425a2c675cSTim Small fail:
3435a2c675cSTim Small 	edac_mc_free(mci);
3445a2c675cSTim Small 	return -ENODEV;
3455a2c675cSTim Small }
34611116601SDouglas Thompson 
3475a2c675cSTim Small EXPORT_SYMBOL_GPL(i82443bxgx_edacmc_probe1);
3485a2c675cSTim Small 
3495a2c675cSTim Small /* returns count (>= 0), or negative on error */
3505a2c675cSTim Small static int __devinit i82443bxgx_edacmc_init_one(struct pci_dev *pdev,
3515a2c675cSTim Small 						const struct pci_device_id *ent)
3525a2c675cSTim Small {
35353a2fe58SVladislav Bogdanov 	int rc;
35453a2fe58SVladislav Bogdanov 
35563ae96beSJoe Perches 	debugf0("MC: %s: %s()\n", __FILE__, __func__);
3565a2c675cSTim Small 
357ee6583f6SRoman Fietze 	/* don't need to call pci_enable_device() */
35853a2fe58SVladislav Bogdanov 	rc = i82443bxgx_edacmc_probe1(pdev, ent->driver_data);
35953a2fe58SVladislav Bogdanov 
36053a2fe58SVladislav Bogdanov 	if (mci_pdev == NULL)
36153a2fe58SVladislav Bogdanov 		mci_pdev = pci_dev_get(pdev);
36253a2fe58SVladislav Bogdanov 
36353a2fe58SVladislav Bogdanov 	return rc;
3645a2c675cSTim Small }
3655a2c675cSTim Small 
3665a2c675cSTim Small static void __devexit i82443bxgx_edacmc_remove_one(struct pci_dev *pdev)
3675a2c675cSTim Small {
3685a2c675cSTim Small 	struct mem_ctl_info *mci;
3695a2c675cSTim Small 
37063ae96beSJoe Perches 	debugf0("%s: %s()\n", __FILE__, __func__);
3715a2c675cSTim Small 
372456a2f95SDave Jiang 	if (i82443bxgx_pci)
373456a2f95SDave Jiang 		edac_pci_release_generic_ctl(i82443bxgx_pci);
374456a2f95SDave Jiang 
3755a2c675cSTim Small 	if ((mci = edac_mc_del_mc(&pdev->dev)) == NULL)
3765a2c675cSTim Small 		return;
3775a2c675cSTim Small 
3785a2c675cSTim Small 	edac_mc_free(mci);
3795a2c675cSTim Small }
3805a2c675cSTim Small 
38111116601SDouglas Thompson EXPORT_SYMBOL_GPL(i82443bxgx_edacmc_remove_one);
3825a2c675cSTim Small 
3835a2c675cSTim Small static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitdata = {
3845a2c675cSTim Small 	{PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_0)},
3855a2c675cSTim Small 	{PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_2)},
3865a2c675cSTim Small 	{PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0)},
3875a2c675cSTim Small 	{PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_2)},
3885a2c675cSTim Small 	{0,}			/* 0 terminated list. */
3895a2c675cSTim Small };
3905a2c675cSTim Small 
3915a2c675cSTim Small MODULE_DEVICE_TABLE(pci, i82443bxgx_pci_tbl);
3925a2c675cSTim Small 
3935a2c675cSTim Small static struct pci_driver i82443bxgx_edacmc_driver = {
3945a2c675cSTim Small 	.name = EDAC_MOD_STR,
3955a2c675cSTim Small 	.probe = i82443bxgx_edacmc_init_one,
3965a2c675cSTim Small 	.remove = __devexit_p(i82443bxgx_edacmc_remove_one),
3975a2c675cSTim Small 	.id_table = i82443bxgx_pci_tbl,
3985a2c675cSTim Small };
3995a2c675cSTim Small 
4005a2c675cSTim Small static int __init i82443bxgx_edacmc_init(void)
4015a2c675cSTim Small {
40253a2fe58SVladislav Bogdanov 	int pci_rc;
403c3c52bceSHitoshi Mitake        /* Ensure that the OPSTATE is set correctly for POLL or NMI */
404c3c52bceSHitoshi Mitake        opstate_init();
405c3c52bceSHitoshi Mitake 
40653a2fe58SVladislav Bogdanov 	pci_rc = pci_register_driver(&i82443bxgx_edacmc_driver);
40753a2fe58SVladislav Bogdanov 	if (pci_rc < 0)
40853a2fe58SVladislav Bogdanov 		goto fail0;
40953a2fe58SVladislav Bogdanov 
41053a2fe58SVladislav Bogdanov 	if (mci_pdev == NULL) {
41153a2fe58SVladislav Bogdanov 		const struct pci_device_id *id = &i82443bxgx_pci_tbl[0];
41253a2fe58SVladislav Bogdanov 		int i = 0;
41353a2fe58SVladislav Bogdanov 		i82443bxgx_registered = 0;
41453a2fe58SVladislav Bogdanov 
41553a2fe58SVladislav Bogdanov 		while (mci_pdev == NULL && id->vendor != 0) {
41653a2fe58SVladislav Bogdanov 			mci_pdev = pci_get_device(id->vendor,
41753a2fe58SVladislav Bogdanov 					id->device, NULL);
41853a2fe58SVladislav Bogdanov 			i++;
41953a2fe58SVladislav Bogdanov 			id = &i82443bxgx_pci_tbl[i];
42053a2fe58SVladislav Bogdanov 		}
42153a2fe58SVladislav Bogdanov 		if (!mci_pdev) {
42253a2fe58SVladislav Bogdanov 			debugf0("i82443bxgx pci_get_device fail\n");
42353a2fe58SVladislav Bogdanov 			pci_rc = -ENODEV;
42453a2fe58SVladislav Bogdanov 			goto fail1;
42553a2fe58SVladislav Bogdanov 		}
42653a2fe58SVladislav Bogdanov 
42753a2fe58SVladislav Bogdanov 		pci_rc = i82443bxgx_edacmc_init_one(mci_pdev, i82443bxgx_pci_tbl);
42853a2fe58SVladislav Bogdanov 
42953a2fe58SVladislav Bogdanov 		if (pci_rc < 0) {
43053a2fe58SVladislav Bogdanov 			debugf0("i82443bxgx init fail\n");
43153a2fe58SVladislav Bogdanov 			pci_rc = -ENODEV;
43253a2fe58SVladislav Bogdanov 			goto fail1;
43353a2fe58SVladislav Bogdanov 		}
43453a2fe58SVladislav Bogdanov 	}
43553a2fe58SVladislav Bogdanov 
43653a2fe58SVladislav Bogdanov 	return 0;
43753a2fe58SVladislav Bogdanov 
43853a2fe58SVladislav Bogdanov fail1:
43953a2fe58SVladislav Bogdanov 	pci_unregister_driver(&i82443bxgx_edacmc_driver);
44053a2fe58SVladislav Bogdanov 
44153a2fe58SVladislav Bogdanov fail0:
44253a2fe58SVladislav Bogdanov 	if (mci_pdev != NULL)
44353a2fe58SVladislav Bogdanov 		pci_dev_put(mci_pdev);
44453a2fe58SVladislav Bogdanov 
44553a2fe58SVladislav Bogdanov 	return pci_rc;
4465a2c675cSTim Small }
4475a2c675cSTim Small 
4485a2c675cSTim Small static void __exit i82443bxgx_edacmc_exit(void)
4495a2c675cSTim Small {
4505a2c675cSTim Small 	pci_unregister_driver(&i82443bxgx_edacmc_driver);
45153a2fe58SVladislav Bogdanov 
45253a2fe58SVladislav Bogdanov 	if (!i82443bxgx_registered)
45353a2fe58SVladislav Bogdanov 		i82443bxgx_edacmc_remove_one(mci_pdev);
45453a2fe58SVladislav Bogdanov 
45553a2fe58SVladislav Bogdanov 	if (mci_pdev)
45653a2fe58SVladislav Bogdanov 		pci_dev_put(mci_pdev);
4575a2c675cSTim Small }
4585a2c675cSTim Small 
4595a2c675cSTim Small module_init(i82443bxgx_edacmc_init);
4605a2c675cSTim Small module_exit(i82443bxgx_edacmc_exit);
4615a2c675cSTim Small 
4625a2c675cSTim Small MODULE_LICENSE("GPL");
4635a2c675cSTim Small MODULE_AUTHOR("Tim Small <tim@buttersideup.com> - WPAD");
4645a2c675cSTim Small MODULE_DESCRIPTION("EDAC MC support for Intel 82443BX/GX memory controllers");
465c3c52bceSHitoshi Mitake 
466c3c52bceSHitoshi Mitake module_param(edac_op_state, int, 0444);
467c3c52bceSHitoshi Mitake MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");
468