i7300_edac.c 27 KB

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