i7300_edac.c 33 KB

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