18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Intel 5000(P/V/X) class Memory Controllers kernel module
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * This file may be distributed under the terms of the
58c2ecf20Sopenharmony_ci * GNU General Public License.
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Written by Douglas Thompson Linux Networx (http://lnxi.com)
88c2ecf20Sopenharmony_ci *	norsk5@xmission.com
98c2ecf20Sopenharmony_ci *
108c2ecf20Sopenharmony_ci * This module is based on the following document:
118c2ecf20Sopenharmony_ci *
128c2ecf20Sopenharmony_ci * Intel 5000X Chipset Memory Controller Hub (MCH) - Datasheet
138c2ecf20Sopenharmony_ci * 	http://developer.intel.com/design/chipsets/datashts/313070.htm
148c2ecf20Sopenharmony_ci *
158c2ecf20Sopenharmony_ci */
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#include <linux/module.h>
188c2ecf20Sopenharmony_ci#include <linux/init.h>
198c2ecf20Sopenharmony_ci#include <linux/pci.h>
208c2ecf20Sopenharmony_ci#include <linux/pci_ids.h>
218c2ecf20Sopenharmony_ci#include <linux/slab.h>
228c2ecf20Sopenharmony_ci#include <linux/edac.h>
238c2ecf20Sopenharmony_ci#include <asm/mmzone.h>
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci#include "edac_module.h"
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci/*
288c2ecf20Sopenharmony_ci * Alter this version for the I5000 module when modifications are made
298c2ecf20Sopenharmony_ci */
308c2ecf20Sopenharmony_ci#define I5000_REVISION    " Ver: 2.0.12"
318c2ecf20Sopenharmony_ci#define EDAC_MOD_STR      "i5000_edac"
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci#define i5000_printk(level, fmt, arg...) \
348c2ecf20Sopenharmony_ci        edac_printk(level, "i5000", fmt, ##arg)
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#define i5000_mc_printk(mci, level, fmt, arg...) \
378c2ecf20Sopenharmony_ci        edac_mc_chipset_printk(mci, level, "i5000", fmt, ##arg)
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#ifndef PCI_DEVICE_ID_INTEL_FBD_0
408c2ecf20Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_FBD_0	0x25F5
418c2ecf20Sopenharmony_ci#endif
428c2ecf20Sopenharmony_ci#ifndef PCI_DEVICE_ID_INTEL_FBD_1
438c2ecf20Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_FBD_1	0x25F6
448c2ecf20Sopenharmony_ci#endif
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci/* Device 16,
478c2ecf20Sopenharmony_ci * Function 0: System Address
488c2ecf20Sopenharmony_ci * Function 1: Memory Branch Map, Control, Errors Register
498c2ecf20Sopenharmony_ci * Function 2: FSB Error Registers
508c2ecf20Sopenharmony_ci *
518c2ecf20Sopenharmony_ci * All 3 functions of Device 16 (0,1,2) share the SAME DID
528c2ecf20Sopenharmony_ci */
538c2ecf20Sopenharmony_ci#define	PCI_DEVICE_ID_INTEL_I5000_DEV16	0x25F0
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci/* OFFSETS for Function 0 */
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci/* OFFSETS for Function 1 */
588c2ecf20Sopenharmony_ci#define		AMBASE			0x48
598c2ecf20Sopenharmony_ci#define		MAXCH			0x56
608c2ecf20Sopenharmony_ci#define		MAXDIMMPERCH		0x57
618c2ecf20Sopenharmony_ci#define		TOLM			0x6C
628c2ecf20Sopenharmony_ci#define		REDMEMB			0x7C
638c2ecf20Sopenharmony_ci#define			RED_ECC_LOCATOR(x)	((x) & 0x3FFFF)
648c2ecf20Sopenharmony_ci#define			REC_ECC_LOCATOR_EVEN(x)	((x) & 0x001FF)
658c2ecf20Sopenharmony_ci#define			REC_ECC_LOCATOR_ODD(x)	((x) & 0x3FE00)
668c2ecf20Sopenharmony_ci#define		MIR0			0x80
678c2ecf20Sopenharmony_ci#define		MIR1			0x84
688c2ecf20Sopenharmony_ci#define		MIR2			0x88
698c2ecf20Sopenharmony_ci#define		AMIR0			0x8C
708c2ecf20Sopenharmony_ci#define		AMIR1			0x90
718c2ecf20Sopenharmony_ci#define		AMIR2			0x94
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci#define		FERR_FAT_FBD		0x98
748c2ecf20Sopenharmony_ci#define		NERR_FAT_FBD		0x9C
758c2ecf20Sopenharmony_ci#define			EXTRACT_FBDCHAN_INDX(x)	(((x)>>28) & 0x3)
768c2ecf20Sopenharmony_ci#define			FERR_FAT_FBDCHAN 0x30000000
778c2ecf20Sopenharmony_ci#define			FERR_FAT_M3ERR	0x00000004
788c2ecf20Sopenharmony_ci#define			FERR_FAT_M2ERR	0x00000002
798c2ecf20Sopenharmony_ci#define			FERR_FAT_M1ERR	0x00000001
808c2ecf20Sopenharmony_ci#define			FERR_FAT_MASK	(FERR_FAT_M1ERR | \
818c2ecf20Sopenharmony_ci						FERR_FAT_M2ERR | \
828c2ecf20Sopenharmony_ci						FERR_FAT_M3ERR)
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci#define		FERR_NF_FBD		0xA0
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci/* Thermal and SPD or BFD errors */
878c2ecf20Sopenharmony_ci#define			FERR_NF_M28ERR	0x01000000
888c2ecf20Sopenharmony_ci#define			FERR_NF_M27ERR	0x00800000
898c2ecf20Sopenharmony_ci#define			FERR_NF_M26ERR	0x00400000
908c2ecf20Sopenharmony_ci#define			FERR_NF_M25ERR	0x00200000
918c2ecf20Sopenharmony_ci#define			FERR_NF_M24ERR	0x00100000
928c2ecf20Sopenharmony_ci#define			FERR_NF_M23ERR	0x00080000
938c2ecf20Sopenharmony_ci#define			FERR_NF_M22ERR	0x00040000
948c2ecf20Sopenharmony_ci#define			FERR_NF_M21ERR	0x00020000
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci/* Correctable errors */
978c2ecf20Sopenharmony_ci#define			FERR_NF_M20ERR	0x00010000
988c2ecf20Sopenharmony_ci#define			FERR_NF_M19ERR	0x00008000
998c2ecf20Sopenharmony_ci#define			FERR_NF_M18ERR	0x00004000
1008c2ecf20Sopenharmony_ci#define			FERR_NF_M17ERR	0x00002000
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci/* Non-Retry or redundant Retry errors */
1038c2ecf20Sopenharmony_ci#define			FERR_NF_M16ERR	0x00001000
1048c2ecf20Sopenharmony_ci#define			FERR_NF_M15ERR	0x00000800
1058c2ecf20Sopenharmony_ci#define			FERR_NF_M14ERR	0x00000400
1068c2ecf20Sopenharmony_ci#define			FERR_NF_M13ERR	0x00000200
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci/* Uncorrectable errors */
1098c2ecf20Sopenharmony_ci#define			FERR_NF_M12ERR	0x00000100
1108c2ecf20Sopenharmony_ci#define			FERR_NF_M11ERR	0x00000080
1118c2ecf20Sopenharmony_ci#define			FERR_NF_M10ERR	0x00000040
1128c2ecf20Sopenharmony_ci#define			FERR_NF_M9ERR	0x00000020
1138c2ecf20Sopenharmony_ci#define			FERR_NF_M8ERR	0x00000010
1148c2ecf20Sopenharmony_ci#define			FERR_NF_M7ERR	0x00000008
1158c2ecf20Sopenharmony_ci#define			FERR_NF_M6ERR	0x00000004
1168c2ecf20Sopenharmony_ci#define			FERR_NF_M5ERR	0x00000002
1178c2ecf20Sopenharmony_ci#define			FERR_NF_M4ERR	0x00000001
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci#define			FERR_NF_UNCORRECTABLE	(FERR_NF_M12ERR | \
1208c2ecf20Sopenharmony_ci							FERR_NF_M11ERR | \
1218c2ecf20Sopenharmony_ci							FERR_NF_M10ERR | \
1228c2ecf20Sopenharmony_ci							FERR_NF_M9ERR | \
1238c2ecf20Sopenharmony_ci							FERR_NF_M8ERR | \
1248c2ecf20Sopenharmony_ci							FERR_NF_M7ERR | \
1258c2ecf20Sopenharmony_ci							FERR_NF_M6ERR | \
1268c2ecf20Sopenharmony_ci							FERR_NF_M5ERR | \
1278c2ecf20Sopenharmony_ci							FERR_NF_M4ERR)
1288c2ecf20Sopenharmony_ci#define			FERR_NF_CORRECTABLE	(FERR_NF_M20ERR | \
1298c2ecf20Sopenharmony_ci							FERR_NF_M19ERR | \
1308c2ecf20Sopenharmony_ci							FERR_NF_M18ERR | \
1318c2ecf20Sopenharmony_ci							FERR_NF_M17ERR)
1328c2ecf20Sopenharmony_ci#define			FERR_NF_DIMM_SPARE	(FERR_NF_M27ERR | \
1338c2ecf20Sopenharmony_ci							FERR_NF_M28ERR)
1348c2ecf20Sopenharmony_ci#define			FERR_NF_THERMAL		(FERR_NF_M26ERR | \
1358c2ecf20Sopenharmony_ci							FERR_NF_M25ERR | \
1368c2ecf20Sopenharmony_ci							FERR_NF_M24ERR | \
1378c2ecf20Sopenharmony_ci							FERR_NF_M23ERR)
1388c2ecf20Sopenharmony_ci#define			FERR_NF_SPD_PROTOCOL	(FERR_NF_M22ERR)
1398c2ecf20Sopenharmony_ci#define			FERR_NF_NORTH_CRC	(FERR_NF_M21ERR)
1408c2ecf20Sopenharmony_ci#define			FERR_NF_NON_RETRY	(FERR_NF_M13ERR | \
1418c2ecf20Sopenharmony_ci							FERR_NF_M14ERR | \
1428c2ecf20Sopenharmony_ci							FERR_NF_M15ERR)
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci#define		NERR_NF_FBD		0xA4
1458c2ecf20Sopenharmony_ci#define			FERR_NF_MASK		(FERR_NF_UNCORRECTABLE | \
1468c2ecf20Sopenharmony_ci							FERR_NF_CORRECTABLE | \
1478c2ecf20Sopenharmony_ci							FERR_NF_DIMM_SPARE | \
1488c2ecf20Sopenharmony_ci							FERR_NF_THERMAL | \
1498c2ecf20Sopenharmony_ci							FERR_NF_SPD_PROTOCOL | \
1508c2ecf20Sopenharmony_ci							FERR_NF_NORTH_CRC | \
1518c2ecf20Sopenharmony_ci							FERR_NF_NON_RETRY)
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci#define		EMASK_FBD		0xA8
1548c2ecf20Sopenharmony_ci#define			EMASK_FBD_M28ERR	0x08000000
1558c2ecf20Sopenharmony_ci#define			EMASK_FBD_M27ERR	0x04000000
1568c2ecf20Sopenharmony_ci#define			EMASK_FBD_M26ERR	0x02000000
1578c2ecf20Sopenharmony_ci#define			EMASK_FBD_M25ERR	0x01000000
1588c2ecf20Sopenharmony_ci#define			EMASK_FBD_M24ERR	0x00800000
1598c2ecf20Sopenharmony_ci#define			EMASK_FBD_M23ERR	0x00400000
1608c2ecf20Sopenharmony_ci#define			EMASK_FBD_M22ERR	0x00200000
1618c2ecf20Sopenharmony_ci#define			EMASK_FBD_M21ERR	0x00100000
1628c2ecf20Sopenharmony_ci#define			EMASK_FBD_M20ERR	0x00080000
1638c2ecf20Sopenharmony_ci#define			EMASK_FBD_M19ERR	0x00040000
1648c2ecf20Sopenharmony_ci#define			EMASK_FBD_M18ERR	0x00020000
1658c2ecf20Sopenharmony_ci#define			EMASK_FBD_M17ERR	0x00010000
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_ci#define			EMASK_FBD_M15ERR	0x00004000
1688c2ecf20Sopenharmony_ci#define			EMASK_FBD_M14ERR	0x00002000
1698c2ecf20Sopenharmony_ci#define			EMASK_FBD_M13ERR	0x00001000
1708c2ecf20Sopenharmony_ci#define			EMASK_FBD_M12ERR	0x00000800
1718c2ecf20Sopenharmony_ci#define			EMASK_FBD_M11ERR	0x00000400
1728c2ecf20Sopenharmony_ci#define			EMASK_FBD_M10ERR	0x00000200
1738c2ecf20Sopenharmony_ci#define			EMASK_FBD_M9ERR		0x00000100
1748c2ecf20Sopenharmony_ci#define			EMASK_FBD_M8ERR		0x00000080
1758c2ecf20Sopenharmony_ci#define			EMASK_FBD_M7ERR		0x00000040
1768c2ecf20Sopenharmony_ci#define			EMASK_FBD_M6ERR		0x00000020
1778c2ecf20Sopenharmony_ci#define			EMASK_FBD_M5ERR		0x00000010
1788c2ecf20Sopenharmony_ci#define			EMASK_FBD_M4ERR		0x00000008
1798c2ecf20Sopenharmony_ci#define			EMASK_FBD_M3ERR		0x00000004
1808c2ecf20Sopenharmony_ci#define			EMASK_FBD_M2ERR		0x00000002
1818c2ecf20Sopenharmony_ci#define			EMASK_FBD_M1ERR		0x00000001
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ci#define			ENABLE_EMASK_FBD_FATAL_ERRORS	(EMASK_FBD_M1ERR | \
1848c2ecf20Sopenharmony_ci							EMASK_FBD_M2ERR | \
1858c2ecf20Sopenharmony_ci							EMASK_FBD_M3ERR)
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_ci#define 		ENABLE_EMASK_FBD_UNCORRECTABLE	(EMASK_FBD_M4ERR | \
1888c2ecf20Sopenharmony_ci							EMASK_FBD_M5ERR | \
1898c2ecf20Sopenharmony_ci							EMASK_FBD_M6ERR | \
1908c2ecf20Sopenharmony_ci							EMASK_FBD_M7ERR | \
1918c2ecf20Sopenharmony_ci							EMASK_FBD_M8ERR | \
1928c2ecf20Sopenharmony_ci							EMASK_FBD_M9ERR | \
1938c2ecf20Sopenharmony_ci							EMASK_FBD_M10ERR | \
1948c2ecf20Sopenharmony_ci							EMASK_FBD_M11ERR | \
1958c2ecf20Sopenharmony_ci							EMASK_FBD_M12ERR)
1968c2ecf20Sopenharmony_ci#define 		ENABLE_EMASK_FBD_CORRECTABLE	(EMASK_FBD_M17ERR | \
1978c2ecf20Sopenharmony_ci							EMASK_FBD_M18ERR | \
1988c2ecf20Sopenharmony_ci							EMASK_FBD_M19ERR | \
1998c2ecf20Sopenharmony_ci							EMASK_FBD_M20ERR)
2008c2ecf20Sopenharmony_ci#define			ENABLE_EMASK_FBD_DIMM_SPARE	(EMASK_FBD_M27ERR | \
2018c2ecf20Sopenharmony_ci							EMASK_FBD_M28ERR)
2028c2ecf20Sopenharmony_ci#define			ENABLE_EMASK_FBD_THERMALS	(EMASK_FBD_M26ERR | \
2038c2ecf20Sopenharmony_ci							EMASK_FBD_M25ERR | \
2048c2ecf20Sopenharmony_ci							EMASK_FBD_M24ERR | \
2058c2ecf20Sopenharmony_ci							EMASK_FBD_M23ERR)
2068c2ecf20Sopenharmony_ci#define			ENABLE_EMASK_FBD_SPD_PROTOCOL	(EMASK_FBD_M22ERR)
2078c2ecf20Sopenharmony_ci#define			ENABLE_EMASK_FBD_NORTH_CRC	(EMASK_FBD_M21ERR)
2088c2ecf20Sopenharmony_ci#define			ENABLE_EMASK_FBD_NON_RETRY	(EMASK_FBD_M15ERR | \
2098c2ecf20Sopenharmony_ci							EMASK_FBD_M14ERR | \
2108c2ecf20Sopenharmony_ci							EMASK_FBD_M13ERR)
2118c2ecf20Sopenharmony_ci
2128c2ecf20Sopenharmony_ci#define		ENABLE_EMASK_ALL	(ENABLE_EMASK_FBD_NON_RETRY | \
2138c2ecf20Sopenharmony_ci					ENABLE_EMASK_FBD_NORTH_CRC | \
2148c2ecf20Sopenharmony_ci					ENABLE_EMASK_FBD_SPD_PROTOCOL | \
2158c2ecf20Sopenharmony_ci					ENABLE_EMASK_FBD_THERMALS | \
2168c2ecf20Sopenharmony_ci					ENABLE_EMASK_FBD_DIMM_SPARE | \
2178c2ecf20Sopenharmony_ci					ENABLE_EMASK_FBD_FATAL_ERRORS | \
2188c2ecf20Sopenharmony_ci					ENABLE_EMASK_FBD_CORRECTABLE | \
2198c2ecf20Sopenharmony_ci					ENABLE_EMASK_FBD_UNCORRECTABLE)
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_ci#define		ERR0_FBD		0xAC
2228c2ecf20Sopenharmony_ci#define		ERR1_FBD		0xB0
2238c2ecf20Sopenharmony_ci#define		ERR2_FBD		0xB4
2248c2ecf20Sopenharmony_ci#define		MCERR_FBD		0xB8
2258c2ecf20Sopenharmony_ci#define		NRECMEMA		0xBE
2268c2ecf20Sopenharmony_ci#define			NREC_BANK(x)		(((x)>>12) & 0x7)
2278c2ecf20Sopenharmony_ci#define			NREC_RDWR(x)		(((x)>>11) & 1)
2288c2ecf20Sopenharmony_ci#define			NREC_RANK(x)		(((x)>>8) & 0x7)
2298c2ecf20Sopenharmony_ci#define		NRECMEMB		0xC0
2308c2ecf20Sopenharmony_ci#define			NREC_CAS(x)		(((x)>>16) & 0xFFF)
2318c2ecf20Sopenharmony_ci#define			NREC_RAS(x)		((x) & 0x7FFF)
2328c2ecf20Sopenharmony_ci#define		NRECFGLOG		0xC4
2338c2ecf20Sopenharmony_ci#define		NREEECFBDA		0xC8
2348c2ecf20Sopenharmony_ci#define		NREEECFBDB		0xCC
2358c2ecf20Sopenharmony_ci#define		NREEECFBDC		0xD0
2368c2ecf20Sopenharmony_ci#define		NREEECFBDD		0xD4
2378c2ecf20Sopenharmony_ci#define		NREEECFBDE		0xD8
2388c2ecf20Sopenharmony_ci#define		REDMEMA			0xDC
2398c2ecf20Sopenharmony_ci#define		RECMEMA			0xE2
2408c2ecf20Sopenharmony_ci#define			REC_BANK(x)		(((x)>>12) & 0x7)
2418c2ecf20Sopenharmony_ci#define			REC_RDWR(x)		(((x)>>11) & 1)
2428c2ecf20Sopenharmony_ci#define			REC_RANK(x)		(((x)>>8) & 0x7)
2438c2ecf20Sopenharmony_ci#define		RECMEMB			0xE4
2448c2ecf20Sopenharmony_ci#define			REC_CAS(x)		(((x)>>16) & 0xFFFFFF)
2458c2ecf20Sopenharmony_ci#define			REC_RAS(x)		((x) & 0x7FFF)
2468c2ecf20Sopenharmony_ci#define		RECFGLOG		0xE8
2478c2ecf20Sopenharmony_ci#define		RECFBDA			0xEC
2488c2ecf20Sopenharmony_ci#define		RECFBDB			0xF0
2498c2ecf20Sopenharmony_ci#define		RECFBDC			0xF4
2508c2ecf20Sopenharmony_ci#define		RECFBDD			0xF8
2518c2ecf20Sopenharmony_ci#define		RECFBDE			0xFC
2528c2ecf20Sopenharmony_ci
2538c2ecf20Sopenharmony_ci/* OFFSETS for Function 2 */
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_ci/*
2568c2ecf20Sopenharmony_ci * Device 21,
2578c2ecf20Sopenharmony_ci * Function 0: Memory Map Branch 0
2588c2ecf20Sopenharmony_ci *
2598c2ecf20Sopenharmony_ci * Device 22,
2608c2ecf20Sopenharmony_ci * Function 0: Memory Map Branch 1
2618c2ecf20Sopenharmony_ci */
2628c2ecf20Sopenharmony_ci#define PCI_DEVICE_ID_I5000_BRANCH_0	0x25F5
2638c2ecf20Sopenharmony_ci#define PCI_DEVICE_ID_I5000_BRANCH_1	0x25F6
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_ci#define AMB_PRESENT_0	0x64
2668c2ecf20Sopenharmony_ci#define AMB_PRESENT_1	0x66
2678c2ecf20Sopenharmony_ci#define MTR0		0x80
2688c2ecf20Sopenharmony_ci#define MTR1		0x84
2698c2ecf20Sopenharmony_ci#define MTR2		0x88
2708c2ecf20Sopenharmony_ci#define MTR3		0x8C
2718c2ecf20Sopenharmony_ci
2728c2ecf20Sopenharmony_ci#define NUM_MTRS		4
2738c2ecf20Sopenharmony_ci#define CHANNELS_PER_BRANCH	2
2748c2ecf20Sopenharmony_ci#define MAX_BRANCHES		2
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_ci/* Defines to extract the various fields from the
2778c2ecf20Sopenharmony_ci *	MTRx - Memory Technology Registers
2788c2ecf20Sopenharmony_ci */
2798c2ecf20Sopenharmony_ci#define MTR_DIMMS_PRESENT(mtr)		((mtr) & (0x1 << 8))
2808c2ecf20Sopenharmony_ci#define MTR_DRAM_WIDTH(mtr)		((((mtr) >> 6) & 0x1) ? 8 : 4)
2818c2ecf20Sopenharmony_ci#define MTR_DRAM_BANKS(mtr)		((((mtr) >> 5) & 0x1) ? 8 : 4)
2828c2ecf20Sopenharmony_ci#define MTR_DRAM_BANKS_ADDR_BITS(mtr)	((MTR_DRAM_BANKS(mtr) == 8) ? 3 : 2)
2838c2ecf20Sopenharmony_ci#define MTR_DIMM_RANK(mtr)		(((mtr) >> 4) & 0x1)
2848c2ecf20Sopenharmony_ci#define MTR_DIMM_RANK_ADDR_BITS(mtr)	(MTR_DIMM_RANK(mtr) ? 2 : 1)
2858c2ecf20Sopenharmony_ci#define MTR_DIMM_ROWS(mtr)		(((mtr) >> 2) & 0x3)
2868c2ecf20Sopenharmony_ci#define MTR_DIMM_ROWS_ADDR_BITS(mtr)	(MTR_DIMM_ROWS(mtr) + 13)
2878c2ecf20Sopenharmony_ci#define MTR_DIMM_COLS(mtr)		((mtr) & 0x3)
2888c2ecf20Sopenharmony_ci#define MTR_DIMM_COLS_ADDR_BITS(mtr)	(MTR_DIMM_COLS(mtr) + 10)
2898c2ecf20Sopenharmony_ci
2908c2ecf20Sopenharmony_ci/* enables the report of miscellaneous messages as CE errors - default off */
2918c2ecf20Sopenharmony_cistatic int misc_messages;
2928c2ecf20Sopenharmony_ci
2938c2ecf20Sopenharmony_ci/* Enumeration of supported devices */
2948c2ecf20Sopenharmony_cienum i5000_chips {
2958c2ecf20Sopenharmony_ci	I5000P = 0,
2968c2ecf20Sopenharmony_ci	I5000V = 1,		/* future */
2978c2ecf20Sopenharmony_ci	I5000X = 2		/* future */
2988c2ecf20Sopenharmony_ci};
2998c2ecf20Sopenharmony_ci
3008c2ecf20Sopenharmony_ci/* Device name and register DID (Device ID) */
3018c2ecf20Sopenharmony_cistruct i5000_dev_info {
3028c2ecf20Sopenharmony_ci	const char *ctl_name;	/* name for this device */
3038c2ecf20Sopenharmony_ci	u16 fsb_mapping_errors;	/* DID for the branchmap,control */
3048c2ecf20Sopenharmony_ci};
3058c2ecf20Sopenharmony_ci
3068c2ecf20Sopenharmony_ci/* Table of devices attributes supported by this driver */
3078c2ecf20Sopenharmony_cistatic const struct i5000_dev_info i5000_devs[] = {
3088c2ecf20Sopenharmony_ci	[I5000P] = {
3098c2ecf20Sopenharmony_ci		.ctl_name = "I5000",
3108c2ecf20Sopenharmony_ci		.fsb_mapping_errors = PCI_DEVICE_ID_INTEL_I5000_DEV16,
3118c2ecf20Sopenharmony_ci	},
3128c2ecf20Sopenharmony_ci};
3138c2ecf20Sopenharmony_ci
3148c2ecf20Sopenharmony_cistruct i5000_dimm_info {
3158c2ecf20Sopenharmony_ci	int megabytes;		/* size, 0 means not present  */
3168c2ecf20Sopenharmony_ci	int dual_rank;
3178c2ecf20Sopenharmony_ci};
3188c2ecf20Sopenharmony_ci
3198c2ecf20Sopenharmony_ci#define	MAX_CHANNELS	6	/* max possible channels */
3208c2ecf20Sopenharmony_ci#define MAX_CSROWS	(8*2)	/* max possible csrows per channel */
3218c2ecf20Sopenharmony_ci
3228c2ecf20Sopenharmony_ci/* driver private data structure */
3238c2ecf20Sopenharmony_cistruct i5000_pvt {
3248c2ecf20Sopenharmony_ci	struct pci_dev *system_address;	/* 16.0 */
3258c2ecf20Sopenharmony_ci	struct pci_dev *branchmap_werrors;	/* 16.1 */
3268c2ecf20Sopenharmony_ci	struct pci_dev *fsb_error_regs;	/* 16.2 */
3278c2ecf20Sopenharmony_ci	struct pci_dev *branch_0;	/* 21.0 */
3288c2ecf20Sopenharmony_ci	struct pci_dev *branch_1;	/* 22.0 */
3298c2ecf20Sopenharmony_ci
3308c2ecf20Sopenharmony_ci	u16 tolm;		/* top of low memory */
3318c2ecf20Sopenharmony_ci	union {
3328c2ecf20Sopenharmony_ci		u64 ambase;		/* AMB BAR */
3338c2ecf20Sopenharmony_ci		struct {
3348c2ecf20Sopenharmony_ci			u32 ambase_bottom;
3358c2ecf20Sopenharmony_ci			u32 ambase_top;
3368c2ecf20Sopenharmony_ci		} u __packed;
3378c2ecf20Sopenharmony_ci	};
3388c2ecf20Sopenharmony_ci
3398c2ecf20Sopenharmony_ci	u16 mir0, mir1, mir2;
3408c2ecf20Sopenharmony_ci
3418c2ecf20Sopenharmony_ci	u16 b0_mtr[NUM_MTRS];	/* Memory Technlogy Reg */
3428c2ecf20Sopenharmony_ci	u16 b0_ambpresent0;	/* Branch 0, Channel 0 */
3438c2ecf20Sopenharmony_ci	u16 b0_ambpresent1;	/* Brnach 0, Channel 1 */
3448c2ecf20Sopenharmony_ci
3458c2ecf20Sopenharmony_ci	u16 b1_mtr[NUM_MTRS];	/* Memory Technlogy Reg */
3468c2ecf20Sopenharmony_ci	u16 b1_ambpresent0;	/* Branch 1, Channel 8 */
3478c2ecf20Sopenharmony_ci	u16 b1_ambpresent1;	/* Branch 1, Channel 1 */
3488c2ecf20Sopenharmony_ci
3498c2ecf20Sopenharmony_ci	/* DIMM information matrix, allocating architecture maximums */
3508c2ecf20Sopenharmony_ci	struct i5000_dimm_info dimm_info[MAX_CSROWS][MAX_CHANNELS];
3518c2ecf20Sopenharmony_ci
3528c2ecf20Sopenharmony_ci	/* Actual values for this controller */
3538c2ecf20Sopenharmony_ci	int maxch;		/* Max channels */
3548c2ecf20Sopenharmony_ci	int maxdimmperch;	/* Max DIMMs per channel */
3558c2ecf20Sopenharmony_ci};
3568c2ecf20Sopenharmony_ci
3578c2ecf20Sopenharmony_ci/* I5000 MCH error information retrieved from Hardware */
3588c2ecf20Sopenharmony_cistruct i5000_error_info {
3598c2ecf20Sopenharmony_ci
3608c2ecf20Sopenharmony_ci	/* These registers are always read from the MC */
3618c2ecf20Sopenharmony_ci	u32 ferr_fat_fbd;	/* First Errors Fatal */
3628c2ecf20Sopenharmony_ci	u32 nerr_fat_fbd;	/* Next Errors Fatal */
3638c2ecf20Sopenharmony_ci	u32 ferr_nf_fbd;	/* First Errors Non-Fatal */
3648c2ecf20Sopenharmony_ci	u32 nerr_nf_fbd;	/* Next Errors Non-Fatal */
3658c2ecf20Sopenharmony_ci
3668c2ecf20Sopenharmony_ci	/* These registers are input ONLY if there was a Recoverable  Error */
3678c2ecf20Sopenharmony_ci	u32 redmemb;		/* Recoverable Mem Data Error log B */
3688c2ecf20Sopenharmony_ci	u16 recmema;		/* Recoverable Mem Error log A */
3698c2ecf20Sopenharmony_ci	u32 recmemb;		/* Recoverable Mem Error log B */
3708c2ecf20Sopenharmony_ci
3718c2ecf20Sopenharmony_ci	/* These registers are input ONLY if there was a
3728c2ecf20Sopenharmony_ci	 * Non-Recoverable Error */
3738c2ecf20Sopenharmony_ci	u16 nrecmema;		/* Non-Recoverable Mem log A */
3748c2ecf20Sopenharmony_ci	u32 nrecmemb;		/* Non-Recoverable Mem log B */
3758c2ecf20Sopenharmony_ci
3768c2ecf20Sopenharmony_ci};
3778c2ecf20Sopenharmony_ci
3788c2ecf20Sopenharmony_cistatic struct edac_pci_ctl_info *i5000_pci;
3798c2ecf20Sopenharmony_ci
3808c2ecf20Sopenharmony_ci/*
3818c2ecf20Sopenharmony_ci *	i5000_get_error_info	Retrieve the hardware error information from
3828c2ecf20Sopenharmony_ci *				the hardware and cache it in the 'info'
3838c2ecf20Sopenharmony_ci *				structure
3848c2ecf20Sopenharmony_ci */
3858c2ecf20Sopenharmony_cistatic void i5000_get_error_info(struct mem_ctl_info *mci,
3868c2ecf20Sopenharmony_ci				 struct i5000_error_info *info)
3878c2ecf20Sopenharmony_ci{
3888c2ecf20Sopenharmony_ci	struct i5000_pvt *pvt;
3898c2ecf20Sopenharmony_ci	u32 value;
3908c2ecf20Sopenharmony_ci
3918c2ecf20Sopenharmony_ci	pvt = mci->pvt_info;
3928c2ecf20Sopenharmony_ci
3938c2ecf20Sopenharmony_ci	/* read in the 1st FATAL error register */
3948c2ecf20Sopenharmony_ci	pci_read_config_dword(pvt->branchmap_werrors, FERR_FAT_FBD, &value);
3958c2ecf20Sopenharmony_ci
3968c2ecf20Sopenharmony_ci	/* Mask only the bits that the doc says are valid
3978c2ecf20Sopenharmony_ci	 */
3988c2ecf20Sopenharmony_ci	value &= (FERR_FAT_FBDCHAN | FERR_FAT_MASK);
3998c2ecf20Sopenharmony_ci
4008c2ecf20Sopenharmony_ci	/* If there is an error, then read in the */
4018c2ecf20Sopenharmony_ci	/* NEXT FATAL error register and the Memory Error Log Register A */
4028c2ecf20Sopenharmony_ci	if (value & FERR_FAT_MASK) {
4038c2ecf20Sopenharmony_ci		info->ferr_fat_fbd = value;
4048c2ecf20Sopenharmony_ci
4058c2ecf20Sopenharmony_ci		/* harvest the various error data we need */
4068c2ecf20Sopenharmony_ci		pci_read_config_dword(pvt->branchmap_werrors,
4078c2ecf20Sopenharmony_ci				NERR_FAT_FBD, &info->nerr_fat_fbd);
4088c2ecf20Sopenharmony_ci		pci_read_config_word(pvt->branchmap_werrors,
4098c2ecf20Sopenharmony_ci				NRECMEMA, &info->nrecmema);
4108c2ecf20Sopenharmony_ci		pci_read_config_dword(pvt->branchmap_werrors,
4118c2ecf20Sopenharmony_ci				NRECMEMB, &info->nrecmemb);
4128c2ecf20Sopenharmony_ci
4138c2ecf20Sopenharmony_ci		/* Clear the error bits, by writing them back */
4148c2ecf20Sopenharmony_ci		pci_write_config_dword(pvt->branchmap_werrors,
4158c2ecf20Sopenharmony_ci				FERR_FAT_FBD, value);
4168c2ecf20Sopenharmony_ci	} else {
4178c2ecf20Sopenharmony_ci		info->ferr_fat_fbd = 0;
4188c2ecf20Sopenharmony_ci		info->nerr_fat_fbd = 0;
4198c2ecf20Sopenharmony_ci		info->nrecmema = 0;
4208c2ecf20Sopenharmony_ci		info->nrecmemb = 0;
4218c2ecf20Sopenharmony_ci	}
4228c2ecf20Sopenharmony_ci
4238c2ecf20Sopenharmony_ci	/* read in the 1st NON-FATAL error register */
4248c2ecf20Sopenharmony_ci	pci_read_config_dword(pvt->branchmap_werrors, FERR_NF_FBD, &value);
4258c2ecf20Sopenharmony_ci
4268c2ecf20Sopenharmony_ci	/* If there is an error, then read in the 1st NON-FATAL error
4278c2ecf20Sopenharmony_ci	 * register as well */
4288c2ecf20Sopenharmony_ci	if (value & FERR_NF_MASK) {
4298c2ecf20Sopenharmony_ci		info->ferr_nf_fbd = value;
4308c2ecf20Sopenharmony_ci
4318c2ecf20Sopenharmony_ci		/* harvest the various error data we need */
4328c2ecf20Sopenharmony_ci		pci_read_config_dword(pvt->branchmap_werrors,
4338c2ecf20Sopenharmony_ci				NERR_NF_FBD, &info->nerr_nf_fbd);
4348c2ecf20Sopenharmony_ci		pci_read_config_word(pvt->branchmap_werrors,
4358c2ecf20Sopenharmony_ci				RECMEMA, &info->recmema);
4368c2ecf20Sopenharmony_ci		pci_read_config_dword(pvt->branchmap_werrors,
4378c2ecf20Sopenharmony_ci				RECMEMB, &info->recmemb);
4388c2ecf20Sopenharmony_ci		pci_read_config_dword(pvt->branchmap_werrors,
4398c2ecf20Sopenharmony_ci				REDMEMB, &info->redmemb);
4408c2ecf20Sopenharmony_ci
4418c2ecf20Sopenharmony_ci		/* Clear the error bits, by writing them back */
4428c2ecf20Sopenharmony_ci		pci_write_config_dword(pvt->branchmap_werrors,
4438c2ecf20Sopenharmony_ci				FERR_NF_FBD, value);
4448c2ecf20Sopenharmony_ci	} else {
4458c2ecf20Sopenharmony_ci		info->ferr_nf_fbd = 0;
4468c2ecf20Sopenharmony_ci		info->nerr_nf_fbd = 0;
4478c2ecf20Sopenharmony_ci		info->recmema = 0;
4488c2ecf20Sopenharmony_ci		info->recmemb = 0;
4498c2ecf20Sopenharmony_ci		info->redmemb = 0;
4508c2ecf20Sopenharmony_ci	}
4518c2ecf20Sopenharmony_ci}
4528c2ecf20Sopenharmony_ci
4538c2ecf20Sopenharmony_ci/*
4548c2ecf20Sopenharmony_ci * i5000_process_fatal_error_info(struct mem_ctl_info *mci,
4558c2ecf20Sopenharmony_ci * 					struct i5000_error_info *info,
4568c2ecf20Sopenharmony_ci * 					int handle_errors);
4578c2ecf20Sopenharmony_ci *
4588c2ecf20Sopenharmony_ci *	handle the Intel FATAL errors, if any
4598c2ecf20Sopenharmony_ci */
4608c2ecf20Sopenharmony_cistatic void i5000_process_fatal_error_info(struct mem_ctl_info *mci,
4618c2ecf20Sopenharmony_ci					struct i5000_error_info *info,
4628c2ecf20Sopenharmony_ci					int handle_errors)
4638c2ecf20Sopenharmony_ci{
4648c2ecf20Sopenharmony_ci	char msg[EDAC_MC_LABEL_LEN + 1 + 160];
4658c2ecf20Sopenharmony_ci	char *specific = NULL;
4668c2ecf20Sopenharmony_ci	u32 allErrors;
4678c2ecf20Sopenharmony_ci	int channel;
4688c2ecf20Sopenharmony_ci	int bank;
4698c2ecf20Sopenharmony_ci	int rank;
4708c2ecf20Sopenharmony_ci	int rdwr;
4718c2ecf20Sopenharmony_ci	int ras, cas;
4728c2ecf20Sopenharmony_ci
4738c2ecf20Sopenharmony_ci	/* mask off the Error bits that are possible */
4748c2ecf20Sopenharmony_ci	allErrors = (info->ferr_fat_fbd & FERR_FAT_MASK);
4758c2ecf20Sopenharmony_ci	if (!allErrors)
4768c2ecf20Sopenharmony_ci		return;		/* if no error, return now */
4778c2ecf20Sopenharmony_ci
4788c2ecf20Sopenharmony_ci	channel = EXTRACT_FBDCHAN_INDX(info->ferr_fat_fbd);
4798c2ecf20Sopenharmony_ci
4808c2ecf20Sopenharmony_ci	/* Use the NON-Recoverable macros to extract data */
4818c2ecf20Sopenharmony_ci	bank = NREC_BANK(info->nrecmema);
4828c2ecf20Sopenharmony_ci	rank = NREC_RANK(info->nrecmema);
4838c2ecf20Sopenharmony_ci	rdwr = NREC_RDWR(info->nrecmema);
4848c2ecf20Sopenharmony_ci	ras = NREC_RAS(info->nrecmemb);
4858c2ecf20Sopenharmony_ci	cas = NREC_CAS(info->nrecmemb);
4868c2ecf20Sopenharmony_ci
4878c2ecf20Sopenharmony_ci	edac_dbg(0, "\t\tCSROW= %d  Channel= %d (DRAM Bank= %d rdwr= %s ras= %d cas= %d)\n",
4888c2ecf20Sopenharmony_ci		 rank, channel, bank,
4898c2ecf20Sopenharmony_ci		 rdwr ? "Write" : "Read", ras, cas);
4908c2ecf20Sopenharmony_ci
4918c2ecf20Sopenharmony_ci	/* Only 1 bit will be on */
4928c2ecf20Sopenharmony_ci	switch (allErrors) {
4938c2ecf20Sopenharmony_ci	case FERR_FAT_M1ERR:
4948c2ecf20Sopenharmony_ci		specific = "Alert on non-redundant retry or fast "
4958c2ecf20Sopenharmony_ci				"reset timeout";
4968c2ecf20Sopenharmony_ci		break;
4978c2ecf20Sopenharmony_ci	case FERR_FAT_M2ERR:
4988c2ecf20Sopenharmony_ci		specific = "Northbound CRC error on non-redundant "
4998c2ecf20Sopenharmony_ci				"retry";
5008c2ecf20Sopenharmony_ci		break;
5018c2ecf20Sopenharmony_ci	case FERR_FAT_M3ERR:
5028c2ecf20Sopenharmony_ci		{
5038c2ecf20Sopenharmony_ci		static int done;
5048c2ecf20Sopenharmony_ci
5058c2ecf20Sopenharmony_ci		/*
5068c2ecf20Sopenharmony_ci		 * This error is generated to inform that the intelligent
5078c2ecf20Sopenharmony_ci		 * throttling is disabled and the temperature passed the
5088c2ecf20Sopenharmony_ci		 * specified middle point. Since this is something the BIOS
5098c2ecf20Sopenharmony_ci		 * should take care of, we'll warn only once to avoid
5108c2ecf20Sopenharmony_ci		 * worthlessly flooding the log.
5118c2ecf20Sopenharmony_ci		 */
5128c2ecf20Sopenharmony_ci		if (done)
5138c2ecf20Sopenharmony_ci			return;
5148c2ecf20Sopenharmony_ci		done++;
5158c2ecf20Sopenharmony_ci
5168c2ecf20Sopenharmony_ci		specific = ">Tmid Thermal event with intelligent "
5178c2ecf20Sopenharmony_ci			   "throttling disabled";
5188c2ecf20Sopenharmony_ci		}
5198c2ecf20Sopenharmony_ci		break;
5208c2ecf20Sopenharmony_ci	}
5218c2ecf20Sopenharmony_ci
5228c2ecf20Sopenharmony_ci	/* Form out message */
5238c2ecf20Sopenharmony_ci	snprintf(msg, sizeof(msg),
5248c2ecf20Sopenharmony_ci		 "Bank=%d RAS=%d CAS=%d FATAL Err=0x%x (%s)",
5258c2ecf20Sopenharmony_ci		 bank, ras, cas, allErrors, specific);
5268c2ecf20Sopenharmony_ci
5278c2ecf20Sopenharmony_ci	/* Call the helper to output message */
5288c2ecf20Sopenharmony_ci	edac_mc_handle_error(HW_EVENT_ERR_FATAL, mci, 1, 0, 0, 0,
5298c2ecf20Sopenharmony_ci			     channel >> 1, channel & 1, rank,
5308c2ecf20Sopenharmony_ci			     rdwr ? "Write error" : "Read error",
5318c2ecf20Sopenharmony_ci			     msg);
5328c2ecf20Sopenharmony_ci}
5338c2ecf20Sopenharmony_ci
5348c2ecf20Sopenharmony_ci/*
5358c2ecf20Sopenharmony_ci * i5000_process_fatal_error_info(struct mem_ctl_info *mci,
5368c2ecf20Sopenharmony_ci * 				struct i5000_error_info *info,
5378c2ecf20Sopenharmony_ci * 				int handle_errors);
5388c2ecf20Sopenharmony_ci *
5398c2ecf20Sopenharmony_ci *	handle the Intel NON-FATAL errors, if any
5408c2ecf20Sopenharmony_ci */
5418c2ecf20Sopenharmony_cistatic void i5000_process_nonfatal_error_info(struct mem_ctl_info *mci,
5428c2ecf20Sopenharmony_ci					struct i5000_error_info *info,
5438c2ecf20Sopenharmony_ci					int handle_errors)
5448c2ecf20Sopenharmony_ci{
5458c2ecf20Sopenharmony_ci	char msg[EDAC_MC_LABEL_LEN + 1 + 170];
5468c2ecf20Sopenharmony_ci	char *specific = NULL;
5478c2ecf20Sopenharmony_ci	u32 allErrors;
5488c2ecf20Sopenharmony_ci	u32 ue_errors;
5498c2ecf20Sopenharmony_ci	u32 ce_errors;
5508c2ecf20Sopenharmony_ci	u32 misc_errors;
5518c2ecf20Sopenharmony_ci	int branch;
5528c2ecf20Sopenharmony_ci	int channel;
5538c2ecf20Sopenharmony_ci	int bank;
5548c2ecf20Sopenharmony_ci	int rank;
5558c2ecf20Sopenharmony_ci	int rdwr;
5568c2ecf20Sopenharmony_ci	int ras, cas;
5578c2ecf20Sopenharmony_ci
5588c2ecf20Sopenharmony_ci	/* mask off the Error bits that are possible */
5598c2ecf20Sopenharmony_ci	allErrors = (info->ferr_nf_fbd & FERR_NF_MASK);
5608c2ecf20Sopenharmony_ci	if (!allErrors)
5618c2ecf20Sopenharmony_ci		return;		/* if no error, return now */
5628c2ecf20Sopenharmony_ci
5638c2ecf20Sopenharmony_ci	/* ONLY ONE of the possible error bits will be set, as per the docs */
5648c2ecf20Sopenharmony_ci	ue_errors = allErrors & FERR_NF_UNCORRECTABLE;
5658c2ecf20Sopenharmony_ci	if (ue_errors) {
5668c2ecf20Sopenharmony_ci		edac_dbg(0, "\tUncorrected bits= 0x%x\n", ue_errors);
5678c2ecf20Sopenharmony_ci
5688c2ecf20Sopenharmony_ci		branch = EXTRACT_FBDCHAN_INDX(info->ferr_nf_fbd);
5698c2ecf20Sopenharmony_ci
5708c2ecf20Sopenharmony_ci		/*
5718c2ecf20Sopenharmony_ci		 * According with i5000 datasheet, bit 28 has no significance
5728c2ecf20Sopenharmony_ci		 * for errors M4Err-M12Err and M17Err-M21Err, on FERR_NF_FBD
5738c2ecf20Sopenharmony_ci		 */
5748c2ecf20Sopenharmony_ci		channel = branch & 2;
5758c2ecf20Sopenharmony_ci
5768c2ecf20Sopenharmony_ci		bank = NREC_BANK(info->nrecmema);
5778c2ecf20Sopenharmony_ci		rank = NREC_RANK(info->nrecmema);
5788c2ecf20Sopenharmony_ci		rdwr = NREC_RDWR(info->nrecmema);
5798c2ecf20Sopenharmony_ci		ras = NREC_RAS(info->nrecmemb);
5808c2ecf20Sopenharmony_ci		cas = NREC_CAS(info->nrecmemb);
5818c2ecf20Sopenharmony_ci
5828c2ecf20Sopenharmony_ci		edac_dbg(0, "\t\tCSROW= %d  Channels= %d,%d  (Branch= %d DRAM Bank= %d rdwr= %s ras= %d cas= %d)\n",
5838c2ecf20Sopenharmony_ci			 rank, channel, channel + 1, branch >> 1, bank,
5848c2ecf20Sopenharmony_ci			 rdwr ? "Write" : "Read", ras, cas);
5858c2ecf20Sopenharmony_ci
5868c2ecf20Sopenharmony_ci		switch (ue_errors) {
5878c2ecf20Sopenharmony_ci		case FERR_NF_M12ERR:
5888c2ecf20Sopenharmony_ci			specific = "Non-Aliased Uncorrectable Patrol Data ECC";
5898c2ecf20Sopenharmony_ci			break;
5908c2ecf20Sopenharmony_ci		case FERR_NF_M11ERR:
5918c2ecf20Sopenharmony_ci			specific = "Non-Aliased Uncorrectable Spare-Copy "
5928c2ecf20Sopenharmony_ci					"Data ECC";
5938c2ecf20Sopenharmony_ci			break;
5948c2ecf20Sopenharmony_ci		case FERR_NF_M10ERR:
5958c2ecf20Sopenharmony_ci			specific = "Non-Aliased Uncorrectable Mirrored Demand "
5968c2ecf20Sopenharmony_ci					"Data ECC";
5978c2ecf20Sopenharmony_ci			break;
5988c2ecf20Sopenharmony_ci		case FERR_NF_M9ERR:
5998c2ecf20Sopenharmony_ci			specific = "Non-Aliased Uncorrectable Non-Mirrored "
6008c2ecf20Sopenharmony_ci					"Demand Data ECC";
6018c2ecf20Sopenharmony_ci			break;
6028c2ecf20Sopenharmony_ci		case FERR_NF_M8ERR:
6038c2ecf20Sopenharmony_ci			specific = "Aliased Uncorrectable Patrol Data ECC";
6048c2ecf20Sopenharmony_ci			break;
6058c2ecf20Sopenharmony_ci		case FERR_NF_M7ERR:
6068c2ecf20Sopenharmony_ci			specific = "Aliased Uncorrectable Spare-Copy Data ECC";
6078c2ecf20Sopenharmony_ci			break;
6088c2ecf20Sopenharmony_ci		case FERR_NF_M6ERR:
6098c2ecf20Sopenharmony_ci			specific = "Aliased Uncorrectable Mirrored Demand "
6108c2ecf20Sopenharmony_ci					"Data ECC";
6118c2ecf20Sopenharmony_ci			break;
6128c2ecf20Sopenharmony_ci		case FERR_NF_M5ERR:
6138c2ecf20Sopenharmony_ci			specific = "Aliased Uncorrectable Non-Mirrored Demand "
6148c2ecf20Sopenharmony_ci					"Data ECC";
6158c2ecf20Sopenharmony_ci			break;
6168c2ecf20Sopenharmony_ci		case FERR_NF_M4ERR:
6178c2ecf20Sopenharmony_ci			specific = "Uncorrectable Data ECC on Replay";
6188c2ecf20Sopenharmony_ci			break;
6198c2ecf20Sopenharmony_ci		}
6208c2ecf20Sopenharmony_ci
6218c2ecf20Sopenharmony_ci		/* Form out message */
6228c2ecf20Sopenharmony_ci		snprintf(msg, sizeof(msg),
6238c2ecf20Sopenharmony_ci			 "Rank=%d Bank=%d RAS=%d CAS=%d, UE Err=0x%x (%s)",
6248c2ecf20Sopenharmony_ci			 rank, bank, ras, cas, ue_errors, specific);
6258c2ecf20Sopenharmony_ci
6268c2ecf20Sopenharmony_ci		/* Call the helper to output message */
6278c2ecf20Sopenharmony_ci		edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, 1, 0, 0, 0,
6288c2ecf20Sopenharmony_ci				channel >> 1, -1, rank,
6298c2ecf20Sopenharmony_ci				rdwr ? "Write error" : "Read error",
6308c2ecf20Sopenharmony_ci				msg);
6318c2ecf20Sopenharmony_ci	}
6328c2ecf20Sopenharmony_ci
6338c2ecf20Sopenharmony_ci	/* Check correctable errors */
6348c2ecf20Sopenharmony_ci	ce_errors = allErrors & FERR_NF_CORRECTABLE;
6358c2ecf20Sopenharmony_ci	if (ce_errors) {
6368c2ecf20Sopenharmony_ci		edac_dbg(0, "\tCorrected bits= 0x%x\n", ce_errors);
6378c2ecf20Sopenharmony_ci
6388c2ecf20Sopenharmony_ci		branch = EXTRACT_FBDCHAN_INDX(info->ferr_nf_fbd);
6398c2ecf20Sopenharmony_ci
6408c2ecf20Sopenharmony_ci		channel = 0;
6418c2ecf20Sopenharmony_ci		if (REC_ECC_LOCATOR_ODD(info->redmemb))
6428c2ecf20Sopenharmony_ci			channel = 1;
6438c2ecf20Sopenharmony_ci
6448c2ecf20Sopenharmony_ci		/* Convert channel to be based from zero, instead of
6458c2ecf20Sopenharmony_ci		 * from branch base of 0 */
6468c2ecf20Sopenharmony_ci		channel += branch;
6478c2ecf20Sopenharmony_ci
6488c2ecf20Sopenharmony_ci		bank = REC_BANK(info->recmema);
6498c2ecf20Sopenharmony_ci		rank = REC_RANK(info->recmema);
6508c2ecf20Sopenharmony_ci		rdwr = REC_RDWR(info->recmema);
6518c2ecf20Sopenharmony_ci		ras = REC_RAS(info->recmemb);
6528c2ecf20Sopenharmony_ci		cas = REC_CAS(info->recmemb);
6538c2ecf20Sopenharmony_ci
6548c2ecf20Sopenharmony_ci		edac_dbg(0, "\t\tCSROW= %d Channel= %d  (Branch %d DRAM Bank= %d rdwr= %s ras= %d cas= %d)\n",
6558c2ecf20Sopenharmony_ci			 rank, channel, branch >> 1, bank,
6568c2ecf20Sopenharmony_ci			 rdwr ? "Write" : "Read", ras, cas);
6578c2ecf20Sopenharmony_ci
6588c2ecf20Sopenharmony_ci		switch (ce_errors) {
6598c2ecf20Sopenharmony_ci		case FERR_NF_M17ERR:
6608c2ecf20Sopenharmony_ci			specific = "Correctable Non-Mirrored Demand Data ECC";
6618c2ecf20Sopenharmony_ci			break;
6628c2ecf20Sopenharmony_ci		case FERR_NF_M18ERR:
6638c2ecf20Sopenharmony_ci			specific = "Correctable Mirrored Demand Data ECC";
6648c2ecf20Sopenharmony_ci			break;
6658c2ecf20Sopenharmony_ci		case FERR_NF_M19ERR:
6668c2ecf20Sopenharmony_ci			specific = "Correctable Spare-Copy Data ECC";
6678c2ecf20Sopenharmony_ci			break;
6688c2ecf20Sopenharmony_ci		case FERR_NF_M20ERR:
6698c2ecf20Sopenharmony_ci			specific = "Correctable Patrol Data ECC";
6708c2ecf20Sopenharmony_ci			break;
6718c2ecf20Sopenharmony_ci		}
6728c2ecf20Sopenharmony_ci
6738c2ecf20Sopenharmony_ci		/* Form out message */
6748c2ecf20Sopenharmony_ci		snprintf(msg, sizeof(msg),
6758c2ecf20Sopenharmony_ci			 "Rank=%d Bank=%d RDWR=%s RAS=%d "
6768c2ecf20Sopenharmony_ci			 "CAS=%d, CE Err=0x%x (%s))", branch >> 1, bank,
6778c2ecf20Sopenharmony_ci			 rdwr ? "Write" : "Read", ras, cas, ce_errors,
6788c2ecf20Sopenharmony_ci			 specific);
6798c2ecf20Sopenharmony_ci
6808c2ecf20Sopenharmony_ci		/* Call the helper to output message */
6818c2ecf20Sopenharmony_ci		edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 1, 0, 0, 0,
6828c2ecf20Sopenharmony_ci				channel >> 1, channel % 2, rank,
6838c2ecf20Sopenharmony_ci				rdwr ? "Write error" : "Read error",
6848c2ecf20Sopenharmony_ci				msg);
6858c2ecf20Sopenharmony_ci	}
6868c2ecf20Sopenharmony_ci
6878c2ecf20Sopenharmony_ci	if (!misc_messages)
6888c2ecf20Sopenharmony_ci		return;
6898c2ecf20Sopenharmony_ci
6908c2ecf20Sopenharmony_ci	misc_errors = allErrors & (FERR_NF_NON_RETRY | FERR_NF_NORTH_CRC |
6918c2ecf20Sopenharmony_ci				   FERR_NF_SPD_PROTOCOL | FERR_NF_DIMM_SPARE);
6928c2ecf20Sopenharmony_ci	if (misc_errors) {
6938c2ecf20Sopenharmony_ci		switch (misc_errors) {
6948c2ecf20Sopenharmony_ci		case FERR_NF_M13ERR:
6958c2ecf20Sopenharmony_ci			specific = "Non-Retry or Redundant Retry FBD Memory "
6968c2ecf20Sopenharmony_ci					"Alert or Redundant Fast Reset Timeout";
6978c2ecf20Sopenharmony_ci			break;
6988c2ecf20Sopenharmony_ci		case FERR_NF_M14ERR:
6998c2ecf20Sopenharmony_ci			specific = "Non-Retry or Redundant Retry FBD "
7008c2ecf20Sopenharmony_ci					"Configuration Alert";
7018c2ecf20Sopenharmony_ci			break;
7028c2ecf20Sopenharmony_ci		case FERR_NF_M15ERR:
7038c2ecf20Sopenharmony_ci			specific = "Non-Retry or Redundant Retry FBD "
7048c2ecf20Sopenharmony_ci					"Northbound CRC error on read data";
7058c2ecf20Sopenharmony_ci			break;
7068c2ecf20Sopenharmony_ci		case FERR_NF_M21ERR:
7078c2ecf20Sopenharmony_ci			specific = "FBD Northbound CRC error on "
7088c2ecf20Sopenharmony_ci					"FBD Sync Status";
7098c2ecf20Sopenharmony_ci			break;
7108c2ecf20Sopenharmony_ci		case FERR_NF_M22ERR:
7118c2ecf20Sopenharmony_ci			specific = "SPD protocol error";
7128c2ecf20Sopenharmony_ci			break;
7138c2ecf20Sopenharmony_ci		case FERR_NF_M27ERR:
7148c2ecf20Sopenharmony_ci			specific = "DIMM-spare copy started";
7158c2ecf20Sopenharmony_ci			break;
7168c2ecf20Sopenharmony_ci		case FERR_NF_M28ERR:
7178c2ecf20Sopenharmony_ci			specific = "DIMM-spare copy completed";
7188c2ecf20Sopenharmony_ci			break;
7198c2ecf20Sopenharmony_ci		}
7208c2ecf20Sopenharmony_ci		branch = EXTRACT_FBDCHAN_INDX(info->ferr_nf_fbd);
7218c2ecf20Sopenharmony_ci
7228c2ecf20Sopenharmony_ci		/* Form out message */
7238c2ecf20Sopenharmony_ci		snprintf(msg, sizeof(msg),
7248c2ecf20Sopenharmony_ci			 "Err=%#x (%s)", misc_errors, specific);
7258c2ecf20Sopenharmony_ci
7268c2ecf20Sopenharmony_ci		/* Call the helper to output message */
7278c2ecf20Sopenharmony_ci		edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 1, 0, 0, 0,
7288c2ecf20Sopenharmony_ci				branch >> 1, -1, -1,
7298c2ecf20Sopenharmony_ci				"Misc error", msg);
7308c2ecf20Sopenharmony_ci	}
7318c2ecf20Sopenharmony_ci}
7328c2ecf20Sopenharmony_ci
7338c2ecf20Sopenharmony_ci/*
7348c2ecf20Sopenharmony_ci *	i5000_process_error_info	Process the error info that is
7358c2ecf20Sopenharmony_ci *	in the 'info' structure, previously retrieved from hardware
7368c2ecf20Sopenharmony_ci */
7378c2ecf20Sopenharmony_cistatic void i5000_process_error_info(struct mem_ctl_info *mci,
7388c2ecf20Sopenharmony_ci				struct i5000_error_info *info,
7398c2ecf20Sopenharmony_ci				int handle_errors)
7408c2ecf20Sopenharmony_ci{
7418c2ecf20Sopenharmony_ci	/* First handle any fatal errors that occurred */
7428c2ecf20Sopenharmony_ci	i5000_process_fatal_error_info(mci, info, handle_errors);
7438c2ecf20Sopenharmony_ci
7448c2ecf20Sopenharmony_ci	/* now handle any non-fatal errors that occurred */
7458c2ecf20Sopenharmony_ci	i5000_process_nonfatal_error_info(mci, info, handle_errors);
7468c2ecf20Sopenharmony_ci}
7478c2ecf20Sopenharmony_ci
7488c2ecf20Sopenharmony_ci/*
7498c2ecf20Sopenharmony_ci *	i5000_clear_error	Retrieve any error from the hardware
7508c2ecf20Sopenharmony_ci *				but do NOT process that error.
7518c2ecf20Sopenharmony_ci *				Used for 'clearing' out of previous errors
7528c2ecf20Sopenharmony_ci *				Called by the Core module.
7538c2ecf20Sopenharmony_ci */
7548c2ecf20Sopenharmony_cistatic void i5000_clear_error(struct mem_ctl_info *mci)
7558c2ecf20Sopenharmony_ci{
7568c2ecf20Sopenharmony_ci	struct i5000_error_info info;
7578c2ecf20Sopenharmony_ci
7588c2ecf20Sopenharmony_ci	i5000_get_error_info(mci, &info);
7598c2ecf20Sopenharmony_ci}
7608c2ecf20Sopenharmony_ci
7618c2ecf20Sopenharmony_ci/*
7628c2ecf20Sopenharmony_ci *	i5000_check_error	Retrieve and process errors reported by the
7638c2ecf20Sopenharmony_ci *				hardware. Called by the Core module.
7648c2ecf20Sopenharmony_ci */
7658c2ecf20Sopenharmony_cistatic void i5000_check_error(struct mem_ctl_info *mci)
7668c2ecf20Sopenharmony_ci{
7678c2ecf20Sopenharmony_ci	struct i5000_error_info info;
7688c2ecf20Sopenharmony_ci	edac_dbg(4, "MC%d\n", mci->mc_idx);
7698c2ecf20Sopenharmony_ci	i5000_get_error_info(mci, &info);
7708c2ecf20Sopenharmony_ci	i5000_process_error_info(mci, &info, 1);
7718c2ecf20Sopenharmony_ci}
7728c2ecf20Sopenharmony_ci
7738c2ecf20Sopenharmony_ci/*
7748c2ecf20Sopenharmony_ci *	i5000_get_devices	Find and perform 'get' operation on the MCH's
7758c2ecf20Sopenharmony_ci *			device/functions we want to reference for this driver
7768c2ecf20Sopenharmony_ci *
7778c2ecf20Sopenharmony_ci *			Need to 'get' device 16 func 1 and func 2
7788c2ecf20Sopenharmony_ci */
7798c2ecf20Sopenharmony_cistatic int i5000_get_devices(struct mem_ctl_info *mci, int dev_idx)
7808c2ecf20Sopenharmony_ci{
7818c2ecf20Sopenharmony_ci	//const struct i5000_dev_info *i5000_dev = &i5000_devs[dev_idx];
7828c2ecf20Sopenharmony_ci	struct i5000_pvt *pvt;
7838c2ecf20Sopenharmony_ci	struct pci_dev *pdev;
7848c2ecf20Sopenharmony_ci
7858c2ecf20Sopenharmony_ci	pvt = mci->pvt_info;
7868c2ecf20Sopenharmony_ci
7878c2ecf20Sopenharmony_ci	/* Attempt to 'get' the MCH register we want */
7888c2ecf20Sopenharmony_ci	pdev = NULL;
7898c2ecf20Sopenharmony_ci	while (1) {
7908c2ecf20Sopenharmony_ci		pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
7918c2ecf20Sopenharmony_ci				PCI_DEVICE_ID_INTEL_I5000_DEV16, pdev);
7928c2ecf20Sopenharmony_ci
7938c2ecf20Sopenharmony_ci		/* End of list, leave */
7948c2ecf20Sopenharmony_ci		if (pdev == NULL) {
7958c2ecf20Sopenharmony_ci			i5000_printk(KERN_ERR,
7968c2ecf20Sopenharmony_ci				"'system address,Process Bus' "
7978c2ecf20Sopenharmony_ci				"device not found:"
7988c2ecf20Sopenharmony_ci				"vendor 0x%x device 0x%x FUNC 1 "
7998c2ecf20Sopenharmony_ci				"(broken BIOS?)\n",
8008c2ecf20Sopenharmony_ci				PCI_VENDOR_ID_INTEL,
8018c2ecf20Sopenharmony_ci				PCI_DEVICE_ID_INTEL_I5000_DEV16);
8028c2ecf20Sopenharmony_ci
8038c2ecf20Sopenharmony_ci			return 1;
8048c2ecf20Sopenharmony_ci		}
8058c2ecf20Sopenharmony_ci
8068c2ecf20Sopenharmony_ci		/* Scan for device 16 func 1 */
8078c2ecf20Sopenharmony_ci		if (PCI_FUNC(pdev->devfn) == 1)
8088c2ecf20Sopenharmony_ci			break;
8098c2ecf20Sopenharmony_ci	}
8108c2ecf20Sopenharmony_ci
8118c2ecf20Sopenharmony_ci	pvt->branchmap_werrors = pdev;
8128c2ecf20Sopenharmony_ci
8138c2ecf20Sopenharmony_ci	/* Attempt to 'get' the MCH register we want */
8148c2ecf20Sopenharmony_ci	pdev = NULL;
8158c2ecf20Sopenharmony_ci	while (1) {
8168c2ecf20Sopenharmony_ci		pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
8178c2ecf20Sopenharmony_ci				PCI_DEVICE_ID_INTEL_I5000_DEV16, pdev);
8188c2ecf20Sopenharmony_ci
8198c2ecf20Sopenharmony_ci		if (pdev == NULL) {
8208c2ecf20Sopenharmony_ci			i5000_printk(KERN_ERR,
8218c2ecf20Sopenharmony_ci				"MC: 'branchmap,control,errors' "
8228c2ecf20Sopenharmony_ci				"device not found:"
8238c2ecf20Sopenharmony_ci				"vendor 0x%x device 0x%x Func 2 "
8248c2ecf20Sopenharmony_ci				"(broken BIOS?)\n",
8258c2ecf20Sopenharmony_ci				PCI_VENDOR_ID_INTEL,
8268c2ecf20Sopenharmony_ci				PCI_DEVICE_ID_INTEL_I5000_DEV16);
8278c2ecf20Sopenharmony_ci
8288c2ecf20Sopenharmony_ci			pci_dev_put(pvt->branchmap_werrors);
8298c2ecf20Sopenharmony_ci			return 1;
8308c2ecf20Sopenharmony_ci		}
8318c2ecf20Sopenharmony_ci
8328c2ecf20Sopenharmony_ci		/* Scan for device 16 func 1 */
8338c2ecf20Sopenharmony_ci		if (PCI_FUNC(pdev->devfn) == 2)
8348c2ecf20Sopenharmony_ci			break;
8358c2ecf20Sopenharmony_ci	}
8368c2ecf20Sopenharmony_ci
8378c2ecf20Sopenharmony_ci	pvt->fsb_error_regs = pdev;
8388c2ecf20Sopenharmony_ci
8398c2ecf20Sopenharmony_ci	edac_dbg(1, "System Address, processor bus- PCI Bus ID: %s  %x:%x\n",
8408c2ecf20Sopenharmony_ci		 pci_name(pvt->system_address),
8418c2ecf20Sopenharmony_ci		 pvt->system_address->vendor, pvt->system_address->device);
8428c2ecf20Sopenharmony_ci	edac_dbg(1, "Branchmap, control and errors - PCI Bus ID: %s  %x:%x\n",
8438c2ecf20Sopenharmony_ci		 pci_name(pvt->branchmap_werrors),
8448c2ecf20Sopenharmony_ci		 pvt->branchmap_werrors->vendor,
8458c2ecf20Sopenharmony_ci		 pvt->branchmap_werrors->device);
8468c2ecf20Sopenharmony_ci	edac_dbg(1, "FSB Error Regs - PCI Bus ID: %s  %x:%x\n",
8478c2ecf20Sopenharmony_ci		 pci_name(pvt->fsb_error_regs),
8488c2ecf20Sopenharmony_ci		 pvt->fsb_error_regs->vendor, pvt->fsb_error_regs->device);
8498c2ecf20Sopenharmony_ci
8508c2ecf20Sopenharmony_ci	pdev = NULL;
8518c2ecf20Sopenharmony_ci	pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
8528c2ecf20Sopenharmony_ci			PCI_DEVICE_ID_I5000_BRANCH_0, pdev);
8538c2ecf20Sopenharmony_ci
8548c2ecf20Sopenharmony_ci	if (pdev == NULL) {
8558c2ecf20Sopenharmony_ci		i5000_printk(KERN_ERR,
8568c2ecf20Sopenharmony_ci			"MC: 'BRANCH 0' device not found:"
8578c2ecf20Sopenharmony_ci			"vendor 0x%x device 0x%x Func 0 (broken BIOS?)\n",
8588c2ecf20Sopenharmony_ci			PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_I5000_BRANCH_0);
8598c2ecf20Sopenharmony_ci
8608c2ecf20Sopenharmony_ci		pci_dev_put(pvt->branchmap_werrors);
8618c2ecf20Sopenharmony_ci		pci_dev_put(pvt->fsb_error_regs);
8628c2ecf20Sopenharmony_ci		return 1;
8638c2ecf20Sopenharmony_ci	}
8648c2ecf20Sopenharmony_ci
8658c2ecf20Sopenharmony_ci	pvt->branch_0 = pdev;
8668c2ecf20Sopenharmony_ci
8678c2ecf20Sopenharmony_ci	/* If this device claims to have more than 2 channels then
8688c2ecf20Sopenharmony_ci	 * fetch Branch 1's information
8698c2ecf20Sopenharmony_ci	 */
8708c2ecf20Sopenharmony_ci	if (pvt->maxch >= CHANNELS_PER_BRANCH) {
8718c2ecf20Sopenharmony_ci		pdev = NULL;
8728c2ecf20Sopenharmony_ci		pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
8738c2ecf20Sopenharmony_ci				PCI_DEVICE_ID_I5000_BRANCH_1, pdev);
8748c2ecf20Sopenharmony_ci
8758c2ecf20Sopenharmony_ci		if (pdev == NULL) {
8768c2ecf20Sopenharmony_ci			i5000_printk(KERN_ERR,
8778c2ecf20Sopenharmony_ci				"MC: 'BRANCH 1' device not found:"
8788c2ecf20Sopenharmony_ci				"vendor 0x%x device 0x%x Func 0 "
8798c2ecf20Sopenharmony_ci				"(broken BIOS?)\n",
8808c2ecf20Sopenharmony_ci				PCI_VENDOR_ID_INTEL,
8818c2ecf20Sopenharmony_ci				PCI_DEVICE_ID_I5000_BRANCH_1);
8828c2ecf20Sopenharmony_ci
8838c2ecf20Sopenharmony_ci			pci_dev_put(pvt->branchmap_werrors);
8848c2ecf20Sopenharmony_ci			pci_dev_put(pvt->fsb_error_regs);
8858c2ecf20Sopenharmony_ci			pci_dev_put(pvt->branch_0);
8868c2ecf20Sopenharmony_ci			return 1;
8878c2ecf20Sopenharmony_ci		}
8888c2ecf20Sopenharmony_ci
8898c2ecf20Sopenharmony_ci		pvt->branch_1 = pdev;
8908c2ecf20Sopenharmony_ci	}
8918c2ecf20Sopenharmony_ci
8928c2ecf20Sopenharmony_ci	return 0;
8938c2ecf20Sopenharmony_ci}
8948c2ecf20Sopenharmony_ci
8958c2ecf20Sopenharmony_ci/*
8968c2ecf20Sopenharmony_ci *	i5000_put_devices	'put' all the devices that we have
8978c2ecf20Sopenharmony_ci *				reserved via 'get'
8988c2ecf20Sopenharmony_ci */
8998c2ecf20Sopenharmony_cistatic void i5000_put_devices(struct mem_ctl_info *mci)
9008c2ecf20Sopenharmony_ci{
9018c2ecf20Sopenharmony_ci	struct i5000_pvt *pvt;
9028c2ecf20Sopenharmony_ci
9038c2ecf20Sopenharmony_ci	pvt = mci->pvt_info;
9048c2ecf20Sopenharmony_ci
9058c2ecf20Sopenharmony_ci	pci_dev_put(pvt->branchmap_werrors);	/* FUNC 1 */
9068c2ecf20Sopenharmony_ci	pci_dev_put(pvt->fsb_error_regs);	/* FUNC 2 */
9078c2ecf20Sopenharmony_ci	pci_dev_put(pvt->branch_0);	/* DEV 21 */
9088c2ecf20Sopenharmony_ci
9098c2ecf20Sopenharmony_ci	/* Only if more than 2 channels do we release the second branch */
9108c2ecf20Sopenharmony_ci	if (pvt->maxch >= CHANNELS_PER_BRANCH)
9118c2ecf20Sopenharmony_ci		pci_dev_put(pvt->branch_1);	/* DEV 22 */
9128c2ecf20Sopenharmony_ci}
9138c2ecf20Sopenharmony_ci
9148c2ecf20Sopenharmony_ci/*
9158c2ecf20Sopenharmony_ci *	determine_amb_resent
9168c2ecf20Sopenharmony_ci *
9178c2ecf20Sopenharmony_ci *		the information is contained in NUM_MTRS different registers
9188c2ecf20Sopenharmony_ci *		determineing which of the NUM_MTRS requires knowing
9198c2ecf20Sopenharmony_ci *		which channel is in question
9208c2ecf20Sopenharmony_ci *
9218c2ecf20Sopenharmony_ci *	2 branches, each with 2 channels
9228c2ecf20Sopenharmony_ci *		b0_ambpresent0 for channel '0'
9238c2ecf20Sopenharmony_ci *		b0_ambpresent1 for channel '1'
9248c2ecf20Sopenharmony_ci *		b1_ambpresent0 for channel '2'
9258c2ecf20Sopenharmony_ci *		b1_ambpresent1 for channel '3'
9268c2ecf20Sopenharmony_ci */
9278c2ecf20Sopenharmony_cistatic int determine_amb_present_reg(struct i5000_pvt *pvt, int channel)
9288c2ecf20Sopenharmony_ci{
9298c2ecf20Sopenharmony_ci	int amb_present;
9308c2ecf20Sopenharmony_ci
9318c2ecf20Sopenharmony_ci	if (channel < CHANNELS_PER_BRANCH) {
9328c2ecf20Sopenharmony_ci		if (channel & 0x1)
9338c2ecf20Sopenharmony_ci			amb_present = pvt->b0_ambpresent1;
9348c2ecf20Sopenharmony_ci		else
9358c2ecf20Sopenharmony_ci			amb_present = pvt->b0_ambpresent0;
9368c2ecf20Sopenharmony_ci	} else {
9378c2ecf20Sopenharmony_ci		if (channel & 0x1)
9388c2ecf20Sopenharmony_ci			amb_present = pvt->b1_ambpresent1;
9398c2ecf20Sopenharmony_ci		else
9408c2ecf20Sopenharmony_ci			amb_present = pvt->b1_ambpresent0;
9418c2ecf20Sopenharmony_ci	}
9428c2ecf20Sopenharmony_ci
9438c2ecf20Sopenharmony_ci	return amb_present;
9448c2ecf20Sopenharmony_ci}
9458c2ecf20Sopenharmony_ci
9468c2ecf20Sopenharmony_ci/*
9478c2ecf20Sopenharmony_ci * determine_mtr(pvt, csrow, channel)
9488c2ecf20Sopenharmony_ci *
9498c2ecf20Sopenharmony_ci *	return the proper MTR register as determine by the csrow and channel desired
9508c2ecf20Sopenharmony_ci */
9518c2ecf20Sopenharmony_cistatic int determine_mtr(struct i5000_pvt *pvt, int slot, int channel)
9528c2ecf20Sopenharmony_ci{
9538c2ecf20Sopenharmony_ci	int mtr;
9548c2ecf20Sopenharmony_ci
9558c2ecf20Sopenharmony_ci	if (channel < CHANNELS_PER_BRANCH)
9568c2ecf20Sopenharmony_ci		mtr = pvt->b0_mtr[slot];
9578c2ecf20Sopenharmony_ci	else
9588c2ecf20Sopenharmony_ci		mtr = pvt->b1_mtr[slot];
9598c2ecf20Sopenharmony_ci
9608c2ecf20Sopenharmony_ci	return mtr;
9618c2ecf20Sopenharmony_ci}
9628c2ecf20Sopenharmony_ci
9638c2ecf20Sopenharmony_ci/*
9648c2ecf20Sopenharmony_ci */
9658c2ecf20Sopenharmony_cistatic void decode_mtr(int slot_row, u16 mtr)
9668c2ecf20Sopenharmony_ci{
9678c2ecf20Sopenharmony_ci	int ans;
9688c2ecf20Sopenharmony_ci
9698c2ecf20Sopenharmony_ci	ans = MTR_DIMMS_PRESENT(mtr);
9708c2ecf20Sopenharmony_ci
9718c2ecf20Sopenharmony_ci	edac_dbg(2, "\tMTR%d=0x%x:  DIMMs are %sPresent\n",
9728c2ecf20Sopenharmony_ci		 slot_row, mtr, ans ? "" : "NOT ");
9738c2ecf20Sopenharmony_ci	if (!ans)
9748c2ecf20Sopenharmony_ci		return;
9758c2ecf20Sopenharmony_ci
9768c2ecf20Sopenharmony_ci	edac_dbg(2, "\t\tWIDTH: x%d\n", MTR_DRAM_WIDTH(mtr));
9778c2ecf20Sopenharmony_ci	edac_dbg(2, "\t\tNUMBANK: %d bank(s)\n", MTR_DRAM_BANKS(mtr));
9788c2ecf20Sopenharmony_ci	edac_dbg(2, "\t\tNUMRANK: %s\n",
9798c2ecf20Sopenharmony_ci		 MTR_DIMM_RANK(mtr) ? "double" : "single");
9808c2ecf20Sopenharmony_ci	edac_dbg(2, "\t\tNUMROW: %s\n",
9818c2ecf20Sopenharmony_ci		 MTR_DIMM_ROWS(mtr) == 0 ? "8,192 - 13 rows" :
9828c2ecf20Sopenharmony_ci		 MTR_DIMM_ROWS(mtr) == 1 ? "16,384 - 14 rows" :
9838c2ecf20Sopenharmony_ci		 MTR_DIMM_ROWS(mtr) == 2 ? "32,768 - 15 rows" :
9848c2ecf20Sopenharmony_ci		 "reserved");
9858c2ecf20Sopenharmony_ci	edac_dbg(2, "\t\tNUMCOL: %s\n",
9868c2ecf20Sopenharmony_ci		 MTR_DIMM_COLS(mtr) == 0 ? "1,024 - 10 columns" :
9878c2ecf20Sopenharmony_ci		 MTR_DIMM_COLS(mtr) == 1 ? "2,048 - 11 columns" :
9888c2ecf20Sopenharmony_ci		 MTR_DIMM_COLS(mtr) == 2 ? "4,096 - 12 columns" :
9898c2ecf20Sopenharmony_ci		 "reserved");
9908c2ecf20Sopenharmony_ci}
9918c2ecf20Sopenharmony_ci
9928c2ecf20Sopenharmony_cistatic void handle_channel(struct i5000_pvt *pvt, int slot, int channel,
9938c2ecf20Sopenharmony_ci			struct i5000_dimm_info *dinfo)
9948c2ecf20Sopenharmony_ci{
9958c2ecf20Sopenharmony_ci	int mtr;
9968c2ecf20Sopenharmony_ci	int amb_present_reg;
9978c2ecf20Sopenharmony_ci	int addrBits;
9988c2ecf20Sopenharmony_ci
9998c2ecf20Sopenharmony_ci	mtr = determine_mtr(pvt, slot, channel);
10008c2ecf20Sopenharmony_ci	if (MTR_DIMMS_PRESENT(mtr)) {
10018c2ecf20Sopenharmony_ci		amb_present_reg = determine_amb_present_reg(pvt, channel);
10028c2ecf20Sopenharmony_ci
10038c2ecf20Sopenharmony_ci		/* Determine if there is a DIMM present in this DIMM slot */
10048c2ecf20Sopenharmony_ci		if (amb_present_reg) {
10058c2ecf20Sopenharmony_ci			dinfo->dual_rank = MTR_DIMM_RANK(mtr);
10068c2ecf20Sopenharmony_ci
10078c2ecf20Sopenharmony_ci			/* Start with the number of bits for a Bank
10088c2ecf20Sopenharmony_ci				* on the DRAM */
10098c2ecf20Sopenharmony_ci			addrBits = MTR_DRAM_BANKS_ADDR_BITS(mtr);
10108c2ecf20Sopenharmony_ci			/* Add the number of ROW bits */
10118c2ecf20Sopenharmony_ci			addrBits += MTR_DIMM_ROWS_ADDR_BITS(mtr);
10128c2ecf20Sopenharmony_ci			/* add the number of COLUMN bits */
10138c2ecf20Sopenharmony_ci			addrBits += MTR_DIMM_COLS_ADDR_BITS(mtr);
10148c2ecf20Sopenharmony_ci
10158c2ecf20Sopenharmony_ci			/* Dual-rank memories have twice the size */
10168c2ecf20Sopenharmony_ci			if (dinfo->dual_rank)
10178c2ecf20Sopenharmony_ci				addrBits++;
10188c2ecf20Sopenharmony_ci
10198c2ecf20Sopenharmony_ci			addrBits += 6;	/* add 64 bits per DIMM */
10208c2ecf20Sopenharmony_ci			addrBits -= 20;	/* divide by 2^^20 */
10218c2ecf20Sopenharmony_ci			addrBits -= 3;	/* 8 bits per bytes */
10228c2ecf20Sopenharmony_ci
10238c2ecf20Sopenharmony_ci			dinfo->megabytes = 1 << addrBits;
10248c2ecf20Sopenharmony_ci		}
10258c2ecf20Sopenharmony_ci	}
10268c2ecf20Sopenharmony_ci}
10278c2ecf20Sopenharmony_ci
10288c2ecf20Sopenharmony_ci/*
10298c2ecf20Sopenharmony_ci *	calculate_dimm_size
10308c2ecf20Sopenharmony_ci *
10318c2ecf20Sopenharmony_ci *	also will output a DIMM matrix map, if debug is enabled, for viewing
10328c2ecf20Sopenharmony_ci *	how the DIMMs are populated
10338c2ecf20Sopenharmony_ci */
10348c2ecf20Sopenharmony_cistatic void calculate_dimm_size(struct i5000_pvt *pvt)
10358c2ecf20Sopenharmony_ci{
10368c2ecf20Sopenharmony_ci	struct i5000_dimm_info *dinfo;
10378c2ecf20Sopenharmony_ci	int slot, channel, branch;
10388c2ecf20Sopenharmony_ci	char *p, *mem_buffer;
10398c2ecf20Sopenharmony_ci	int space, n;
10408c2ecf20Sopenharmony_ci
10418c2ecf20Sopenharmony_ci	/* ================= Generate some debug output ================= */
10428c2ecf20Sopenharmony_ci	space = PAGE_SIZE;
10438c2ecf20Sopenharmony_ci	mem_buffer = p = kmalloc(space, GFP_KERNEL);
10448c2ecf20Sopenharmony_ci	if (p == NULL) {
10458c2ecf20Sopenharmony_ci		i5000_printk(KERN_ERR, "MC: %s:%s() kmalloc() failed\n",
10468c2ecf20Sopenharmony_ci			__FILE__, __func__);
10478c2ecf20Sopenharmony_ci		return;
10488c2ecf20Sopenharmony_ci	}
10498c2ecf20Sopenharmony_ci
10508c2ecf20Sopenharmony_ci	/* Scan all the actual slots
10518c2ecf20Sopenharmony_ci	 * and calculate the information for each DIMM
10528c2ecf20Sopenharmony_ci	 * Start with the highest slot first, to display it first
10538c2ecf20Sopenharmony_ci	 * and work toward the 0th slot
10548c2ecf20Sopenharmony_ci	 */
10558c2ecf20Sopenharmony_ci	for (slot = pvt->maxdimmperch - 1; slot >= 0; slot--) {
10568c2ecf20Sopenharmony_ci
10578c2ecf20Sopenharmony_ci		/* on an odd slot, first output a 'boundary' marker,
10588c2ecf20Sopenharmony_ci		 * then reset the message buffer  */
10598c2ecf20Sopenharmony_ci		if (slot & 0x1) {
10608c2ecf20Sopenharmony_ci			n = snprintf(p, space, "--------------------------"
10618c2ecf20Sopenharmony_ci				"--------------------------------");
10628c2ecf20Sopenharmony_ci			p += n;
10638c2ecf20Sopenharmony_ci			space -= n;
10648c2ecf20Sopenharmony_ci			edac_dbg(2, "%s\n", mem_buffer);
10658c2ecf20Sopenharmony_ci			p = mem_buffer;
10668c2ecf20Sopenharmony_ci			space = PAGE_SIZE;
10678c2ecf20Sopenharmony_ci		}
10688c2ecf20Sopenharmony_ci		n = snprintf(p, space, "slot %2d    ", slot);
10698c2ecf20Sopenharmony_ci		p += n;
10708c2ecf20Sopenharmony_ci		space -= n;
10718c2ecf20Sopenharmony_ci
10728c2ecf20Sopenharmony_ci		for (channel = 0; channel < pvt->maxch; channel++) {
10738c2ecf20Sopenharmony_ci			dinfo = &pvt->dimm_info[slot][channel];
10748c2ecf20Sopenharmony_ci			handle_channel(pvt, slot, channel, dinfo);
10758c2ecf20Sopenharmony_ci			if (dinfo->megabytes)
10768c2ecf20Sopenharmony_ci				n = snprintf(p, space, "%4d MB %dR| ",
10778c2ecf20Sopenharmony_ci					     dinfo->megabytes, dinfo->dual_rank + 1);
10788c2ecf20Sopenharmony_ci			else
10798c2ecf20Sopenharmony_ci				n = snprintf(p, space, "%4d MB   | ", 0);
10808c2ecf20Sopenharmony_ci			p += n;
10818c2ecf20Sopenharmony_ci			space -= n;
10828c2ecf20Sopenharmony_ci		}
10838c2ecf20Sopenharmony_ci		p += n;
10848c2ecf20Sopenharmony_ci		space -= n;
10858c2ecf20Sopenharmony_ci		edac_dbg(2, "%s\n", mem_buffer);
10868c2ecf20Sopenharmony_ci		p = mem_buffer;
10878c2ecf20Sopenharmony_ci		space = PAGE_SIZE;
10888c2ecf20Sopenharmony_ci	}
10898c2ecf20Sopenharmony_ci
10908c2ecf20Sopenharmony_ci	/* Output the last bottom 'boundary' marker */
10918c2ecf20Sopenharmony_ci	n = snprintf(p, space, "--------------------------"
10928c2ecf20Sopenharmony_ci		"--------------------------------");
10938c2ecf20Sopenharmony_ci	p += n;
10948c2ecf20Sopenharmony_ci	space -= n;
10958c2ecf20Sopenharmony_ci	edac_dbg(2, "%s\n", mem_buffer);
10968c2ecf20Sopenharmony_ci	p = mem_buffer;
10978c2ecf20Sopenharmony_ci	space = PAGE_SIZE;
10988c2ecf20Sopenharmony_ci
10998c2ecf20Sopenharmony_ci	/* now output the 'channel' labels */
11008c2ecf20Sopenharmony_ci	n = snprintf(p, space, "           ");
11018c2ecf20Sopenharmony_ci	p += n;
11028c2ecf20Sopenharmony_ci	space -= n;
11038c2ecf20Sopenharmony_ci	for (channel = 0; channel < pvt->maxch; channel++) {
11048c2ecf20Sopenharmony_ci		n = snprintf(p, space, "channel %d | ", channel);
11058c2ecf20Sopenharmony_ci		p += n;
11068c2ecf20Sopenharmony_ci		space -= n;
11078c2ecf20Sopenharmony_ci	}
11088c2ecf20Sopenharmony_ci	edac_dbg(2, "%s\n", mem_buffer);
11098c2ecf20Sopenharmony_ci	p = mem_buffer;
11108c2ecf20Sopenharmony_ci	space = PAGE_SIZE;
11118c2ecf20Sopenharmony_ci
11128c2ecf20Sopenharmony_ci	n = snprintf(p, space, "           ");
11138c2ecf20Sopenharmony_ci	p += n;
11148c2ecf20Sopenharmony_ci	for (branch = 0; branch < MAX_BRANCHES; branch++) {
11158c2ecf20Sopenharmony_ci		n = snprintf(p, space, "       branch %d       | ", branch);
11168c2ecf20Sopenharmony_ci		p += n;
11178c2ecf20Sopenharmony_ci		space -= n;
11188c2ecf20Sopenharmony_ci	}
11198c2ecf20Sopenharmony_ci
11208c2ecf20Sopenharmony_ci	/* output the last message and free buffer */
11218c2ecf20Sopenharmony_ci	edac_dbg(2, "%s\n", mem_buffer);
11228c2ecf20Sopenharmony_ci	kfree(mem_buffer);
11238c2ecf20Sopenharmony_ci}
11248c2ecf20Sopenharmony_ci
11258c2ecf20Sopenharmony_ci/*
11268c2ecf20Sopenharmony_ci *	i5000_get_mc_regs	read in the necessary registers and
11278c2ecf20Sopenharmony_ci *				cache locally
11288c2ecf20Sopenharmony_ci *
11298c2ecf20Sopenharmony_ci *			Fills in the private data members
11308c2ecf20Sopenharmony_ci */
11318c2ecf20Sopenharmony_cistatic void i5000_get_mc_regs(struct mem_ctl_info *mci)
11328c2ecf20Sopenharmony_ci{
11338c2ecf20Sopenharmony_ci	struct i5000_pvt *pvt;
11348c2ecf20Sopenharmony_ci	u32 actual_tolm;
11358c2ecf20Sopenharmony_ci	u16 limit;
11368c2ecf20Sopenharmony_ci	int slot_row;
11378c2ecf20Sopenharmony_ci	int way0, way1;
11388c2ecf20Sopenharmony_ci
11398c2ecf20Sopenharmony_ci	pvt = mci->pvt_info;
11408c2ecf20Sopenharmony_ci
11418c2ecf20Sopenharmony_ci	pci_read_config_dword(pvt->system_address, AMBASE,
11428c2ecf20Sopenharmony_ci			&pvt->u.ambase_bottom);
11438c2ecf20Sopenharmony_ci	pci_read_config_dword(pvt->system_address, AMBASE + sizeof(u32),
11448c2ecf20Sopenharmony_ci			&pvt->u.ambase_top);
11458c2ecf20Sopenharmony_ci
11468c2ecf20Sopenharmony_ci	edac_dbg(2, "AMBASE= 0x%lx  MAXCH= %d  MAX-DIMM-Per-CH= %d\n",
11478c2ecf20Sopenharmony_ci		 (long unsigned int)pvt->ambase, pvt->maxch, pvt->maxdimmperch);
11488c2ecf20Sopenharmony_ci
11498c2ecf20Sopenharmony_ci	/* Get the Branch Map regs */
11508c2ecf20Sopenharmony_ci	pci_read_config_word(pvt->branchmap_werrors, TOLM, &pvt->tolm);
11518c2ecf20Sopenharmony_ci	pvt->tolm >>= 12;
11528c2ecf20Sopenharmony_ci	edac_dbg(2, "TOLM (number of 256M regions) =%u (0x%x)\n",
11538c2ecf20Sopenharmony_ci		 pvt->tolm, pvt->tolm);
11548c2ecf20Sopenharmony_ci
11558c2ecf20Sopenharmony_ci	actual_tolm = pvt->tolm << 28;
11568c2ecf20Sopenharmony_ci	edac_dbg(2, "Actual TOLM byte addr=%u (0x%x)\n",
11578c2ecf20Sopenharmony_ci		 actual_tolm, actual_tolm);
11588c2ecf20Sopenharmony_ci
11598c2ecf20Sopenharmony_ci	pci_read_config_word(pvt->branchmap_werrors, MIR0, &pvt->mir0);
11608c2ecf20Sopenharmony_ci	pci_read_config_word(pvt->branchmap_werrors, MIR1, &pvt->mir1);
11618c2ecf20Sopenharmony_ci	pci_read_config_word(pvt->branchmap_werrors, MIR2, &pvt->mir2);
11628c2ecf20Sopenharmony_ci
11638c2ecf20Sopenharmony_ci	/* Get the MIR[0-2] regs */
11648c2ecf20Sopenharmony_ci	limit = (pvt->mir0 >> 4) & 0x0FFF;
11658c2ecf20Sopenharmony_ci	way0 = pvt->mir0 & 0x1;
11668c2ecf20Sopenharmony_ci	way1 = pvt->mir0 & 0x2;
11678c2ecf20Sopenharmony_ci	edac_dbg(2, "MIR0: limit= 0x%x  WAY1= %u  WAY0= %x\n",
11688c2ecf20Sopenharmony_ci		 limit, way1, way0);
11698c2ecf20Sopenharmony_ci	limit = (pvt->mir1 >> 4) & 0x0FFF;
11708c2ecf20Sopenharmony_ci	way0 = pvt->mir1 & 0x1;
11718c2ecf20Sopenharmony_ci	way1 = pvt->mir1 & 0x2;
11728c2ecf20Sopenharmony_ci	edac_dbg(2, "MIR1: limit= 0x%x  WAY1= %u  WAY0= %x\n",
11738c2ecf20Sopenharmony_ci		 limit, way1, way0);
11748c2ecf20Sopenharmony_ci	limit = (pvt->mir2 >> 4) & 0x0FFF;
11758c2ecf20Sopenharmony_ci	way0 = pvt->mir2 & 0x1;
11768c2ecf20Sopenharmony_ci	way1 = pvt->mir2 & 0x2;
11778c2ecf20Sopenharmony_ci	edac_dbg(2, "MIR2: limit= 0x%x  WAY1= %u  WAY0= %x\n",
11788c2ecf20Sopenharmony_ci		 limit, way1, way0);
11798c2ecf20Sopenharmony_ci
11808c2ecf20Sopenharmony_ci	/* Get the MTR[0-3] regs */
11818c2ecf20Sopenharmony_ci	for (slot_row = 0; slot_row < NUM_MTRS; slot_row++) {
11828c2ecf20Sopenharmony_ci		int where = MTR0 + (slot_row * sizeof(u32));
11838c2ecf20Sopenharmony_ci
11848c2ecf20Sopenharmony_ci		pci_read_config_word(pvt->branch_0, where,
11858c2ecf20Sopenharmony_ci				&pvt->b0_mtr[slot_row]);
11868c2ecf20Sopenharmony_ci
11878c2ecf20Sopenharmony_ci		edac_dbg(2, "MTR%d where=0x%x B0 value=0x%x\n",
11888c2ecf20Sopenharmony_ci			 slot_row, where, pvt->b0_mtr[slot_row]);
11898c2ecf20Sopenharmony_ci
11908c2ecf20Sopenharmony_ci		if (pvt->maxch >= CHANNELS_PER_BRANCH) {
11918c2ecf20Sopenharmony_ci			pci_read_config_word(pvt->branch_1, where,
11928c2ecf20Sopenharmony_ci					&pvt->b1_mtr[slot_row]);
11938c2ecf20Sopenharmony_ci			edac_dbg(2, "MTR%d where=0x%x B1 value=0x%x\n",
11948c2ecf20Sopenharmony_ci				 slot_row, where, pvt->b1_mtr[slot_row]);
11958c2ecf20Sopenharmony_ci		} else {
11968c2ecf20Sopenharmony_ci			pvt->b1_mtr[slot_row] = 0;
11978c2ecf20Sopenharmony_ci		}
11988c2ecf20Sopenharmony_ci	}
11998c2ecf20Sopenharmony_ci
12008c2ecf20Sopenharmony_ci	/* Read and dump branch 0's MTRs */
12018c2ecf20Sopenharmony_ci	edac_dbg(2, "Memory Technology Registers:\n");
12028c2ecf20Sopenharmony_ci	edac_dbg(2, "   Branch 0:\n");
12038c2ecf20Sopenharmony_ci	for (slot_row = 0; slot_row < NUM_MTRS; slot_row++) {
12048c2ecf20Sopenharmony_ci		decode_mtr(slot_row, pvt->b0_mtr[slot_row]);
12058c2ecf20Sopenharmony_ci	}
12068c2ecf20Sopenharmony_ci	pci_read_config_word(pvt->branch_0, AMB_PRESENT_0,
12078c2ecf20Sopenharmony_ci			&pvt->b0_ambpresent0);
12088c2ecf20Sopenharmony_ci	edac_dbg(2, "\t\tAMB-Branch 0-present0 0x%x:\n", pvt->b0_ambpresent0);
12098c2ecf20Sopenharmony_ci	pci_read_config_word(pvt->branch_0, AMB_PRESENT_1,
12108c2ecf20Sopenharmony_ci			&pvt->b0_ambpresent1);
12118c2ecf20Sopenharmony_ci	edac_dbg(2, "\t\tAMB-Branch 0-present1 0x%x:\n", pvt->b0_ambpresent1);
12128c2ecf20Sopenharmony_ci
12138c2ecf20Sopenharmony_ci	/* Only if we have 2 branchs (4 channels) */
12148c2ecf20Sopenharmony_ci	if (pvt->maxch < CHANNELS_PER_BRANCH) {
12158c2ecf20Sopenharmony_ci		pvt->b1_ambpresent0 = 0;
12168c2ecf20Sopenharmony_ci		pvt->b1_ambpresent1 = 0;
12178c2ecf20Sopenharmony_ci	} else {
12188c2ecf20Sopenharmony_ci		/* Read and dump  branch 1's MTRs */
12198c2ecf20Sopenharmony_ci		edac_dbg(2, "   Branch 1:\n");
12208c2ecf20Sopenharmony_ci		for (slot_row = 0; slot_row < NUM_MTRS; slot_row++) {
12218c2ecf20Sopenharmony_ci			decode_mtr(slot_row, pvt->b1_mtr[slot_row]);
12228c2ecf20Sopenharmony_ci		}
12238c2ecf20Sopenharmony_ci		pci_read_config_word(pvt->branch_1, AMB_PRESENT_0,
12248c2ecf20Sopenharmony_ci				&pvt->b1_ambpresent0);
12258c2ecf20Sopenharmony_ci		edac_dbg(2, "\t\tAMB-Branch 1-present0 0x%x:\n",
12268c2ecf20Sopenharmony_ci			 pvt->b1_ambpresent0);
12278c2ecf20Sopenharmony_ci		pci_read_config_word(pvt->branch_1, AMB_PRESENT_1,
12288c2ecf20Sopenharmony_ci				&pvt->b1_ambpresent1);
12298c2ecf20Sopenharmony_ci		edac_dbg(2, "\t\tAMB-Branch 1-present1 0x%x:\n",
12308c2ecf20Sopenharmony_ci			 pvt->b1_ambpresent1);
12318c2ecf20Sopenharmony_ci	}
12328c2ecf20Sopenharmony_ci
12338c2ecf20Sopenharmony_ci	/* Go and determine the size of each DIMM and place in an
12348c2ecf20Sopenharmony_ci	 * orderly matrix */
12358c2ecf20Sopenharmony_ci	calculate_dimm_size(pvt);
12368c2ecf20Sopenharmony_ci}
12378c2ecf20Sopenharmony_ci
12388c2ecf20Sopenharmony_ci/*
12398c2ecf20Sopenharmony_ci *	i5000_init_csrows	Initialize the 'csrows' table within
12408c2ecf20Sopenharmony_ci *				the mci control	structure with the
12418c2ecf20Sopenharmony_ci *				addressing of memory.
12428c2ecf20Sopenharmony_ci *
12438c2ecf20Sopenharmony_ci *	return:
12448c2ecf20Sopenharmony_ci *		0	success
12458c2ecf20Sopenharmony_ci *		1	no actual memory found on this MC
12468c2ecf20Sopenharmony_ci */
12478c2ecf20Sopenharmony_cistatic int i5000_init_csrows(struct mem_ctl_info *mci)
12488c2ecf20Sopenharmony_ci{
12498c2ecf20Sopenharmony_ci	struct i5000_pvt *pvt;
12508c2ecf20Sopenharmony_ci	struct dimm_info *dimm;
12518c2ecf20Sopenharmony_ci	int empty;
12528c2ecf20Sopenharmony_ci	int max_csrows;
12538c2ecf20Sopenharmony_ci	int mtr;
12548c2ecf20Sopenharmony_ci	int csrow_megs;
12558c2ecf20Sopenharmony_ci	int channel;
12568c2ecf20Sopenharmony_ci	int slot;
12578c2ecf20Sopenharmony_ci
12588c2ecf20Sopenharmony_ci	pvt = mci->pvt_info;
12598c2ecf20Sopenharmony_ci	max_csrows = pvt->maxdimmperch * 2;
12608c2ecf20Sopenharmony_ci
12618c2ecf20Sopenharmony_ci	empty = 1;		/* Assume NO memory */
12628c2ecf20Sopenharmony_ci
12638c2ecf20Sopenharmony_ci	/*
12648c2ecf20Sopenharmony_ci	 * FIXME: The memory layout used to map slot/channel into the
12658c2ecf20Sopenharmony_ci	 * real memory architecture is weird: branch+slot are "csrows"
12668c2ecf20Sopenharmony_ci	 * and channel is channel. That required an extra array (dimm_info)
12678c2ecf20Sopenharmony_ci	 * to map the dimms. A good cleanup would be to remove this array,
12688c2ecf20Sopenharmony_ci	 * and do a loop here with branch, channel, slot
12698c2ecf20Sopenharmony_ci	 */
12708c2ecf20Sopenharmony_ci	for (slot = 0; slot < max_csrows; slot++) {
12718c2ecf20Sopenharmony_ci		for (channel = 0; channel < pvt->maxch; channel++) {
12728c2ecf20Sopenharmony_ci
12738c2ecf20Sopenharmony_ci			mtr = determine_mtr(pvt, slot, channel);
12748c2ecf20Sopenharmony_ci
12758c2ecf20Sopenharmony_ci			if (!MTR_DIMMS_PRESENT(mtr))
12768c2ecf20Sopenharmony_ci				continue;
12778c2ecf20Sopenharmony_ci
12788c2ecf20Sopenharmony_ci			dimm = edac_get_dimm(mci, channel / MAX_BRANCHES,
12798c2ecf20Sopenharmony_ci					     channel % MAX_BRANCHES, slot);
12808c2ecf20Sopenharmony_ci
12818c2ecf20Sopenharmony_ci			csrow_megs = pvt->dimm_info[slot][channel].megabytes;
12828c2ecf20Sopenharmony_ci			dimm->grain = 8;
12838c2ecf20Sopenharmony_ci
12848c2ecf20Sopenharmony_ci			/* Assume DDR2 for now */
12858c2ecf20Sopenharmony_ci			dimm->mtype = MEM_FB_DDR2;
12868c2ecf20Sopenharmony_ci
12878c2ecf20Sopenharmony_ci			/* ask what device type on this row */
12888c2ecf20Sopenharmony_ci			if (MTR_DRAM_WIDTH(mtr) == 8)
12898c2ecf20Sopenharmony_ci				dimm->dtype = DEV_X8;
12908c2ecf20Sopenharmony_ci			else
12918c2ecf20Sopenharmony_ci				dimm->dtype = DEV_X4;
12928c2ecf20Sopenharmony_ci
12938c2ecf20Sopenharmony_ci			dimm->edac_mode = EDAC_S8ECD8ED;
12948c2ecf20Sopenharmony_ci			dimm->nr_pages = csrow_megs << 8;
12958c2ecf20Sopenharmony_ci		}
12968c2ecf20Sopenharmony_ci
12978c2ecf20Sopenharmony_ci		empty = 0;
12988c2ecf20Sopenharmony_ci	}
12998c2ecf20Sopenharmony_ci
13008c2ecf20Sopenharmony_ci	return empty;
13018c2ecf20Sopenharmony_ci}
13028c2ecf20Sopenharmony_ci
13038c2ecf20Sopenharmony_ci/*
13048c2ecf20Sopenharmony_ci *	i5000_enable_error_reporting
13058c2ecf20Sopenharmony_ci *			Turn on the memory reporting features of the hardware
13068c2ecf20Sopenharmony_ci */
13078c2ecf20Sopenharmony_cistatic void i5000_enable_error_reporting(struct mem_ctl_info *mci)
13088c2ecf20Sopenharmony_ci{
13098c2ecf20Sopenharmony_ci	struct i5000_pvt *pvt;
13108c2ecf20Sopenharmony_ci	u32 fbd_error_mask;
13118c2ecf20Sopenharmony_ci
13128c2ecf20Sopenharmony_ci	pvt = mci->pvt_info;
13138c2ecf20Sopenharmony_ci
13148c2ecf20Sopenharmony_ci	/* Read the FBD Error Mask Register */
13158c2ecf20Sopenharmony_ci	pci_read_config_dword(pvt->branchmap_werrors, EMASK_FBD,
13168c2ecf20Sopenharmony_ci			&fbd_error_mask);
13178c2ecf20Sopenharmony_ci
13188c2ecf20Sopenharmony_ci	/* Enable with a '0' */
13198c2ecf20Sopenharmony_ci	fbd_error_mask &= ~(ENABLE_EMASK_ALL);
13208c2ecf20Sopenharmony_ci
13218c2ecf20Sopenharmony_ci	pci_write_config_dword(pvt->branchmap_werrors, EMASK_FBD,
13228c2ecf20Sopenharmony_ci			fbd_error_mask);
13238c2ecf20Sopenharmony_ci}
13248c2ecf20Sopenharmony_ci
13258c2ecf20Sopenharmony_ci/*
13268c2ecf20Sopenharmony_ci * i5000_get_dimm_and_channel_counts(pdev, &nr_csrows, &num_channels)
13278c2ecf20Sopenharmony_ci *
13288c2ecf20Sopenharmony_ci *	ask the device how many channels are present and how many CSROWS
13298c2ecf20Sopenharmony_ci *	 as well
13308c2ecf20Sopenharmony_ci */
13318c2ecf20Sopenharmony_cistatic void i5000_get_dimm_and_channel_counts(struct pci_dev *pdev,
13328c2ecf20Sopenharmony_ci					int *num_dimms_per_channel,
13338c2ecf20Sopenharmony_ci					int *num_channels)
13348c2ecf20Sopenharmony_ci{
13358c2ecf20Sopenharmony_ci	u8 value;
13368c2ecf20Sopenharmony_ci
13378c2ecf20Sopenharmony_ci	/* Need to retrieve just how many channels and dimms per channel are
13388c2ecf20Sopenharmony_ci	 * supported on this memory controller
13398c2ecf20Sopenharmony_ci	 */
13408c2ecf20Sopenharmony_ci	pci_read_config_byte(pdev, MAXDIMMPERCH, &value);
13418c2ecf20Sopenharmony_ci	*num_dimms_per_channel = (int)value;
13428c2ecf20Sopenharmony_ci
13438c2ecf20Sopenharmony_ci	pci_read_config_byte(pdev, MAXCH, &value);
13448c2ecf20Sopenharmony_ci	*num_channels = (int)value;
13458c2ecf20Sopenharmony_ci}
13468c2ecf20Sopenharmony_ci
13478c2ecf20Sopenharmony_ci/*
13488c2ecf20Sopenharmony_ci *	i5000_probe1	Probe for ONE instance of device to see if it is
13498c2ecf20Sopenharmony_ci *			present.
13508c2ecf20Sopenharmony_ci *	return:
13518c2ecf20Sopenharmony_ci *		0 for FOUND a device
13528c2ecf20Sopenharmony_ci *		< 0 for error code
13538c2ecf20Sopenharmony_ci */
13548c2ecf20Sopenharmony_cistatic int i5000_probe1(struct pci_dev *pdev, int dev_idx)
13558c2ecf20Sopenharmony_ci{
13568c2ecf20Sopenharmony_ci	struct mem_ctl_info *mci;
13578c2ecf20Sopenharmony_ci	struct edac_mc_layer layers[3];
13588c2ecf20Sopenharmony_ci	struct i5000_pvt *pvt;
13598c2ecf20Sopenharmony_ci	int num_channels;
13608c2ecf20Sopenharmony_ci	int num_dimms_per_channel;
13618c2ecf20Sopenharmony_ci
13628c2ecf20Sopenharmony_ci	edac_dbg(0, "MC: pdev bus %u dev=0x%x fn=0x%x\n",
13638c2ecf20Sopenharmony_ci		 pdev->bus->number,
13648c2ecf20Sopenharmony_ci		 PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
13658c2ecf20Sopenharmony_ci
13668c2ecf20Sopenharmony_ci	/* We only are looking for func 0 of the set */
13678c2ecf20Sopenharmony_ci	if (PCI_FUNC(pdev->devfn) != 0)
13688c2ecf20Sopenharmony_ci		return -ENODEV;
13698c2ecf20Sopenharmony_ci
13708c2ecf20Sopenharmony_ci	/* Ask the devices for the number of CSROWS and CHANNELS so
13718c2ecf20Sopenharmony_ci	 * that we can calculate the memory resources, etc
13728c2ecf20Sopenharmony_ci	 *
13738c2ecf20Sopenharmony_ci	 * The Chipset will report what it can handle which will be greater
13748c2ecf20Sopenharmony_ci	 * or equal to what the motherboard manufacturer will implement.
13758c2ecf20Sopenharmony_ci	 *
13768c2ecf20Sopenharmony_ci	 * As we don't have a motherboard identification routine to determine
13778c2ecf20Sopenharmony_ci	 * actual number of slots/dimms per channel, we thus utilize the
13788c2ecf20Sopenharmony_ci	 * resource as specified by the chipset. Thus, we might have
13798c2ecf20Sopenharmony_ci	 * have more DIMMs per channel than actually on the mobo, but this
13808c2ecf20Sopenharmony_ci	 * allows the driver to support up to the chipset max, without
13818c2ecf20Sopenharmony_ci	 * some fancy mobo determination.
13828c2ecf20Sopenharmony_ci	 */
13838c2ecf20Sopenharmony_ci	i5000_get_dimm_and_channel_counts(pdev, &num_dimms_per_channel,
13848c2ecf20Sopenharmony_ci					&num_channels);
13858c2ecf20Sopenharmony_ci
13868c2ecf20Sopenharmony_ci	edac_dbg(0, "MC: Number of Branches=2 Channels= %d  DIMMS= %d\n",
13878c2ecf20Sopenharmony_ci		 num_channels, num_dimms_per_channel);
13888c2ecf20Sopenharmony_ci
13898c2ecf20Sopenharmony_ci	/* allocate a new MC control structure */
13908c2ecf20Sopenharmony_ci
13918c2ecf20Sopenharmony_ci	layers[0].type = EDAC_MC_LAYER_BRANCH;
13928c2ecf20Sopenharmony_ci	layers[0].size = MAX_BRANCHES;
13938c2ecf20Sopenharmony_ci	layers[0].is_virt_csrow = false;
13948c2ecf20Sopenharmony_ci	layers[1].type = EDAC_MC_LAYER_CHANNEL;
13958c2ecf20Sopenharmony_ci	layers[1].size = num_channels / MAX_BRANCHES;
13968c2ecf20Sopenharmony_ci	layers[1].is_virt_csrow = false;
13978c2ecf20Sopenharmony_ci	layers[2].type = EDAC_MC_LAYER_SLOT;
13988c2ecf20Sopenharmony_ci	layers[2].size = num_dimms_per_channel;
13998c2ecf20Sopenharmony_ci	layers[2].is_virt_csrow = true;
14008c2ecf20Sopenharmony_ci	mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers, sizeof(*pvt));
14018c2ecf20Sopenharmony_ci	if (mci == NULL)
14028c2ecf20Sopenharmony_ci		return -ENOMEM;
14038c2ecf20Sopenharmony_ci
14048c2ecf20Sopenharmony_ci	edac_dbg(0, "MC: mci = %p\n", mci);
14058c2ecf20Sopenharmony_ci
14068c2ecf20Sopenharmony_ci	mci->pdev = &pdev->dev;	/* record ptr  to the generic device */
14078c2ecf20Sopenharmony_ci
14088c2ecf20Sopenharmony_ci	pvt = mci->pvt_info;
14098c2ecf20Sopenharmony_ci	pvt->system_address = pdev;	/* Record this device in our private */
14108c2ecf20Sopenharmony_ci	pvt->maxch = num_channels;
14118c2ecf20Sopenharmony_ci	pvt->maxdimmperch = num_dimms_per_channel;
14128c2ecf20Sopenharmony_ci
14138c2ecf20Sopenharmony_ci	/* 'get' the pci devices we want to reserve for our use */
14148c2ecf20Sopenharmony_ci	if (i5000_get_devices(mci, dev_idx))
14158c2ecf20Sopenharmony_ci		goto fail0;
14168c2ecf20Sopenharmony_ci
14178c2ecf20Sopenharmony_ci	/* Time to get serious */
14188c2ecf20Sopenharmony_ci	i5000_get_mc_regs(mci);	/* retrieve the hardware registers */
14198c2ecf20Sopenharmony_ci
14208c2ecf20Sopenharmony_ci	mci->mc_idx = 0;
14218c2ecf20Sopenharmony_ci	mci->mtype_cap = MEM_FLAG_FB_DDR2;
14228c2ecf20Sopenharmony_ci	mci->edac_ctl_cap = EDAC_FLAG_NONE;
14238c2ecf20Sopenharmony_ci	mci->edac_cap = EDAC_FLAG_NONE;
14248c2ecf20Sopenharmony_ci	mci->mod_name = "i5000_edac.c";
14258c2ecf20Sopenharmony_ci	mci->ctl_name = i5000_devs[dev_idx].ctl_name;
14268c2ecf20Sopenharmony_ci	mci->dev_name = pci_name(pdev);
14278c2ecf20Sopenharmony_ci	mci->ctl_page_to_phys = NULL;
14288c2ecf20Sopenharmony_ci
14298c2ecf20Sopenharmony_ci	/* Set the function pointer to an actual operation function */
14308c2ecf20Sopenharmony_ci	mci->edac_check = i5000_check_error;
14318c2ecf20Sopenharmony_ci
14328c2ecf20Sopenharmony_ci	/* initialize the MC control structure 'csrows' table
14338c2ecf20Sopenharmony_ci	 * with the mapping and control information */
14348c2ecf20Sopenharmony_ci	if (i5000_init_csrows(mci)) {
14358c2ecf20Sopenharmony_ci		edac_dbg(0, "MC: Setting mci->edac_cap to EDAC_FLAG_NONE because i5000_init_csrows() returned nonzero value\n");
14368c2ecf20Sopenharmony_ci		mci->edac_cap = EDAC_FLAG_NONE;	/* no csrows found */
14378c2ecf20Sopenharmony_ci	} else {
14388c2ecf20Sopenharmony_ci		edac_dbg(1, "MC: Enable error reporting now\n");
14398c2ecf20Sopenharmony_ci		i5000_enable_error_reporting(mci);
14408c2ecf20Sopenharmony_ci	}
14418c2ecf20Sopenharmony_ci
14428c2ecf20Sopenharmony_ci	/* add this new MC control structure to EDAC's list of MCs */
14438c2ecf20Sopenharmony_ci	if (edac_mc_add_mc(mci)) {
14448c2ecf20Sopenharmony_ci		edac_dbg(0, "MC: failed edac_mc_add_mc()\n");
14458c2ecf20Sopenharmony_ci		/* FIXME: perhaps some code should go here that disables error
14468c2ecf20Sopenharmony_ci		 * reporting if we just enabled it
14478c2ecf20Sopenharmony_ci		 */
14488c2ecf20Sopenharmony_ci		goto fail1;
14498c2ecf20Sopenharmony_ci	}
14508c2ecf20Sopenharmony_ci
14518c2ecf20Sopenharmony_ci	i5000_clear_error(mci);
14528c2ecf20Sopenharmony_ci
14538c2ecf20Sopenharmony_ci	/* allocating generic PCI control info */
14548c2ecf20Sopenharmony_ci	i5000_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR);
14558c2ecf20Sopenharmony_ci	if (!i5000_pci) {
14568c2ecf20Sopenharmony_ci		printk(KERN_WARNING
14578c2ecf20Sopenharmony_ci			"%s(): Unable to create PCI control\n",
14588c2ecf20Sopenharmony_ci			__func__);
14598c2ecf20Sopenharmony_ci		printk(KERN_WARNING
14608c2ecf20Sopenharmony_ci			"%s(): PCI error report via EDAC not setup\n",
14618c2ecf20Sopenharmony_ci			__func__);
14628c2ecf20Sopenharmony_ci	}
14638c2ecf20Sopenharmony_ci
14648c2ecf20Sopenharmony_ci	return 0;
14658c2ecf20Sopenharmony_ci
14668c2ecf20Sopenharmony_ci	/* Error exit unwinding stack */
14678c2ecf20Sopenharmony_cifail1:
14688c2ecf20Sopenharmony_ci
14698c2ecf20Sopenharmony_ci	i5000_put_devices(mci);
14708c2ecf20Sopenharmony_ci
14718c2ecf20Sopenharmony_cifail0:
14728c2ecf20Sopenharmony_ci	edac_mc_free(mci);
14738c2ecf20Sopenharmony_ci	return -ENODEV;
14748c2ecf20Sopenharmony_ci}
14758c2ecf20Sopenharmony_ci
14768c2ecf20Sopenharmony_ci/*
14778c2ecf20Sopenharmony_ci *	i5000_init_one	constructor for one instance of device
14788c2ecf20Sopenharmony_ci *
14798c2ecf20Sopenharmony_ci * 	returns:
14808c2ecf20Sopenharmony_ci *		negative on error
14818c2ecf20Sopenharmony_ci *		count (>= 0)
14828c2ecf20Sopenharmony_ci */
14838c2ecf20Sopenharmony_cistatic int i5000_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
14848c2ecf20Sopenharmony_ci{
14858c2ecf20Sopenharmony_ci	int rc;
14868c2ecf20Sopenharmony_ci
14878c2ecf20Sopenharmony_ci	edac_dbg(0, "MC:\n");
14888c2ecf20Sopenharmony_ci
14898c2ecf20Sopenharmony_ci	/* wake up device */
14908c2ecf20Sopenharmony_ci	rc = pci_enable_device(pdev);
14918c2ecf20Sopenharmony_ci	if (rc)
14928c2ecf20Sopenharmony_ci		return rc;
14938c2ecf20Sopenharmony_ci
14948c2ecf20Sopenharmony_ci	/* now probe and enable the device */
14958c2ecf20Sopenharmony_ci	return i5000_probe1(pdev, id->driver_data);
14968c2ecf20Sopenharmony_ci}
14978c2ecf20Sopenharmony_ci
14988c2ecf20Sopenharmony_ci/*
14998c2ecf20Sopenharmony_ci *	i5000_remove_one	destructor for one instance of device
15008c2ecf20Sopenharmony_ci *
15018c2ecf20Sopenharmony_ci */
15028c2ecf20Sopenharmony_cistatic void i5000_remove_one(struct pci_dev *pdev)
15038c2ecf20Sopenharmony_ci{
15048c2ecf20Sopenharmony_ci	struct mem_ctl_info *mci;
15058c2ecf20Sopenharmony_ci
15068c2ecf20Sopenharmony_ci	edac_dbg(0, "\n");
15078c2ecf20Sopenharmony_ci
15088c2ecf20Sopenharmony_ci	if (i5000_pci)
15098c2ecf20Sopenharmony_ci		edac_pci_release_generic_ctl(i5000_pci);
15108c2ecf20Sopenharmony_ci
15118c2ecf20Sopenharmony_ci	if ((mci = edac_mc_del_mc(&pdev->dev)) == NULL)
15128c2ecf20Sopenharmony_ci		return;
15138c2ecf20Sopenharmony_ci
15148c2ecf20Sopenharmony_ci	/* retrieve references to resources, and free those resources */
15158c2ecf20Sopenharmony_ci	i5000_put_devices(mci);
15168c2ecf20Sopenharmony_ci	edac_mc_free(mci);
15178c2ecf20Sopenharmony_ci}
15188c2ecf20Sopenharmony_ci
15198c2ecf20Sopenharmony_ci/*
15208c2ecf20Sopenharmony_ci *	pci_device_id	table for which devices we are looking for
15218c2ecf20Sopenharmony_ci *
15228c2ecf20Sopenharmony_ci *	The "E500P" device is the first device supported.
15238c2ecf20Sopenharmony_ci */
15248c2ecf20Sopenharmony_cistatic const struct pci_device_id i5000_pci_tbl[] = {
15258c2ecf20Sopenharmony_ci	{PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000_DEV16),
15268c2ecf20Sopenharmony_ci	 .driver_data = I5000P},
15278c2ecf20Sopenharmony_ci
15288c2ecf20Sopenharmony_ci	{0,}			/* 0 terminated list. */
15298c2ecf20Sopenharmony_ci};
15308c2ecf20Sopenharmony_ci
15318c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(pci, i5000_pci_tbl);
15328c2ecf20Sopenharmony_ci
15338c2ecf20Sopenharmony_ci/*
15348c2ecf20Sopenharmony_ci *	i5000_driver	pci_driver structure for this module
15358c2ecf20Sopenharmony_ci *
15368c2ecf20Sopenharmony_ci */
15378c2ecf20Sopenharmony_cistatic struct pci_driver i5000_driver = {
15388c2ecf20Sopenharmony_ci	.name = KBUILD_BASENAME,
15398c2ecf20Sopenharmony_ci	.probe = i5000_init_one,
15408c2ecf20Sopenharmony_ci	.remove = i5000_remove_one,
15418c2ecf20Sopenharmony_ci	.id_table = i5000_pci_tbl,
15428c2ecf20Sopenharmony_ci};
15438c2ecf20Sopenharmony_ci
15448c2ecf20Sopenharmony_ci/*
15458c2ecf20Sopenharmony_ci *	i5000_init		Module entry function
15468c2ecf20Sopenharmony_ci *			Try to initialize this module for its devices
15478c2ecf20Sopenharmony_ci */
15488c2ecf20Sopenharmony_cistatic int __init i5000_init(void)
15498c2ecf20Sopenharmony_ci{
15508c2ecf20Sopenharmony_ci	int pci_rc;
15518c2ecf20Sopenharmony_ci
15528c2ecf20Sopenharmony_ci	edac_dbg(2, "MC:\n");
15538c2ecf20Sopenharmony_ci
15548c2ecf20Sopenharmony_ci	/* Ensure that the OPSTATE is set correctly for POLL or NMI */
15558c2ecf20Sopenharmony_ci	opstate_init();
15568c2ecf20Sopenharmony_ci
15578c2ecf20Sopenharmony_ci	pci_rc = pci_register_driver(&i5000_driver);
15588c2ecf20Sopenharmony_ci
15598c2ecf20Sopenharmony_ci	return (pci_rc < 0) ? pci_rc : 0;
15608c2ecf20Sopenharmony_ci}
15618c2ecf20Sopenharmony_ci
15628c2ecf20Sopenharmony_ci/*
15638c2ecf20Sopenharmony_ci *	i5000_exit()	Module exit function
15648c2ecf20Sopenharmony_ci *			Unregister the driver
15658c2ecf20Sopenharmony_ci */
15668c2ecf20Sopenharmony_cistatic void __exit i5000_exit(void)
15678c2ecf20Sopenharmony_ci{
15688c2ecf20Sopenharmony_ci	edac_dbg(2, "MC:\n");
15698c2ecf20Sopenharmony_ci	pci_unregister_driver(&i5000_driver);
15708c2ecf20Sopenharmony_ci}
15718c2ecf20Sopenharmony_ci
15728c2ecf20Sopenharmony_cimodule_init(i5000_init);
15738c2ecf20Sopenharmony_cimodule_exit(i5000_exit);
15748c2ecf20Sopenharmony_ci
15758c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL");
15768c2ecf20Sopenharmony_ciMODULE_AUTHOR
15778c2ecf20Sopenharmony_ci    ("Linux Networx (http://lnxi.com) Doug Thompson <norsk5@xmission.com>");
15788c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("MC Driver for Intel I5000 memory controllers - "
15798c2ecf20Sopenharmony_ci		I5000_REVISION);
15808c2ecf20Sopenharmony_ci
15818c2ecf20Sopenharmony_cimodule_param(edac_op_state, int, 0444);
15828c2ecf20Sopenharmony_ciMODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");
15838c2ecf20Sopenharmony_cimodule_param(misc_messages, int, 0444);
15848c2ecf20Sopenharmony_ciMODULE_PARM_DESC(misc_messages, "Log miscellaneous non fatal messages");
15858c2ecf20Sopenharmony_ci
1586