xref: /openbmc/linux/drivers/edac/i82443bxgx_edac.c (revision cdd38c5f1ce4398ec58fec95904b75824daab7b5)
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>
32*78d88e8aSMauro Carvalho Chehab #include "edac_module.h"
335a2c675cSTim Small 
345a2c675cSTim Small #define EDAC_MOD_STR    "i82443bxgx_edac"
355a2c675cSTim Small 
365a2c675cSTim Small /* The 82443BX supports SDRAM, or EDO (EDO for mobile only), "Memory
375a2c675cSTim Small  * Size: 8 MB to 512 MB (1GB with Registered DIMMs) with eight memory
385a2c675cSTim Small  * rows" "The 82443BX supports multiple-bit error detection and
395a2c675cSTim Small  * single-bit error correction when ECC mode is enabled and
405a2c675cSTim Small  * single/multi-bit error detection when correction is disabled.
415a2c675cSTim Small  * During writes to the DRAM, the 82443BX generates ECC for the data
425a2c675cSTim Small  * on a QWord basis. Partial QWord writes require a read-modify-write
435a2c675cSTim Small  * cycle when ECC is enabled."
445a2c675cSTim Small */
455a2c675cSTim Small 
465a2c675cSTim Small /* "Additionally, the 82443BX ensures that the data is corrected in
475a2c675cSTim Small  * main memory so that accumulation of errors is prevented. Another
485a2c675cSTim Small  * error within the same QWord would result in a double-bit error
495a2c675cSTim Small  * which is unrecoverable. This is known as hardware scrubbing since
505a2c675cSTim Small  * it requires no software intervention to correct the data in memory."
515a2c675cSTim Small  */
525a2c675cSTim Small 
535a2c675cSTim Small /* [Also see page 100 (section 4.3), "DRAM Interface"]
545a2c675cSTim Small  * [Also see page 112 (section 4.6.1.4), ECC]
555a2c675cSTim Small  */
565a2c675cSTim Small 
575a2c675cSTim Small #define I82443BXGX_NR_CSROWS 8
585a2c675cSTim Small #define I82443BXGX_NR_CHANS  1
595a2c675cSTim Small #define I82443BXGX_NR_DIMMS  4
605a2c675cSTim Small 
615a2c675cSTim Small /* 82443 PCI Device 0 */
625a2c675cSTim Small #define I82443BXGX_NBXCFG 0x50	/* 32bit register starting at this PCI
635a2c675cSTim Small 				 * config space offset */
645a2c675cSTim Small #define I82443BXGX_NBXCFG_OFFSET_NON_ECCROW 24	/* Array of bits, zero if
655a2c675cSTim Small 						 * row is non-ECC */
665a2c675cSTim Small #define I82443BXGX_NBXCFG_OFFSET_DRAM_FREQ 12	/* 2 bits,00=100MHz,10=66 MHz */
675a2c675cSTim Small 
685a2c675cSTim Small #define I82443BXGX_NBXCFG_OFFSET_DRAM_INTEGRITY 7	/* 2 bits:       */
695a2c675cSTim Small #define I82443BXGX_NBXCFG_INTEGRITY_NONE   0x0	/* 00 = Non-ECC */
705a2c675cSTim Small #define I82443BXGX_NBXCFG_INTEGRITY_EC     0x1	/* 01 = EC (only) */
715a2c675cSTim Small #define I82443BXGX_NBXCFG_INTEGRITY_ECC    0x2	/* 10 = ECC */
725a2c675cSTim Small #define I82443BXGX_NBXCFG_INTEGRITY_SCRUB  0x3	/* 11 = ECC + HW Scrub */
735a2c675cSTim Small 
745a2c675cSTim Small #define I82443BXGX_NBXCFG_OFFSET_ECC_DIAG_ENABLE  6
755a2c675cSTim Small 
765a2c675cSTim Small /* 82443 PCI Device 0 */
775a2c675cSTim Small #define I82443BXGX_EAP   0x80	/* 32bit register starting at this PCI
785a2c675cSTim Small 				 * config space offset, Error Address
795a2c675cSTim Small 				 * Pointer Register */
805a2c675cSTim Small #define I82443BXGX_EAP_OFFSET_EAP  12	/* High 20 bits of error address */
815a2c675cSTim Small #define I82443BXGX_EAP_OFFSET_MBE  BIT(1)	/* Err at EAP was multi-bit (W1TC) */
825a2c675cSTim Small #define I82443BXGX_EAP_OFFSET_SBE  BIT(0)	/* Err at EAP was single-bit (W1TC) */
835a2c675cSTim Small 
845a2c675cSTim Small #define I82443BXGX_ERRCMD  0x90	/* 8bit register starting at this PCI
855a2c675cSTim Small 				 * config space offset. */
865a2c675cSTim Small #define I82443BXGX_ERRCMD_OFFSET_SERR_ON_MBE BIT(1)	/* 1 = enable */
875a2c675cSTim Small #define I82443BXGX_ERRCMD_OFFSET_SERR_ON_SBE BIT(0)	/* 1 = enable */
885a2c675cSTim Small 
895a2c675cSTim Small #define I82443BXGX_ERRSTS  0x91	/* 16bit register starting at this PCI
905a2c675cSTim Small 				 * config space offset. */
915a2c675cSTim Small #define I82443BXGX_ERRSTS_OFFSET_MBFRE 5	/* 3 bits - first err row multibit */
925a2c675cSTim Small #define I82443BXGX_ERRSTS_OFFSET_MEF   BIT(4)	/* 1 = MBE occurred */
935a2c675cSTim Small #define I82443BXGX_ERRSTS_OFFSET_SBFRE 1	/* 3 bits - first err row singlebit */
945a2c675cSTim Small #define I82443BXGX_ERRSTS_OFFSET_SEF   BIT(0)	/* 1 = SBE occurred */
955a2c675cSTim Small 
965a2c675cSTim Small #define I82443BXGX_DRAMC 0x57	/* 8bit register starting at this PCI
975a2c675cSTim Small 				 * config space offset. */
985a2c675cSTim Small #define I82443BXGX_DRAMC_OFFSET_DT 3	/* 2 bits, DRAM Type */
995a2c675cSTim Small #define I82443BXGX_DRAMC_DRAM_IS_EDO 0	/* 00 = EDO */
1005a2c675cSTim Small #define I82443BXGX_DRAMC_DRAM_IS_SDRAM 1	/* 01 = SDRAM */
1015a2c675cSTim Small #define I82443BXGX_DRAMC_DRAM_IS_RSDRAM 2	/* 10 = Registered SDRAM */
1025a2c675cSTim Small 
1035a2c675cSTim Small #define I82443BXGX_DRB 0x60	/* 8x 8bit registers starting at this PCI
1045a2c675cSTim Small 				 * config space offset. */
1055a2c675cSTim Small 
1065a2c675cSTim Small /* FIXME - don't poll when ECC disabled? */
1075a2c675cSTim Small 
1085a2c675cSTim Small struct i82443bxgx_edacmc_error_info {
1095a2c675cSTim Small 	u32 eap;
1105a2c675cSTim Small };
1115a2c675cSTim Small 
112456a2f95SDave Jiang static struct edac_pci_ctl_info *i82443bxgx_pci;
113456a2f95SDave Jiang 
11453a2fe58SVladislav Bogdanov static struct pci_dev *mci_pdev;	/* init dev: in case that AGP code has
11553a2fe58SVladislav Bogdanov 					 * already registered driver
11653a2fe58SVladislav Bogdanov 					 */
11753a2fe58SVladislav Bogdanov 
11853a2fe58SVladislav Bogdanov static int i82443bxgx_registered = 1;
11953a2fe58SVladislav Bogdanov 
i82443bxgx_edacmc_get_error_info(struct mem_ctl_info * mci,struct i82443bxgx_edacmc_error_info * info)1205a2c675cSTim Small static void i82443bxgx_edacmc_get_error_info(struct mem_ctl_info *mci,
12111116601SDouglas Thompson 				struct i82443bxgx_edacmc_error_info
12211116601SDouglas Thompson 				*info)
1235a2c675cSTim Small {
1245a2c675cSTim Small 	struct pci_dev *pdev;
125fd687502SMauro Carvalho Chehab 	pdev = to_pci_dev(mci->pdev);
1265a2c675cSTim Small 	pci_read_config_dword(pdev, I82443BXGX_EAP, &info->eap);
1275a2c675cSTim Small 	if (info->eap & I82443BXGX_EAP_OFFSET_SBE)
1285a2c675cSTim Small 		/* Clear error to allow next error to be reported [p.61] */
1295a2c675cSTim Small 		pci_write_bits32(pdev, I82443BXGX_EAP,
1305a2c675cSTim Small 				 I82443BXGX_EAP_OFFSET_SBE,
1315a2c675cSTim Small 				 I82443BXGX_EAP_OFFSET_SBE);
1325a2c675cSTim Small 
1335a2c675cSTim Small 	if (info->eap & I82443BXGX_EAP_OFFSET_MBE)
1345a2c675cSTim Small 		/* Clear error to allow next error to be reported [p.61] */
1355a2c675cSTim Small 		pci_write_bits32(pdev, I82443BXGX_EAP,
1365a2c675cSTim Small 				 I82443BXGX_EAP_OFFSET_MBE,
1375a2c675cSTim Small 				 I82443BXGX_EAP_OFFSET_MBE);
1385a2c675cSTim Small }
1395a2c675cSTim Small 
i82443bxgx_edacmc_process_error_info(struct mem_ctl_info * mci,struct i82443bxgx_edacmc_error_info * info,int handle_errors)1405a2c675cSTim Small static int i82443bxgx_edacmc_process_error_info(struct mem_ctl_info *mci,
14111116601SDouglas Thompson 						struct
14211116601SDouglas Thompson 						i82443bxgx_edacmc_error_info
14311116601SDouglas Thompson 						*info, int handle_errors)
1445a2c675cSTim Small {
1455a2c675cSTim Small 	int error_found = 0;
1465a2c675cSTim Small 	u32 eapaddr, page, pageoffset;
1475a2c675cSTim Small 
1485a2c675cSTim Small 	/* bits 30:12 hold the 4kb block in which the error occurred
1495a2c675cSTim Small 	 * [p.61] */
1505a2c675cSTim Small 	eapaddr = (info->eap & 0xfffff000);
1515a2c675cSTim Small 	page = eapaddr >> PAGE_SHIFT;
1525a2c675cSTim Small 	pageoffset = eapaddr - (page << PAGE_SHIFT);
1535a2c675cSTim Small 
1545a2c675cSTim Small 	if (info->eap & I82443BXGX_EAP_OFFSET_SBE) {
1555a2c675cSTim Small 		error_found = 1;
1565a2c675cSTim Small 		if (handle_errors)
1579eb07a7fSMauro Carvalho Chehab 			edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 1,
15840f562b1SMauro Carvalho Chehab 					     page, pageoffset, 0,
15940f562b1SMauro Carvalho Chehab 					     edac_mc_find_csrow_by_page(mci, page),
16003f7eae8SMauro Carvalho Chehab 					     0, -1, mci->ctl_name, "");
1615a2c675cSTim Small 	}
1625a2c675cSTim Small 
1635a2c675cSTim Small 	if (info->eap & I82443BXGX_EAP_OFFSET_MBE) {
1645a2c675cSTim Small 		error_found = 1;
1655a2c675cSTim Small 		if (handle_errors)
1669eb07a7fSMauro Carvalho Chehab 			edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, 1,
16740f562b1SMauro Carvalho Chehab 					     page, pageoffset, 0,
1685a2c675cSTim Small 					     edac_mc_find_csrow_by_page(mci, page),
16903f7eae8SMauro Carvalho Chehab 					     0, -1, mci->ctl_name, "");
1705a2c675cSTim Small 	}
1715a2c675cSTim Small 
1725a2c675cSTim Small 	return error_found;
1735a2c675cSTim Small }
1745a2c675cSTim Small 
i82443bxgx_edacmc_check(struct mem_ctl_info * mci)1755a2c675cSTim Small static void i82443bxgx_edacmc_check(struct mem_ctl_info *mci)
1765a2c675cSTim Small {
1775a2c675cSTim Small 	struct i82443bxgx_edacmc_error_info info;
1785a2c675cSTim Small 
1795a2c675cSTim Small 	i82443bxgx_edacmc_get_error_info(mci, &info);
1805a2c675cSTim Small 	i82443bxgx_edacmc_process_error_info(mci, &info, 1);
1815a2c675cSTim Small }
1825a2c675cSTim Small 
i82443bxgx_init_csrows(struct mem_ctl_info * mci,struct pci_dev * pdev,enum edac_type edac_mode,enum mem_type mtype)1835a2c675cSTim Small static void i82443bxgx_init_csrows(struct mem_ctl_info *mci,
1845a2c675cSTim Small 				struct pci_dev *pdev,
1855a2c675cSTim Small 				enum edac_type edac_mode,
1865a2c675cSTim Small 				enum mem_type mtype)
1875a2c675cSTim Small {
1885a2c675cSTim Small 	struct csrow_info *csrow;
189084a4fccSMauro Carvalho Chehab 	struct dimm_info *dimm;
1905a2c675cSTim Small 	int index;
1915a2c675cSTim Small 	u8 drbar, dramc;
1925a2c675cSTim Small 	u32 row_base, row_high_limit, row_high_limit_last;
1935a2c675cSTim Small 
1945a2c675cSTim Small 	pci_read_config_byte(pdev, I82443BXGX_DRAMC, &dramc);
1955a2c675cSTim Small 	row_high_limit_last = 0;
1965a2c675cSTim Small 	for (index = 0; index < mci->nr_csrows; index++) {
197de3910ebSMauro Carvalho Chehab 		csrow = mci->csrows[index];
198de3910ebSMauro Carvalho Chehab 		dimm = csrow->channels[0]->dimm;
199084a4fccSMauro Carvalho Chehab 
2005a2c675cSTim Small 		pci_read_config_byte(pdev, I82443BXGX_DRB + index, &drbar);
201956b9ba1SJoe Perches 		edac_dbg(1, "MC%d: Row=%d DRB = %#0x\n",
202dd23cd6eSMauro Carvalho Chehab 			 mci->mc_idx, index, drbar);
2035a2c675cSTim Small 		row_high_limit = ((u32) drbar << 23);
2045a2c675cSTim Small 		/* find the DRAM Chip Select Base address and mask */
205956b9ba1SJoe Perches 		edac_dbg(1, "MC%d: Row=%d, Boundary Address=%#0x, Last = %#0x\n",
206dd23cd6eSMauro Carvalho Chehab 			 mci->mc_idx, index, row_high_limit,
2075a2c675cSTim Small 			 row_high_limit_last);
2085a2c675cSTim Small 
2095a2c675cSTim Small 		/* 440GX goes to 2GB, represented with a DRB of 0. */
2105a2c675cSTim Small 		if (row_high_limit_last && !row_high_limit)
2115a2c675cSTim Small 			row_high_limit = 1UL << 31;
2125a2c675cSTim Small 
2135a2c675cSTim Small 		/* This row is empty [p.49] */
2145a2c675cSTim Small 		if (row_high_limit == row_high_limit_last)
2155a2c675cSTim Small 			continue;
2165a2c675cSTim Small 		row_base = row_high_limit_last;
2175a2c675cSTim Small 		csrow->first_page = row_base >> PAGE_SHIFT;
2185a2c675cSTim Small 		csrow->last_page = (row_high_limit >> PAGE_SHIFT) - 1;
219a895bf8bSMauro Carvalho Chehab 		dimm->nr_pages = csrow->last_page - csrow->first_page + 1;
2205a2c675cSTim Small 		/* EAP reports in 4kilobyte granularity [61] */
221084a4fccSMauro Carvalho Chehab 		dimm->grain = 1 << 12;
222084a4fccSMauro Carvalho Chehab 		dimm->mtype = mtype;
2235a2c675cSTim Small 		/* I don't think 440BX can tell you device type? FIXME? */
224084a4fccSMauro Carvalho Chehab 		dimm->dtype = DEV_UNKNOWN;
2255a2c675cSTim Small 		/* Mode is global to all rows on 440BX */
226084a4fccSMauro Carvalho Chehab 		dimm->edac_mode = edac_mode;
2275a2c675cSTim Small 		row_high_limit_last = row_high_limit;
2285a2c675cSTim Small 	}
2295a2c675cSTim Small }
2305a2c675cSTim Small 
i82443bxgx_edacmc_probe1(struct pci_dev * pdev,int dev_idx)2315a2c675cSTim Small static int i82443bxgx_edacmc_probe1(struct pci_dev *pdev, int dev_idx)
2325a2c675cSTim Small {
2335a2c675cSTim Small 	struct mem_ctl_info *mci;
23440f562b1SMauro Carvalho Chehab 	struct edac_mc_layer layers[2];
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 
240956b9ba1SJoe Perches 	edac_dbg(0, "MC:\n");
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 
24840f562b1SMauro Carvalho Chehab 	layers[0].type = EDAC_MC_LAYER_CHIP_SELECT;
24940f562b1SMauro Carvalho Chehab 	layers[0].size = I82443BXGX_NR_CSROWS;
25040f562b1SMauro Carvalho Chehab 	layers[0].is_virt_csrow = true;
25140f562b1SMauro Carvalho Chehab 	layers[1].type = EDAC_MC_LAYER_CHANNEL;
25240f562b1SMauro Carvalho Chehab 	layers[1].size = I82443BXGX_NR_CHANS;
25340f562b1SMauro Carvalho Chehab 	layers[1].is_virt_csrow = false;
254ca0907b9SMauro Carvalho Chehab 	mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers, 0);
2555a2c675cSTim Small 	if (mci == NULL)
2565a2c675cSTim Small 		return -ENOMEM;
2575a2c675cSTim Small 
258956b9ba1SJoe Perches 	edac_dbg(0, "MC: mci = %p\n", mci);
259fd687502SMauro Carvalho Chehab 	mci->pdev = &pdev->dev;
2605a2c675cSTim Small 	mci->mtype_cap = MEM_FLAG_EDO | MEM_FLAG_SDR | MEM_FLAG_RDR;
2615a2c675cSTim Small 	mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_EC | EDAC_FLAG_SECDED;
2625a2c675cSTim Small 	pci_read_config_byte(pdev, I82443BXGX_DRAMC, &dramc);
2635a2c675cSTim Small 	switch ((dramc >> I82443BXGX_DRAMC_OFFSET_DT) & (BIT(0) | BIT(1))) {
2645a2c675cSTim Small 	case I82443BXGX_DRAMC_DRAM_IS_EDO:
2655a2c675cSTim Small 		mtype = MEM_EDO;
2665a2c675cSTim Small 		break;
2675a2c675cSTim Small 	case I82443BXGX_DRAMC_DRAM_IS_SDRAM:
2685a2c675cSTim Small 		mtype = MEM_SDR;
2695a2c675cSTim Small 		break;
2705a2c675cSTim Small 	case I82443BXGX_DRAMC_DRAM_IS_RSDRAM:
2715a2c675cSTim Small 		mtype = MEM_RDR;
2725a2c675cSTim Small 		break;
2735a2c675cSTim Small 	default:
274956b9ba1SJoe Perches 		edac_dbg(0, "Unknown/reserved DRAM type value in DRAMC register!\n");
2755a2c675cSTim Small 		mtype = -MEM_UNKNOWN;
2765a2c675cSTim Small 	}
2775a2c675cSTim Small 
2785a2c675cSTim Small 	if ((mtype == MEM_SDR) || (mtype == MEM_RDR))
2795a2c675cSTim Small 		mci->edac_cap = mci->edac_ctl_cap;
2805a2c675cSTim Small 	else
2815a2c675cSTim Small 		mci->edac_cap = EDAC_FLAG_NONE;
2825a2c675cSTim Small 
2835a2c675cSTim Small 	mci->scrub_cap = SCRUB_FLAG_HW_SRC;
2845a2c675cSTim Small 	pci_read_config_dword(pdev, I82443BXGX_NBXCFG, &nbxcfg);
2855a2c675cSTim Small 	ecc_mode = ((nbxcfg >> I82443BXGX_NBXCFG_OFFSET_DRAM_INTEGRITY) &
2865a2c675cSTim Small 		(BIT(0) | BIT(1)));
2875a2c675cSTim Small 
2885a2c675cSTim Small 	mci->scrub_mode = (ecc_mode == I82443BXGX_NBXCFG_INTEGRITY_SCRUB)
28911116601SDouglas Thompson 		? SCRUB_HW_SRC : SCRUB_NONE;
2905a2c675cSTim Small 
2915a2c675cSTim Small 	switch (ecc_mode) {
2925a2c675cSTim Small 	case I82443BXGX_NBXCFG_INTEGRITY_NONE:
2935a2c675cSTim Small 		edac_mode = EDAC_NONE;
2945a2c675cSTim Small 		break;
2955a2c675cSTim Small 	case I82443BXGX_NBXCFG_INTEGRITY_EC:
2965a2c675cSTim Small 		edac_mode = EDAC_EC;
2975a2c675cSTim Small 		break;
2985a2c675cSTim Small 	case I82443BXGX_NBXCFG_INTEGRITY_ECC:
2995a2c675cSTim Small 	case I82443BXGX_NBXCFG_INTEGRITY_SCRUB:
3005a2c675cSTim Small 		edac_mode = EDAC_SECDED;
3015a2c675cSTim Small 		break;
3025a2c675cSTim Small 	default:
303956b9ba1SJoe Perches 		edac_dbg(0, "Unknown/reserved ECC state in NBXCFG register!\n");
3045a2c675cSTim Small 		edac_mode = EDAC_UNKNOWN;
3055a2c675cSTim Small 		break;
3065a2c675cSTim Small 	}
3075a2c675cSTim Small 
3085a2c675cSTim Small 	i82443bxgx_init_csrows(mci, pdev, edac_mode, mtype);
3095a2c675cSTim Small 
3105a2c675cSTim Small 	/* Many BIOSes don't clear error flags on boot, so do this
31125985edcSLucas De Marchi 	 * here, or we get "phantom" errors occurring at module-load
3125a2c675cSTim Small 	 * time. */
3135a2c675cSTim Small 	pci_write_bits32(pdev, I82443BXGX_EAP,
31411116601SDouglas Thompson 			(I82443BXGX_EAP_OFFSET_SBE |
31511116601SDouglas Thompson 				I82443BXGX_EAP_OFFSET_MBE),
31611116601SDouglas Thompson 			(I82443BXGX_EAP_OFFSET_SBE |
31711116601SDouglas Thompson 				I82443BXGX_EAP_OFFSET_MBE));
3185a2c675cSTim Small 
3195a2c675cSTim Small 	mci->mod_name = EDAC_MOD_STR;
3205a2c675cSTim Small 	mci->ctl_name = "I82443BXGX";
321c4192705SDave Jiang 	mci->dev_name = pci_name(pdev);
3225a2c675cSTim Small 	mci->edac_check = i82443bxgx_edacmc_check;
3235a2c675cSTim Small 	mci->ctl_page_to_phys = NULL;
3245a2c675cSTim Small 
325b8f6f975SDoug Thompson 	if (edac_mc_add_mc(mci)) {
326956b9ba1SJoe Perches 		edac_dbg(3, "failed edac_mc_add_mc()\n");
3275a2c675cSTim Small 		goto fail;
3285a2c675cSTim Small 	}
3295a2c675cSTim Small 
330456a2f95SDave Jiang 	/* allocating generic PCI control info */
331456a2f95SDave Jiang 	i82443bxgx_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR);
332456a2f95SDave Jiang 	if (!i82443bxgx_pci) {
333456a2f95SDave Jiang 		printk(KERN_WARNING
334456a2f95SDave Jiang 			"%s(): Unable to create PCI control\n",
335456a2f95SDave Jiang 			__func__);
336456a2f95SDave Jiang 		printk(KERN_WARNING
337456a2f95SDave Jiang 			"%s(): PCI error report via EDAC not setup\n",
338456a2f95SDave Jiang 			__func__);
339456a2f95SDave Jiang 	}
340456a2f95SDave Jiang 
341956b9ba1SJoe Perches 	edac_dbg(3, "MC: success\n");
3425a2c675cSTim Small 	return 0;
3435a2c675cSTim Small 
3445a2c675cSTim Small fail:
3455a2c675cSTim Small 	edac_mc_free(mci);
3465a2c675cSTim Small 	return -ENODEV;
3475a2c675cSTim Small }
34811116601SDouglas Thompson 
3495a2c675cSTim Small /* returns count (>= 0), or negative on error */
i82443bxgx_edacmc_init_one(struct pci_dev * pdev,const struct pci_device_id * ent)3509b3c6e85SGreg Kroah-Hartman static int i82443bxgx_edacmc_init_one(struct pci_dev *pdev,
3515a2c675cSTim Small 				      const struct pci_device_id *ent)
3525a2c675cSTim Small {
35353a2fe58SVladislav Bogdanov 	int rc;
35453a2fe58SVladislav Bogdanov 
355956b9ba1SJoe Perches 	edac_dbg(0, "MC:\n");
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 
i82443bxgx_edacmc_remove_one(struct pci_dev * pdev)3669b3c6e85SGreg Kroah-Hartman static void i82443bxgx_edacmc_remove_one(struct pci_dev *pdev)
3675a2c675cSTim Small {
3685a2c675cSTim Small 	struct mem_ctl_info *mci;
3695a2c675cSTim Small 
370956b9ba1SJoe Perches 	edac_dbg(0, "\n");
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 
381ba935f40SJingoo Han static const struct pci_device_id i82443bxgx_pci_tbl[] = {
3825a2c675cSTim Small 	{PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_0)},
3835a2c675cSTim Small 	{PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_2)},
3845a2c675cSTim Small 	{PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0)},
3855a2c675cSTim Small 	{PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_2)},
3865a2c675cSTim Small 	{0,}			/* 0 terminated list. */
3875a2c675cSTim Small };
3885a2c675cSTim Small 
3895a2c675cSTim Small MODULE_DEVICE_TABLE(pci, i82443bxgx_pci_tbl);
3905a2c675cSTim Small 
3915a2c675cSTim Small static struct pci_driver i82443bxgx_edacmc_driver = {
3925a2c675cSTim Small 	.name = EDAC_MOD_STR,
3935a2c675cSTim Small 	.probe = i82443bxgx_edacmc_init_one,
3949b3c6e85SGreg Kroah-Hartman 	.remove = i82443bxgx_edacmc_remove_one,
3955a2c675cSTim Small 	.id_table = i82443bxgx_pci_tbl,
3965a2c675cSTim Small };
3975a2c675cSTim Small 
i82443bxgx_edacmc_init(void)3985a2c675cSTim Small static int __init i82443bxgx_edacmc_init(void)
3995a2c675cSTim Small {
40053a2fe58SVladislav Bogdanov 	int pci_rc;
401c3c52bceSHitoshi Mitake        /* Ensure that the OPSTATE is set correctly for POLL or NMI */
402c3c52bceSHitoshi Mitake        opstate_init();
403c3c52bceSHitoshi Mitake 
40453a2fe58SVladislav Bogdanov 	pci_rc = pci_register_driver(&i82443bxgx_edacmc_driver);
40553a2fe58SVladislav Bogdanov 	if (pci_rc < 0)
40653a2fe58SVladislav Bogdanov 		goto fail0;
40753a2fe58SVladislav Bogdanov 
40853a2fe58SVladislav Bogdanov 	if (mci_pdev == NULL) {
40953a2fe58SVladislav Bogdanov 		const struct pci_device_id *id = &i82443bxgx_pci_tbl[0];
41053a2fe58SVladislav Bogdanov 		int i = 0;
41153a2fe58SVladislav Bogdanov 		i82443bxgx_registered = 0;
41253a2fe58SVladislav Bogdanov 
41353a2fe58SVladislav Bogdanov 		while (mci_pdev == NULL && id->vendor != 0) {
41453a2fe58SVladislav Bogdanov 			mci_pdev = pci_get_device(id->vendor,
41553a2fe58SVladislav Bogdanov 					id->device, NULL);
41653a2fe58SVladislav Bogdanov 			i++;
41753a2fe58SVladislav Bogdanov 			id = &i82443bxgx_pci_tbl[i];
41853a2fe58SVladislav Bogdanov 		}
41953a2fe58SVladislav Bogdanov 		if (!mci_pdev) {
420956b9ba1SJoe Perches 			edac_dbg(0, "i82443bxgx pci_get_device fail\n");
42153a2fe58SVladislav Bogdanov 			pci_rc = -ENODEV;
42253a2fe58SVladislav Bogdanov 			goto fail1;
42353a2fe58SVladislav Bogdanov 		}
42453a2fe58SVladislav Bogdanov 
42553a2fe58SVladislav Bogdanov 		pci_rc = i82443bxgx_edacmc_init_one(mci_pdev, i82443bxgx_pci_tbl);
42653a2fe58SVladislav Bogdanov 
42753a2fe58SVladislav Bogdanov 		if (pci_rc < 0) {
428956b9ba1SJoe Perches 			edac_dbg(0, "i82443bxgx init fail\n");
42953a2fe58SVladislav Bogdanov 			pci_rc = -ENODEV;
43053a2fe58SVladislav Bogdanov 			goto fail1;
43153a2fe58SVladislav Bogdanov 		}
43253a2fe58SVladislav Bogdanov 	}
43353a2fe58SVladislav Bogdanov 
43453a2fe58SVladislav Bogdanov 	return 0;
43553a2fe58SVladislav Bogdanov 
43653a2fe58SVladislav Bogdanov fail1:
43753a2fe58SVladislav Bogdanov 	pci_unregister_driver(&i82443bxgx_edacmc_driver);
43853a2fe58SVladislav Bogdanov 
43953a2fe58SVladislav Bogdanov fail0:
44053a2fe58SVladislav Bogdanov 	pci_dev_put(mci_pdev);
44153a2fe58SVladislav Bogdanov 	return pci_rc;
4425a2c675cSTim Small }
4435a2c675cSTim Small 
i82443bxgx_edacmc_exit(void)4445a2c675cSTim Small static void __exit i82443bxgx_edacmc_exit(void)
4455a2c675cSTim Small {
4465a2c675cSTim Small 	pci_unregister_driver(&i82443bxgx_edacmc_driver);
44753a2fe58SVladislav Bogdanov 
44853a2fe58SVladislav Bogdanov 	if (!i82443bxgx_registered)
44953a2fe58SVladislav Bogdanov 		i82443bxgx_edacmc_remove_one(mci_pdev);
45053a2fe58SVladislav Bogdanov 
45153a2fe58SVladislav Bogdanov 	pci_dev_put(mci_pdev);
4525a2c675cSTim Small }
4535a2c675cSTim Small 
4545a2c675cSTim Small module_init(i82443bxgx_edacmc_init);
4555a2c675cSTim Small module_exit(i82443bxgx_edacmc_exit);
4565a2c675cSTim Small 
4575a2c675cSTim Small MODULE_LICENSE("GPL");
4585a2c675cSTim Small MODULE_AUTHOR("Tim Small <tim@buttersideup.com> - WPAD");
4595a2c675cSTim Small MODULE_DESCRIPTION("EDAC MC support for Intel 82443BX/GX memory controllers");
460c3c52bceSHitoshi Mitake 
461c3c52bceSHitoshi Mitake module_param(edac_op_state, int, 0444);
462c3c52bceSHitoshi Mitake MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");
463