1 /* Intel Sandy Bridge -EN/-EP/-EX Memory Controller kernel module
3 * This driver supports the memory controllers found on the Intel
4 * processor family Sandy Bridge.
6 * This file may be distributed under the terms of the
7 * GNU General Public License version 2 only.
9 * Copyright (c) 2011 by:
10 * Mauro Carvalho Chehab
13 #include <linux/module.h>
14 #include <linux/init.h>
15 #include <linux/pci.h>
16 #include <linux/pci_ids.h>
17 #include <linux/slab.h>
18 #include <linux/delay.h>
19 #include <linux/edac.h>
20 #include <linux/mmzone.h>
21 #include <linux/smp.h>
22 #include <linux/bitmap.h>
23 #include <linux/math64.h>
24 #include <asm/processor.h>
27 #include "edac_core.h"
30 static LIST_HEAD(sbridge_edac_list);
31 static DEFINE_MUTEX(sbridge_edac_lock);
35 * Alter this version for the module when modifications are made
37 #define SBRIDGE_REVISION " Ver: 1.1.1 "
38 #define EDAC_MOD_STR "sbridge_edac"
43 #define sbridge_printk(level, fmt, arg...) \
44 edac_printk(level, "sbridge", fmt, ##arg)
46 #define sbridge_mc_printk(mci, level, fmt, arg...) \
47 edac_mc_chipset_printk(mci, level, "sbridge", fmt, ##arg)
50 * Get a bit field at register value <v>, from bit <lo> to bit <hi>
52 #define GET_BITFIELD(v, lo, hi) \
53 (((v) & GENMASK_ULL(hi, lo)) >> (lo))
55 /* Devices 12 Function 6, Offsets 0x80 to 0xcc */
56 static const u32 sbridge_dram_rule[] = {
57 0x80, 0x88, 0x90, 0x98, 0xa0,
58 0xa8, 0xb0, 0xb8, 0xc0, 0xc8,
61 static const u32 ibridge_dram_rule[] = {
62 0x60, 0x68, 0x70, 0x78, 0x80,
63 0x88, 0x90, 0x98, 0xa0, 0xa8,
64 0xb0, 0xb8, 0xc0, 0xc8, 0xd0,
65 0xd8, 0xe0, 0xe8, 0xf0, 0xf8,
68 static const u32 knl_dram_rule[] = {
69 0x60, 0x68, 0x70, 0x78, 0x80, /* 0-4 */
70 0x88, 0x90, 0x98, 0xa0, 0xa8, /* 5-9 */
71 0xb0, 0xb8, 0xc0, 0xc8, 0xd0, /* 10-14 */
72 0xd8, 0xe0, 0xe8, 0xf0, 0xf8, /* 15-19 */
73 0x100, 0x108, 0x110, 0x118, /* 20-23 */
76 #define DRAM_RULE_ENABLE(reg) GET_BITFIELD(reg, 0, 0)
77 #define A7MODE(reg) GET_BITFIELD(reg, 26, 26)
79 static char *show_dram_attr(u32 attr)
93 static const u32 sbridge_interleave_list[] = {
94 0x84, 0x8c, 0x94, 0x9c, 0xa4,
95 0xac, 0xb4, 0xbc, 0xc4, 0xcc,
98 static const u32 ibridge_interleave_list[] = {
99 0x64, 0x6c, 0x74, 0x7c, 0x84,
100 0x8c, 0x94, 0x9c, 0xa4, 0xac,
101 0xb4, 0xbc, 0xc4, 0xcc, 0xd4,
102 0xdc, 0xe4, 0xec, 0xf4, 0xfc,
105 static const u32 knl_interleave_list[] = {
106 0x64, 0x6c, 0x74, 0x7c, 0x84, /* 0-4 */
107 0x8c, 0x94, 0x9c, 0xa4, 0xac, /* 5-9 */
108 0xb4, 0xbc, 0xc4, 0xcc, 0xd4, /* 10-14 */
109 0xdc, 0xe4, 0xec, 0xf4, 0xfc, /* 15-19 */
110 0x104, 0x10c, 0x114, 0x11c, /* 20-23 */
113 struct interleave_pkg {
118 static const struct interleave_pkg sbridge_interleave_pkg[] = {
129 static const struct interleave_pkg ibridge_interleave_pkg[] = {
140 static inline int sad_pkg(const struct interleave_pkg *table, u32 reg,
143 return GET_BITFIELD(reg, table[interleave].start,
144 table[interleave].end);
147 /* Devices 12 Function 7 */
151 #define HASWELL_TOLM 0xd0
152 #define HASWELL_TOHM_0 0xd4
153 #define HASWELL_TOHM_1 0xd8
154 #define KNL_TOLM 0xd0
155 #define KNL_TOHM_0 0xd4
156 #define KNL_TOHM_1 0xd8
158 #define GET_TOLM(reg) ((GET_BITFIELD(reg, 0, 3) << 28) | 0x3ffffff)
159 #define GET_TOHM(reg) ((GET_BITFIELD(reg, 0, 20) << 25) | 0x3ffffff)
161 /* Device 13 Function 6 */
163 #define SAD_TARGET 0xf0
165 #define SOURCE_ID(reg) GET_BITFIELD(reg, 9, 11)
167 #define SOURCE_ID_KNL(reg) GET_BITFIELD(reg, 12, 14)
169 #define SAD_CONTROL 0xf4
171 /* Device 14 function 0 */
173 static const u32 tad_dram_rule[] = {
174 0x40, 0x44, 0x48, 0x4c,
175 0x50, 0x54, 0x58, 0x5c,
176 0x60, 0x64, 0x68, 0x6c,
178 #define MAX_TAD ARRAY_SIZE(tad_dram_rule)
180 #define TAD_LIMIT(reg) ((GET_BITFIELD(reg, 12, 31) << 26) | 0x3ffffff)
181 #define TAD_SOCK(reg) GET_BITFIELD(reg, 10, 11)
182 #define TAD_CH(reg) GET_BITFIELD(reg, 8, 9)
183 #define TAD_TGT3(reg) GET_BITFIELD(reg, 6, 7)
184 #define TAD_TGT2(reg) GET_BITFIELD(reg, 4, 5)
185 #define TAD_TGT1(reg) GET_BITFIELD(reg, 2, 3)
186 #define TAD_TGT0(reg) GET_BITFIELD(reg, 0, 1)
188 /* Device 15, function 0 */
191 #define KNL_MCMTR 0x624
193 #define IS_ECC_ENABLED(mcmtr) GET_BITFIELD(mcmtr, 2, 2)
194 #define IS_LOCKSTEP_ENABLED(mcmtr) GET_BITFIELD(mcmtr, 1, 1)
195 #define IS_CLOSE_PG(mcmtr) GET_BITFIELD(mcmtr, 0, 0)
197 /* Device 15, function 1 */
199 #define RASENABLES 0xac
200 #define IS_MIRROR_ENABLED(reg) GET_BITFIELD(reg, 0, 0)
202 /* Device 15, functions 2-5 */
204 static const int mtr_regs[] = {
208 static const int knl_mtr_reg = 0xb60;
210 #define RANK_DISABLE(mtr) GET_BITFIELD(mtr, 16, 19)
211 #define IS_DIMM_PRESENT(mtr) GET_BITFIELD(mtr, 14, 14)
212 #define RANK_CNT_BITS(mtr) GET_BITFIELD(mtr, 12, 13)
213 #define RANK_WIDTH_BITS(mtr) GET_BITFIELD(mtr, 2, 4)
214 #define COL_WIDTH_BITS(mtr) GET_BITFIELD(mtr, 0, 1)
216 static const u32 tad_ch_nilv_offset[] = {
217 0x90, 0x94, 0x98, 0x9c,
218 0xa0, 0xa4, 0xa8, 0xac,
219 0xb0, 0xb4, 0xb8, 0xbc,
221 #define CHN_IDX_OFFSET(reg) GET_BITFIELD(reg, 28, 29)
222 #define TAD_OFFSET(reg) (GET_BITFIELD(reg, 6, 25) << 26)
224 static const u32 rir_way_limit[] = {
225 0x108, 0x10c, 0x110, 0x114, 0x118,
227 #define MAX_RIR_RANGES ARRAY_SIZE(rir_way_limit)
229 #define IS_RIR_VALID(reg) GET_BITFIELD(reg, 31, 31)
230 #define RIR_WAY(reg) GET_BITFIELD(reg, 28, 29)
232 #define MAX_RIR_WAY 8
234 static const u32 rir_offset[MAX_RIR_RANGES][MAX_RIR_WAY] = {
235 { 0x120, 0x124, 0x128, 0x12c, 0x130, 0x134, 0x138, 0x13c },
236 { 0x140, 0x144, 0x148, 0x14c, 0x150, 0x154, 0x158, 0x15c },
237 { 0x160, 0x164, 0x168, 0x16c, 0x170, 0x174, 0x178, 0x17c },
238 { 0x180, 0x184, 0x188, 0x18c, 0x190, 0x194, 0x198, 0x19c },
239 { 0x1a0, 0x1a4, 0x1a8, 0x1ac, 0x1b0, 0x1b4, 0x1b8, 0x1bc },
242 #define RIR_RNK_TGT(reg) GET_BITFIELD(reg, 16, 19)
243 #define RIR_OFFSET(reg) GET_BITFIELD(reg, 2, 14)
245 /* Device 16, functions 2-7 */
248 * FIXME: Implement the error count reads directly
251 static const u32 correrrcnt[] = {
252 0x104, 0x108, 0x10c, 0x110,
255 #define RANK_ODD_OV(reg) GET_BITFIELD(reg, 31, 31)
256 #define RANK_ODD_ERR_CNT(reg) GET_BITFIELD(reg, 16, 30)
257 #define RANK_EVEN_OV(reg) GET_BITFIELD(reg, 15, 15)
258 #define RANK_EVEN_ERR_CNT(reg) GET_BITFIELD(reg, 0, 14)
260 static const u32 correrrthrsld[] = {
261 0x11c, 0x120, 0x124, 0x128,
264 #define RANK_ODD_ERR_THRSLD(reg) GET_BITFIELD(reg, 16, 30)
265 #define RANK_EVEN_ERR_THRSLD(reg) GET_BITFIELD(reg, 0, 14)
268 /* Device 17, function 0 */
270 #define SB_RANK_CFG_A 0x0328
272 #define IB_RANK_CFG_A 0x0320
278 #define NUM_CHANNELS 8 /* 2MC per socket, four chan per MC */
279 #define MAX_DIMMS 3 /* Max DIMMS per channel */
280 #define KNL_MAX_CHAS 38 /* KNL max num. of Cache Home Agents */
281 #define KNL_MAX_CHANNELS 6 /* KNL max num. of PCI channels */
282 #define KNL_MAX_EDCS 8 /* Embedded DRAM controllers */
283 #define CHANNEL_UNSPECIFIED 0xf /* Intel IA32 SDM 15-14 */
294 struct sbridge_info {
298 u64 (*get_tolm)(struct sbridge_pvt *pvt);
299 u64 (*get_tohm)(struct sbridge_pvt *pvt);
300 u64 (*rir_limit)(u32 reg);
301 u64 (*sad_limit)(u32 reg);
302 u32 (*interleave_mode)(u32 reg);
303 char* (*show_interleave_mode)(u32 reg);
304 u32 (*dram_attr)(u32 reg);
305 const u32 *dram_rule;
306 const u32 *interleave_list;
307 const struct interleave_pkg *interleave_pkg;
310 u8 (*get_node_id)(struct sbridge_pvt *pvt);
311 enum mem_type (*get_memory_type)(struct sbridge_pvt *pvt);
312 enum dev_type (*get_width)(struct sbridge_pvt *pvt, u32 mtr);
313 struct pci_dev *pci_vtd;
316 struct sbridge_channel {
321 struct pci_id_descr {
326 struct pci_id_table {
327 const struct pci_id_descr *descr;
332 struct list_head list;
334 u8 node_id, source_id;
335 struct pci_dev **pdev;
337 struct mem_ctl_info *mci;
341 struct pci_dev *pci_cha[KNL_MAX_CHAS];
342 struct pci_dev *pci_channel[KNL_MAX_CHANNELS];
343 struct pci_dev *pci_mc0;
344 struct pci_dev *pci_mc1;
345 struct pci_dev *pci_mc0_misc;
346 struct pci_dev *pci_mc1_misc;
347 struct pci_dev *pci_mc_info; /* tolm, tohm */
351 struct pci_dev *pci_ta, *pci_ddrio, *pci_ras;
352 struct pci_dev *pci_sad0, *pci_sad1;
353 struct pci_dev *pci_ha0, *pci_ha1;
354 struct pci_dev *pci_br0, *pci_br1;
355 struct pci_dev *pci_ha1_ta;
356 struct pci_dev *pci_tad[NUM_CHANNELS];
358 struct sbridge_dev *sbridge_dev;
360 struct sbridge_info info;
361 struct sbridge_channel channel[NUM_CHANNELS];
363 /* Memory type detection */
364 bool is_mirrored, is_lockstep, is_close_pg;
366 /* Memory description */
371 #define PCI_DESCR(device_id, opt) \
372 .dev_id = (device_id), \
375 static const struct pci_id_descr pci_dev_descr_sbridge[] = {
376 /* Processor Home Agent */
377 { PCI_DESCR(PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_HA0, 0) },
379 /* Memory controller */
380 { PCI_DESCR(PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TA, 0) },
381 { PCI_DESCR(PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_RAS, 0) },
382 { PCI_DESCR(PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD0, 0) },
383 { PCI_DESCR(PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD1, 0) },
384 { PCI_DESCR(PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD2, 0) },
385 { PCI_DESCR(PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD3, 0) },
386 { PCI_DESCR(PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_DDRIO, 1) },
388 /* System Address Decoder */
389 { PCI_DESCR(PCI_DEVICE_ID_INTEL_SBRIDGE_SAD0, 0) },
390 { PCI_DESCR(PCI_DEVICE_ID_INTEL_SBRIDGE_SAD1, 0) },
392 /* Broadcast Registers */
393 { PCI_DESCR(PCI_DEVICE_ID_INTEL_SBRIDGE_BR, 0) },
396 #define PCI_ID_TABLE_ENTRY(A) { .descr=A, .n_devs = ARRAY_SIZE(A) }
397 static const struct pci_id_table pci_dev_descr_sbridge_table[] = {
398 PCI_ID_TABLE_ENTRY(pci_dev_descr_sbridge),
399 {0,} /* 0 terminated list. */
402 /* This changes depending if 1HA or 2HA:
404 * 0x0eb8 (17.0) is DDRIO0
406 * 0x0ebc (17.4) is DDRIO0
408 #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_1HA_DDRIO0 0x0eb8
409 #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_2HA_DDRIO0 0x0ebc
412 #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0 0x0ea0
413 #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TA 0x0ea8
414 #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_RAS 0x0e71
415 #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD0 0x0eaa
416 #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD1 0x0eab
417 #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD2 0x0eac
418 #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD3 0x0ead
419 #define PCI_DEVICE_ID_INTEL_IBRIDGE_SAD 0x0ec8
420 #define PCI_DEVICE_ID_INTEL_IBRIDGE_BR0 0x0ec9
421 #define PCI_DEVICE_ID_INTEL_IBRIDGE_BR1 0x0eca
422 #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1 0x0e60
423 #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TA 0x0e68
424 #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_RAS 0x0e79
425 #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD0 0x0e6a
426 #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD1 0x0e6b
427 #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD2 0x0e6c
428 #define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD3 0x0e6d
430 static const struct pci_id_descr pci_dev_descr_ibridge[] = {
431 /* Processor Home Agent */
432 { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0, 0) },
434 /* Memory controller */
435 { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TA, 0) },
436 { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_RAS, 0) },
437 { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD0, 0) },
438 { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD1, 0) },
439 { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD2, 0) },
440 { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD3, 0) },
442 /* System Address Decoder */
443 { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_SAD, 0) },
445 /* Broadcast Registers */
446 { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_BR0, 1) },
447 { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_BR1, 0) },
449 /* Optional, mode 2HA */
450 { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1, 1) },
452 { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TA, 1) },
453 { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_RAS, 1) },
455 { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD0, 1) },
456 { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD1, 1) },
457 { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD2, 1) },
458 { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD3, 1) },
460 { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_1HA_DDRIO0, 1) },
461 { PCI_DESCR(PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_2HA_DDRIO0, 1) },
464 static const struct pci_id_table pci_dev_descr_ibridge_table[] = {
465 PCI_ID_TABLE_ENTRY(pci_dev_descr_ibridge),
466 {0,} /* 0 terminated list. */
469 /* Haswell support */
472 * - 3 DDR3 channels, 2 DPC per channel
475 * - 4 DDR4 channels, 3 DPC per channel
478 * - 4 DDR4 channels, 3 DPC per channel
481 * - each IMC interfaces with a SMI 2 channel
482 * - each SMI channel interfaces with a scalable memory buffer
483 * - each scalable memory buffer supports 4 DDR3/DDR4 channels, 3 DPC
485 #define HASWELL_DDRCRCLKCONTROLS 0xa10 /* Ditto on Broadwell */
486 #define HASWELL_HASYSDEFEATURE2 0x84
487 #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_VTD_MISC 0x2f28
488 #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0 0x2fa0
489 #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1 0x2f60
490 #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TA 0x2fa8
491 #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_THERMAL 0x2f71
492 #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TA 0x2f68
493 #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_THERMAL 0x2f79
494 #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_CBO_SAD0 0x2ffc
495 #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_CBO_SAD1 0x2ffd
496 #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD0 0x2faa
497 #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD1 0x2fab
498 #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD2 0x2fac
499 #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD3 0x2fad
500 #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD0 0x2f6a
501 #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD1 0x2f6b
502 #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD2 0x2f6c
503 #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD3 0x2f6d
504 #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_DDRIO0 0x2fbd
505 #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_DDRIO1 0x2fbf
506 #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_DDRIO2 0x2fb9
507 #define PCI_DEVICE_ID_INTEL_HASWELL_IMC_DDRIO3 0x2fbb
508 static const struct pci_id_descr pci_dev_descr_haswell[] = {
509 /* first item must be the HA */
510 { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0, 0) },
512 { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_CBO_SAD0, 0) },
513 { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_CBO_SAD1, 0) },
515 { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1, 1) },
517 { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TA, 0) },
518 { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_THERMAL, 0) },
519 { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD0, 0) },
520 { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD1, 0) },
521 { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD2, 1) },
522 { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD3, 1) },
524 { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_DDRIO0, 1) },
525 { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_DDRIO1, 1) },
526 { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_DDRIO2, 1) },
527 { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_DDRIO3, 1) },
529 { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TA, 1) },
530 { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_THERMAL, 1) },
531 { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD0, 1) },
532 { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD1, 1) },
533 { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD2, 1) },
534 { PCI_DESCR(PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD3, 1) },
537 static const struct pci_id_table pci_dev_descr_haswell_table[] = {
538 PCI_ID_TABLE_ENTRY(pci_dev_descr_haswell),
539 {0,} /* 0 terminated list. */
542 /* Knight's Landing Support */
544 * KNL's memory channels are swizzled between memory controllers.
545 * MC0 is mapped to CH3,5,6 and MC1 is mapped to CH0,1,2
547 #define knl_channel_remap(channel) ((channel + 3) % 6)
549 /* Memory controller, TAD tables, error injection - 2-8-0, 2-9-0 (2 of these) */
550 #define PCI_DEVICE_ID_INTEL_KNL_IMC_MC 0x7840
551 /* DRAM channel stuff; bank addrs, dimmmtr, etc.. 2-8-2 - 2-9-4 (6 of these) */
552 #define PCI_DEVICE_ID_INTEL_KNL_IMC_CHANNEL 0x7843
553 /* kdrwdbu TAD limits/offsets, MCMTR - 2-10-1, 2-11-1 (2 of these) */
554 #define PCI_DEVICE_ID_INTEL_KNL_IMC_TA 0x7844
555 /* CHA broadcast registers, dram rules - 1-29-0 (1 of these) */
556 #define PCI_DEVICE_ID_INTEL_KNL_IMC_SAD0 0x782a
557 /* SAD target - 1-29-1 (1 of these) */
558 #define PCI_DEVICE_ID_INTEL_KNL_IMC_SAD1 0x782b
559 /* Caching / Home Agent */
560 #define PCI_DEVICE_ID_INTEL_KNL_IMC_CHA 0x782c
561 /* Device with TOLM and TOHM, 0-5-0 (1 of these) */
562 #define PCI_DEVICE_ID_INTEL_KNL_IMC_TOLHM 0x7810
565 * KNL differs from SB, IB, and Haswell in that it has multiple
566 * instances of the same device with the same device ID, so we handle that
567 * by creating as many copies in the table as we expect to find.
568 * (Like device ID must be grouped together.)
571 static const struct pci_id_descr pci_dev_descr_knl[] = {
572 [0] = { PCI_DESCR(PCI_DEVICE_ID_INTEL_KNL_IMC_SAD0, 0) },
573 [1] = { PCI_DESCR(PCI_DEVICE_ID_INTEL_KNL_IMC_SAD1, 0) },
574 [2 ... 3] = { PCI_DESCR(PCI_DEVICE_ID_INTEL_KNL_IMC_MC, 0)},
575 [4 ... 41] = { PCI_DESCR(PCI_DEVICE_ID_INTEL_KNL_IMC_CHA, 0) },
576 [42 ... 47] = { PCI_DESCR(PCI_DEVICE_ID_INTEL_KNL_IMC_CHANNEL, 0) },
577 [48] = { PCI_DESCR(PCI_DEVICE_ID_INTEL_KNL_IMC_TA, 0) },
578 [49] = { PCI_DESCR(PCI_DEVICE_ID_INTEL_KNL_IMC_TOLHM, 0) },
581 static const struct pci_id_table pci_dev_descr_knl_table[] = {
582 PCI_ID_TABLE_ENTRY(pci_dev_descr_knl),
591 * - 2 DDR3 channels, 2 DPC per channel
594 * - 4 DDR4 channels, 3 DPC per channel
597 * - 4 DDR4 channels, 3 DPC per channel
600 * - each IMC interfaces with a SMI 2 channel
601 * - each SMI channel interfaces with a scalable memory buffer
602 * - each scalable memory buffer supports 4 DDR3/DDR4 channels, 3 DPC
604 #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_VTD_MISC 0x6f28
605 #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0 0x6fa0
606 #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1 0x6f60
607 #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TA 0x6fa8
608 #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_THERMAL 0x6f71
609 #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TA 0x6f68
610 #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_THERMAL 0x6f79
611 #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_CBO_SAD0 0x6ffc
612 #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_CBO_SAD1 0x6ffd
613 #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD0 0x6faa
614 #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD1 0x6fab
615 #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD2 0x6fac
616 #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD3 0x6fad
617 #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TAD0 0x6f6a
618 #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TAD1 0x6f6b
619 #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TAD2 0x6f6c
620 #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TAD3 0x6f6d
621 #define PCI_DEVICE_ID_INTEL_BROADWELL_IMC_DDRIO0 0x6faf
623 static const struct pci_id_descr pci_dev_descr_broadwell[] = {
624 /* first item must be the HA */
625 { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0, 0) },
627 { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_CBO_SAD0, 0) },
628 { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_CBO_SAD1, 0) },
630 { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1, 1) },
632 { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TA, 0) },
633 { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_THERMAL, 0) },
634 { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD0, 0) },
635 { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD1, 0) },
636 { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD2, 1) },
637 { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD3, 1) },
639 { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_DDRIO0, 1) },
641 { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TA, 1) },
642 { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_THERMAL, 1) },
643 { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TAD0, 1) },
644 { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TAD1, 1) },
645 { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TAD2, 1) },
646 { PCI_DESCR(PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TAD3, 1) },
649 static const struct pci_id_table pci_dev_descr_broadwell_table[] = {
650 PCI_ID_TABLE_ENTRY(pci_dev_descr_broadwell),
651 {0,} /* 0 terminated list. */
655 * pci_device_id table for which devices we are looking for
657 static const struct pci_device_id sbridge_pci_tbl[] = {
658 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_HA0)},
659 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TA)},
660 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0)},
661 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0)},
662 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_KNL_IMC_SAD0)},
663 {0,} /* 0 terminated list. */
667 /****************************************************************************
668 Ancillary status routines
669 ****************************************************************************/
671 static inline int numrank(enum type type, u32 mtr)
673 int ranks = (1 << RANK_CNT_BITS(mtr));
676 if (type == HASWELL || type == BROADWELL || type == KNIGHTS_LANDING)
680 edac_dbg(0, "Invalid number of ranks: %d (max = %i) raw value = %x (%04x)\n",
681 ranks, max, (unsigned int)RANK_CNT_BITS(mtr), mtr);
688 static inline int numrow(u32 mtr)
690 int rows = (RANK_WIDTH_BITS(mtr) + 12);
692 if (rows < 13 || rows > 18) {
693 edac_dbg(0, "Invalid number of rows: %d (should be between 14 and 17) raw value = %x (%04x)\n",
694 rows, (unsigned int)RANK_WIDTH_BITS(mtr), mtr);
701 static inline int numcol(u32 mtr)
703 int cols = (COL_WIDTH_BITS(mtr) + 10);
706 edac_dbg(0, "Invalid number of cols: %d (max = 4) raw value = %x (%04x)\n",
707 cols, (unsigned int)COL_WIDTH_BITS(mtr), mtr);
714 static struct sbridge_dev *get_sbridge_dev(u8 bus, int multi_bus)
716 struct sbridge_dev *sbridge_dev;
719 * If we have devices scattered across several busses that pertain
720 * to the same memory controller, we'll lump them all together.
723 return list_first_entry_or_null(&sbridge_edac_list,
724 struct sbridge_dev, list);
727 list_for_each_entry(sbridge_dev, &sbridge_edac_list, list) {
728 if (sbridge_dev->bus == bus)
735 static struct sbridge_dev *alloc_sbridge_dev(u8 bus,
736 const struct pci_id_table *table)
738 struct sbridge_dev *sbridge_dev;
740 sbridge_dev = kzalloc(sizeof(*sbridge_dev), GFP_KERNEL);
744 sbridge_dev->pdev = kzalloc(sizeof(*sbridge_dev->pdev) * table->n_devs,
746 if (!sbridge_dev->pdev) {
751 sbridge_dev->bus = bus;
752 sbridge_dev->n_devs = table->n_devs;
753 list_add_tail(&sbridge_dev->list, &sbridge_edac_list);
758 static void free_sbridge_dev(struct sbridge_dev *sbridge_dev)
760 list_del(&sbridge_dev->list);
761 kfree(sbridge_dev->pdev);
765 static u64 sbridge_get_tolm(struct sbridge_pvt *pvt)
769 /* Address range is 32:28 */
770 pci_read_config_dword(pvt->pci_sad1, TOLM, ®);
771 return GET_TOLM(reg);
774 static u64 sbridge_get_tohm(struct sbridge_pvt *pvt)
778 pci_read_config_dword(pvt->pci_sad1, TOHM, ®);
779 return GET_TOHM(reg);
782 static u64 ibridge_get_tolm(struct sbridge_pvt *pvt)
786 pci_read_config_dword(pvt->pci_br1, TOLM, ®);
788 return GET_TOLM(reg);
791 static u64 ibridge_get_tohm(struct sbridge_pvt *pvt)
795 pci_read_config_dword(pvt->pci_br1, TOHM, ®);
797 return GET_TOHM(reg);
800 static u64 rir_limit(u32 reg)
802 return ((u64)GET_BITFIELD(reg, 1, 10) << 29) | 0x1fffffff;
805 static u64 sad_limit(u32 reg)
807 return (GET_BITFIELD(reg, 6, 25) << 26) | 0x3ffffff;
810 static u32 interleave_mode(u32 reg)
812 return GET_BITFIELD(reg, 1, 1);
815 char *show_interleave_mode(u32 reg)
817 return interleave_mode(reg) ? "8:6" : "[8:6]XOR[18:16]";
820 static u32 dram_attr(u32 reg)
822 return GET_BITFIELD(reg, 2, 3);
825 static u64 knl_sad_limit(u32 reg)
827 return (GET_BITFIELD(reg, 7, 26) << 26) | 0x3ffffff;
830 static u32 knl_interleave_mode(u32 reg)
832 return GET_BITFIELD(reg, 1, 2);
835 static char *knl_show_interleave_mode(u32 reg)
839 switch (knl_interleave_mode(reg)) {
841 s = "use address bits [8:6]";
844 s = "use address bits [10:8]";
847 s = "use address bits [14:12]";
850 s = "use address bits [32:30]";
860 static u32 dram_attr_knl(u32 reg)
862 return GET_BITFIELD(reg, 3, 4);
866 static enum mem_type get_memory_type(struct sbridge_pvt *pvt)
871 if (pvt->pci_ddrio) {
872 pci_read_config_dword(pvt->pci_ddrio, pvt->info.rankcfgr,
874 if (GET_BITFIELD(reg, 11, 11))
875 /* FIXME: Can also be LRDIMM */
885 static enum mem_type haswell_get_memory_type(struct sbridge_pvt *pvt)
888 bool registered = false;
889 enum mem_type mtype = MEM_UNKNOWN;
894 pci_read_config_dword(pvt->pci_ddrio,
895 HASWELL_DDRCRCLKCONTROLS, ®);
897 if (GET_BITFIELD(reg, 16, 16))
900 pci_read_config_dword(pvt->pci_ta, MCMTR, ®);
901 if (GET_BITFIELD(reg, 14, 14)) {
917 static enum dev_type knl_get_width(struct sbridge_pvt *pvt, u32 mtr)
919 /* for KNL value is fixed */
923 static enum dev_type sbridge_get_width(struct sbridge_pvt *pvt, u32 mtr)
925 /* there's no way to figure out */
929 static enum dev_type __ibridge_get_width(u32 mtr)
951 static enum dev_type ibridge_get_width(struct sbridge_pvt *pvt, u32 mtr)
954 * ddr3_width on the documentation but also valid for DDR4 on
957 return __ibridge_get_width(GET_BITFIELD(mtr, 7, 8));
960 static enum dev_type broadwell_get_width(struct sbridge_pvt *pvt, u32 mtr)
962 /* ddr3_width on the documentation but also valid for DDR4 */
963 return __ibridge_get_width(GET_BITFIELD(mtr, 8, 9));
966 static enum mem_type knl_get_memory_type(struct sbridge_pvt *pvt)
968 /* DDR4 RDIMMS and LRDIMMS are supported */
972 static u8 get_node_id(struct sbridge_pvt *pvt)
975 pci_read_config_dword(pvt->pci_br0, SAD_CONTROL, ®);
976 return GET_BITFIELD(reg, 0, 2);
979 static u8 haswell_get_node_id(struct sbridge_pvt *pvt)
983 pci_read_config_dword(pvt->pci_sad1, SAD_CONTROL, ®);
984 return GET_BITFIELD(reg, 0, 3);
987 static u8 knl_get_node_id(struct sbridge_pvt *pvt)
991 pci_read_config_dword(pvt->pci_sad1, SAD_CONTROL, ®);
992 return GET_BITFIELD(reg, 0, 2);
996 static u64 haswell_get_tolm(struct sbridge_pvt *pvt)
1000 pci_read_config_dword(pvt->info.pci_vtd, HASWELL_TOLM, ®);
1001 return (GET_BITFIELD(reg, 26, 31) << 26) | 0x3ffffff;
1004 static u64 haswell_get_tohm(struct sbridge_pvt *pvt)
1009 pci_read_config_dword(pvt->info.pci_vtd, HASWELL_TOHM_0, ®);
1010 rc = GET_BITFIELD(reg, 26, 31);
1011 pci_read_config_dword(pvt->info.pci_vtd, HASWELL_TOHM_1, ®);
1012 rc = ((reg << 6) | rc) << 26;
1014 return rc | 0x1ffffff;
1017 static u64 knl_get_tolm(struct sbridge_pvt *pvt)
1021 pci_read_config_dword(pvt->knl.pci_mc_info, KNL_TOLM, ®);
1022 return (GET_BITFIELD(reg, 26, 31) << 26) | 0x3ffffff;
1025 static u64 knl_get_tohm(struct sbridge_pvt *pvt)
1030 pci_read_config_dword(pvt->knl.pci_mc_info, KNL_TOHM_0, ®_lo);
1031 pci_read_config_dword(pvt->knl.pci_mc_info, KNL_TOHM_1, ®_hi);
1032 rc = ((u64)reg_hi << 32) | reg_lo;
1033 return rc | 0x3ffffff;
1037 static u64 haswell_rir_limit(u32 reg)
1039 return (((u64)GET_BITFIELD(reg, 1, 11) + 1) << 29) - 1;
1042 static inline u8 sad_pkg_socket(u8 pkg)
1044 /* on Ivy Bridge, nodeID is SASS, where A is HA and S is node id */
1045 return ((pkg >> 3) << 2) | (pkg & 0x3);
1048 static inline u8 sad_pkg_ha(u8 pkg)
1050 return (pkg >> 2) & 0x1;
1053 /****************************************************************************
1054 Memory check routines
1055 ****************************************************************************/
1056 static struct pci_dev *get_pdev_same_bus(u8 bus, u32 id)
1058 struct pci_dev *pdev = NULL;
1061 pdev = pci_get_device(PCI_VENDOR_ID_INTEL, id, pdev);
1062 if (pdev && pdev->bus->number == bus)
1070 * check_if_ecc_is_active() - Checks if ECC is active
1072 * @type: Memory controller type
1073 * returns: 0 in case ECC is active, -ENODEV if it can't be determined or
1076 static int check_if_ecc_is_active(const u8 bus, enum type type)
1078 struct pci_dev *pdev = NULL;
1083 id = PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TA;
1086 id = PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TA;
1089 id = PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TA;
1092 id = PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TA;
1094 case KNIGHTS_LANDING:
1096 * KNL doesn't group things by bus the same way
1097 * SB/IB/Haswell does.
1099 id = PCI_DEVICE_ID_INTEL_KNL_IMC_TA;
1105 if (type != KNIGHTS_LANDING)
1106 pdev = get_pdev_same_bus(bus, id);
1108 pdev = pci_get_device(PCI_VENDOR_ID_INTEL, id, 0);
1111 sbridge_printk(KERN_ERR, "Couldn't find PCI device "
1112 "%04x:%04x! on bus %02d\n",
1113 PCI_VENDOR_ID_INTEL, id, bus);
1117 pci_read_config_dword(pdev,
1118 type == KNIGHTS_LANDING ? KNL_MCMTR : MCMTR, &mcmtr);
1119 if (!IS_ECC_ENABLED(mcmtr)) {
1120 sbridge_printk(KERN_ERR, "ECC is disabled. Aborting\n");
1126 /* Low bits of TAD limit, and some metadata. */
1127 static const u32 knl_tad_dram_limit_lo[] = {
1128 0x400, 0x500, 0x600, 0x700,
1129 0x800, 0x900, 0xa00, 0xb00,
1132 /* Low bits of TAD offset. */
1133 static const u32 knl_tad_dram_offset_lo[] = {
1134 0x404, 0x504, 0x604, 0x704,
1135 0x804, 0x904, 0xa04, 0xb04,
1138 /* High 16 bits of TAD limit and offset. */
1139 static const u32 knl_tad_dram_hi[] = {
1140 0x408, 0x508, 0x608, 0x708,
1141 0x808, 0x908, 0xa08, 0xb08,
1144 /* Number of ways a tad entry is interleaved. */
1145 static const u32 knl_tad_ways[] = {
1150 * Retrieve the n'th Target Address Decode table entry
1151 * from the memory controller's TAD table.
1153 * @pvt: driver private data
1154 * @entry: which entry you want to retrieve
1155 * @mc: which memory controller (0 or 1)
1156 * @offset: output tad range offset
1157 * @limit: output address of first byte above tad range
1158 * @ways: output number of interleave ways
1160 * The offset value has curious semantics. It's a sort of running total
1161 * of the sizes of all the memory regions that aren't mapped in this
1164 static int knl_get_tad(const struct sbridge_pvt *pvt,
1171 u32 reg_limit_lo, reg_offset_lo, reg_hi;
1172 struct pci_dev *pci_mc;
1177 pci_mc = pvt->knl.pci_mc0;
1180 pci_mc = pvt->knl.pci_mc1;
1187 pci_read_config_dword(pci_mc,
1188 knl_tad_dram_limit_lo[entry], ®_limit_lo);
1189 pci_read_config_dword(pci_mc,
1190 knl_tad_dram_offset_lo[entry], ®_offset_lo);
1191 pci_read_config_dword(pci_mc,
1192 knl_tad_dram_hi[entry], ®_hi);
1194 /* Is this TAD entry enabled? */
1195 if (!GET_BITFIELD(reg_limit_lo, 0, 0))
1198 way_id = GET_BITFIELD(reg_limit_lo, 3, 5);
1200 if (way_id < ARRAY_SIZE(knl_tad_ways)) {
1201 *ways = knl_tad_ways[way_id];
1204 sbridge_printk(KERN_ERR,
1205 "Unexpected value %d in mc_tad_limit_lo wayness field\n",
1211 * The least significant 6 bits of base and limit are truncated.
1212 * For limit, we fill the missing bits with 1s.
1214 *offset = ((u64) GET_BITFIELD(reg_offset_lo, 6, 31) << 6) |
1215 ((u64) GET_BITFIELD(reg_hi, 0, 15) << 32);
1216 *limit = ((u64) GET_BITFIELD(reg_limit_lo, 6, 31) << 6) | 63 |
1217 ((u64) GET_BITFIELD(reg_hi, 16, 31) << 32);
1222 /* Determine which memory controller is responsible for a given channel. */
1223 static int knl_channel_mc(int channel)
1225 WARN_ON(channel < 0 || channel >= 6);
1227 return channel < 3 ? 1 : 0;
1231 * Get the Nth entry from EDC_ROUTE_TABLE register.
1232 * (This is the per-tile mapping of logical interleave targets to
1233 * physical EDC modules.)
1245 static u32 knl_get_edc_route(int entry, u32 reg)
1247 WARN_ON(entry >= KNL_MAX_EDCS);
1248 return GET_BITFIELD(reg, entry*3, (entry*3)+2);
1252 * Get the Nth entry from MC_ROUTE_TABLE register.
1253 * (This is the per-tile mapping of logical interleave targets to
1254 * physical DRAM channels modules.)
1256 * entry 0: mc 0:2 channel 18:19
1257 * 1: mc 3:5 channel 20:21
1258 * 2: mc 6:8 channel 22:23
1259 * 3: mc 9:11 channel 24:25
1260 * 4: mc 12:14 channel 26:27
1261 * 5: mc 15:17 channel 28:29
1264 * Though we have 3 bits to identify the MC, we should only see
1265 * the values 0 or 1.
1268 static u32 knl_get_mc_route(int entry, u32 reg)
1272 WARN_ON(entry >= KNL_MAX_CHANNELS);
1274 mc = GET_BITFIELD(reg, entry*3, (entry*3)+2);
1275 chan = GET_BITFIELD(reg, (entry*2) + 18, (entry*2) + 18 + 1);
1277 return knl_channel_remap(mc*3 + chan);
1281 * Render the EDC_ROUTE register in human-readable form.
1282 * Output string s should be at least KNL_MAX_EDCS*2 bytes.
1284 static void knl_show_edc_route(u32 reg, char *s)
1288 for (i = 0; i < KNL_MAX_EDCS; i++) {
1289 s[i*2] = knl_get_edc_route(i, reg) + '0';
1293 s[KNL_MAX_EDCS*2 - 1] = '\0';
1297 * Render the MC_ROUTE register in human-readable form.
1298 * Output string s should be at least KNL_MAX_CHANNELS*2 bytes.
1300 static void knl_show_mc_route(u32 reg, char *s)
1304 for (i = 0; i < KNL_MAX_CHANNELS; i++) {
1305 s[i*2] = knl_get_mc_route(i, reg) + '0';
1309 s[KNL_MAX_CHANNELS*2 - 1] = '\0';
1312 #define KNL_EDC_ROUTE 0xb8
1313 #define KNL_MC_ROUTE 0xb4
1315 /* Is this dram rule backed by regular DRAM in flat mode? */
1316 #define KNL_EDRAM(reg) GET_BITFIELD(reg, 29, 29)
1318 /* Is this dram rule cached? */
1319 #define KNL_CACHEABLE(reg) GET_BITFIELD(reg, 28, 28)
1321 /* Is this rule backed by edc ? */
1322 #define KNL_EDRAM_ONLY(reg) GET_BITFIELD(reg, 29, 29)
1324 /* Is this rule backed by DRAM, cacheable in EDRAM? */
1325 #define KNL_CACHEABLE(reg) GET_BITFIELD(reg, 28, 28)
1327 /* Is this rule mod3? */
1328 #define KNL_MOD3(reg) GET_BITFIELD(reg, 27, 27)
1331 * Figure out how big our RAM modules are.
1333 * The DIMMMTR register in KNL doesn't tell us the size of the DIMMs, so we
1334 * have to figure this out from the SAD rules, interleave lists, route tables,
1337 * SAD rules can have holes in them (e.g. the 3G-4G hole), so we have to
1338 * inspect the TAD rules to figure out how large the SAD regions really are.
1340 * When we know the real size of a SAD region and how many ways it's
1341 * interleaved, we know the individual contribution of each channel to
1344 * Finally, we have to check whether each channel participates in each SAD
1347 * Fortunately, KNL only supports one DIMM per channel, so once we know how
1348 * much memory the channel uses, we know the DIMM is at least that large.
1349 * (The BIOS might possibly choose not to map all available memory, in which
1350 * case we will underreport the size of the DIMM.)
1352 * In theory, we could try to determine the EDC sizes as well, but that would
1353 * only work in flat mode, not in cache mode.
1355 * @mc_sizes: Output sizes of channels (must have space for KNL_MAX_CHANNELS
1358 static int knl_get_dimm_capacity(struct sbridge_pvt *pvt, u64 *mc_sizes)
1360 u64 sad_base, sad_size, sad_limit = 0;
1361 u64 tad_base, tad_size, tad_limit, tad_deadspace, tad_livespace;
1364 int intrlv_ways, tad_ways;
1367 u64 sad_actual_size[2]; /* sad size accounting for holes, per mc */
1368 u32 dram_rule, interleave_reg;
1369 u32 mc_route_reg[KNL_MAX_CHAS];
1370 u32 edc_route_reg[KNL_MAX_CHAS];
1372 char edc_route_string[KNL_MAX_EDCS*2];
1373 char mc_route_string[KNL_MAX_CHANNELS*2];
1378 int participants[KNL_MAX_CHANNELS];
1379 int participant_count = 0;
1381 for (i = 0; i < KNL_MAX_CHANNELS; i++)
1384 /* Read the EDC route table in each CHA. */
1386 for (i = 0; i < KNL_MAX_CHAS; i++) {
1387 pci_read_config_dword(pvt->knl.pci_cha[i],
1388 KNL_EDC_ROUTE, &edc_route_reg[i]);
1390 if (i > 0 && edc_route_reg[i] != edc_route_reg[i-1]) {
1391 knl_show_edc_route(edc_route_reg[i-1],
1393 if (cur_reg_start == i-1)
1394 edac_dbg(0, "edc route table for CHA %d: %s\n",
1395 cur_reg_start, edc_route_string);
1397 edac_dbg(0, "edc route table for CHA %d-%d: %s\n",
1398 cur_reg_start, i-1, edc_route_string);
1402 knl_show_edc_route(edc_route_reg[i-1], edc_route_string);
1403 if (cur_reg_start == i-1)
1404 edac_dbg(0, "edc route table for CHA %d: %s\n",
1405 cur_reg_start, edc_route_string);
1407 edac_dbg(0, "edc route table for CHA %d-%d: %s\n",
1408 cur_reg_start, i-1, edc_route_string);
1410 /* Read the MC route table in each CHA. */
1412 for (i = 0; i < KNL_MAX_CHAS; i++) {
1413 pci_read_config_dword(pvt->knl.pci_cha[i],
1414 KNL_MC_ROUTE, &mc_route_reg[i]);
1416 if (i > 0 && mc_route_reg[i] != mc_route_reg[i-1]) {
1417 knl_show_mc_route(mc_route_reg[i-1], mc_route_string);
1418 if (cur_reg_start == i-1)
1419 edac_dbg(0, "mc route table for CHA %d: %s\n",
1420 cur_reg_start, mc_route_string);
1422 edac_dbg(0, "mc route table for CHA %d-%d: %s\n",
1423 cur_reg_start, i-1, mc_route_string);
1427 knl_show_mc_route(mc_route_reg[i-1], mc_route_string);
1428 if (cur_reg_start == i-1)
1429 edac_dbg(0, "mc route table for CHA %d: %s\n",
1430 cur_reg_start, mc_route_string);
1432 edac_dbg(0, "mc route table for CHA %d-%d: %s\n",
1433 cur_reg_start, i-1, mc_route_string);
1435 /* Process DRAM rules */
1436 for (sad_rule = 0; sad_rule < pvt->info.max_sad; sad_rule++) {
1437 /* previous limit becomes the new base */
1438 sad_base = sad_limit;
1440 pci_read_config_dword(pvt->pci_sad0,
1441 pvt->info.dram_rule[sad_rule], &dram_rule);
1443 if (!DRAM_RULE_ENABLE(dram_rule))
1446 edram_only = KNL_EDRAM_ONLY(dram_rule);
1448 sad_limit = pvt->info.sad_limit(dram_rule)+1;
1449 sad_size = sad_limit - sad_base;
1451 pci_read_config_dword(pvt->pci_sad0,
1452 pvt->info.interleave_list[sad_rule], &interleave_reg);
1455 * Find out how many ways this dram rule is interleaved.
1456 * We stop when we see the first channel again.
1458 first_pkg = sad_pkg(pvt->info.interleave_pkg,
1460 for (intrlv_ways = 1; intrlv_ways < 8; intrlv_ways++) {
1461 pkg = sad_pkg(pvt->info.interleave_pkg,
1462 interleave_reg, intrlv_ways);
1464 if ((pkg & 0x8) == 0) {
1466 * 0 bit means memory is non-local,
1467 * which KNL doesn't support
1469 edac_dbg(0, "Unexpected interleave target %d\n",
1474 if (pkg == first_pkg)
1477 if (KNL_MOD3(dram_rule))
1480 edac_dbg(3, "dram rule %d (base 0x%llx, limit 0x%llx), %d way interleave%s\n",
1485 edram_only ? ", EDRAM" : "");
1488 * Find out how big the SAD region really is by iterating
1489 * over TAD tables (SAD regions may contain holes).
1490 * Each memory controller might have a different TAD table, so
1491 * we have to look at both.
1493 * Livespace is the memory that's mapped in this TAD table,
1494 * deadspace is the holes (this could be the MMIO hole, or it
1495 * could be memory that's mapped by the other TAD table but
1498 for (mc = 0; mc < 2; mc++) {
1499 sad_actual_size[mc] = 0;
1502 tad_rule < ARRAY_SIZE(
1503 knl_tad_dram_limit_lo);
1505 if (knl_get_tad(pvt,
1513 tad_size = (tad_limit+1) -
1514 (tad_livespace + tad_deadspace);
1515 tad_livespace += tad_size;
1516 tad_base = (tad_limit+1) - tad_size;
1518 if (tad_base < sad_base) {
1519 if (tad_limit > sad_base)
1520 edac_dbg(0, "TAD region overlaps lower SAD boundary -- TAD tables may be configured incorrectly.\n");
1521 } else if (tad_base < sad_limit) {
1522 if (tad_limit+1 > sad_limit) {
1523 edac_dbg(0, "TAD region overlaps upper SAD boundary -- TAD tables may be configured incorrectly.\n");
1525 /* TAD region is completely inside SAD region */
1526 edac_dbg(3, "TAD region %d 0x%llx - 0x%llx (%lld bytes) table%d\n",
1528 tad_limit, tad_size,
1530 sad_actual_size[mc] += tad_size;
1533 tad_base = tad_limit+1;
1537 for (mc = 0; mc < 2; mc++) {
1538 edac_dbg(3, " total TAD DRAM footprint in table%d : 0x%llx (%lld bytes)\n",
1539 mc, sad_actual_size[mc], sad_actual_size[mc]);
1542 /* Ignore EDRAM rule */
1546 /* Figure out which channels participate in interleave. */
1547 for (channel = 0; channel < KNL_MAX_CHANNELS; channel++)
1548 participants[channel] = 0;
1550 /* For each channel, does at least one CHA have
1551 * this channel mapped to the given target?
1553 for (channel = 0; channel < KNL_MAX_CHANNELS; channel++) {
1554 for (way = 0; way < intrlv_ways; way++) {
1558 if (KNL_MOD3(dram_rule))
1561 target = 0x7 & sad_pkg(
1562 pvt->info.interleave_pkg, interleave_reg, way);
1564 for (cha = 0; cha < KNL_MAX_CHAS; cha++) {
1565 if (knl_get_mc_route(target,
1566 mc_route_reg[cha]) == channel
1567 && !participants[channel]) {
1568 participant_count++;
1569 participants[channel] = 1;
1576 if (participant_count != intrlv_ways)
1577 edac_dbg(0, "participant_count (%d) != interleave_ways (%d): DIMM size may be incorrect\n",
1578 participant_count, intrlv_ways);
1580 for (channel = 0; channel < KNL_MAX_CHANNELS; channel++) {
1581 mc = knl_channel_mc(channel);
1582 if (participants[channel]) {
1583 edac_dbg(4, "mc channel %d contributes %lld bytes via sad entry %d\n",
1585 sad_actual_size[mc]/intrlv_ways,
1587 mc_sizes[channel] +=
1588 sad_actual_size[mc]/intrlv_ways;
1596 static int get_dimm_config(struct mem_ctl_info *mci)
1598 struct sbridge_pvt *pvt = mci->pvt_info;
1599 struct dimm_info *dimm;
1600 unsigned i, j, banks, ranks, rows, cols, npages;
1603 enum edac_type mode;
1604 enum mem_type mtype;
1605 int channels = pvt->info.type == KNIGHTS_LANDING ?
1606 KNL_MAX_CHANNELS : NUM_CHANNELS;
1607 u64 knl_mc_sizes[KNL_MAX_CHANNELS];
1609 if (pvt->info.type == HASWELL || pvt->info.type == BROADWELL ||
1610 pvt->info.type == KNIGHTS_LANDING)
1611 pci_read_config_dword(pvt->pci_sad1, SAD_TARGET, ®);
1613 pci_read_config_dword(pvt->pci_br0, SAD_TARGET, ®);
1615 if (pvt->info.type == KNIGHTS_LANDING)
1616 pvt->sbridge_dev->source_id = SOURCE_ID_KNL(reg);
1618 pvt->sbridge_dev->source_id = SOURCE_ID(reg);
1620 pvt->sbridge_dev->node_id = pvt->info.get_node_id(pvt);
1621 edac_dbg(0, "mc#%d: Node ID: %d, source ID: %d\n",
1622 pvt->sbridge_dev->mc,
1623 pvt->sbridge_dev->node_id,
1624 pvt->sbridge_dev->source_id);
1626 /* KNL doesn't support mirroring or lockstep,
1627 * and is always closed page
1629 if (pvt->info.type == KNIGHTS_LANDING) {
1630 mode = EDAC_S4ECD4ED;
1631 pvt->is_mirrored = false;
1633 if (knl_get_dimm_capacity(pvt, knl_mc_sizes) != 0)
1636 pci_read_config_dword(pvt->pci_ras, RASENABLES, ®);
1637 if (IS_MIRROR_ENABLED(reg)) {
1638 edac_dbg(0, "Memory mirror is enabled\n");
1639 pvt->is_mirrored = true;
1641 edac_dbg(0, "Memory mirror is disabled\n");
1642 pvt->is_mirrored = false;
1645 pci_read_config_dword(pvt->pci_ta, MCMTR, &pvt->info.mcmtr);
1646 if (IS_LOCKSTEP_ENABLED(pvt->info.mcmtr)) {
1647 edac_dbg(0, "Lockstep is enabled\n");
1648 mode = EDAC_S8ECD8ED;
1649 pvt->is_lockstep = true;
1651 edac_dbg(0, "Lockstep is disabled\n");
1652 mode = EDAC_S4ECD4ED;
1653 pvt->is_lockstep = false;
1655 if (IS_CLOSE_PG(pvt->info.mcmtr)) {
1656 edac_dbg(0, "address map is on closed page mode\n");
1657 pvt->is_close_pg = true;
1659 edac_dbg(0, "address map is on open page mode\n");
1660 pvt->is_close_pg = false;
1664 mtype = pvt->info.get_memory_type(pvt);
1665 if (mtype == MEM_RDDR3 || mtype == MEM_RDDR4)
1666 edac_dbg(0, "Memory is registered\n");
1667 else if (mtype == MEM_UNKNOWN)
1668 edac_dbg(0, "Cannot determine memory type\n");
1670 edac_dbg(0, "Memory is unregistered\n");
1672 if (mtype == MEM_DDR4 || mtype == MEM_RDDR4)
1677 for (i = 0; i < channels; i++) {
1680 int max_dimms_per_channel;
1682 if (pvt->info.type == KNIGHTS_LANDING) {
1683 max_dimms_per_channel = 1;
1684 if (!pvt->knl.pci_channel[i])
1687 max_dimms_per_channel = ARRAY_SIZE(mtr_regs);
1688 if (!pvt->pci_tad[i])
1692 for (j = 0; j < max_dimms_per_channel; j++) {
1693 dimm = EDAC_DIMM_PTR(mci->layers, mci->dimms, mci->n_layers,
1695 if (pvt->info.type == KNIGHTS_LANDING) {
1696 pci_read_config_dword(pvt->knl.pci_channel[i],
1699 pci_read_config_dword(pvt->pci_tad[i],
1702 edac_dbg(4, "Channel #%d MTR%d = %x\n", i, j, mtr);
1703 if (IS_DIMM_PRESENT(mtr)) {
1704 pvt->channel[i].dimms++;
1706 ranks = numrank(pvt->info.type, mtr);
1708 if (pvt->info.type == KNIGHTS_LANDING) {
1709 /* For DDR4, this is fixed. */
1711 rows = knl_mc_sizes[i] /
1712 ((u64) cols * ranks * banks * 8);
1718 size = ((u64)rows * cols * banks * ranks) >> (20 - 3);
1719 npages = MiB_TO_PAGES(size);
1721 edac_dbg(0, "mc#%d: ha %d channel %d, dimm %d, %lld Mb (%d pages) bank: %d, rank: %d, row: %#x, col: %#x\n",
1722 pvt->sbridge_dev->mc, i/4, i%4, j,
1724 banks, ranks, rows, cols);
1726 dimm->nr_pages = npages;
1728 dimm->dtype = pvt->info.get_width(pvt, mtr);
1729 dimm->mtype = mtype;
1730 dimm->edac_mode = mode;
1731 snprintf(dimm->label, sizeof(dimm->label),
1732 "CPU_SrcID#%u_Ha#%u_Chan#%u_DIMM#%u",
1733 pvt->sbridge_dev->source_id, i/4, i%4, j);
1741 static void get_memory_layout(const struct mem_ctl_info *mci)
1743 struct sbridge_pvt *pvt = mci->pvt_info;
1744 int i, j, k, n_sads, n_tads, sad_interl;
1752 * Step 1) Get TOLM/TOHM ranges
1755 pvt->tolm = pvt->info.get_tolm(pvt);
1756 tmp_mb = (1 + pvt->tolm) >> 20;
1758 gb = div_u64_rem(tmp_mb, 1024, &mb);
1759 edac_dbg(0, "TOLM: %u.%03u GB (0x%016Lx)\n",
1760 gb, (mb*1000)/1024, (u64)pvt->tolm);
1762 /* Address range is already 45:25 */
1763 pvt->tohm = pvt->info.get_tohm(pvt);
1764 tmp_mb = (1 + pvt->tohm) >> 20;
1766 gb = div_u64_rem(tmp_mb, 1024, &mb);
1767 edac_dbg(0, "TOHM: %u.%03u GB (0x%016Lx)\n",
1768 gb, (mb*1000)/1024, (u64)pvt->tohm);
1771 * Step 2) Get SAD range and SAD Interleave list
1772 * TAD registers contain the interleave wayness. However, it
1773 * seems simpler to just discover it indirectly, with the
1777 for (n_sads = 0; n_sads < pvt->info.max_sad; n_sads++) {
1778 /* SAD_LIMIT Address range is 45:26 */
1779 pci_read_config_dword(pvt->pci_sad0, pvt->info.dram_rule[n_sads],
1781 limit = pvt->info.sad_limit(reg);
1783 if (!DRAM_RULE_ENABLE(reg))
1789 tmp_mb = (limit + 1) >> 20;
1790 gb = div_u64_rem(tmp_mb, 1024, &mb);
1791 edac_dbg(0, "SAD#%d %s up to %u.%03u GB (0x%016Lx) Interleave: %s reg=0x%08x\n",
1793 show_dram_attr(pvt->info.dram_attr(reg)),
1795 ((u64)tmp_mb) << 20L,
1796 pvt->info.show_interleave_mode(reg),
1800 pci_read_config_dword(pvt->pci_sad0, pvt->info.interleave_list[n_sads],
1802 sad_interl = sad_pkg(pvt->info.interleave_pkg, reg, 0);
1803 for (j = 0; j < 8; j++) {
1804 u32 pkg = sad_pkg(pvt->info.interleave_pkg, reg, j);
1805 if (j > 0 && sad_interl == pkg)
1808 edac_dbg(0, "SAD#%d, interleave #%d: %d\n",
1813 if (pvt->info.type == KNIGHTS_LANDING)
1817 * Step 3) Get TAD range
1820 for (n_tads = 0; n_tads < MAX_TAD; n_tads++) {
1821 pci_read_config_dword(pvt->pci_ha0, tad_dram_rule[n_tads],
1823 limit = TAD_LIMIT(reg);
1826 tmp_mb = (limit + 1) >> 20;
1828 gb = div_u64_rem(tmp_mb, 1024, &mb);
1829 edac_dbg(0, "TAD#%d: up to %u.%03u GB (0x%016Lx), socket interleave %d, memory interleave %d, TGT: %d, %d, %d, %d, reg=0x%08x\n",
1830 n_tads, gb, (mb*1000)/1024,
1831 ((u64)tmp_mb) << 20L,
1832 (u32)(1 << TAD_SOCK(reg)),
1833 (u32)TAD_CH(reg) + 1,
1843 * Step 4) Get TAD offsets, per each channel
1845 for (i = 0; i < NUM_CHANNELS; i++) {
1846 if (!pvt->channel[i].dimms)
1848 for (j = 0; j < n_tads; j++) {
1849 pci_read_config_dword(pvt->pci_tad[i],
1850 tad_ch_nilv_offset[j],
1852 tmp_mb = TAD_OFFSET(reg) >> 20;
1853 gb = div_u64_rem(tmp_mb, 1024, &mb);
1854 edac_dbg(0, "TAD CH#%d, offset #%d: %u.%03u GB (0x%016Lx), reg=0x%08x\n",
1857 ((u64)tmp_mb) << 20L,
1863 * Step 6) Get RIR Wayness/Limit, per each channel
1865 for (i = 0; i < NUM_CHANNELS; i++) {
1866 if (!pvt->channel[i].dimms)
1868 for (j = 0; j < MAX_RIR_RANGES; j++) {
1869 pci_read_config_dword(pvt->pci_tad[i],
1873 if (!IS_RIR_VALID(reg))
1876 tmp_mb = pvt->info.rir_limit(reg) >> 20;
1877 rir_way = 1 << RIR_WAY(reg);
1878 gb = div_u64_rem(tmp_mb, 1024, &mb);
1879 edac_dbg(0, "CH#%d RIR#%d, limit: %u.%03u GB (0x%016Lx), way: %d, reg=0x%08x\n",
1882 ((u64)tmp_mb) << 20L,
1886 for (k = 0; k < rir_way; k++) {
1887 pci_read_config_dword(pvt->pci_tad[i],
1890 tmp_mb = RIR_OFFSET(reg) << 6;
1892 gb = div_u64_rem(tmp_mb, 1024, &mb);
1893 edac_dbg(0, "CH#%d RIR#%d INTL#%d, offset %u.%03u GB (0x%016Lx), tgt: %d, reg=0x%08x\n",
1896 ((u64)tmp_mb) << 20L,
1897 (u32)RIR_RNK_TGT(reg),
1904 static struct mem_ctl_info *get_mci_for_node_id(u8 node_id)
1906 struct sbridge_dev *sbridge_dev;
1908 list_for_each_entry(sbridge_dev, &sbridge_edac_list, list) {
1909 if (sbridge_dev->node_id == node_id)
1910 return sbridge_dev->mci;
1915 static int get_memory_error_data(struct mem_ctl_info *mci,
1920 char **area_type, char *msg)
1922 struct mem_ctl_info *new_mci;
1923 struct sbridge_pvt *pvt = mci->pvt_info;
1924 struct pci_dev *pci_ha;
1925 int n_rir, n_sads, n_tads, sad_way, sck_xch;
1926 int sad_interl, idx, base_ch;
1927 int interleave_mode, shiftup = 0;
1928 unsigned sad_interleave[pvt->info.max_interleave];
1930 u8 ch_way, sck_way, pkg, sad_ha = 0, ch_add = 0;
1934 u64 ch_addr, offset, limit = 0, prv = 0;
1938 * Step 0) Check if the address is at special memory ranges
1939 * The check bellow is probably enough to fill all cases where
1940 * the error is not inside a memory, except for the legacy
1941 * range (e. g. VGA addresses). It is unlikely, however, that the
1942 * memory controller would generate an error on that range.
1944 if ((addr > (u64) pvt->tolm) && (addr < (1LL << 32))) {
1945 sprintf(msg, "Error at TOLM area, on addr 0x%08Lx", addr);
1948 if (addr >= (u64)pvt->tohm) {
1949 sprintf(msg, "Error at MMIOH area, on addr 0x%016Lx", addr);
1954 * Step 1) Get socket
1956 for (n_sads = 0; n_sads < pvt->info.max_sad; n_sads++) {
1957 pci_read_config_dword(pvt->pci_sad0, pvt->info.dram_rule[n_sads],
1960 if (!DRAM_RULE_ENABLE(reg))
1963 limit = pvt->info.sad_limit(reg);
1965 sprintf(msg, "Can't discover the memory socket");
1972 if (n_sads == pvt->info.max_sad) {
1973 sprintf(msg, "Can't discover the memory socket");
1977 *area_type = show_dram_attr(pvt->info.dram_attr(dram_rule));
1978 interleave_mode = pvt->info.interleave_mode(dram_rule);
1980 pci_read_config_dword(pvt->pci_sad0, pvt->info.interleave_list[n_sads],
1983 if (pvt->info.type == SANDY_BRIDGE) {
1984 sad_interl = sad_pkg(pvt->info.interleave_pkg, reg, 0);
1985 for (sad_way = 0; sad_way < 8; sad_way++) {
1986 u32 pkg = sad_pkg(pvt->info.interleave_pkg, reg, sad_way);
1987 if (sad_way > 0 && sad_interl == pkg)
1989 sad_interleave[sad_way] = pkg;
1990 edac_dbg(0, "SAD interleave #%d: %d\n",
1991 sad_way, sad_interleave[sad_way]);
1993 edac_dbg(0, "mc#%d: Error detected on SAD#%d: address 0x%016Lx < 0x%016Lx, Interleave [%d:6]%s\n",
1994 pvt->sbridge_dev->mc,
1999 !interleave_mode ? "" : "XOR[18:16]");
2000 if (interleave_mode)
2001 idx = ((addr >> 6) ^ (addr >> 16)) & 7;
2003 idx = (addr >> 6) & 7;
2017 sprintf(msg, "Can't discover socket interleave");
2020 *socket = sad_interleave[idx];
2021 edac_dbg(0, "SAD interleave index: %d (wayness %d) = CPU socket %d\n",
2022 idx, sad_way, *socket);
2023 } else if (pvt->info.type == HASWELL || pvt->info.type == BROADWELL) {
2024 int bits, a7mode = A7MODE(dram_rule);
2027 /* A7 mode swaps P9 with P6 */
2028 bits = GET_BITFIELD(addr, 7, 8) << 1;
2029 bits |= GET_BITFIELD(addr, 9, 9);
2031 bits = GET_BITFIELD(addr, 6, 8);
2033 if (interleave_mode == 0) {
2034 /* interleave mode will XOR {8,7,6} with {18,17,16} */
2035 idx = GET_BITFIELD(addr, 16, 18);
2040 pkg = sad_pkg(pvt->info.interleave_pkg, reg, idx);
2041 *socket = sad_pkg_socket(pkg);
2042 sad_ha = sad_pkg_ha(pkg);
2047 /* MCChanShiftUpEnable */
2048 pci_read_config_dword(pvt->pci_ha0,
2049 HASWELL_HASYSDEFEATURE2, ®);
2050 shiftup = GET_BITFIELD(reg, 22, 22);
2053 edac_dbg(0, "SAD interleave package: %d = CPU socket %d, HA %i, shiftup: %i\n",
2054 idx, *socket, sad_ha, shiftup);
2056 /* Ivy Bridge's SAD mode doesn't support XOR interleave mode */
2057 idx = (addr >> 6) & 7;
2058 pkg = sad_pkg(pvt->info.interleave_pkg, reg, idx);
2059 *socket = sad_pkg_socket(pkg);
2060 sad_ha = sad_pkg_ha(pkg);
2063 edac_dbg(0, "SAD interleave package: %d = CPU socket %d, HA %d\n",
2064 idx, *socket, sad_ha);
2070 * Move to the proper node structure, in order to access the
2071 * right PCI registers
2073 new_mci = get_mci_for_node_id(*socket);
2075 sprintf(msg, "Struct for socket #%u wasn't initialized",
2080 pvt = mci->pvt_info;
2083 * Step 2) Get memory channel
2086 if (pvt->info.type == SANDY_BRIDGE)
2087 pci_ha = pvt->pci_ha0;
2090 pci_ha = pvt->pci_ha1;
2092 pci_ha = pvt->pci_ha0;
2094 for (n_tads = 0; n_tads < MAX_TAD; n_tads++) {
2095 pci_read_config_dword(pci_ha, tad_dram_rule[n_tads], ®);
2096 limit = TAD_LIMIT(reg);
2098 sprintf(msg, "Can't discover the memory channel");
2105 if (n_tads == MAX_TAD) {
2106 sprintf(msg, "Can't discover the memory channel");
2110 ch_way = TAD_CH(reg) + 1;
2111 sck_way = 1 << TAD_SOCK(reg);
2116 idx = (addr >> (6 + sck_way + shiftup)) & 0x3;
2120 * FIXME: Shouldn't we use CHN_IDX_OFFSET() here, when ch_way == 3 ???
2124 base_ch = TAD_TGT0(reg);
2127 base_ch = TAD_TGT1(reg);
2130 base_ch = TAD_TGT2(reg);
2133 base_ch = TAD_TGT3(reg);
2136 sprintf(msg, "Can't discover the TAD target");
2139 *channel_mask = 1 << base_ch;
2141 pci_read_config_dword(pvt->pci_tad[ch_add + base_ch],
2142 tad_ch_nilv_offset[n_tads],
2145 if (pvt->is_mirrored) {
2146 *channel_mask |= 1 << ((base_ch + 2) % 4);
2150 sck_xch = 1 << sck_way * (ch_way >> 1);
2153 sprintf(msg, "Invalid mirror set. Can't decode addr");
2157 sck_xch = (1 << sck_way) * ch_way;
2159 if (pvt->is_lockstep)
2160 *channel_mask |= 1 << ((base_ch + 1) % 4);
2162 offset = TAD_OFFSET(tad_offset);
2164 edac_dbg(0, "TAD#%d: address 0x%016Lx < 0x%016Lx, socket interleave %d, channel interleave %d (offset 0x%08Lx), index %d, base ch: %d, ch mask: 0x%02lx\n",
2175 /* Calculate channel address */
2176 /* Remove the TAD offset */
2178 if (offset > addr) {
2179 sprintf(msg, "Can't calculate ch addr: TAD offset 0x%08Lx is too high for addr 0x%08Lx!",
2184 ch_addr = addr - offset;
2185 ch_addr >>= (6 + shiftup);
2186 ch_addr /= ch_way * sck_way;
2187 ch_addr <<= (6 + shiftup);
2188 ch_addr |= addr & ((1 << (6 + shiftup)) - 1);
2191 * Step 3) Decode rank
2193 for (n_rir = 0; n_rir < MAX_RIR_RANGES; n_rir++) {
2194 pci_read_config_dword(pvt->pci_tad[ch_add + base_ch],
2195 rir_way_limit[n_rir],
2198 if (!IS_RIR_VALID(reg))
2201 limit = pvt->info.rir_limit(reg);
2202 gb = div_u64_rem(limit >> 20, 1024, &mb);
2203 edac_dbg(0, "RIR#%d, limit: %u.%03u GB (0x%016Lx), way: %d\n",
2208 if (ch_addr <= limit)
2211 if (n_rir == MAX_RIR_RANGES) {
2212 sprintf(msg, "Can't discover the memory rank for ch addr 0x%08Lx",
2216 rir_way = RIR_WAY(reg);
2218 if (pvt->is_close_pg)
2219 idx = (ch_addr >> 6);
2221 idx = (ch_addr >> 13); /* FIXME: Datasheet says to shift by 15 */
2222 idx %= 1 << rir_way;
2224 pci_read_config_dword(pvt->pci_tad[ch_add + base_ch],
2225 rir_offset[n_rir][idx],
2227 *rank = RIR_RNK_TGT(reg);
2229 edac_dbg(0, "RIR#%d: channel address 0x%08Lx < 0x%08Lx, RIR interleave %d, index %d\n",
2239 /****************************************************************************
2240 Device initialization routines: put/get, init/exit
2241 ****************************************************************************/
2244 * sbridge_put_all_devices 'put' all the devices that we have
2245 * reserved via 'get'
2247 static void sbridge_put_devices(struct sbridge_dev *sbridge_dev)
2252 for (i = 0; i < sbridge_dev->n_devs; i++) {
2253 struct pci_dev *pdev = sbridge_dev->pdev[i];
2256 edac_dbg(0, "Removing dev %02x:%02x.%d\n",
2258 PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
2263 static void sbridge_put_all_devices(void)
2265 struct sbridge_dev *sbridge_dev, *tmp;
2267 list_for_each_entry_safe(sbridge_dev, tmp, &sbridge_edac_list, list) {
2268 sbridge_put_devices(sbridge_dev);
2269 free_sbridge_dev(sbridge_dev);
2273 static int sbridge_get_onedevice(struct pci_dev **prev,
2275 const struct pci_id_table *table,
2276 const unsigned devno,
2277 const int multi_bus)
2279 struct sbridge_dev *sbridge_dev;
2280 const struct pci_id_descr *dev_descr = &table->descr[devno];
2281 struct pci_dev *pdev = NULL;
2284 sbridge_printk(KERN_DEBUG,
2285 "Seeking for: PCI ID %04x:%04x\n",
2286 PCI_VENDOR_ID_INTEL, dev_descr->dev_id);
2288 pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
2289 dev_descr->dev_id, *prev);
2297 if (dev_descr->optional)
2300 /* if the HA wasn't found */
2304 sbridge_printk(KERN_INFO,
2305 "Device not found: %04x:%04x\n",
2306 PCI_VENDOR_ID_INTEL, dev_descr->dev_id);
2308 /* End of list, leave */
2311 bus = pdev->bus->number;
2313 sbridge_dev = get_sbridge_dev(bus, multi_bus);
2315 sbridge_dev = alloc_sbridge_dev(bus, table);
2323 if (sbridge_dev->pdev[devno]) {
2324 sbridge_printk(KERN_ERR,
2325 "Duplicated device for %04x:%04x\n",
2326 PCI_VENDOR_ID_INTEL, dev_descr->dev_id);
2331 sbridge_dev->pdev[devno] = pdev;
2333 /* Be sure that the device is enabled */
2334 if (unlikely(pci_enable_device(pdev) < 0)) {
2335 sbridge_printk(KERN_ERR,
2336 "Couldn't enable %04x:%04x\n",
2337 PCI_VENDOR_ID_INTEL, dev_descr->dev_id);
2341 edac_dbg(0, "Detected %04x:%04x\n",
2342 PCI_VENDOR_ID_INTEL, dev_descr->dev_id);
2345 * As stated on drivers/pci/search.c, the reference count for
2346 * @from is always decremented if it is not %NULL. So, as we need
2347 * to get all devices up to null, we need to do a get for the device
2357 * sbridge_get_all_devices - Find and perform 'get' operation on the MCH's
2358 * devices we want to reference for this driver.
2359 * @num_mc: pointer to the memory controllers count, to be incremented in case
2361 * @table: model specific table
2362 * @allow_dups: allow for multiple devices to exist with the same device id
2363 * (as implemented, this isn't expected to work correctly in the
2364 * multi-socket case).
2365 * @multi_bus: don't assume devices on different buses belong to different
2366 * memory controllers.
2368 * returns 0 in case of success or error code
2370 static int sbridge_get_all_devices_full(u8 *num_mc,
2371 const struct pci_id_table *table,
2376 struct pci_dev *pdev = NULL;
2378 while (table && table->descr) {
2379 for (i = 0; i < table->n_devs; i++) {
2380 if (!allow_dups || i == 0 ||
2381 table->descr[i].dev_id !=
2382 table->descr[i-1].dev_id) {
2386 rc = sbridge_get_onedevice(&pdev, num_mc,
2387 table, i, multi_bus);
2393 sbridge_put_all_devices();
2396 } while (pdev && !allow_dups);
2404 #define sbridge_get_all_devices(num_mc, table) \
2405 sbridge_get_all_devices_full(num_mc, table, 0, 0)
2406 #define sbridge_get_all_devices_knl(num_mc, table) \
2407 sbridge_get_all_devices_full(num_mc, table, 1, 1)
2409 static int sbridge_mci_bind_devs(struct mem_ctl_info *mci,
2410 struct sbridge_dev *sbridge_dev)
2412 struct sbridge_pvt *pvt = mci->pvt_info;
2413 struct pci_dev *pdev;
2414 u8 saw_chan_mask = 0;
2417 for (i = 0; i < sbridge_dev->n_devs; i++) {
2418 pdev = sbridge_dev->pdev[i];
2422 switch (pdev->device) {
2423 case PCI_DEVICE_ID_INTEL_SBRIDGE_SAD0:
2424 pvt->pci_sad0 = pdev;
2426 case PCI_DEVICE_ID_INTEL_SBRIDGE_SAD1:
2427 pvt->pci_sad1 = pdev;
2429 case PCI_DEVICE_ID_INTEL_SBRIDGE_BR:
2430 pvt->pci_br0 = pdev;
2432 case PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_HA0:
2433 pvt->pci_ha0 = pdev;
2435 case PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TA:
2438 case PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_RAS:
2439 pvt->pci_ras = pdev;
2441 case PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD0:
2442 case PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD1:
2443 case PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD2:
2444 case PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD3:
2446 int id = pdev->device - PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD0;
2447 pvt->pci_tad[id] = pdev;
2448 saw_chan_mask |= 1 << id;
2451 case PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_DDRIO:
2452 pvt->pci_ddrio = pdev;
2458 edac_dbg(0, "Associated PCI %02x:%02x, bus %d with dev = %p\n",
2459 pdev->vendor, pdev->device,
2464 /* Check if everything were registered */
2465 if (!pvt->pci_sad0 || !pvt->pci_sad1 || !pvt->pci_ha0 ||
2466 !pvt-> pci_tad || !pvt->pci_ras || !pvt->pci_ta)
2469 if (saw_chan_mask != 0x0f)
2474 sbridge_printk(KERN_ERR, "Some needed devices are missing\n");
2478 sbridge_printk(KERN_ERR, "Unexpected device %02x:%02x\n",
2479 PCI_VENDOR_ID_INTEL, pdev->device);
2483 static int ibridge_mci_bind_devs(struct mem_ctl_info *mci,
2484 struct sbridge_dev *sbridge_dev)
2486 struct sbridge_pvt *pvt = mci->pvt_info;
2487 struct pci_dev *pdev;
2488 u8 saw_chan_mask = 0;
2491 for (i = 0; i < sbridge_dev->n_devs; i++) {
2492 pdev = sbridge_dev->pdev[i];
2496 switch (pdev->device) {
2497 case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0:
2498 pvt->pci_ha0 = pdev;
2500 case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TA:
2502 case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_RAS:
2503 pvt->pci_ras = pdev;
2505 case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD0:
2506 case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD1:
2507 case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD2:
2508 case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD3:
2510 int id = pdev->device - PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD0;
2511 pvt->pci_tad[id] = pdev;
2512 saw_chan_mask |= 1 << id;
2515 case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_2HA_DDRIO0:
2516 pvt->pci_ddrio = pdev;
2518 case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_1HA_DDRIO0:
2519 pvt->pci_ddrio = pdev;
2521 case PCI_DEVICE_ID_INTEL_IBRIDGE_SAD:
2522 pvt->pci_sad0 = pdev;
2524 case PCI_DEVICE_ID_INTEL_IBRIDGE_BR0:
2525 pvt->pci_br0 = pdev;
2527 case PCI_DEVICE_ID_INTEL_IBRIDGE_BR1:
2528 pvt->pci_br1 = pdev;
2530 case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1:
2531 pvt->pci_ha1 = pdev;
2533 case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD0:
2534 case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD1:
2535 case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD2:
2536 case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD3:
2538 int id = pdev->device - PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD0 + 4;
2539 pvt->pci_tad[id] = pdev;
2540 saw_chan_mask |= 1 << id;
2547 edac_dbg(0, "Associated PCI %02x.%02d.%d with dev = %p\n",
2549 PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
2553 /* Check if everything were registered */
2554 if (!pvt->pci_sad0 || !pvt->pci_ha0 || !pvt->pci_br0 ||
2555 !pvt->pci_br1 || !pvt->pci_tad || !pvt->pci_ras ||
2559 if (saw_chan_mask != 0x0f && /* -EN */
2560 saw_chan_mask != 0x33 && /* -EP */
2561 saw_chan_mask != 0xff) /* -EX */
2566 sbridge_printk(KERN_ERR, "Some needed devices are missing\n");
2570 sbridge_printk(KERN_ERR,
2571 "Unexpected device %02x:%02x\n", PCI_VENDOR_ID_INTEL,
2576 static int haswell_mci_bind_devs(struct mem_ctl_info *mci,
2577 struct sbridge_dev *sbridge_dev)
2579 struct sbridge_pvt *pvt = mci->pvt_info;
2580 struct pci_dev *pdev;
2581 u8 saw_chan_mask = 0;
2584 /* there's only one device per system; not tied to any bus */
2585 if (pvt->info.pci_vtd == NULL)
2586 /* result will be checked later */
2587 pvt->info.pci_vtd = pci_get_device(PCI_VENDOR_ID_INTEL,
2588 PCI_DEVICE_ID_INTEL_HASWELL_IMC_VTD_MISC,
2591 for (i = 0; i < sbridge_dev->n_devs; i++) {
2592 pdev = sbridge_dev->pdev[i];
2596 switch (pdev->device) {
2597 case PCI_DEVICE_ID_INTEL_HASWELL_IMC_CBO_SAD0:
2598 pvt->pci_sad0 = pdev;
2600 case PCI_DEVICE_ID_INTEL_HASWELL_IMC_CBO_SAD1:
2601 pvt->pci_sad1 = pdev;
2603 case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0:
2604 pvt->pci_ha0 = pdev;
2606 case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TA:
2609 case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_THERMAL:
2610 pvt->pci_ras = pdev;
2612 case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD0:
2613 case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD1:
2614 case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD2:
2615 case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD3:
2617 int id = pdev->device - PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0_TAD0;
2619 pvt->pci_tad[id] = pdev;
2620 saw_chan_mask |= 1 << id;
2623 case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD0:
2624 case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD1:
2625 case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD2:
2626 case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD3:
2628 int id = pdev->device - PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TAD0 + 4;
2630 pvt->pci_tad[id] = pdev;
2631 saw_chan_mask |= 1 << id;
2634 case PCI_DEVICE_ID_INTEL_HASWELL_IMC_DDRIO0:
2635 case PCI_DEVICE_ID_INTEL_HASWELL_IMC_DDRIO1:
2636 case PCI_DEVICE_ID_INTEL_HASWELL_IMC_DDRIO2:
2637 case PCI_DEVICE_ID_INTEL_HASWELL_IMC_DDRIO3:
2638 if (!pvt->pci_ddrio)
2639 pvt->pci_ddrio = pdev;
2641 case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1:
2642 pvt->pci_ha1 = pdev;
2644 case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA1_TA:
2645 pvt->pci_ha1_ta = pdev;
2651 edac_dbg(0, "Associated PCI %02x.%02d.%d with dev = %p\n",
2653 PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
2657 /* Check if everything were registered */
2658 if (!pvt->pci_sad0 || !pvt->pci_ha0 || !pvt->pci_sad1 ||
2659 !pvt->pci_ras || !pvt->pci_ta || !pvt->info.pci_vtd)
2662 if (saw_chan_mask != 0x0f && /* -EN */
2663 saw_chan_mask != 0x33 && /* -EP */
2664 saw_chan_mask != 0xff) /* -EX */
2669 sbridge_printk(KERN_ERR, "Some needed devices are missing\n");
2673 static int broadwell_mci_bind_devs(struct mem_ctl_info *mci,
2674 struct sbridge_dev *sbridge_dev)
2676 struct sbridge_pvt *pvt = mci->pvt_info;
2677 struct pci_dev *pdev;
2678 u8 saw_chan_mask = 0;
2681 /* there's only one device per system; not tied to any bus */
2682 if (pvt->info.pci_vtd == NULL)
2683 /* result will be checked later */
2684 pvt->info.pci_vtd = pci_get_device(PCI_VENDOR_ID_INTEL,
2685 PCI_DEVICE_ID_INTEL_BROADWELL_IMC_VTD_MISC,
2688 for (i = 0; i < sbridge_dev->n_devs; i++) {
2689 pdev = sbridge_dev->pdev[i];
2693 switch (pdev->device) {
2694 case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_CBO_SAD0:
2695 pvt->pci_sad0 = pdev;
2697 case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_CBO_SAD1:
2698 pvt->pci_sad1 = pdev;
2700 case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0:
2701 pvt->pci_ha0 = pdev;
2703 case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TA:
2706 case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_THERMAL:
2707 pvt->pci_ras = pdev;
2709 case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD0:
2710 case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD1:
2711 case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD2:
2712 case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD3:
2714 int id = pdev->device - PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TAD0;
2715 pvt->pci_tad[id] = pdev;
2716 saw_chan_mask |= 1 << id;
2719 case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TAD0:
2720 case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TAD1:
2721 case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TAD2:
2722 case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TAD3:
2724 int id = pdev->device - PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TAD0 + 4;
2725 pvt->pci_tad[id] = pdev;
2726 saw_chan_mask |= 1 << id;
2729 case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_DDRIO0:
2730 pvt->pci_ddrio = pdev;
2732 case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1:
2733 pvt->pci_ha1 = pdev;
2735 case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA1_TA:
2736 pvt->pci_ha1_ta = pdev;
2742 edac_dbg(0, "Associated PCI %02x.%02d.%d with dev = %p\n",
2744 PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
2748 /* Check if everything were registered */
2749 if (!pvt->pci_sad0 || !pvt->pci_ha0 || !pvt->pci_sad1 ||
2750 !pvt->pci_ras || !pvt->pci_ta || !pvt->info.pci_vtd)
2753 if (saw_chan_mask != 0x0f && /* -EN */
2754 saw_chan_mask != 0x33 && /* -EP */
2755 saw_chan_mask != 0xff) /* -EX */
2760 sbridge_printk(KERN_ERR, "Some needed devices are missing\n");
2764 static int knl_mci_bind_devs(struct mem_ctl_info *mci,
2765 struct sbridge_dev *sbridge_dev)
2767 struct sbridge_pvt *pvt = mci->pvt_info;
2768 struct pci_dev *pdev;
2774 for (i = 0; i < sbridge_dev->n_devs; i++) {
2775 pdev = sbridge_dev->pdev[i];
2779 /* Extract PCI device and function. */
2780 dev = (pdev->devfn >> 3) & 0x1f;
2781 func = pdev->devfn & 0x7;
2783 switch (pdev->device) {
2784 case PCI_DEVICE_ID_INTEL_KNL_IMC_MC:
2786 pvt->knl.pci_mc0 = pdev;
2788 pvt->knl.pci_mc1 = pdev;
2790 sbridge_printk(KERN_ERR,
2791 "Memory controller in unexpected place! (dev %d, fn %d)\n",
2797 case PCI_DEVICE_ID_INTEL_KNL_IMC_SAD0:
2798 pvt->pci_sad0 = pdev;
2801 case PCI_DEVICE_ID_INTEL_KNL_IMC_SAD1:
2802 pvt->pci_sad1 = pdev;
2805 case PCI_DEVICE_ID_INTEL_KNL_IMC_CHA:
2806 /* There are one of these per tile, and range from
2809 devidx = ((dev-14)*8)+func;
2811 if (devidx < 0 || devidx >= KNL_MAX_CHAS) {
2812 sbridge_printk(KERN_ERR,
2813 "Caching and Home Agent in unexpected place! (dev %d, fn %d)\n",
2818 WARN_ON(pvt->knl.pci_cha[devidx] != NULL);
2820 pvt->knl.pci_cha[devidx] = pdev;
2823 case PCI_DEVICE_ID_INTEL_KNL_IMC_CHANNEL:
2827 * MC0 channels 0-2 are device 9 function 2-4,
2828 * MC1 channels 3-5 are device 8 function 2-4.
2834 devidx = 3 + (func-2);
2836 if (devidx < 0 || devidx >= KNL_MAX_CHANNELS) {
2837 sbridge_printk(KERN_ERR,
2838 "DRAM Channel Registers in unexpected place! (dev %d, fn %d)\n",
2843 WARN_ON(pvt->knl.pci_channel[devidx] != NULL);
2844 pvt->knl.pci_channel[devidx] = pdev;
2847 case PCI_DEVICE_ID_INTEL_KNL_IMC_TOLHM:
2848 pvt->knl.pci_mc_info = pdev;
2851 case PCI_DEVICE_ID_INTEL_KNL_IMC_TA:
2856 sbridge_printk(KERN_ERR, "Unexpected device %d\n",
2862 if (!pvt->knl.pci_mc0 || !pvt->knl.pci_mc1 ||
2863 !pvt->pci_sad0 || !pvt->pci_sad1 ||
2868 for (i = 0; i < KNL_MAX_CHANNELS; i++) {
2869 if (!pvt->knl.pci_channel[i]) {
2870 sbridge_printk(KERN_ERR, "Missing channel %d\n", i);
2875 for (i = 0; i < KNL_MAX_CHAS; i++) {
2876 if (!pvt->knl.pci_cha[i]) {
2877 sbridge_printk(KERN_ERR, "Missing CHA %d\n", i);
2885 sbridge_printk(KERN_ERR, "Some needed devices are missing\n");
2889 /****************************************************************************
2890 Error check routines
2891 ****************************************************************************/
2894 * While Sandy Bridge has error count registers, SMI BIOS read values from
2895 * and resets the counters. So, they are not reliable for the OS to read
2896 * from them. So, we have no option but to just trust on whatever MCE is
2897 * telling us about the errors.
2899 static void sbridge_mce_output_error(struct mem_ctl_info *mci,
2900 const struct mce *m)
2902 struct mem_ctl_info *new_mci;
2903 struct sbridge_pvt *pvt = mci->pvt_info;
2904 enum hw_event_mc_err_type tp_event;
2905 char *type, *optype, msg[256];
2906 bool ripv = GET_BITFIELD(m->mcgstatus, 0, 0);
2907 bool overflow = GET_BITFIELD(m->status, 62, 62);
2908 bool uncorrected_error = GET_BITFIELD(m->status, 61, 61);
2910 u32 core_err_cnt = GET_BITFIELD(m->status, 38, 52);
2911 u32 mscod = GET_BITFIELD(m->status, 16, 31);
2912 u32 errcode = GET_BITFIELD(m->status, 0, 15);
2913 u32 channel = GET_BITFIELD(m->status, 0, 3);
2914 u32 optypenum = GET_BITFIELD(m->status, 4, 6);
2915 long channel_mask, first_channel;
2916 u8 rank, socket, ha;
2918 char *area_type = NULL;
2920 if (pvt->info.type != SANDY_BRIDGE)
2923 recoverable = GET_BITFIELD(m->status, 56, 56);
2925 if (uncorrected_error) {
2928 tp_event = HW_EVENT_ERR_FATAL;
2931 tp_event = HW_EVENT_ERR_UNCORRECTED;
2935 tp_event = HW_EVENT_ERR_CORRECTED;
2939 * According with Table 15-9 of the Intel Architecture spec vol 3A,
2940 * memory errors should fit in this mask:
2941 * 000f 0000 1mmm cccc (binary)
2943 * f = Correction Report Filtering Bit. If 1, subsequent errors
2947 * If the mask doesn't match, report an error to the parsing logic
2949 if (! ((errcode & 0xef80) == 0x80)) {
2950 optype = "Can't parse: it is not a mem";
2952 switch (optypenum) {
2954 optype = "generic undef request error";
2957 optype = "memory read error";
2960 optype = "memory write error";
2963 optype = "addr/cmd error";
2966 optype = "memory scrubbing error";
2969 optype = "reserved";
2974 /* Only decode errors with an valid address (ADDRV) */
2975 if (!GET_BITFIELD(m->status, 58, 58))
2978 if (pvt->info.type == KNIGHTS_LANDING) {
2979 if (channel == 14) {
2980 edac_dbg(0, "%s%s err_code:%04x:%04x EDRAM bank %d\n",
2981 overflow ? " OVERFLOW" : "",
2982 (uncorrected_error && recoverable)
2983 ? " recoverable" : "",
2989 channel = knl_channel_remap(channel);
2990 channel_mask = 1 << channel;
2991 snprintf(msg, sizeof(msg),
2992 "%s%s err_code:%04x:%04x channel:%d (DIMM_%c)",
2993 overflow ? " OVERFLOW" : "",
2994 (uncorrected_error && recoverable)
2995 ? " recoverable" : " ",
2996 mscod, errcode, channel, A + channel);
2997 edac_mc_handle_error(tp_event, mci, core_err_cnt,
2998 m->addr >> PAGE_SHIFT, m->addr & ~PAGE_MASK, 0,
3004 rc = get_memory_error_data(mci, m->addr, &socket, &ha,
3005 &channel_mask, &rank, &area_type, msg);
3010 new_mci = get_mci_for_node_id(socket);
3012 strcpy(msg, "Error: socket got corrupted!");
3016 pvt = mci->pvt_info;
3018 first_channel = find_first_bit(&channel_mask, NUM_CHANNELS);
3029 * FIXME: On some memory configurations (mirror, lockstep), the
3030 * Memory Controller can't point the error to a single DIMM. The
3031 * EDAC core should be handling the channel mask, in order to point
3032 * to the group of dimm's where the error may be happening.
3034 if (!pvt->is_lockstep && !pvt->is_mirrored && !pvt->is_close_pg)
3035 channel = first_channel;
3037 snprintf(msg, sizeof(msg),
3038 "%s%s area:%s err_code:%04x:%04x socket:%d ha:%d channel_mask:%ld rank:%d",
3039 overflow ? " OVERFLOW" : "",
3040 (uncorrected_error && recoverable) ? " recoverable" : "",
3047 edac_dbg(0, "%s\n", msg);
3049 /* FIXME: need support for channel mask */
3051 if (channel == CHANNEL_UNSPECIFIED)
3054 /* Call the helper to output message */
3055 edac_mc_handle_error(tp_event, mci, core_err_cnt,
3056 m->addr >> PAGE_SHIFT, m->addr & ~PAGE_MASK, 0,
3057 4*ha+channel, dimm, -1,
3061 edac_mc_handle_error(tp_event, mci, core_err_cnt, 0, 0, 0,
3068 * Check that logging is enabled and that this is the right type
3069 * of error for us to handle.
3071 static int sbridge_mce_check_error(struct notifier_block *nb, unsigned long val,
3074 struct mce *mce = (struct mce *)data;
3075 struct mem_ctl_info *mci;
3076 struct sbridge_pvt *pvt;
3079 if (get_edac_report_status() == EDAC_REPORTING_DISABLED)
3082 mci = get_mci_for_node_id(mce->socketid);
3085 pvt = mci->pvt_info;
3088 * Just let mcelog handle it if the error is
3089 * outside the memory controller. A memory error
3090 * is indicated by bit 7 = 1 and bits = 8-11,13-15 = 0.
3091 * bit 12 has an special meaning.
3093 if ((mce->status & 0xefff) >> 7 != 1)
3096 if (mce->mcgstatus & MCG_STATUS_MCIP)
3101 sbridge_mc_printk(mci, KERN_DEBUG, "HANDLING MCE MEMORY ERROR\n");
3103 sbridge_mc_printk(mci, KERN_DEBUG, "CPU %d: Machine Check %s: %Lx "
3104 "Bank %d: %016Lx\n", mce->extcpu, type,
3105 mce->mcgstatus, mce->bank, mce->status);
3106 sbridge_mc_printk(mci, KERN_DEBUG, "TSC %llx ", mce->tsc);
3107 sbridge_mc_printk(mci, KERN_DEBUG, "ADDR %llx ", mce->addr);
3108 sbridge_mc_printk(mci, KERN_DEBUG, "MISC %llx ", mce->misc);
3110 sbridge_mc_printk(mci, KERN_DEBUG, "PROCESSOR %u:%x TIME %llu SOCKET "
3111 "%u APIC %x\n", mce->cpuvendor, mce->cpuid,
3112 mce->time, mce->socketid, mce->apicid);
3114 sbridge_mce_output_error(mci, mce);
3116 /* Advice mcelog that the error were handled */
3120 static struct notifier_block sbridge_mce_dec = {
3121 .notifier_call = sbridge_mce_check_error,
3124 /****************************************************************************
3125 EDAC register/unregister logic
3126 ****************************************************************************/
3128 static void sbridge_unregister_mci(struct sbridge_dev *sbridge_dev)
3130 struct mem_ctl_info *mci = sbridge_dev->mci;
3131 struct sbridge_pvt *pvt;
3133 if (unlikely(!mci || !mci->pvt_info)) {
3134 edac_dbg(0, "MC: dev = %p\n", &sbridge_dev->pdev[0]->dev);
3136 sbridge_printk(KERN_ERR, "Couldn't find mci handler\n");
3140 pvt = mci->pvt_info;
3142 edac_dbg(0, "MC: mci = %p, dev = %p\n",
3143 mci, &sbridge_dev->pdev[0]->dev);
3145 /* Remove MC sysfs nodes */
3146 edac_mc_del_mc(mci->pdev);
3148 edac_dbg(1, "%s: free mci struct\n", mci->ctl_name);
3149 kfree(mci->ctl_name);
3151 sbridge_dev->mci = NULL;
3154 static int sbridge_register_mci(struct sbridge_dev *sbridge_dev, enum type type)
3156 struct mem_ctl_info *mci;
3157 struct edac_mc_layer layers[2];
3158 struct sbridge_pvt *pvt;
3159 struct pci_dev *pdev = sbridge_dev->pdev[0];
3162 /* Check the number of active and not disabled channels */
3163 rc = check_if_ecc_is_active(sbridge_dev->bus, type);
3164 if (unlikely(rc < 0))
3167 /* allocate a new MC control structure */
3168 layers[0].type = EDAC_MC_LAYER_CHANNEL;
3169 layers[0].size = type == KNIGHTS_LANDING ?
3170 KNL_MAX_CHANNELS : NUM_CHANNELS;
3171 layers[0].is_virt_csrow = false;
3172 layers[1].type = EDAC_MC_LAYER_SLOT;
3173 layers[1].size = type == KNIGHTS_LANDING ? 1 : MAX_DIMMS;
3174 layers[1].is_virt_csrow = true;
3175 mci = edac_mc_alloc(sbridge_dev->mc, ARRAY_SIZE(layers), layers,
3181 edac_dbg(0, "MC: mci = %p, dev = %p\n",
3184 pvt = mci->pvt_info;
3185 memset(pvt, 0, sizeof(*pvt));
3187 /* Associate sbridge_dev and mci for future usage */
3188 pvt->sbridge_dev = sbridge_dev;
3189 sbridge_dev->mci = mci;
3191 mci->mtype_cap = type == KNIGHTS_LANDING ?
3192 MEM_FLAG_DDR4 : MEM_FLAG_DDR3;
3193 mci->edac_ctl_cap = EDAC_FLAG_NONE;
3194 mci->edac_cap = EDAC_FLAG_NONE;
3195 mci->mod_name = "sbridge_edac.c";
3196 mci->mod_ver = SBRIDGE_REVISION;
3197 mci->dev_name = pci_name(pdev);
3198 mci->ctl_page_to_phys = NULL;
3200 pvt->info.type = type;
3203 pvt->info.rankcfgr = IB_RANK_CFG_A;
3204 pvt->info.get_tolm = ibridge_get_tolm;
3205 pvt->info.get_tohm = ibridge_get_tohm;
3206 pvt->info.dram_rule = ibridge_dram_rule;
3207 pvt->info.get_memory_type = get_memory_type;
3208 pvt->info.get_node_id = get_node_id;
3209 pvt->info.rir_limit = rir_limit;
3210 pvt->info.sad_limit = sad_limit;
3211 pvt->info.interleave_mode = interleave_mode;
3212 pvt->info.show_interleave_mode = show_interleave_mode;
3213 pvt->info.dram_attr = dram_attr;
3214 pvt->info.max_sad = ARRAY_SIZE(ibridge_dram_rule);
3215 pvt->info.interleave_list = ibridge_interleave_list;
3216 pvt->info.max_interleave = ARRAY_SIZE(ibridge_interleave_list);
3217 pvt->info.interleave_pkg = ibridge_interleave_pkg;
3218 pvt->info.get_width = ibridge_get_width;
3219 mci->ctl_name = kasprintf(GFP_KERNEL, "Ivy Bridge Socket#%d", mci->mc_idx);
3221 /* Store pci devices at mci for faster access */
3222 rc = ibridge_mci_bind_devs(mci, sbridge_dev);
3223 if (unlikely(rc < 0))
3227 pvt->info.rankcfgr = SB_RANK_CFG_A;
3228 pvt->info.get_tolm = sbridge_get_tolm;
3229 pvt->info.get_tohm = sbridge_get_tohm;
3230 pvt->info.dram_rule = sbridge_dram_rule;
3231 pvt->info.get_memory_type = get_memory_type;
3232 pvt->info.get_node_id = get_node_id;
3233 pvt->info.rir_limit = rir_limit;
3234 pvt->info.sad_limit = sad_limit;
3235 pvt->info.interleave_mode = interleave_mode;
3236 pvt->info.show_interleave_mode = show_interleave_mode;
3237 pvt->info.dram_attr = dram_attr;
3238 pvt->info.max_sad = ARRAY_SIZE(sbridge_dram_rule);
3239 pvt->info.interleave_list = sbridge_interleave_list;
3240 pvt->info.max_interleave = ARRAY_SIZE(sbridge_interleave_list);
3241 pvt->info.interleave_pkg = sbridge_interleave_pkg;
3242 pvt->info.get_width = sbridge_get_width;
3243 mci->ctl_name = kasprintf(GFP_KERNEL, "Sandy Bridge Socket#%d", mci->mc_idx);
3245 /* Store pci devices at mci for faster access */
3246 rc = sbridge_mci_bind_devs(mci, sbridge_dev);
3247 if (unlikely(rc < 0))
3251 /* rankcfgr isn't used */
3252 pvt->info.get_tolm = haswell_get_tolm;
3253 pvt->info.get_tohm = haswell_get_tohm;
3254 pvt->info.dram_rule = ibridge_dram_rule;
3255 pvt->info.get_memory_type = haswell_get_memory_type;
3256 pvt->info.get_node_id = haswell_get_node_id;
3257 pvt->info.rir_limit = haswell_rir_limit;
3258 pvt->info.sad_limit = sad_limit;
3259 pvt->info.interleave_mode = interleave_mode;
3260 pvt->info.show_interleave_mode = show_interleave_mode;
3261 pvt->info.dram_attr = dram_attr;
3262 pvt->info.max_sad = ARRAY_SIZE(ibridge_dram_rule);
3263 pvt->info.interleave_list = ibridge_interleave_list;
3264 pvt->info.max_interleave = ARRAY_SIZE(ibridge_interleave_list);
3265 pvt->info.interleave_pkg = ibridge_interleave_pkg;
3266 pvt->info.get_width = ibridge_get_width;
3267 mci->ctl_name = kasprintf(GFP_KERNEL, "Haswell Socket#%d", mci->mc_idx);
3269 /* Store pci devices at mci for faster access */
3270 rc = haswell_mci_bind_devs(mci, sbridge_dev);
3271 if (unlikely(rc < 0))
3275 /* rankcfgr isn't used */
3276 pvt->info.get_tolm = haswell_get_tolm;
3277 pvt->info.get_tohm = haswell_get_tohm;
3278 pvt->info.dram_rule = ibridge_dram_rule;
3279 pvt->info.get_memory_type = haswell_get_memory_type;
3280 pvt->info.get_node_id = haswell_get_node_id;
3281 pvt->info.rir_limit = haswell_rir_limit;
3282 pvt->info.sad_limit = sad_limit;
3283 pvt->info.interleave_mode = interleave_mode;
3284 pvt->info.show_interleave_mode = show_interleave_mode;
3285 pvt->info.dram_attr = dram_attr;
3286 pvt->info.max_sad = ARRAY_SIZE(ibridge_dram_rule);
3287 pvt->info.interleave_list = ibridge_interleave_list;
3288 pvt->info.max_interleave = ARRAY_SIZE(ibridge_interleave_list);
3289 pvt->info.interleave_pkg = ibridge_interleave_pkg;
3290 pvt->info.get_width = broadwell_get_width;
3291 mci->ctl_name = kasprintf(GFP_KERNEL, "Broadwell Socket#%d", mci->mc_idx);
3293 /* Store pci devices at mci for faster access */
3294 rc = broadwell_mci_bind_devs(mci, sbridge_dev);
3295 if (unlikely(rc < 0))
3298 case KNIGHTS_LANDING:
3299 /* pvt->info.rankcfgr == ??? */
3300 pvt->info.get_tolm = knl_get_tolm;
3301 pvt->info.get_tohm = knl_get_tohm;
3302 pvt->info.dram_rule = knl_dram_rule;
3303 pvt->info.get_memory_type = knl_get_memory_type;
3304 pvt->info.get_node_id = knl_get_node_id;
3305 pvt->info.rir_limit = NULL;
3306 pvt->info.sad_limit = knl_sad_limit;
3307 pvt->info.interleave_mode = knl_interleave_mode;
3308 pvt->info.show_interleave_mode = knl_show_interleave_mode;
3309 pvt->info.dram_attr = dram_attr_knl;
3310 pvt->info.max_sad = ARRAY_SIZE(knl_dram_rule);
3311 pvt->info.interleave_list = knl_interleave_list;
3312 pvt->info.max_interleave = ARRAY_SIZE(knl_interleave_list);
3313 pvt->info.interleave_pkg = ibridge_interleave_pkg;
3314 pvt->info.get_width = knl_get_width;
3315 mci->ctl_name = kasprintf(GFP_KERNEL,
3316 "Knights Landing Socket#%d", mci->mc_idx);
3318 rc = knl_mci_bind_devs(mci, sbridge_dev);
3319 if (unlikely(rc < 0))
3324 /* Get dimm basic config and the memory layout */
3325 get_dimm_config(mci);
3326 get_memory_layout(mci);
3328 /* record ptr to the generic device */
3329 mci->pdev = &pdev->dev;
3331 /* add this new MC control structure to EDAC's list of MCs */
3332 if (unlikely(edac_mc_add_mc(mci))) {
3333 edac_dbg(0, "MC: failed edac_mc_add_mc()\n");
3341 kfree(mci->ctl_name);
3343 sbridge_dev->mci = NULL;
3348 * sbridge_probe Probe for ONE instance of device to see if it is
3351 * 0 for FOUND a device
3352 * < 0 for error code
3355 static int sbridge_probe(struct pci_dev *pdev, const struct pci_device_id *id)
3359 struct sbridge_dev *sbridge_dev;
3360 enum type type = SANDY_BRIDGE;
3362 /* get the pci devices we want to reserve for our use */
3363 mutex_lock(&sbridge_edac_lock);
3366 * All memory controllers are allocated at the first pass.
3368 if (unlikely(probed >= 1)) {
3369 mutex_unlock(&sbridge_edac_lock);
3374 switch (pdev->device) {
3375 case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TA:
3376 rc = sbridge_get_all_devices(&num_mc,
3377 pci_dev_descr_ibridge_table);
3380 case PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_HA0:
3381 rc = sbridge_get_all_devices(&num_mc,
3382 pci_dev_descr_sbridge_table);
3383 type = SANDY_BRIDGE;
3385 case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0:
3386 rc = sbridge_get_all_devices(&num_mc,
3387 pci_dev_descr_haswell_table);
3390 case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0:
3391 rc = sbridge_get_all_devices(&num_mc,
3392 pci_dev_descr_broadwell_table);
3395 case PCI_DEVICE_ID_INTEL_KNL_IMC_SAD0:
3396 rc = sbridge_get_all_devices_knl(&num_mc,
3397 pci_dev_descr_knl_table);
3398 type = KNIGHTS_LANDING;
3401 if (unlikely(rc < 0)) {
3402 edac_dbg(0, "couldn't get all devices for 0x%x\n", pdev->device);
3408 list_for_each_entry(sbridge_dev, &sbridge_edac_list, list) {
3409 edac_dbg(0, "Registering MC#%d (%d of %d)\n",
3410 mc, mc + 1, num_mc);
3412 sbridge_dev->mc = mc++;
3413 rc = sbridge_register_mci(sbridge_dev, type);
3414 if (unlikely(rc < 0))
3418 sbridge_printk(KERN_INFO, "%s\n", SBRIDGE_REVISION);
3420 mutex_unlock(&sbridge_edac_lock);
3424 list_for_each_entry(sbridge_dev, &sbridge_edac_list, list)
3425 sbridge_unregister_mci(sbridge_dev);
3427 sbridge_put_all_devices();
3429 mutex_unlock(&sbridge_edac_lock);
3434 * sbridge_remove destructor for one instance of device
3437 static void sbridge_remove(struct pci_dev *pdev)
3439 struct sbridge_dev *sbridge_dev;
3444 * we have a trouble here: pdev value for removal will be wrong, since
3445 * it will point to the X58 register used to detect that the machine
3446 * is a Nehalem or upper design. However, due to the way several PCI
3447 * devices are grouped together to provide MC functionality, we need
3448 * to use a different method for releasing the devices
3451 mutex_lock(&sbridge_edac_lock);
3453 if (unlikely(!probed)) {
3454 mutex_unlock(&sbridge_edac_lock);
3458 list_for_each_entry(sbridge_dev, &sbridge_edac_list, list)
3459 sbridge_unregister_mci(sbridge_dev);
3461 /* Release PCI resources */
3462 sbridge_put_all_devices();
3466 mutex_unlock(&sbridge_edac_lock);
3469 MODULE_DEVICE_TABLE(pci, sbridge_pci_tbl);
3472 * sbridge_driver pci_driver structure for this module
3475 static struct pci_driver sbridge_driver = {
3476 .name = "sbridge_edac",
3477 .probe = sbridge_probe,
3478 .remove = sbridge_remove,
3479 .id_table = sbridge_pci_tbl,
3483 * sbridge_init Module entry function
3484 * Try to initialize this module for its devices
3486 static int __init sbridge_init(void)
3492 /* Ensure that the OPSTATE is set correctly for POLL or NMI */
3495 pci_rc = pci_register_driver(&sbridge_driver);
3497 mce_register_decode_chain(&sbridge_mce_dec);
3498 if (get_edac_report_status() == EDAC_REPORTING_DISABLED)
3499 sbridge_printk(KERN_WARNING, "Loading driver, error reporting disabled.\n");
3503 sbridge_printk(KERN_ERR, "Failed to register device with error %d.\n",
3510 * sbridge_exit() Module exit function
3511 * Unregister the driver
3513 static void __exit sbridge_exit(void)
3516 pci_unregister_driver(&sbridge_driver);
3517 mce_unregister_decode_chain(&sbridge_mce_dec);
3520 module_init(sbridge_init);
3521 module_exit(sbridge_exit);
3523 module_param(edac_op_state, int, 0444);
3524 MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");
3526 MODULE_LICENSE("GPL");
3527 MODULE_AUTHOR("Mauro Carvalho Chehab");
3528 MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)");
3529 MODULE_DESCRIPTION("MC Driver for Intel Sandy Bridge and Ivy Bridge memory controllers - "