xref: /openbmc/linux/drivers/edac/i7300_edac.c (revision 5de6e07ed75ee29a302f50e149339ca747131121)
1fcaf780bSMauro Carvalho Chehab /*
2fcaf780bSMauro Carvalho Chehab  * Intel 7300 class Memory Controllers kernel module (Clarksboro)
3fcaf780bSMauro Carvalho Chehab  *
4fcaf780bSMauro Carvalho Chehab  * This file may be distributed under the terms of the
5fcaf780bSMauro Carvalho Chehab  * GNU General Public License version 2 only.
6fcaf780bSMauro Carvalho Chehab  *
7fcaf780bSMauro Carvalho Chehab  * Copyright (c) 2010 by:
8fcaf780bSMauro Carvalho Chehab  *	 Mauro Carvalho Chehab <mchehab@redhat.com>
9fcaf780bSMauro Carvalho Chehab  *
10fcaf780bSMauro Carvalho Chehab  * Red Hat Inc. http://www.redhat.com
11fcaf780bSMauro Carvalho Chehab  *
12fcaf780bSMauro Carvalho Chehab  * Intel 7300 Chipset Memory Controller Hub (MCH) - Datasheet
13fcaf780bSMauro Carvalho Chehab  *	http://www.intel.com/Assets/PDF/datasheet/318082.pdf
14fcaf780bSMauro Carvalho Chehab  *
15fcaf780bSMauro Carvalho Chehab  * TODO: The chipset allow checking for PCI Express errors also. Currently,
16fcaf780bSMauro Carvalho Chehab  *	 the driver covers only memory error errors
17fcaf780bSMauro Carvalho Chehab  *
18fcaf780bSMauro Carvalho Chehab  * This driver uses "csrows" EDAC attribute to represent DIMM slot#
19fcaf780bSMauro Carvalho Chehab  */
20fcaf780bSMauro Carvalho Chehab 
21fcaf780bSMauro Carvalho Chehab #include <linux/module.h>
22fcaf780bSMauro Carvalho Chehab #include <linux/init.h>
23fcaf780bSMauro Carvalho Chehab #include <linux/pci.h>
24fcaf780bSMauro Carvalho Chehab #include <linux/pci_ids.h>
25fcaf780bSMauro Carvalho Chehab #include <linux/slab.h>
26fcaf780bSMauro Carvalho Chehab #include <linux/edac.h>
27fcaf780bSMauro Carvalho Chehab #include <linux/mmzone.h>
28fcaf780bSMauro Carvalho Chehab 
29fcaf780bSMauro Carvalho Chehab #include "edac_core.h"
30fcaf780bSMauro Carvalho Chehab 
31fcaf780bSMauro Carvalho Chehab /*
32fcaf780bSMauro Carvalho Chehab  * Alter this version for the I7300 module when modifications are made
33fcaf780bSMauro Carvalho Chehab  */
34fcaf780bSMauro Carvalho Chehab #define I7300_REVISION    " Ver: 1.0.0 " __DATE__
35fcaf780bSMauro Carvalho Chehab 
36fcaf780bSMauro Carvalho Chehab #define EDAC_MOD_STR      "i7300_edac"
37fcaf780bSMauro Carvalho Chehab 
38fcaf780bSMauro Carvalho Chehab #define i7300_printk(level, fmt, arg...) \
39fcaf780bSMauro Carvalho Chehab 	edac_printk(level, "i7300", fmt, ##arg)
40fcaf780bSMauro Carvalho Chehab 
41fcaf780bSMauro Carvalho Chehab #define i7300_mc_printk(mci, level, fmt, arg...) \
42fcaf780bSMauro Carvalho Chehab 	edac_mc_chipset_printk(mci, level, "i7300", fmt, ##arg)
43fcaf780bSMauro Carvalho Chehab 
44fcaf780bSMauro Carvalho Chehab /*
45fcaf780bSMauro Carvalho Chehab  * Memory topology is organized as:
46fcaf780bSMauro Carvalho Chehab  *	Branch 0 - 2 channels: channels 0 and 1 (FDB0 PCI dev 21.0)
47fcaf780bSMauro Carvalho Chehab  *	Branch 1 - 2 channels: channels 2 and 3 (FDB1 PCI dev 22.0)
48fcaf780bSMauro Carvalho Chehab  * Each channel can have to 8 DIMM sets (called as SLOTS)
49fcaf780bSMauro Carvalho Chehab  * Slots should generally be filled in pairs
50fcaf780bSMauro Carvalho Chehab  *	Except on Single Channel mode of operation
51fcaf780bSMauro Carvalho Chehab  *		just slot 0/channel0 filled on this mode
52fcaf780bSMauro Carvalho Chehab  *	On normal operation mode, the two channels on a branch should be
53c3af2eafSMauro Carvalho Chehab  *		filled together for the same SLOT#
54fcaf780bSMauro Carvalho Chehab  * When in mirrored mode, Branch 1 replicate memory at Branch 0, so, the four
55fcaf780bSMauro Carvalho Chehab  *		channels on both branches should be filled
56fcaf780bSMauro Carvalho Chehab  */
57fcaf780bSMauro Carvalho Chehab 
58fcaf780bSMauro Carvalho Chehab /* Limits for i7300 */
59fcaf780bSMauro Carvalho Chehab #define MAX_SLOTS		8
60fcaf780bSMauro Carvalho Chehab #define MAX_BRANCHES		2
61fcaf780bSMauro Carvalho Chehab #define MAX_CH_PER_BRANCH	2
62fcaf780bSMauro Carvalho Chehab #define MAX_CHANNELS		(MAX_CH_PER_BRANCH * MAX_BRANCHES)
63fcaf780bSMauro Carvalho Chehab #define MAX_MIR			3
64fcaf780bSMauro Carvalho Chehab 
65fcaf780bSMauro Carvalho Chehab #define to_channel(ch, branch)	((((branch)) << 1) | (ch))
66fcaf780bSMauro Carvalho Chehab 
67fcaf780bSMauro Carvalho Chehab #define to_csrow(slot, ch, branch)					\
68fcaf780bSMauro Carvalho Chehab 		(to_channel(ch, branch) | ((slot) << 2))
69fcaf780bSMauro Carvalho Chehab 
70c3af2eafSMauro Carvalho Chehab /*
71c3af2eafSMauro Carvalho Chehab  * I7300 devices
72fcaf780bSMauro Carvalho Chehab  * All 3 functions of Device 16 (0,1,2) share the SAME DID and
73fcaf780bSMauro Carvalho Chehab  * uses PCI_DEVICE_ID_INTEL_I7300_MCH_ERR for device 16 (0,1,2),
74fcaf780bSMauro Carvalho Chehab  * PCI_DEVICE_ID_INTEL_I7300_MCH_FB0 and PCI_DEVICE_ID_INTEL_I7300_MCH_FB1
75fcaf780bSMauro Carvalho Chehab  * for device 21 (0,1).
76fcaf780bSMauro Carvalho Chehab  */
77fcaf780bSMauro Carvalho Chehab 
78c3af2eafSMauro Carvalho Chehab /****************************************************
79c3af2eafSMauro Carvalho Chehab  * i7300 Register definitions for memory enumberation
80c3af2eafSMauro Carvalho Chehab  ****************************************************/
81c3af2eafSMauro Carvalho Chehab 
82c3af2eafSMauro Carvalho Chehab /*
83c3af2eafSMauro Carvalho Chehab  * Device 16,
84c3af2eafSMauro Carvalho Chehab  * Function 0: System Address (not documented)
85c3af2eafSMauro Carvalho Chehab  * Function 1: Memory Branch Map, Control, Errors Register
86c3af2eafSMauro Carvalho Chehab  */
87c3af2eafSMauro Carvalho Chehab 
88fcaf780bSMauro Carvalho Chehab 	/* OFFSETS for Function 0 */
89fcaf780bSMauro Carvalho Chehab #define AMBASE			0x48 /* AMB Mem Mapped Reg Region Base */
90fcaf780bSMauro Carvalho Chehab #define MAXCH			0x56 /* Max Channel Number */
91fcaf780bSMauro Carvalho Chehab #define MAXDIMMPERCH		0x57 /* Max DIMM PER Channel Number */
92fcaf780bSMauro Carvalho Chehab 
93fcaf780bSMauro Carvalho Chehab 	/* OFFSETS for Function 1 */
94af3d8831SMauro Carvalho Chehab #define MC_SETTINGS		0x40
95af3d8831SMauro Carvalho Chehab 
96fcaf780bSMauro Carvalho Chehab #define TOLM			0x6C
97fcaf780bSMauro Carvalho Chehab #define REDMEMB			0x7C
98fcaf780bSMauro Carvalho Chehab 
99fcaf780bSMauro Carvalho Chehab #define MIR0			0x80
100fcaf780bSMauro Carvalho Chehab #define MIR1			0x84
101fcaf780bSMauro Carvalho Chehab #define MIR2			0x88
102fcaf780bSMauro Carvalho Chehab 
103fcaf780bSMauro Carvalho Chehab /*
104fcaf780bSMauro Carvalho Chehab  * Note: Other Intel EDAC drivers use AMBPRESENT to identify if the available
105fcaf780bSMauro Carvalho Chehab  * memory. From datasheet item 7.3.1 (FB-DIMM technology & organization), it
106fcaf780bSMauro Carvalho Chehab  * seems that we cannot use this information directly for the same usage.
107fcaf780bSMauro Carvalho Chehab  * Each memory slot may have up to 2 AMB interfaces, one for income and another
108fcaf780bSMauro Carvalho Chehab  * for outcome interface to the next slot.
109fcaf780bSMauro Carvalho Chehab  * For now, the driver just stores the AMB present registers, but rely only at
110fcaf780bSMauro Carvalho Chehab  * the MTR info to detect memory.
111fcaf780bSMauro Carvalho Chehab  * Datasheet is also not clear about how to map each AMBPRESENT registers to
112fcaf780bSMauro Carvalho Chehab  * one of the 4 available channels.
113fcaf780bSMauro Carvalho Chehab  */
114fcaf780bSMauro Carvalho Chehab #define AMBPRESENT_0	0x64
115fcaf780bSMauro Carvalho Chehab #define AMBPRESENT_1	0x66
116fcaf780bSMauro Carvalho Chehab 
117fcaf780bSMauro Carvalho Chehab const static u16 mtr_regs [MAX_SLOTS] = {
118fcaf780bSMauro Carvalho Chehab 	0x80, 0x84, 0x88, 0x8c,
119fcaf780bSMauro Carvalho Chehab 	0x82, 0x86, 0x8a, 0x8e
120fcaf780bSMauro Carvalho Chehab };
121fcaf780bSMauro Carvalho Chehab 
122fcaf780bSMauro Carvalho Chehab /* Defines to extract the vaious fields from the
123fcaf780bSMauro Carvalho Chehab  *	MTRx - Memory Technology Registers
124fcaf780bSMauro Carvalho Chehab  */
125fcaf780bSMauro Carvalho Chehab #define MTR_DIMMS_PRESENT(mtr)		((mtr) & (1 << 8))
126fcaf780bSMauro Carvalho Chehab #define MTR_DIMMS_ETHROTTLE(mtr)	((mtr) & (1 << 7))
127fcaf780bSMauro Carvalho Chehab #define MTR_DRAM_WIDTH(mtr)		(((mtr) & (1 << 6)) ? 8 : 4)
128fcaf780bSMauro Carvalho Chehab #define MTR_DRAM_BANKS(mtr)		(((mtr) & (1 << 5)) ? 8 : 4)
129fcaf780bSMauro Carvalho Chehab #define MTR_DIMM_RANKS(mtr)		(((mtr) & (1 << 4)) ? 1 : 0)
130fcaf780bSMauro Carvalho Chehab #define MTR_DIMM_ROWS(mtr)		(((mtr) >> 2) & 0x3)
131fcaf780bSMauro Carvalho Chehab #define MTR_DRAM_BANKS_ADDR_BITS	2
132fcaf780bSMauro Carvalho Chehab #define MTR_DIMM_ROWS_ADDR_BITS(mtr)	(MTR_DIMM_ROWS(mtr) + 13)
133fcaf780bSMauro Carvalho Chehab #define MTR_DIMM_COLS(mtr)		((mtr) & 0x3)
134fcaf780bSMauro Carvalho Chehab #define MTR_DIMM_COLS_ADDR_BITS(mtr)	(MTR_DIMM_COLS(mtr) + 10)
135fcaf780bSMauro Carvalho Chehab 
136fcaf780bSMauro Carvalho Chehab #ifdef CONFIG_EDAC_DEBUG
137fcaf780bSMauro Carvalho Chehab /* MTR NUMROW */
138fcaf780bSMauro Carvalho Chehab static const char *numrow_toString[] = {
139fcaf780bSMauro Carvalho Chehab 	"8,192 - 13 rows",
140fcaf780bSMauro Carvalho Chehab 	"16,384 - 14 rows",
141fcaf780bSMauro Carvalho Chehab 	"32,768 - 15 rows",
142fcaf780bSMauro Carvalho Chehab 	"65,536 - 16 rows"
143fcaf780bSMauro Carvalho Chehab };
144fcaf780bSMauro Carvalho Chehab 
145fcaf780bSMauro Carvalho Chehab /* MTR NUMCOL */
146fcaf780bSMauro Carvalho Chehab static const char *numcol_toString[] = {
147fcaf780bSMauro Carvalho Chehab 	"1,024 - 10 columns",
148fcaf780bSMauro Carvalho Chehab 	"2,048 - 11 columns",
149fcaf780bSMauro Carvalho Chehab 	"4,096 - 12 columns",
150fcaf780bSMauro Carvalho Chehab 	"reserved"
151fcaf780bSMauro Carvalho Chehab };
152fcaf780bSMauro Carvalho Chehab #endif
153fcaf780bSMauro Carvalho Chehab 
154c3af2eafSMauro Carvalho Chehab /************************************************
155c3af2eafSMauro Carvalho Chehab  * i7300 Register definitions for error detection
156c3af2eafSMauro Carvalho Chehab  ************************************************/
157c3af2eafSMauro Carvalho Chehab /*
158c3af2eafSMauro Carvalho Chehab  * Device 16.2: Global Error Registers
159c3af2eafSMauro Carvalho Chehab  */
160c3af2eafSMauro Carvalho Chehab 
161*5de6e07eSMauro Carvalho Chehab #define FERR_GLOBAL_HI	0x48
162*5de6e07eSMauro Carvalho Chehab static const char *ferr_global_hi_name[] = {
163*5de6e07eSMauro Carvalho Chehab 	[3] = "FSB 3 Fatal Error",
164*5de6e07eSMauro Carvalho Chehab 	[2] = "FSB 2 Fatal Error",
165*5de6e07eSMauro Carvalho Chehab 	[1] = "FSB 1 Fatal Error",
166*5de6e07eSMauro Carvalho Chehab 	[0] = "FSB 0 Fatal Error",
167*5de6e07eSMauro Carvalho Chehab };
168*5de6e07eSMauro Carvalho Chehab #define ferr_global_hi_is_fatal(errno)	1
169*5de6e07eSMauro Carvalho Chehab 
170c3af2eafSMauro Carvalho Chehab #define FERR_GLOBAL_LO	0x40
171*5de6e07eSMauro Carvalho Chehab static const char *ferr_global_lo_name[] = {
172c3af2eafSMauro Carvalho Chehab 	[31] = "Internal MCH Fatal Error",
173c3af2eafSMauro Carvalho Chehab 	[30] = "Intel QuickData Technology Device Fatal Error",
174c3af2eafSMauro Carvalho Chehab 	[29] = "FSB1 Fatal Error",
175c3af2eafSMauro Carvalho Chehab 	[28] = "FSB0 Fatal Error",
176c3af2eafSMauro Carvalho Chehab 	[27] = "FBD Channel 3 Fatal Error",
177c3af2eafSMauro Carvalho Chehab 	[26] = "FBD Channel 2 Fatal Error",
178c3af2eafSMauro Carvalho Chehab 	[25] = "FBD Channel 1 Fatal Error",
179c3af2eafSMauro Carvalho Chehab 	[24] = "FBD Channel 0 Fatal Error",
180c3af2eafSMauro Carvalho Chehab 	[23] = "PCI Express Device 7Fatal Error",
181c3af2eafSMauro Carvalho Chehab 	[22] = "PCI Express Device 6 Fatal Error",
182c3af2eafSMauro Carvalho Chehab 	[21] = "PCI Express Device 5 Fatal Error",
183c3af2eafSMauro Carvalho Chehab 	[20] = "PCI Express Device 4 Fatal Error",
184c3af2eafSMauro Carvalho Chehab 	[19] = "PCI Express Device 3 Fatal Error",
185c3af2eafSMauro Carvalho Chehab 	[18] = "PCI Express Device 2 Fatal Error",
186c3af2eafSMauro Carvalho Chehab 	[17] = "PCI Express Device 1 Fatal Error",
187c3af2eafSMauro Carvalho Chehab 	[16] = "ESI Fatal Error",
188c3af2eafSMauro Carvalho Chehab 	[15] = "Internal MCH Non-Fatal Error",
189c3af2eafSMauro Carvalho Chehab 	[14] = "Intel QuickData Technology Device Non Fatal Error",
190c3af2eafSMauro Carvalho Chehab 	[13] = "FSB1 Non-Fatal Error",
191c3af2eafSMauro Carvalho Chehab 	[12] = "FSB 0 Non-Fatal Error",
192c3af2eafSMauro Carvalho Chehab 	[11] = "FBD Channel 3 Non-Fatal Error",
193c3af2eafSMauro Carvalho Chehab 	[10] = "FBD Channel 2 Non-Fatal Error",
194c3af2eafSMauro Carvalho Chehab 	[9]  = "FBD Channel 1 Non-Fatal Error",
195c3af2eafSMauro Carvalho Chehab 	[8]  = "FBD Channel 0 Non-Fatal Error",
196c3af2eafSMauro Carvalho Chehab 	[7]  = "PCI Express Device 7 Non-Fatal Error",
197c3af2eafSMauro Carvalho Chehab 	[6]  = "PCI Express Device 6 Non-Fatal Error",
198c3af2eafSMauro Carvalho Chehab 	[5]  = "PCI Express Device 5 Non-Fatal Error",
199c3af2eafSMauro Carvalho Chehab 	[4]  = "PCI Express Device 4 Non-Fatal Error",
200c3af2eafSMauro Carvalho Chehab 	[3]  = "PCI Express Device 3 Non-Fatal Error",
201c3af2eafSMauro Carvalho Chehab 	[2]  = "PCI Express Device 2 Non-Fatal Error",
202c3af2eafSMauro Carvalho Chehab 	[1]  = "PCI Express Device 1 Non-Fatal Error",
203c3af2eafSMauro Carvalho Chehab 	[0]  = "ESI Non-Fatal Error",
204c3af2eafSMauro Carvalho Chehab };
205*5de6e07eSMauro Carvalho Chehab #define ferr_global_lo_is_fatal(errno)	((errno < 16) ? 0 : 1)
206fcaf780bSMauro Carvalho Chehab 
207fcaf780bSMauro Carvalho Chehab /* Device name and register DID (Device ID) */
208fcaf780bSMauro Carvalho Chehab struct i7300_dev_info {
209fcaf780bSMauro Carvalho Chehab 	const char *ctl_name;	/* name for this device */
210fcaf780bSMauro Carvalho Chehab 	u16 fsb_mapping_errors;	/* DID for the branchmap,control */
211fcaf780bSMauro Carvalho Chehab };
212fcaf780bSMauro Carvalho Chehab 
213fcaf780bSMauro Carvalho Chehab /* Table of devices attributes supported by this driver */
214fcaf780bSMauro Carvalho Chehab static const struct i7300_dev_info i7300_devs[] = {
215fcaf780bSMauro Carvalho Chehab 	{
216fcaf780bSMauro Carvalho Chehab 		.ctl_name = "I7300",
217fcaf780bSMauro Carvalho Chehab 		.fsb_mapping_errors = PCI_DEVICE_ID_INTEL_I7300_MCH_ERR,
218fcaf780bSMauro Carvalho Chehab 	},
219fcaf780bSMauro Carvalho Chehab };
220fcaf780bSMauro Carvalho Chehab 
221fcaf780bSMauro Carvalho Chehab struct i7300_dimm_info {
222fcaf780bSMauro Carvalho Chehab 	int megabytes;		/* size, 0 means not present  */
223fcaf780bSMauro Carvalho Chehab };
224fcaf780bSMauro Carvalho Chehab 
225fcaf780bSMauro Carvalho Chehab /* driver private data structure */
226fcaf780bSMauro Carvalho Chehab struct i7300_pvt {
2273e57eef6SMauro Carvalho Chehab 	struct pci_dev *pci_dev_16_0_fsb_ctlr;		/* 16.0 */
2283e57eef6SMauro Carvalho Chehab 	struct pci_dev *pci_dev_16_1_fsb_addr_map;	/* 16.1 */
2293e57eef6SMauro Carvalho Chehab 	struct pci_dev *pci_dev_16_2_fsb_err_regs;	/* 16.2 */
2303e57eef6SMauro Carvalho Chehab 	struct pci_dev *pci_dev_2x_0_fbd_branch[MAX_BRANCHES];	/* 21.0  and 22.0 */
231fcaf780bSMauro Carvalho Chehab 
232fcaf780bSMauro Carvalho Chehab 	u16 tolm;				/* top of low memory */
233fcaf780bSMauro Carvalho Chehab 	u64 ambase;				/* AMB BAR */
234af3d8831SMauro Carvalho Chehab 	u32 mc_settings;
235fcaf780bSMauro Carvalho Chehab 
236fcaf780bSMauro Carvalho Chehab 	u16 mir[MAX_MIR];
237fcaf780bSMauro Carvalho Chehab 
238fcaf780bSMauro Carvalho Chehab 	u16 mtr[MAX_SLOTS][MAX_BRANCHES];		/* Memory Technlogy Reg */
239fcaf780bSMauro Carvalho Chehab 	u16 ambpresent[MAX_CHANNELS];		/* AMB present regs */
240fcaf780bSMauro Carvalho Chehab 
241fcaf780bSMauro Carvalho Chehab 	/* DIMM information matrix, allocating architecture maximums */
242fcaf780bSMauro Carvalho Chehab 	struct i7300_dimm_info dimm_info[MAX_SLOTS][MAX_CHANNELS];
243fcaf780bSMauro Carvalho Chehab };
244fcaf780bSMauro Carvalho Chehab 
245fcaf780bSMauro Carvalho Chehab /* FIXME: Why do we need to have this static? */
246fcaf780bSMauro Carvalho Chehab static struct edac_pci_ctl_info *i7300_pci;
247fcaf780bSMauro Carvalho Chehab 
248*5de6e07eSMauro Carvalho Chehab /********************************************
249*5de6e07eSMauro Carvalho Chehab  * i7300 Functions related to error detection
250*5de6e07eSMauro Carvalho Chehab  ********************************************/
251fcaf780bSMauro Carvalho Chehab 
252*5de6e07eSMauro Carvalho Chehab struct i7300_error_info {
253*5de6e07eSMauro Carvalho Chehab 	int dummy;	/* FIXME */
254*5de6e07eSMauro Carvalho Chehab };
255*5de6e07eSMauro Carvalho Chehab 
256*5de6e07eSMauro Carvalho Chehab const char *get_err_from_table(const char *table[], int size, int pos)
257fcaf780bSMauro Carvalho Chehab {
258*5de6e07eSMauro Carvalho Chehab 	if (pos >= size)
259*5de6e07eSMauro Carvalho Chehab 		return "Reserved";
260*5de6e07eSMauro Carvalho Chehab 
261*5de6e07eSMauro Carvalho Chehab 	return table[pos];
262fcaf780bSMauro Carvalho Chehab }
263*5de6e07eSMauro Carvalho Chehab 
264*5de6e07eSMauro Carvalho Chehab #define GET_ERR_FROM_TABLE(table, pos)				\
265*5de6e07eSMauro Carvalho Chehab 	get_err_from_table(table, ARRAY_SIZE(table), pos)
266fcaf780bSMauro Carvalho Chehab 
267fcaf780bSMauro Carvalho Chehab /*
268fcaf780bSMauro Carvalho Chehab  *	i7300_get_error_info	Retrieve the hardware error information from
269fcaf780bSMauro Carvalho Chehab  *				the hardware and cache it in the 'info'
270fcaf780bSMauro Carvalho Chehab  *				structure
271fcaf780bSMauro Carvalho Chehab  */
272fcaf780bSMauro Carvalho Chehab static void i7300_get_error_info(struct mem_ctl_info *mci,
273fcaf780bSMauro Carvalho Chehab 				 struct i7300_error_info *info)
274fcaf780bSMauro Carvalho Chehab {
275*5de6e07eSMauro Carvalho Chehab }
276*5de6e07eSMauro Carvalho Chehab 
277*5de6e07eSMauro Carvalho Chehab /*
278*5de6e07eSMauro Carvalho Chehab  *	i7300_process_error_global Retrieve the hardware error information from
279*5de6e07eSMauro Carvalho Chehab  *				the hardware and cache it in the 'info'
280*5de6e07eSMauro Carvalho Chehab  *				structure
281*5de6e07eSMauro Carvalho Chehab  */
282*5de6e07eSMauro Carvalho Chehab static void i7300_process_error_global(struct mem_ctl_info *mci,
283*5de6e07eSMauro Carvalho Chehab 				 struct i7300_error_info *info)
284*5de6e07eSMauro Carvalho Chehab {
285fcaf780bSMauro Carvalho Chehab 	struct i7300_pvt *pvt;
286*5de6e07eSMauro Carvalho Chehab 	u32 errnum, value;
287*5de6e07eSMauro Carvalho Chehab 	unsigned long errors;
288*5de6e07eSMauro Carvalho Chehab 	const char *specific;
289*5de6e07eSMauro Carvalho Chehab 	bool is_fatal;
290fcaf780bSMauro Carvalho Chehab 
291fcaf780bSMauro Carvalho Chehab 	pvt = mci->pvt_info;
292fcaf780bSMauro Carvalho Chehab 
293fcaf780bSMauro Carvalho Chehab 	/* read in the 1st FATAL error register */
294*5de6e07eSMauro Carvalho Chehab 	pci_read_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
295*5de6e07eSMauro Carvalho Chehab 			      FERR_GLOBAL_HI, &value);
296*5de6e07eSMauro Carvalho Chehab 	if (unlikely(value)) {
297*5de6e07eSMauro Carvalho Chehab 		errors = value;
298*5de6e07eSMauro Carvalho Chehab 		errnum = find_first_bit(&errors,
299*5de6e07eSMauro Carvalho Chehab 					ARRAY_SIZE(ferr_global_hi_name));
300*5de6e07eSMauro Carvalho Chehab 		specific = GET_ERR_FROM_TABLE(ferr_global_hi_name, errnum);
301*5de6e07eSMauro Carvalho Chehab 		is_fatal = ferr_global_hi_is_fatal(errnum);
302*5de6e07eSMauro Carvalho Chehab 		goto error_global;
303fcaf780bSMauro Carvalho Chehab 	}
304fcaf780bSMauro Carvalho Chehab 
305*5de6e07eSMauro Carvalho Chehab 	pci_read_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
306*5de6e07eSMauro Carvalho Chehab 			      FERR_GLOBAL_LO, &value);
307*5de6e07eSMauro Carvalho Chehab 	if (unlikely(value)) {
308*5de6e07eSMauro Carvalho Chehab 		errors = value;
309*5de6e07eSMauro Carvalho Chehab 		errnum = find_first_bit(&errors,
310*5de6e07eSMauro Carvalho Chehab 					ARRAY_SIZE(ferr_global_lo_name));
311*5de6e07eSMauro Carvalho Chehab 		specific = GET_ERR_FROM_TABLE(ferr_global_lo_name, errnum);
312*5de6e07eSMauro Carvalho Chehab 		is_fatal = ferr_global_lo_is_fatal(errnum);
313*5de6e07eSMauro Carvalho Chehab 		goto error_global;
314fcaf780bSMauro Carvalho Chehab 	}
315fcaf780bSMauro Carvalho Chehab 	return;
316fcaf780bSMauro Carvalho Chehab 
317*5de6e07eSMauro Carvalho Chehab error_global:
318*5de6e07eSMauro Carvalho Chehab 	i7300_mc_printk(mci, KERN_EMERG, "%s misc error: %s\n",
319*5de6e07eSMauro Carvalho Chehab 			is_fatal ? "Fatal" : "NOT fatal", specific);
320fcaf780bSMauro Carvalho Chehab }
321fcaf780bSMauro Carvalho Chehab 
322fcaf780bSMauro Carvalho Chehab /*
323*5de6e07eSMauro Carvalho Chehab  *	i7300_process_error_info Retrieve the hardware error information from
324*5de6e07eSMauro Carvalho Chehab  *				the hardware and cache it in the 'info'
325*5de6e07eSMauro Carvalho Chehab  *				structure
326fcaf780bSMauro Carvalho Chehab  */
327fcaf780bSMauro Carvalho Chehab static void i7300_process_error_info(struct mem_ctl_info *mci,
328fcaf780bSMauro Carvalho Chehab 				 struct i7300_error_info *info)
329*5de6e07eSMauro Carvalho Chehab {
330*5de6e07eSMauro Carvalho Chehab 	i7300_process_error_global(mci, info);
331*5de6e07eSMauro Carvalho Chehab };
332fcaf780bSMauro Carvalho Chehab 
333fcaf780bSMauro Carvalho Chehab /*
334fcaf780bSMauro Carvalho Chehab  *	i7300_clear_error	Retrieve any error from the hardware
335fcaf780bSMauro Carvalho Chehab  *				but do NOT process that error.
336fcaf780bSMauro Carvalho Chehab  *				Used for 'clearing' out of previous errors
337fcaf780bSMauro Carvalho Chehab  *				Called by the Core module.
338fcaf780bSMauro Carvalho Chehab  */
339fcaf780bSMauro Carvalho Chehab static void i7300_clear_error(struct mem_ctl_info *mci)
340fcaf780bSMauro Carvalho Chehab {
341fcaf780bSMauro Carvalho Chehab 	struct i7300_error_info info;
342fcaf780bSMauro Carvalho Chehab 
343fcaf780bSMauro Carvalho Chehab 	i7300_get_error_info(mci, &info);
344fcaf780bSMauro Carvalho Chehab }
345fcaf780bSMauro Carvalho Chehab 
346fcaf780bSMauro Carvalho Chehab /*
347fcaf780bSMauro Carvalho Chehab  *	i7300_check_error	Retrieve and process errors reported by the
348fcaf780bSMauro Carvalho Chehab  *				hardware. Called by the Core module.
349fcaf780bSMauro Carvalho Chehab  */
350fcaf780bSMauro Carvalho Chehab static void i7300_check_error(struct mem_ctl_info *mci)
351fcaf780bSMauro Carvalho Chehab {
352fcaf780bSMauro Carvalho Chehab 	struct i7300_error_info info;
353fcaf780bSMauro Carvalho Chehab 	debugf4("MC%d: " __FILE__ ": %s()\n", mci->mc_idx, __func__);
354*5de6e07eSMauro Carvalho Chehab 
355fcaf780bSMauro Carvalho Chehab 	i7300_get_error_info(mci, &info);
356fcaf780bSMauro Carvalho Chehab 	i7300_process_error_info(mci, &info);
357fcaf780bSMauro Carvalho Chehab }
358fcaf780bSMauro Carvalho Chehab 
359fcaf780bSMauro Carvalho Chehab /*
360fcaf780bSMauro Carvalho Chehab  *	i7300_enable_error_reporting
361fcaf780bSMauro Carvalho Chehab  *			Turn on the memory reporting features of the hardware
362fcaf780bSMauro Carvalho Chehab  */
363fcaf780bSMauro Carvalho Chehab static void i7300_enable_error_reporting(struct mem_ctl_info *mci)
364fcaf780bSMauro Carvalho Chehab {
365fcaf780bSMauro Carvalho Chehab }
366*5de6e07eSMauro Carvalho Chehab 
367*5de6e07eSMauro Carvalho Chehab /************************************************
368*5de6e07eSMauro Carvalho Chehab  * i7300 Functions related to memory enumberation
369*5de6e07eSMauro Carvalho Chehab  ************************************************/
370fcaf780bSMauro Carvalho Chehab 
371fcaf780bSMauro Carvalho Chehab /*
372fcaf780bSMauro Carvalho Chehab  * determine_mtr(pvt, csrow, channel)
373fcaf780bSMauro Carvalho Chehab  *
374fcaf780bSMauro Carvalho Chehab  * return the proper MTR register as determine by the csrow and desired channel
375fcaf780bSMauro Carvalho Chehab  */
376fcaf780bSMauro Carvalho Chehab static int decode_mtr(struct i7300_pvt *pvt,
377fcaf780bSMauro Carvalho Chehab 		      int slot, int ch, int branch,
378fcaf780bSMauro Carvalho Chehab 		      struct i7300_dimm_info *dinfo,
379fcaf780bSMauro Carvalho Chehab 		      struct csrow_info *p_csrow)
380fcaf780bSMauro Carvalho Chehab {
381fcaf780bSMauro Carvalho Chehab 	int mtr, ans, addrBits, channel;
382fcaf780bSMauro Carvalho Chehab 
383fcaf780bSMauro Carvalho Chehab 	channel = to_channel(ch, branch);
384fcaf780bSMauro Carvalho Chehab 
385fcaf780bSMauro Carvalho Chehab 	mtr = pvt->mtr[slot][branch];
386fcaf780bSMauro Carvalho Chehab 	ans = MTR_DIMMS_PRESENT(mtr) ? 1 : 0;
387fcaf780bSMauro Carvalho Chehab 
388fcaf780bSMauro Carvalho Chehab 	debugf2("\tMTR%d CH%d: DIMMs are %s (mtr)\n",
389fcaf780bSMauro Carvalho Chehab 		slot, channel,
390fcaf780bSMauro Carvalho Chehab 		ans ? "Present" : "NOT Present");
391fcaf780bSMauro Carvalho Chehab 
392fcaf780bSMauro Carvalho Chehab 	/* Determine if there is a DIMM present in this DIMM slot */
393fcaf780bSMauro Carvalho Chehab 
394fcaf780bSMauro Carvalho Chehab #if 0
395fcaf780bSMauro Carvalho Chehab 	if (!amb_present || !ans)
396fcaf780bSMauro Carvalho Chehab 		return 0;
397fcaf780bSMauro Carvalho Chehab #else
398fcaf780bSMauro Carvalho Chehab 	if (!ans)
399fcaf780bSMauro Carvalho Chehab 		return 0;
400fcaf780bSMauro Carvalho Chehab #endif
401fcaf780bSMauro Carvalho Chehab 
402fcaf780bSMauro Carvalho Chehab 	/* Start with the number of bits for a Bank
403fcaf780bSMauro Carvalho Chehab 	* on the DRAM */
404fcaf780bSMauro Carvalho Chehab 	addrBits = MTR_DRAM_BANKS_ADDR_BITS;
405fcaf780bSMauro Carvalho Chehab 	/* Add thenumber of ROW bits */
406fcaf780bSMauro Carvalho Chehab 	addrBits += MTR_DIMM_ROWS_ADDR_BITS(mtr);
407fcaf780bSMauro Carvalho Chehab 	/* add the number of COLUMN bits */
408fcaf780bSMauro Carvalho Chehab 	addrBits += MTR_DIMM_COLS_ADDR_BITS(mtr);
409fcaf780bSMauro Carvalho Chehab 	/* add the number of RANK bits */
410fcaf780bSMauro Carvalho Chehab 	addrBits += MTR_DIMM_RANKS(mtr);
411fcaf780bSMauro Carvalho Chehab 
412fcaf780bSMauro Carvalho Chehab 	addrBits += 6;	/* add 64 bits per DIMM */
413fcaf780bSMauro Carvalho Chehab 	addrBits -= 20;	/* divide by 2^^20 */
414fcaf780bSMauro Carvalho Chehab 	addrBits -= 3;	/* 8 bits per bytes */
415fcaf780bSMauro Carvalho Chehab 
416fcaf780bSMauro Carvalho Chehab 	dinfo->megabytes = 1 << addrBits;
417fcaf780bSMauro Carvalho Chehab 
418fcaf780bSMauro Carvalho Chehab 	debugf2("\t\tWIDTH: x%d\n", MTR_DRAM_WIDTH(mtr));
419fcaf780bSMauro Carvalho Chehab 
420fcaf780bSMauro Carvalho Chehab 	debugf2("\t\tELECTRICAL THROTTLING is %s\n",
421fcaf780bSMauro Carvalho Chehab 		MTR_DIMMS_ETHROTTLE(mtr) ? "enabled" : "disabled");
422fcaf780bSMauro Carvalho Chehab 
423fcaf780bSMauro Carvalho Chehab 	debugf2("\t\tNUMBANK: %d bank(s)\n", MTR_DRAM_BANKS(mtr));
424fcaf780bSMauro Carvalho Chehab 	debugf2("\t\tNUMRANK: %s\n", MTR_DIMM_RANKS(mtr) ? "double" : "single");
425fcaf780bSMauro Carvalho Chehab 	debugf2("\t\tNUMROW: %s\n", numrow_toString[MTR_DIMM_ROWS(mtr)]);
426fcaf780bSMauro Carvalho Chehab 	debugf2("\t\tNUMCOL: %s\n", numcol_toString[MTR_DIMM_COLS(mtr)]);
427fcaf780bSMauro Carvalho Chehab 	debugf2("\t\tSIZE: %d MB\n", dinfo->megabytes);
428fcaf780bSMauro Carvalho Chehab 
429fcaf780bSMauro Carvalho Chehab 	p_csrow->grain = 8;
430fcaf780bSMauro Carvalho Chehab 	p_csrow->nr_pages = dinfo->megabytes << 8;
431fcaf780bSMauro Carvalho Chehab 	p_csrow->mtype = MEM_FB_DDR2;
432116389edSMauro Carvalho Chehab 
433116389edSMauro Carvalho Chehab 	/*
434116389edSMauro Carvalho Chehab 	 * FIXME: the type of error detection actually depends of the
435116389edSMauro Carvalho Chehab 	 * mode of operation. When it is just one single memory chip, at
436116389edSMauro Carvalho Chehab 	 * socket 0, channel 0, it uses  8-byte-over-32-byte SECDED+ code.
437116389edSMauro Carvalho Chehab 	 * In normal or mirrored mode, it uses Single Device Data correction,
438116389edSMauro Carvalho Chehab 	 * with the possibility of using an extended algorithm for x8 memories
439116389edSMauro Carvalho Chehab 	 * See datasheet Sections 7.3.6 to 7.3.8
440116389edSMauro Carvalho Chehab 	 */
441fcaf780bSMauro Carvalho Chehab 	p_csrow->edac_mode = EDAC_S8ECD8ED;
442fcaf780bSMauro Carvalho Chehab 
443fcaf780bSMauro Carvalho Chehab 	/* ask what device type on this row */
444fcaf780bSMauro Carvalho Chehab 	if (MTR_DRAM_WIDTH(mtr))
445fcaf780bSMauro Carvalho Chehab 		p_csrow->dtype = DEV_X8;
446fcaf780bSMauro Carvalho Chehab 	else
447fcaf780bSMauro Carvalho Chehab 		p_csrow->dtype = DEV_X4;
448fcaf780bSMauro Carvalho Chehab 
449fcaf780bSMauro Carvalho Chehab 	return mtr;
450fcaf780bSMauro Carvalho Chehab }
451fcaf780bSMauro Carvalho Chehab 
452fcaf780bSMauro Carvalho Chehab /*
453fcaf780bSMauro Carvalho Chehab  *	print_dimm_size
454fcaf780bSMauro Carvalho Chehab  *
455fcaf780bSMauro Carvalho Chehab  *	also will output a DIMM matrix map, if debug is enabled, for viewing
456fcaf780bSMauro Carvalho Chehab  *	how the DIMMs are populated
457fcaf780bSMauro Carvalho Chehab  */
458fcaf780bSMauro Carvalho Chehab static void print_dimm_size(struct i7300_pvt *pvt)
459fcaf780bSMauro Carvalho Chehab {
460fcaf780bSMauro Carvalho Chehab 	struct i7300_dimm_info *dinfo;
461fcaf780bSMauro Carvalho Chehab 	char *p, *mem_buffer;
462fcaf780bSMauro Carvalho Chehab 	int space, n;
463fcaf780bSMauro Carvalho Chehab 	int channel, slot;
464fcaf780bSMauro Carvalho Chehab 
465fcaf780bSMauro Carvalho Chehab 	space = PAGE_SIZE;
466fcaf780bSMauro Carvalho Chehab 	mem_buffer = p = kmalloc(space, GFP_KERNEL);
467fcaf780bSMauro Carvalho Chehab 	if (p == NULL) {
468fcaf780bSMauro Carvalho Chehab 		i7300_printk(KERN_ERR, "MC: %s:%s() kmalloc() failed\n",
469fcaf780bSMauro Carvalho Chehab 			__FILE__, __func__);
470fcaf780bSMauro Carvalho Chehab 		return;
471fcaf780bSMauro Carvalho Chehab 	}
472fcaf780bSMauro Carvalho Chehab 
473fcaf780bSMauro Carvalho Chehab 	n = snprintf(p, space, "              ");
474fcaf780bSMauro Carvalho Chehab 	p += n;
475fcaf780bSMauro Carvalho Chehab 	space -= n;
476fcaf780bSMauro Carvalho Chehab 	for (channel = 0; channel < MAX_CHANNELS; channel++) {
477fcaf780bSMauro Carvalho Chehab 		n = snprintf(p, space, "channel %d | ", channel);
478fcaf780bSMauro Carvalho Chehab 		p += n;
479fcaf780bSMauro Carvalho Chehab 		space -= n;
480fcaf780bSMauro Carvalho Chehab 	}
481fcaf780bSMauro Carvalho Chehab 	debugf2("%s\n", mem_buffer);
482fcaf780bSMauro Carvalho Chehab 	p = mem_buffer;
483fcaf780bSMauro Carvalho Chehab 	space = PAGE_SIZE;
484fcaf780bSMauro Carvalho Chehab 	n = snprintf(p, space, "-------------------------------"
485fcaf780bSMauro Carvalho Chehab 		               "------------------------------");
486fcaf780bSMauro Carvalho Chehab 	p += n;
487fcaf780bSMauro Carvalho Chehab 	space -= n;
488fcaf780bSMauro Carvalho Chehab 	debugf2("%s\n", mem_buffer);
489fcaf780bSMauro Carvalho Chehab 	p = mem_buffer;
490fcaf780bSMauro Carvalho Chehab 	space = PAGE_SIZE;
491fcaf780bSMauro Carvalho Chehab 
492fcaf780bSMauro Carvalho Chehab 	for (slot = 0; slot < MAX_SLOTS; slot++) {
493fcaf780bSMauro Carvalho Chehab 		n = snprintf(p, space, "csrow/SLOT %d  ", slot);
494fcaf780bSMauro Carvalho Chehab 		p += n;
495fcaf780bSMauro Carvalho Chehab 		space -= n;
496fcaf780bSMauro Carvalho Chehab 
497fcaf780bSMauro Carvalho Chehab 		for (channel = 0; channel < MAX_CHANNELS; channel++) {
498fcaf780bSMauro Carvalho Chehab 			dinfo = &pvt->dimm_info[slot][channel];
499fcaf780bSMauro Carvalho Chehab 			n = snprintf(p, space, "%4d MB   | ", dinfo->megabytes);
500fcaf780bSMauro Carvalho Chehab 			p += n;
501fcaf780bSMauro Carvalho Chehab 			space -= n;
502fcaf780bSMauro Carvalho Chehab 		}
503fcaf780bSMauro Carvalho Chehab 
504fcaf780bSMauro Carvalho Chehab 		debugf2("%s\n", mem_buffer);
505fcaf780bSMauro Carvalho Chehab 		p = mem_buffer;
506fcaf780bSMauro Carvalho Chehab 		space = PAGE_SIZE;
507fcaf780bSMauro Carvalho Chehab 	}
508fcaf780bSMauro Carvalho Chehab 
509fcaf780bSMauro Carvalho Chehab 	n = snprintf(p, space, "-------------------------------"
510fcaf780bSMauro Carvalho Chehab 		               "------------------------------");
511fcaf780bSMauro Carvalho Chehab 	p += n;
512fcaf780bSMauro Carvalho Chehab 	space -= n;
513fcaf780bSMauro Carvalho Chehab 	debugf2("%s\n", mem_buffer);
514fcaf780bSMauro Carvalho Chehab 	p = mem_buffer;
515fcaf780bSMauro Carvalho Chehab 	space = PAGE_SIZE;
516fcaf780bSMauro Carvalho Chehab 
517fcaf780bSMauro Carvalho Chehab 	kfree(mem_buffer);
518fcaf780bSMauro Carvalho Chehab }
519fcaf780bSMauro Carvalho Chehab 
520fcaf780bSMauro Carvalho Chehab /*
521fcaf780bSMauro Carvalho Chehab  *	i7300_init_csrows	Initialize the 'csrows' table within
522fcaf780bSMauro Carvalho Chehab  *				the mci control	structure with the
523fcaf780bSMauro Carvalho Chehab  *				addressing of memory.
524fcaf780bSMauro Carvalho Chehab  *
525fcaf780bSMauro Carvalho Chehab  *	return:
526fcaf780bSMauro Carvalho Chehab  *		0	success
527fcaf780bSMauro Carvalho Chehab  *		1	no actual memory found on this MC
528fcaf780bSMauro Carvalho Chehab  */
529fcaf780bSMauro Carvalho Chehab static int i7300_init_csrows(struct mem_ctl_info *mci)
530fcaf780bSMauro Carvalho Chehab {
531fcaf780bSMauro Carvalho Chehab 	struct i7300_pvt *pvt;
532fcaf780bSMauro Carvalho Chehab 	struct i7300_dimm_info *dinfo;
533fcaf780bSMauro Carvalho Chehab 	struct csrow_info *p_csrow;
534fcaf780bSMauro Carvalho Chehab 	int empty;
535fcaf780bSMauro Carvalho Chehab 	int mtr;
536fcaf780bSMauro Carvalho Chehab 	int ch, branch, slot, channel;
537fcaf780bSMauro Carvalho Chehab 
538fcaf780bSMauro Carvalho Chehab 	pvt = mci->pvt_info;
539fcaf780bSMauro Carvalho Chehab 
540fcaf780bSMauro Carvalho Chehab 	empty = 1;		/* Assume NO memory */
541fcaf780bSMauro Carvalho Chehab 
542fcaf780bSMauro Carvalho Chehab 	debugf2("Memory Technology Registers:\n");
543fcaf780bSMauro Carvalho Chehab 
544fcaf780bSMauro Carvalho Chehab 	/* Get the AMB present registers for the four channels */
545fcaf780bSMauro Carvalho Chehab 	for (branch = 0; branch < MAX_BRANCHES; branch++) {
546fcaf780bSMauro Carvalho Chehab 		/* Read and dump branch 0's MTRs */
547fcaf780bSMauro Carvalho Chehab 		channel = to_channel(0, branch);
5483e57eef6SMauro Carvalho Chehab 		pci_read_config_word(pvt->pci_dev_2x_0_fbd_branch[branch], AMBPRESENT_0,
549fcaf780bSMauro Carvalho Chehab 				&pvt->ambpresent[channel]);
550fcaf780bSMauro Carvalho Chehab 		debugf2("\t\tAMB-present CH%d = 0x%x:\n",
551fcaf780bSMauro Carvalho Chehab 			channel, pvt->ambpresent[channel]);
552fcaf780bSMauro Carvalho Chehab 
553fcaf780bSMauro Carvalho Chehab 		channel = to_channel(1, branch);
5543e57eef6SMauro Carvalho Chehab 		pci_read_config_word(pvt->pci_dev_2x_0_fbd_branch[branch], AMBPRESENT_1,
555fcaf780bSMauro Carvalho Chehab 				&pvt->ambpresent[channel]);
556fcaf780bSMauro Carvalho Chehab 		debugf2("\t\tAMB-present CH%d = 0x%x:\n",
557fcaf780bSMauro Carvalho Chehab 			channel, pvt->ambpresent[channel]);
558fcaf780bSMauro Carvalho Chehab 	}
559fcaf780bSMauro Carvalho Chehab 
560fcaf780bSMauro Carvalho Chehab 	/* Get the set of MTR[0-7] regs by each branch */
561fcaf780bSMauro Carvalho Chehab 	for (slot = 0; slot < MAX_SLOTS; slot++) {
562fcaf780bSMauro Carvalho Chehab 		int where = mtr_regs[slot];
563fcaf780bSMauro Carvalho Chehab 		for (branch = 0; branch < MAX_BRANCHES; branch++) {
5643e57eef6SMauro Carvalho Chehab 			pci_read_config_word(pvt->pci_dev_2x_0_fbd_branch[branch],
565fcaf780bSMauro Carvalho Chehab 					where,
566fcaf780bSMauro Carvalho Chehab 					&pvt->mtr[slot][branch]);
567fcaf780bSMauro Carvalho Chehab 			for (ch = 0; ch < MAX_BRANCHES; ch++) {
568fcaf780bSMauro Carvalho Chehab 				int channel = to_channel(ch, branch);
569fcaf780bSMauro Carvalho Chehab 
570fcaf780bSMauro Carvalho Chehab 				dinfo = &pvt->dimm_info[slot][channel];
571fcaf780bSMauro Carvalho Chehab 				p_csrow = &mci->csrows[slot];
572fcaf780bSMauro Carvalho Chehab 
573fcaf780bSMauro Carvalho Chehab 				mtr = decode_mtr(pvt, slot, ch, branch,
574fcaf780bSMauro Carvalho Chehab 							dinfo, p_csrow);
575fcaf780bSMauro Carvalho Chehab 				/* if no DIMMS on this row, continue */
576fcaf780bSMauro Carvalho Chehab 				if (!MTR_DIMMS_PRESENT(mtr))
577fcaf780bSMauro Carvalho Chehab 					continue;
578fcaf780bSMauro Carvalho Chehab 
579fcaf780bSMauro Carvalho Chehab 				p_csrow->csrow_idx = slot;
580fcaf780bSMauro Carvalho Chehab 
581fcaf780bSMauro Carvalho Chehab 				/* FAKE OUT VALUES, FIXME */
582fcaf780bSMauro Carvalho Chehab 				p_csrow->first_page = 0 + slot * 20;
583fcaf780bSMauro Carvalho Chehab 				p_csrow->last_page = 9 + slot * 20;
584fcaf780bSMauro Carvalho Chehab 				p_csrow->page_mask = 0xfff;
585fcaf780bSMauro Carvalho Chehab 
586fcaf780bSMauro Carvalho Chehab 				empty = 0;
587fcaf780bSMauro Carvalho Chehab 			}
588fcaf780bSMauro Carvalho Chehab 		}
589fcaf780bSMauro Carvalho Chehab 	}
590fcaf780bSMauro Carvalho Chehab 
591fcaf780bSMauro Carvalho Chehab 	return empty;
592fcaf780bSMauro Carvalho Chehab }
593fcaf780bSMauro Carvalho Chehab 
594fcaf780bSMauro Carvalho Chehab static void decode_mir(int mir_no, u16 mir[MAX_MIR])
595fcaf780bSMauro Carvalho Chehab {
596fcaf780bSMauro Carvalho Chehab 	if (mir[mir_no] & 3)
597fcaf780bSMauro Carvalho Chehab 		debugf2("MIR%d: limit= 0x%x Branch(es) that participate: %s %s\n",
598fcaf780bSMauro Carvalho Chehab 			mir_no,
599fcaf780bSMauro Carvalho Chehab 			(mir[mir_no] >> 4) & 0xfff,
600fcaf780bSMauro Carvalho Chehab 			(mir[mir_no] & 1) ? "B0" : "",
601fcaf780bSMauro Carvalho Chehab 			(mir[mir_no] & 2) ? "B1": "");
602fcaf780bSMauro Carvalho Chehab }
603fcaf780bSMauro Carvalho Chehab 
604fcaf780bSMauro Carvalho Chehab /*
605fcaf780bSMauro Carvalho Chehab  *	i7300_get_mc_regs	read in the necessary registers and
606fcaf780bSMauro Carvalho Chehab  *				cache locally
607fcaf780bSMauro Carvalho Chehab  *
608fcaf780bSMauro Carvalho Chehab  *			Fills in the private data members
609fcaf780bSMauro Carvalho Chehab  */
610fcaf780bSMauro Carvalho Chehab static int i7300_get_mc_regs(struct mem_ctl_info *mci)
611fcaf780bSMauro Carvalho Chehab {
612fcaf780bSMauro Carvalho Chehab 	struct i7300_pvt *pvt;
613fcaf780bSMauro Carvalho Chehab 	u32 actual_tolm;
614fcaf780bSMauro Carvalho Chehab 	int i, rc;
615fcaf780bSMauro Carvalho Chehab 
616fcaf780bSMauro Carvalho Chehab 	pvt = mci->pvt_info;
617fcaf780bSMauro Carvalho Chehab 
6183e57eef6SMauro Carvalho Chehab 	pci_read_config_dword(pvt->pci_dev_16_0_fsb_ctlr, AMBASE,
619fcaf780bSMauro Carvalho Chehab 			(u32 *) &pvt->ambase);
620fcaf780bSMauro Carvalho Chehab 
621fcaf780bSMauro Carvalho Chehab 	debugf2("AMBASE= 0x%lx\n", (long unsigned int)pvt->ambase);
622fcaf780bSMauro Carvalho Chehab 
623fcaf780bSMauro Carvalho Chehab 	/* Get the Branch Map regs */
6243e57eef6SMauro Carvalho Chehab 	pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, TOLM, &pvt->tolm);
625fcaf780bSMauro Carvalho Chehab 	pvt->tolm >>= 12;
626fcaf780bSMauro Carvalho Chehab 	debugf2("TOLM (number of 256M regions) =%u (0x%x)\n", pvt->tolm,
627fcaf780bSMauro Carvalho Chehab 		pvt->tolm);
628fcaf780bSMauro Carvalho Chehab 
629fcaf780bSMauro Carvalho Chehab 	actual_tolm = (u32) ((1000l * pvt->tolm) >> (30 - 28));
630fcaf780bSMauro Carvalho Chehab 	debugf2("Actual TOLM byte addr=%u.%03u GB (0x%x)\n",
631fcaf780bSMauro Carvalho Chehab 		actual_tolm/1000, actual_tolm % 1000, pvt->tolm << 28);
632fcaf780bSMauro Carvalho Chehab 
633af3d8831SMauro Carvalho Chehab 	/* Get memory controller settings */
6343e57eef6SMauro Carvalho Chehab 	pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map, MC_SETTINGS,
635af3d8831SMauro Carvalho Chehab 			     &pvt->mc_settings);
636af3d8831SMauro Carvalho Chehab 	debugf0("Memory controller operating on %s mode\n",
637af3d8831SMauro Carvalho Chehab 		pvt->mc_settings & (1 << 16)? "mirrored" : "non-mirrored");
638af3d8831SMauro Carvalho Chehab 	debugf0("Error detection is %s\n",
639af3d8831SMauro Carvalho Chehab 		pvt->mc_settings & (1 << 5)? "enabled" : "disabled");
640af3d8831SMauro Carvalho Chehab 
641af3d8831SMauro Carvalho Chehab 	/* Get Memory Interleave Range registers */
6423e57eef6SMauro Carvalho Chehab 	pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, MIR0, &pvt->mir[0]);
6433e57eef6SMauro Carvalho Chehab 	pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, MIR1, &pvt->mir[1]);
6443e57eef6SMauro Carvalho Chehab 	pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, MIR2, &pvt->mir[2]);
645fcaf780bSMauro Carvalho Chehab 
646fcaf780bSMauro Carvalho Chehab 	/* Decode the MIR regs */
647fcaf780bSMauro Carvalho Chehab 	for (i = 0; i < MAX_MIR; i++)
648fcaf780bSMauro Carvalho Chehab 		decode_mir(i, pvt->mir);
649fcaf780bSMauro Carvalho Chehab 
650fcaf780bSMauro Carvalho Chehab 	rc = i7300_init_csrows(mci);
651fcaf780bSMauro Carvalho Chehab 	if (rc < 0)
652fcaf780bSMauro Carvalho Chehab 		return rc;
653fcaf780bSMauro Carvalho Chehab 
654fcaf780bSMauro Carvalho Chehab 	/* Go and determine the size of each DIMM and place in an
655fcaf780bSMauro Carvalho Chehab 	 * orderly matrix */
656fcaf780bSMauro Carvalho Chehab 	print_dimm_size(pvt);
657fcaf780bSMauro Carvalho Chehab 
658fcaf780bSMauro Carvalho Chehab 	return 0;
659fcaf780bSMauro Carvalho Chehab }
660fcaf780bSMauro Carvalho Chehab 
661*5de6e07eSMauro Carvalho Chehab /*************************************************
662*5de6e07eSMauro Carvalho Chehab  * i7300 Functions related to device probe/release
663*5de6e07eSMauro Carvalho Chehab  *************************************************/
664*5de6e07eSMauro Carvalho Chehab 
665fcaf780bSMauro Carvalho Chehab /*
666fcaf780bSMauro Carvalho Chehab  *	i7300_put_devices	'put' all the devices that we have
667fcaf780bSMauro Carvalho Chehab  *				reserved via 'get'
668fcaf780bSMauro Carvalho Chehab  */
669fcaf780bSMauro Carvalho Chehab static void i7300_put_devices(struct mem_ctl_info *mci)
670fcaf780bSMauro Carvalho Chehab {
671fcaf780bSMauro Carvalho Chehab 	struct i7300_pvt *pvt;
672fcaf780bSMauro Carvalho Chehab 	int branch;
673fcaf780bSMauro Carvalho Chehab 
674fcaf780bSMauro Carvalho Chehab 	pvt = mci->pvt_info;
675fcaf780bSMauro Carvalho Chehab 
676fcaf780bSMauro Carvalho Chehab 	/* Decrement usage count for devices */
677fcaf780bSMauro Carvalho Chehab 	for (branch = 0; branch < MAX_CH_PER_BRANCH; branch++)
6783e57eef6SMauro Carvalho Chehab 		pci_dev_put(pvt->pci_dev_2x_0_fbd_branch[branch]);
6793e57eef6SMauro Carvalho Chehab 	pci_dev_put(pvt->pci_dev_16_2_fsb_err_regs);
6803e57eef6SMauro Carvalho Chehab 	pci_dev_put(pvt->pci_dev_16_1_fsb_addr_map);
681fcaf780bSMauro Carvalho Chehab }
682fcaf780bSMauro Carvalho Chehab 
683fcaf780bSMauro Carvalho Chehab /*
684fcaf780bSMauro Carvalho Chehab  *	i7300_get_devices	Find and perform 'get' operation on the MCH's
685fcaf780bSMauro Carvalho Chehab  *			device/functions we want to reference for this driver
686fcaf780bSMauro Carvalho Chehab  *
687fcaf780bSMauro Carvalho Chehab  *			Need to 'get' device 16 func 1 and func 2
688fcaf780bSMauro Carvalho Chehab  */
689fcaf780bSMauro Carvalho Chehab static int i7300_get_devices(struct mem_ctl_info *mci, int dev_idx)
690fcaf780bSMauro Carvalho Chehab {
691fcaf780bSMauro Carvalho Chehab 	struct i7300_pvt *pvt;
692fcaf780bSMauro Carvalho Chehab 	struct pci_dev *pdev;
693fcaf780bSMauro Carvalho Chehab 
694fcaf780bSMauro Carvalho Chehab 	pvt = mci->pvt_info;
695fcaf780bSMauro Carvalho Chehab 
696fcaf780bSMauro Carvalho Chehab 	/* Attempt to 'get' the MCH register we want */
697fcaf780bSMauro Carvalho Chehab 	pdev = NULL;
6983e57eef6SMauro Carvalho Chehab 	while (!pvt->pci_dev_16_1_fsb_addr_map || !pvt->pci_dev_16_2_fsb_err_regs) {
699fcaf780bSMauro Carvalho Chehab 		pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
700fcaf780bSMauro Carvalho Chehab 				      PCI_DEVICE_ID_INTEL_I7300_MCH_ERR, pdev);
701fcaf780bSMauro Carvalho Chehab 		if (!pdev) {
702fcaf780bSMauro Carvalho Chehab 			/* End of list, leave */
703fcaf780bSMauro Carvalho Chehab 			i7300_printk(KERN_ERR,
704fcaf780bSMauro Carvalho Chehab 				"'system address,Process Bus' "
705fcaf780bSMauro Carvalho Chehab 				"device not found:"
706fcaf780bSMauro Carvalho Chehab 				"vendor 0x%x device 0x%x ERR funcs "
707fcaf780bSMauro Carvalho Chehab 				"(broken BIOS?)\n",
708fcaf780bSMauro Carvalho Chehab 				PCI_VENDOR_ID_INTEL,
709fcaf780bSMauro Carvalho Chehab 				PCI_DEVICE_ID_INTEL_I7300_MCH_ERR);
710fcaf780bSMauro Carvalho Chehab 			goto error;
711fcaf780bSMauro Carvalho Chehab 		}
712fcaf780bSMauro Carvalho Chehab 
713fcaf780bSMauro Carvalho Chehab 		/* Store device 16 funcs 1 and 2 */
714fcaf780bSMauro Carvalho Chehab 		switch (PCI_FUNC(pdev->devfn)) {
715fcaf780bSMauro Carvalho Chehab 		case 1:
7163e57eef6SMauro Carvalho Chehab 			pvt->pci_dev_16_1_fsb_addr_map = pdev;
717fcaf780bSMauro Carvalho Chehab 			break;
718fcaf780bSMauro Carvalho Chehab 		case 2:
7193e57eef6SMauro Carvalho Chehab 			pvt->pci_dev_16_2_fsb_err_regs = pdev;
720fcaf780bSMauro Carvalho Chehab 			break;
721fcaf780bSMauro Carvalho Chehab 		}
722fcaf780bSMauro Carvalho Chehab 	}
723fcaf780bSMauro Carvalho Chehab 
724fcaf780bSMauro Carvalho Chehab 	debugf1("System Address, processor bus- PCI Bus ID: %s  %x:%x\n",
7253e57eef6SMauro Carvalho Chehab 		pci_name(pvt->pci_dev_16_0_fsb_ctlr),
7263e57eef6SMauro Carvalho Chehab 		pvt->pci_dev_16_0_fsb_ctlr->vendor, pvt->pci_dev_16_0_fsb_ctlr->device);
727fcaf780bSMauro Carvalho Chehab 	debugf1("Branchmap, control and errors - PCI Bus ID: %s  %x:%x\n",
7283e57eef6SMauro Carvalho Chehab 		pci_name(pvt->pci_dev_16_1_fsb_addr_map),
7293e57eef6SMauro Carvalho Chehab 		pvt->pci_dev_16_1_fsb_addr_map->vendor, pvt->pci_dev_16_1_fsb_addr_map->device);
730fcaf780bSMauro Carvalho Chehab 	debugf1("FSB Error Regs - PCI Bus ID: %s  %x:%x\n",
7313e57eef6SMauro Carvalho Chehab 		pci_name(pvt->pci_dev_16_2_fsb_err_regs),
7323e57eef6SMauro Carvalho Chehab 		pvt->pci_dev_16_2_fsb_err_regs->vendor, pvt->pci_dev_16_2_fsb_err_regs->device);
733fcaf780bSMauro Carvalho Chehab 
7343e57eef6SMauro Carvalho Chehab 	pvt->pci_dev_2x_0_fbd_branch[0] = pci_get_device(PCI_VENDOR_ID_INTEL,
735fcaf780bSMauro Carvalho Chehab 				            PCI_DEVICE_ID_INTEL_I7300_MCH_FB0,
736fcaf780bSMauro Carvalho Chehab 					    NULL);
7373e57eef6SMauro Carvalho Chehab 	if (!pvt->pci_dev_2x_0_fbd_branch[0]) {
738fcaf780bSMauro Carvalho Chehab 		i7300_printk(KERN_ERR,
739fcaf780bSMauro Carvalho Chehab 			"MC: 'BRANCH 0' device not found:"
740fcaf780bSMauro Carvalho Chehab 			"vendor 0x%x device 0x%x Func 0 (broken BIOS?)\n",
741fcaf780bSMauro Carvalho Chehab 			PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7300_MCH_FB0);
742fcaf780bSMauro Carvalho Chehab 		goto error;
743fcaf780bSMauro Carvalho Chehab 	}
744fcaf780bSMauro Carvalho Chehab 
7453e57eef6SMauro Carvalho Chehab 	pvt->pci_dev_2x_0_fbd_branch[1] = pci_get_device(PCI_VENDOR_ID_INTEL,
746fcaf780bSMauro Carvalho Chehab 					    PCI_DEVICE_ID_INTEL_I7300_MCH_FB1,
747fcaf780bSMauro Carvalho Chehab 					    NULL);
7483e57eef6SMauro Carvalho Chehab 	if (!pvt->pci_dev_2x_0_fbd_branch[1]) {
749fcaf780bSMauro Carvalho Chehab 		i7300_printk(KERN_ERR,
750fcaf780bSMauro Carvalho Chehab 			"MC: 'BRANCH 1' device not found:"
751fcaf780bSMauro Carvalho Chehab 			"vendor 0x%x device 0x%x Func 0 "
752fcaf780bSMauro Carvalho Chehab 			"(broken BIOS?)\n",
753fcaf780bSMauro Carvalho Chehab 			PCI_VENDOR_ID_INTEL,
754fcaf780bSMauro Carvalho Chehab 			PCI_DEVICE_ID_INTEL_I7300_MCH_FB1);
755fcaf780bSMauro Carvalho Chehab 		goto error;
756fcaf780bSMauro Carvalho Chehab 	}
757fcaf780bSMauro Carvalho Chehab 
758fcaf780bSMauro Carvalho Chehab 	return 0;
759fcaf780bSMauro Carvalho Chehab 
760fcaf780bSMauro Carvalho Chehab error:
761fcaf780bSMauro Carvalho Chehab 	i7300_put_devices(mci);
762fcaf780bSMauro Carvalho Chehab 	return -ENODEV;
763fcaf780bSMauro Carvalho Chehab }
764fcaf780bSMauro Carvalho Chehab 
765fcaf780bSMauro Carvalho Chehab /*
766fcaf780bSMauro Carvalho Chehab  *	i7300_probe1	Probe for ONE instance of device to see if it is
767fcaf780bSMauro Carvalho Chehab  *			present.
768fcaf780bSMauro Carvalho Chehab  *	return:
769fcaf780bSMauro Carvalho Chehab  *		0 for FOUND a device
770fcaf780bSMauro Carvalho Chehab  *		< 0 for error code
771fcaf780bSMauro Carvalho Chehab  */
772fcaf780bSMauro Carvalho Chehab static int i7300_probe1(struct pci_dev *pdev, int dev_idx)
773fcaf780bSMauro Carvalho Chehab {
774fcaf780bSMauro Carvalho Chehab 	struct mem_ctl_info *mci;
775fcaf780bSMauro Carvalho Chehab 	struct i7300_pvt *pvt;
776fcaf780bSMauro Carvalho Chehab 	int num_channels;
777fcaf780bSMauro Carvalho Chehab 	int num_dimms_per_channel;
778fcaf780bSMauro Carvalho Chehab 	int num_csrows;
779fcaf780bSMauro Carvalho Chehab 
780fcaf780bSMauro Carvalho Chehab 	if (dev_idx >= ARRAY_SIZE(i7300_devs))
781fcaf780bSMauro Carvalho Chehab 		return -EINVAL;
782fcaf780bSMauro Carvalho Chehab 
783fcaf780bSMauro Carvalho Chehab 	debugf0("MC: " __FILE__ ": %s(), pdev bus %u dev=0x%x fn=0x%x\n",
784fcaf780bSMauro Carvalho Chehab 		__func__,
785fcaf780bSMauro Carvalho Chehab 		pdev->bus->number,
786fcaf780bSMauro Carvalho Chehab 		PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
787fcaf780bSMauro Carvalho Chehab 
788fcaf780bSMauro Carvalho Chehab 	/* We only are looking for func 0 of the set */
789fcaf780bSMauro Carvalho Chehab 	if (PCI_FUNC(pdev->devfn) != 0)
790fcaf780bSMauro Carvalho Chehab 		return -ENODEV;
791fcaf780bSMauro Carvalho Chehab 
792fcaf780bSMauro Carvalho Chehab 	/* As we don't have a motherboard identification routine to determine
793fcaf780bSMauro Carvalho Chehab 	 * actual number of slots/dimms per channel, we thus utilize the
794fcaf780bSMauro Carvalho Chehab 	 * resource as specified by the chipset. Thus, we might have
795fcaf780bSMauro Carvalho Chehab 	 * have more DIMMs per channel than actually on the mobo, but this
796fcaf780bSMauro Carvalho Chehab 	 * allows the driver to support upto the chipset max, without
797fcaf780bSMauro Carvalho Chehab 	 * some fancy mobo determination.
798fcaf780bSMauro Carvalho Chehab 	 */
799fcaf780bSMauro Carvalho Chehab 	num_dimms_per_channel = MAX_SLOTS;
800fcaf780bSMauro Carvalho Chehab 	num_channels = MAX_CHANNELS;
801fcaf780bSMauro Carvalho Chehab 	num_csrows = MAX_SLOTS * MAX_CHANNELS;
802fcaf780bSMauro Carvalho Chehab 
803fcaf780bSMauro Carvalho Chehab 	debugf0("MC: %s(): Number of - Channels= %d  DIMMS= %d  CSROWS= %d\n",
804fcaf780bSMauro Carvalho Chehab 		__func__, num_channels, num_dimms_per_channel, num_csrows);
805fcaf780bSMauro Carvalho Chehab 
806fcaf780bSMauro Carvalho Chehab 	/* allocate a new MC control structure */
807fcaf780bSMauro Carvalho Chehab 	mci = edac_mc_alloc(sizeof(*pvt), num_csrows, num_channels, 0);
808fcaf780bSMauro Carvalho Chehab 
809fcaf780bSMauro Carvalho Chehab 	if (mci == NULL)
810fcaf780bSMauro Carvalho Chehab 		return -ENOMEM;
811fcaf780bSMauro Carvalho Chehab 
812fcaf780bSMauro Carvalho Chehab 	debugf0("MC: " __FILE__ ": %s(): mci = %p\n", __func__, mci);
813fcaf780bSMauro Carvalho Chehab 
814fcaf780bSMauro Carvalho Chehab 	mci->dev = &pdev->dev;	/* record ptr  to the generic device */
815fcaf780bSMauro Carvalho Chehab 
816fcaf780bSMauro Carvalho Chehab 	pvt = mci->pvt_info;
8173e57eef6SMauro Carvalho Chehab 	pvt->pci_dev_16_0_fsb_ctlr = pdev;	/* Record this device in our private */
818fcaf780bSMauro Carvalho Chehab 
819fcaf780bSMauro Carvalho Chehab 	/* 'get' the pci devices we want to reserve for our use */
820fcaf780bSMauro Carvalho Chehab 	if (i7300_get_devices(mci, dev_idx))
821fcaf780bSMauro Carvalho Chehab 		goto fail0;
822fcaf780bSMauro Carvalho Chehab 
823fcaf780bSMauro Carvalho Chehab 	mci->mc_idx = 0;
824fcaf780bSMauro Carvalho Chehab 	mci->mtype_cap = MEM_FLAG_FB_DDR2;
825fcaf780bSMauro Carvalho Chehab 	mci->edac_ctl_cap = EDAC_FLAG_NONE;
826fcaf780bSMauro Carvalho Chehab 	mci->edac_cap = EDAC_FLAG_NONE;
827fcaf780bSMauro Carvalho Chehab 	mci->mod_name = "i7300_edac.c";
828fcaf780bSMauro Carvalho Chehab 	mci->mod_ver = I7300_REVISION;
829fcaf780bSMauro Carvalho Chehab 	mci->ctl_name = i7300_devs[dev_idx].ctl_name;
830fcaf780bSMauro Carvalho Chehab 	mci->dev_name = pci_name(pdev);
831fcaf780bSMauro Carvalho Chehab 	mci->ctl_page_to_phys = NULL;
832fcaf780bSMauro Carvalho Chehab 
833fcaf780bSMauro Carvalho Chehab 	/* Set the function pointer to an actual operation function */
834fcaf780bSMauro Carvalho Chehab 	mci->edac_check = i7300_check_error;
835fcaf780bSMauro Carvalho Chehab 
836fcaf780bSMauro Carvalho Chehab 	/* initialize the MC control structure 'csrows' table
837fcaf780bSMauro Carvalho Chehab 	 * with the mapping and control information */
838fcaf780bSMauro Carvalho Chehab 	if (i7300_get_mc_regs(mci)) {
839fcaf780bSMauro Carvalho Chehab 		debugf0("MC: Setting mci->edac_cap to EDAC_FLAG_NONE\n"
840fcaf780bSMauro Carvalho Chehab 			"    because i7300_init_csrows() returned nonzero "
841fcaf780bSMauro Carvalho Chehab 			"value\n");
842fcaf780bSMauro Carvalho Chehab 		mci->edac_cap = EDAC_FLAG_NONE;	/* no csrows found */
843fcaf780bSMauro Carvalho Chehab 	} else {
844fcaf780bSMauro Carvalho Chehab 		debugf1("MC: Enable error reporting now\n");
845fcaf780bSMauro Carvalho Chehab 		i7300_enable_error_reporting(mci);
846fcaf780bSMauro Carvalho Chehab 	}
847fcaf780bSMauro Carvalho Chehab 
848fcaf780bSMauro Carvalho Chehab 	/* add this new MC control structure to EDAC's list of MCs */
849fcaf780bSMauro Carvalho Chehab 	if (edac_mc_add_mc(mci)) {
850fcaf780bSMauro Carvalho Chehab 		debugf0("MC: " __FILE__
851fcaf780bSMauro Carvalho Chehab 			": %s(): failed edac_mc_add_mc()\n", __func__);
852fcaf780bSMauro Carvalho Chehab 		/* FIXME: perhaps some code should go here that disables error
853fcaf780bSMauro Carvalho Chehab 		 * reporting if we just enabled it
854fcaf780bSMauro Carvalho Chehab 		 */
855fcaf780bSMauro Carvalho Chehab 		goto fail1;
856fcaf780bSMauro Carvalho Chehab 	}
857fcaf780bSMauro Carvalho Chehab 
858fcaf780bSMauro Carvalho Chehab 	i7300_clear_error(mci);
859fcaf780bSMauro Carvalho Chehab 
860fcaf780bSMauro Carvalho Chehab 	/* allocating generic PCI control info */
861fcaf780bSMauro Carvalho Chehab 	i7300_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR);
862fcaf780bSMauro Carvalho Chehab 	if (!i7300_pci) {
863fcaf780bSMauro Carvalho Chehab 		printk(KERN_WARNING
864fcaf780bSMauro Carvalho Chehab 			"%s(): Unable to create PCI control\n",
865fcaf780bSMauro Carvalho Chehab 			__func__);
866fcaf780bSMauro Carvalho Chehab 		printk(KERN_WARNING
867fcaf780bSMauro Carvalho Chehab 			"%s(): PCI error report via EDAC not setup\n",
868fcaf780bSMauro Carvalho Chehab 			__func__);
869fcaf780bSMauro Carvalho Chehab 	}
870fcaf780bSMauro Carvalho Chehab 
871fcaf780bSMauro Carvalho Chehab 	return 0;
872fcaf780bSMauro Carvalho Chehab 
873fcaf780bSMauro Carvalho Chehab 	/* Error exit unwinding stack */
874fcaf780bSMauro Carvalho Chehab fail1:
875fcaf780bSMauro Carvalho Chehab 
876fcaf780bSMauro Carvalho Chehab 	i7300_put_devices(mci);
877fcaf780bSMauro Carvalho Chehab 
878fcaf780bSMauro Carvalho Chehab fail0:
879fcaf780bSMauro Carvalho Chehab 	edac_mc_free(mci);
880fcaf780bSMauro Carvalho Chehab 	return -ENODEV;
881fcaf780bSMauro Carvalho Chehab }
882fcaf780bSMauro Carvalho Chehab 
883fcaf780bSMauro Carvalho Chehab /*
884fcaf780bSMauro Carvalho Chehab  *	i7300_init_one	constructor for one instance of device
885fcaf780bSMauro Carvalho Chehab  *
886fcaf780bSMauro Carvalho Chehab  * 	returns:
887fcaf780bSMauro Carvalho Chehab  *		negative on error
888fcaf780bSMauro Carvalho Chehab  *		count (>= 0)
889fcaf780bSMauro Carvalho Chehab  */
890fcaf780bSMauro Carvalho Chehab static int __devinit i7300_init_one(struct pci_dev *pdev,
891fcaf780bSMauro Carvalho Chehab 				const struct pci_device_id *id)
892fcaf780bSMauro Carvalho Chehab {
893fcaf780bSMauro Carvalho Chehab 	int rc;
894fcaf780bSMauro Carvalho Chehab 
895fcaf780bSMauro Carvalho Chehab 	debugf0("MC: " __FILE__ ": %s()\n", __func__);
896fcaf780bSMauro Carvalho Chehab 
897fcaf780bSMauro Carvalho Chehab 	/* wake up device */
898fcaf780bSMauro Carvalho Chehab 	rc = pci_enable_device(pdev);
899fcaf780bSMauro Carvalho Chehab 	if (rc == -EIO)
900fcaf780bSMauro Carvalho Chehab 		return rc;
901fcaf780bSMauro Carvalho Chehab 
902fcaf780bSMauro Carvalho Chehab 	/* now probe and enable the device */
903fcaf780bSMauro Carvalho Chehab 	return i7300_probe1(pdev, id->driver_data);
904fcaf780bSMauro Carvalho Chehab }
905fcaf780bSMauro Carvalho Chehab 
906fcaf780bSMauro Carvalho Chehab /*
907fcaf780bSMauro Carvalho Chehab  *	i7300_remove_one	destructor for one instance of device
908fcaf780bSMauro Carvalho Chehab  *
909fcaf780bSMauro Carvalho Chehab  */
910fcaf780bSMauro Carvalho Chehab static void __devexit i7300_remove_one(struct pci_dev *pdev)
911fcaf780bSMauro Carvalho Chehab {
912fcaf780bSMauro Carvalho Chehab 	struct mem_ctl_info *mci;
913fcaf780bSMauro Carvalho Chehab 
914fcaf780bSMauro Carvalho Chehab 	debugf0(__FILE__ ": %s()\n", __func__);
915fcaf780bSMauro Carvalho Chehab 
916fcaf780bSMauro Carvalho Chehab 	if (i7300_pci)
917fcaf780bSMauro Carvalho Chehab 		edac_pci_release_generic_ctl(i7300_pci);
918fcaf780bSMauro Carvalho Chehab 
919fcaf780bSMauro Carvalho Chehab 	mci = edac_mc_del_mc(&pdev->dev);
920fcaf780bSMauro Carvalho Chehab 	if (!mci)
921fcaf780bSMauro Carvalho Chehab 		return;
922fcaf780bSMauro Carvalho Chehab 
923fcaf780bSMauro Carvalho Chehab 	/* retrieve references to resources, and free those resources */
924fcaf780bSMauro Carvalho Chehab 	i7300_put_devices(mci);
925fcaf780bSMauro Carvalho Chehab 
926fcaf780bSMauro Carvalho Chehab 	edac_mc_free(mci);
927fcaf780bSMauro Carvalho Chehab }
928fcaf780bSMauro Carvalho Chehab 
929fcaf780bSMauro Carvalho Chehab /*
930fcaf780bSMauro Carvalho Chehab  *	pci_device_id	table for which devices we are looking for
931fcaf780bSMauro Carvalho Chehab  *
932fcaf780bSMauro Carvalho Chehab  *	The "E500P" device is the first device supported.
933fcaf780bSMauro Carvalho Chehab  */
934fcaf780bSMauro Carvalho Chehab static const struct pci_device_id i7300_pci_tbl[] __devinitdata = {
935fcaf780bSMauro Carvalho Chehab 	{PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7300_MCH_ERR)},
936fcaf780bSMauro Carvalho Chehab 	{0,}			/* 0 terminated list. */
937fcaf780bSMauro Carvalho Chehab };
938fcaf780bSMauro Carvalho Chehab 
939fcaf780bSMauro Carvalho Chehab MODULE_DEVICE_TABLE(pci, i7300_pci_tbl);
940fcaf780bSMauro Carvalho Chehab 
941fcaf780bSMauro Carvalho Chehab /*
942fcaf780bSMauro Carvalho Chehab  *	i7300_driver	pci_driver structure for this module
943fcaf780bSMauro Carvalho Chehab  *
944fcaf780bSMauro Carvalho Chehab  */
945fcaf780bSMauro Carvalho Chehab static struct pci_driver i7300_driver = {
946fcaf780bSMauro Carvalho Chehab 	.name = "i7300_edac",
947fcaf780bSMauro Carvalho Chehab 	.probe = i7300_init_one,
948fcaf780bSMauro Carvalho Chehab 	.remove = __devexit_p(i7300_remove_one),
949fcaf780bSMauro Carvalho Chehab 	.id_table = i7300_pci_tbl,
950fcaf780bSMauro Carvalho Chehab };
951fcaf780bSMauro Carvalho Chehab 
952fcaf780bSMauro Carvalho Chehab /*
953fcaf780bSMauro Carvalho Chehab  *	i7300_init		Module entry function
954fcaf780bSMauro Carvalho Chehab  *			Try to initialize this module for its devices
955fcaf780bSMauro Carvalho Chehab  */
956fcaf780bSMauro Carvalho Chehab static int __init i7300_init(void)
957fcaf780bSMauro Carvalho Chehab {
958fcaf780bSMauro Carvalho Chehab 	int pci_rc;
959fcaf780bSMauro Carvalho Chehab 
960fcaf780bSMauro Carvalho Chehab 	debugf2("MC: " __FILE__ ": %s()\n", __func__);
961fcaf780bSMauro Carvalho Chehab 
962fcaf780bSMauro Carvalho Chehab 	/* Ensure that the OPSTATE is set correctly for POLL or NMI */
963fcaf780bSMauro Carvalho Chehab 	opstate_init();
964fcaf780bSMauro Carvalho Chehab 
965fcaf780bSMauro Carvalho Chehab 	pci_rc = pci_register_driver(&i7300_driver);
966fcaf780bSMauro Carvalho Chehab 
967fcaf780bSMauro Carvalho Chehab 	return (pci_rc < 0) ? pci_rc : 0;
968fcaf780bSMauro Carvalho Chehab }
969fcaf780bSMauro Carvalho Chehab 
970fcaf780bSMauro Carvalho Chehab /*
971fcaf780bSMauro Carvalho Chehab  *	i7300_exit()	Module exit function
972fcaf780bSMauro Carvalho Chehab  *			Unregister the driver
973fcaf780bSMauro Carvalho Chehab  */
974fcaf780bSMauro Carvalho Chehab static void __exit i7300_exit(void)
975fcaf780bSMauro Carvalho Chehab {
976fcaf780bSMauro Carvalho Chehab 	debugf2("MC: " __FILE__ ": %s()\n", __func__);
977fcaf780bSMauro Carvalho Chehab 	pci_unregister_driver(&i7300_driver);
978fcaf780bSMauro Carvalho Chehab }
979fcaf780bSMauro Carvalho Chehab 
980fcaf780bSMauro Carvalho Chehab module_init(i7300_init);
981fcaf780bSMauro Carvalho Chehab module_exit(i7300_exit);
982fcaf780bSMauro Carvalho Chehab 
983fcaf780bSMauro Carvalho Chehab MODULE_LICENSE("GPL");
984fcaf780bSMauro Carvalho Chehab MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
985fcaf780bSMauro Carvalho Chehab MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)");
986fcaf780bSMauro Carvalho Chehab MODULE_DESCRIPTION("MC Driver for Intel I7300 memory controllers - "
987fcaf780bSMauro Carvalho Chehab 		   I7300_REVISION);
988fcaf780bSMauro Carvalho Chehab 
989fcaf780bSMauro Carvalho Chehab module_param(edac_op_state, int, 0444);
990fcaf780bSMauro Carvalho Chehab MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");
991