edac_core.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. /*
  2. * Defines, structures, APIs for edac_core module
  3. *
  4. * (C) 2007 Linux Networx (http://lnxi.com)
  5. * This file may be distributed under the terms of the
  6. * GNU General Public License.
  7. *
  8. * Written by Thayne Harbaugh
  9. * Based on work by Dan Hollis <goemon at anime dot net> and others.
  10. * http://www.anime.net/~goemon/linux-ecc/
  11. *
  12. * NMI handling support added by
  13. * Dave Peterson <dsp@llnl.gov> <dave_peterson@pobox.com>
  14. *
  15. * Refactored for multi-source files:
  16. * Doug Thompson <norsk5@xmission.com>
  17. *
  18. */
  19. #ifndef _EDAC_CORE_H_
  20. #define _EDAC_CORE_H_
  21. #include <linux/kernel.h>
  22. #include <linux/types.h>
  23. #include <linux/module.h>
  24. #include <linux/spinlock.h>
  25. #include <linux/smp.h>
  26. #include <linux/pci.h>
  27. #include <linux/time.h>
  28. #include <linux/nmi.h>
  29. #include <linux/rcupdate.h>
  30. #include <linux/completion.h>
  31. #include <linux/kobject.h>
  32. #include <linux/platform_device.h>
  33. #include <linux/sysdev.h>
  34. #include <linux/workqueue.h>
  35. #include <linux/version.h>
  36. #define EDAC_MC_LABEL_LEN 31
  37. #define EDAC_DEVICE_NAME_LEN 31
  38. #define EDAC_ATTRIB_VALUE_LEN 15
  39. #define MC_PROC_NAME_MAX_LEN 7
  40. #if PAGE_SHIFT < 20
  41. #define PAGES_TO_MiB( pages ) ( ( pages ) >> ( 20 - PAGE_SHIFT ) )
  42. #else /* PAGE_SHIFT > 20 */
  43. #define PAGES_TO_MiB( pages ) ( ( pages ) << ( PAGE_SHIFT - 20 ) )
  44. #endif
  45. #define edac_printk(level, prefix, fmt, arg...) \
  46. printk(level "EDAC " prefix ": " fmt, ##arg)
  47. #define edac_mc_printk(mci, level, fmt, arg...) \
  48. printk(level "EDAC MC%d: " fmt, mci->mc_idx, ##arg)
  49. #define edac_mc_chipset_printk(mci, level, prefix, fmt, arg...) \
  50. printk(level "EDAC " prefix " MC%d: " fmt, mci->mc_idx, ##arg)
  51. /* edac_device printk */
  52. #define edac_device_printk(ctl, level, fmt, arg...) \
  53. printk(level "EDAC DEVICE%d: " fmt, ctl->dev_idx, ##arg)
  54. /* prefixes for edac_printk() and edac_mc_printk() */
  55. #define EDAC_MC "MC"
  56. #define EDAC_PCI "PCI"
  57. #define EDAC_DEBUG "DEBUG"
  58. #ifdef CONFIG_EDAC_DEBUG
  59. extern int edac_debug_level;
  60. #define edac_debug_printk(level, fmt, arg...) \
  61. do { \
  62. if (level <= edac_debug_level) \
  63. edac_printk(KERN_EMERG, EDAC_DEBUG, fmt, ##arg); \
  64. } while(0)
  65. #define debugf0( ... ) edac_debug_printk(0, __VA_ARGS__ )
  66. #define debugf1( ... ) edac_debug_printk(1, __VA_ARGS__ )
  67. #define debugf2( ... ) edac_debug_printk(2, __VA_ARGS__ )
  68. #define debugf3( ... ) edac_debug_printk(3, __VA_ARGS__ )
  69. #define debugf4( ... ) edac_debug_printk(4, __VA_ARGS__ )
  70. #else /* !CONFIG_EDAC_DEBUG */
  71. #define debugf0( ... )
  72. #define debugf1( ... )
  73. #define debugf2( ... )
  74. #define debugf3( ... )
  75. #define debugf4( ... )
  76. #endif /* !CONFIG_EDAC_DEBUG */
  77. #define BIT(x) (1 << (x))
  78. #define PCI_VEND_DEV(vend, dev) PCI_VENDOR_ID_ ## vend, \
  79. PCI_DEVICE_ID_ ## vend ## _ ## dev
  80. #define dev_name(dev) (dev)->dev_name
  81. /* memory devices */
  82. enum dev_type {
  83. DEV_UNKNOWN = 0,
  84. DEV_X1,
  85. DEV_X2,
  86. DEV_X4,
  87. DEV_X8,
  88. DEV_X16,
  89. DEV_X32, /* Do these parts exist? */
  90. DEV_X64 /* Do these parts exist? */
  91. };
  92. #define DEV_FLAG_UNKNOWN BIT(DEV_UNKNOWN)
  93. #define DEV_FLAG_X1 BIT(DEV_X1)
  94. #define DEV_FLAG_X2 BIT(DEV_X2)
  95. #define DEV_FLAG_X4 BIT(DEV_X4)
  96. #define DEV_FLAG_X8 BIT(DEV_X8)
  97. #define DEV_FLAG_X16 BIT(DEV_X16)
  98. #define DEV_FLAG_X32 BIT(DEV_X32)
  99. #define DEV_FLAG_X64 BIT(DEV_X64)
  100. /* memory types */
  101. enum mem_type {
  102. MEM_EMPTY = 0, /* Empty csrow */
  103. MEM_RESERVED, /* Reserved csrow type */
  104. MEM_UNKNOWN, /* Unknown csrow type */
  105. MEM_FPM, /* Fast page mode */
  106. MEM_EDO, /* Extended data out */
  107. MEM_BEDO, /* Burst Extended data out */
  108. MEM_SDR, /* Single data rate SDRAM */
  109. MEM_RDR, /* Registered single data rate SDRAM */
  110. MEM_DDR, /* Double data rate SDRAM */
  111. MEM_RDDR, /* Registered Double data rate SDRAM */
  112. MEM_RMBS, /* Rambus DRAM */
  113. MEM_DDR2, /* DDR2 RAM */
  114. MEM_FB_DDR2, /* fully buffered DDR2 */
  115. MEM_RDDR2, /* Registered DDR2 RAM */
  116. };
  117. #define MEM_FLAG_EMPTY BIT(MEM_EMPTY)
  118. #define MEM_FLAG_RESERVED BIT(MEM_RESERVED)
  119. #define MEM_FLAG_UNKNOWN BIT(MEM_UNKNOWN)
  120. #define MEM_FLAG_FPM BIT(MEM_FPM)
  121. #define MEM_FLAG_EDO BIT(MEM_EDO)
  122. #define MEM_FLAG_BEDO BIT(MEM_BEDO)
  123. #define MEM_FLAG_SDR BIT(MEM_SDR)
  124. #define MEM_FLAG_RDR BIT(MEM_RDR)
  125. #define MEM_FLAG_DDR BIT(MEM_DDR)
  126. #define MEM_FLAG_RDDR BIT(MEM_RDDR)
  127. #define MEM_FLAG_RMBS BIT(MEM_RMBS)
  128. #define MEM_FLAG_DDR2 BIT(MEM_DDR2)
  129. #define MEM_FLAG_FB_DDR2 BIT(MEM_FB_DDR2)
  130. #define MEM_FLAG_RDDR2 BIT(MEM_RDDR2)
  131. /* chipset Error Detection and Correction capabilities and mode */
  132. enum edac_type {
  133. EDAC_UNKNOWN = 0, /* Unknown if ECC is available */
  134. EDAC_NONE, /* Doesnt support ECC */
  135. EDAC_RESERVED, /* Reserved ECC type */
  136. EDAC_PARITY, /* Detects parity errors */
  137. EDAC_EC, /* Error Checking - no correction */
  138. EDAC_SECDED, /* Single bit error correction, Double detection */
  139. EDAC_S2ECD2ED, /* Chipkill x2 devices - do these exist? */
  140. EDAC_S4ECD4ED, /* Chipkill x4 devices */
  141. EDAC_S8ECD8ED, /* Chipkill x8 devices */
  142. EDAC_S16ECD16ED, /* Chipkill x16 devices */
  143. };
  144. #define EDAC_FLAG_UNKNOWN BIT(EDAC_UNKNOWN)
  145. #define EDAC_FLAG_NONE BIT(EDAC_NONE)
  146. #define EDAC_FLAG_PARITY BIT(EDAC_PARITY)
  147. #define EDAC_FLAG_EC BIT(EDAC_EC)
  148. #define EDAC_FLAG_SECDED BIT(EDAC_SECDED)
  149. #define EDAC_FLAG_S2ECD2ED BIT(EDAC_S2ECD2ED)
  150. #define EDAC_FLAG_S4ECD4ED BIT(EDAC_S4ECD4ED)
  151. #define EDAC_FLAG_S8ECD8ED BIT(EDAC_S8ECD8ED)
  152. #define EDAC_FLAG_S16ECD16ED BIT(EDAC_S16ECD16ED)
  153. /* scrubbing capabilities */
  154. enum scrub_type {
  155. SCRUB_UNKNOWN = 0, /* Unknown if scrubber is available */
  156. SCRUB_NONE, /* No scrubber */
  157. SCRUB_SW_PROG, /* SW progressive (sequential) scrubbing */
  158. SCRUB_SW_SRC, /* Software scrub only errors */
  159. SCRUB_SW_PROG_SRC, /* Progressive software scrub from an error */
  160. SCRUB_SW_TUNABLE, /* Software scrub frequency is tunable */
  161. SCRUB_HW_PROG, /* HW progressive (sequential) scrubbing */
  162. SCRUB_HW_SRC, /* Hardware scrub only errors */
  163. SCRUB_HW_PROG_SRC, /* Progressive hardware scrub from an error */
  164. SCRUB_HW_TUNABLE /* Hardware scrub frequency is tunable */
  165. };
  166. #define SCRUB_FLAG_SW_PROG BIT(SCRUB_SW_PROG)
  167. #define SCRUB_FLAG_SW_SRC BIT(SCRUB_SW_SRC)
  168. #define SCRUB_FLAG_SW_PROG_SRC BIT(SCRUB_SW_PROG_SRC)
  169. #define SCRUB_FLAG_SW_TUN BIT(SCRUB_SW_SCRUB_TUNABLE)
  170. #define SCRUB_FLAG_HW_PROG BIT(SCRUB_HW_PROG)
  171. #define SCRUB_FLAG_HW_SRC BIT(SCRUB_HW_SRC)
  172. #define SCRUB_FLAG_HW_PROG_SRC BIT(SCRUB_HW_PROG_SRC)
  173. #define SCRUB_FLAG_HW_TUN BIT(SCRUB_HW_TUNABLE)
  174. /* FIXME - should have notify capabilities: NMI, LOG, PROC, etc */
  175. extern char * edac_align_ptr(void *ptr, unsigned size);
  176. /*
  177. * There are several things to be aware of that aren't at all obvious:
  178. *
  179. *
  180. * SOCKETS, SOCKET SETS, BANKS, ROWS, CHIP-SELECT ROWS, CHANNELS, etc..
  181. *
  182. * These are some of the many terms that are thrown about that don't always
  183. * mean what people think they mean (Inconceivable!). In the interest of
  184. * creating a common ground for discussion, terms and their definitions
  185. * will be established.
  186. *
  187. * Memory devices: The individual chip on a memory stick. These devices
  188. * commonly output 4 and 8 bits each. Grouping several
  189. * of these in parallel provides 64 bits which is common
  190. * for a memory stick.
  191. *
  192. * Memory Stick: A printed circuit board that agregates multiple
  193. * memory devices in parallel. This is the atomic
  194. * memory component that is purchaseable by Joe consumer
  195. * and loaded into a memory socket.
  196. *
  197. * Socket: A physical connector on the motherboard that accepts
  198. * a single memory stick.
  199. *
  200. * Channel: Set of memory devices on a memory stick that must be
  201. * grouped in parallel with one or more additional
  202. * channels from other memory sticks. This parallel
  203. * grouping of the output from multiple channels are
  204. * necessary for the smallest granularity of memory access.
  205. * Some memory controllers are capable of single channel -
  206. * which means that memory sticks can be loaded
  207. * individually. Other memory controllers are only
  208. * capable of dual channel - which means that memory
  209. * sticks must be loaded as pairs (see "socket set").
  210. *
  211. * Chip-select row: All of the memory devices that are selected together.
  212. * for a single, minimum grain of memory access.
  213. * This selects all of the parallel memory devices across
  214. * all of the parallel channels. Common chip-select rows
  215. * for single channel are 64 bits, for dual channel 128
  216. * bits.
  217. *
  218. * Single-Ranked stick: A Single-ranked stick has 1 chip-select row of memmory.
  219. * Motherboards commonly drive two chip-select pins to
  220. * a memory stick. A single-ranked stick, will occupy
  221. * only one of those rows. The other will be unused.
  222. *
  223. * Double-Ranked stick: A double-ranked stick has two chip-select rows which
  224. * access different sets of memory devices. The two
  225. * rows cannot be accessed concurrently.
  226. *
  227. * Double-sided stick: DEPRECATED TERM, see Double-Ranked stick.
  228. * A double-sided stick has two chip-select rows which
  229. * access different sets of memory devices. The two
  230. * rows cannot be accessed concurrently. "Double-sided"
  231. * is irrespective of the memory devices being mounted
  232. * on both sides of the memory stick.
  233. *
  234. * Socket set: All of the memory sticks that are required for for
  235. * a single memory access or all of the memory sticks
  236. * spanned by a chip-select row. A single socket set
  237. * has two chip-select rows and if double-sided sticks
  238. * are used these will occupy those chip-select rows.
  239. *
  240. * Bank: This term is avoided because it is unclear when
  241. * needing to distinguish between chip-select rows and
  242. * socket sets.
  243. *
  244. * Controller pages:
  245. *
  246. * Physical pages:
  247. *
  248. * Virtual pages:
  249. *
  250. *
  251. * STRUCTURE ORGANIZATION AND CHOICES
  252. *
  253. *
  254. *
  255. * PS - I enjoyed writing all that about as much as you enjoyed reading it.
  256. */
  257. struct channel_info {
  258. int chan_idx; /* channel index */
  259. u32 ce_count; /* Correctable Errors for this CHANNEL */
  260. char label[EDAC_MC_LABEL_LEN + 1]; /* DIMM label on motherboard */
  261. struct csrow_info *csrow; /* the parent */
  262. };
  263. struct csrow_info {
  264. unsigned long first_page; /* first page number in dimm */
  265. unsigned long last_page; /* last page number in dimm */
  266. unsigned long page_mask; /* used for interleaving -
  267. * 0UL for non intlv
  268. */
  269. u32 nr_pages; /* number of pages in csrow */
  270. u32 grain; /* granularity of reported error in bytes */
  271. int csrow_idx; /* the chip-select row */
  272. enum dev_type dtype; /* memory device type */
  273. u32 ue_count; /* Uncorrectable Errors for this csrow */
  274. u32 ce_count; /* Correctable Errors for this csrow */
  275. enum mem_type mtype; /* memory csrow type */
  276. enum edac_type edac_mode; /* EDAC mode for this csrow */
  277. struct mem_ctl_info *mci; /* the parent */
  278. struct kobject kobj; /* sysfs kobject for this csrow */
  279. struct completion kobj_complete;
  280. /* FIXME the number of CHANNELs might need to become dynamic */
  281. u32 nr_channels;
  282. struct channel_info *channels;
  283. };
  284. struct mem_ctl_info {
  285. struct list_head link; /* for global list of mem_ctl_info structs */
  286. unsigned long mtype_cap; /* memory types supported by mc */
  287. unsigned long edac_ctl_cap; /* Mem controller EDAC capabilities */
  288. unsigned long edac_cap; /* configuration capabilities - this is
  289. * closely related to edac_ctl_cap. The
  290. * difference is that the controller may be
  291. * capable of s4ecd4ed which would be listed
  292. * in edac_ctl_cap, but if channels aren't
  293. * capable of s4ecd4ed then the edac_cap would
  294. * not have that capability.
  295. */
  296. unsigned long scrub_cap; /* chipset scrub capabilities */
  297. enum scrub_type scrub_mode; /* current scrub mode */
  298. /* Translates sdram memory scrub rate given in bytes/sec to the
  299. internal representation and configures whatever else needs
  300. to be configured.
  301. */
  302. int (*set_sdram_scrub_rate) (struct mem_ctl_info *mci, u32 *bw);
  303. /* Get the current sdram memory scrub rate from the internal
  304. representation and converts it to the closest matching
  305. bandwith in bytes/sec.
  306. */
  307. int (*get_sdram_scrub_rate) (struct mem_ctl_info *mci, u32 *bw);
  308. /* pointer to edac checking routine */
  309. void (*edac_check) (struct mem_ctl_info * mci);
  310. /*
  311. * Remaps memory pages: controller pages to physical pages.
  312. * For most MC's, this will be NULL.
  313. */
  314. /* FIXME - why not send the phys page to begin with? */
  315. unsigned long (*ctl_page_to_phys) (struct mem_ctl_info * mci,
  316. unsigned long page);
  317. int mc_idx;
  318. int nr_csrows;
  319. struct csrow_info *csrows;
  320. /*
  321. * FIXME - what about controllers on other busses? - IDs must be
  322. * unique. dev pointer should be sufficiently unique, but
  323. * BUS:SLOT.FUNC numbers may not be unique.
  324. */
  325. struct device *dev;
  326. const char *mod_name;
  327. const char *mod_ver;
  328. const char *ctl_name;
  329. const char *dev_name;
  330. char proc_name[MC_PROC_NAME_MAX_LEN + 1];
  331. void *pvt_info;
  332. u32 ue_noinfo_count; /* Uncorrectable Errors w/o info */
  333. u32 ce_noinfo_count; /* Correctable Errors w/o info */
  334. u32 ue_count; /* Total Uncorrectable Errors for this MC */
  335. u32 ce_count; /* Total Correctable Errors for this MC */
  336. unsigned long start_time; /* mci load start time (in jiffies) */
  337. /* this stuff is for safe removal of mc devices from global list while
  338. * NMI handlers may be traversing list
  339. */
  340. struct rcu_head rcu;
  341. struct completion complete;
  342. /* edac sysfs device control */
  343. struct kobject edac_mci_kobj;
  344. struct completion kobj_complete;
  345. };
  346. /*
  347. * The following are the structures to provide for a generice
  348. * or abstract 'edac_device'. This set of structures and the
  349. * code that implements the APIs for the same, provide for
  350. * registering EDAC type devices which are NOT standard memory.
  351. *
  352. * CPU caches (L1 and L2)
  353. * DMA engines
  354. * Core CPU swithces
  355. * Fabric switch units
  356. * PCIe interface controllers
  357. * other EDAC/ECC type devices that can be monitored for
  358. * errors, etc.
  359. *
  360. * It allows for a 2 level set of hiearchry. For example:
  361. *
  362. * cache could be composed of L1, L2 and L3 levels of cache.
  363. * Each CPU core would have its own L1 cache, while sharing
  364. * L2 and maybe L3 caches.
  365. *
  366. * View them arranged, via the sysfs presentation:
  367. * /sys/devices/system/edac/..
  368. *
  369. * mc/ <existing memory device directory>
  370. * cpu/cpu0/.. <L1 and L2 block directory>
  371. * /L1-cache/ce_count
  372. * /ue_count
  373. * /L2-cache/ce_count
  374. * /ue_count
  375. * cpu/cpu1/.. <L1 and L2 block directory>
  376. * /L1-cache/ce_count
  377. * /ue_count
  378. * /L2-cache/ce_count
  379. * /ue_count
  380. * ...
  381. *
  382. * the L1 and L2 directories would be "edac_device_block's"
  383. */
  384. struct edac_device_counter {
  385. u32 ue_count;
  386. u32 ce_count;
  387. };
  388. #define INC_COUNTER(cnt) (cnt++)
  389. /*
  390. * An array of these is passed to the alloc() function
  391. * to specify attributes of the edac_block
  392. */
  393. struct edac_attrib_spec {
  394. char name[EDAC_DEVICE_NAME_LEN + 1];
  395. int type;
  396. #define EDAC_ATTR_INT 0x01
  397. #define EDAC_ATTR_CHAR 0x02
  398. };
  399. /* Attribute control structure
  400. * In this structure is a pointer to the driver's edac_attrib_spec
  401. * The life of this pointer is inclusive in the life of the driver's
  402. * life cycle.
  403. */
  404. struct edac_attrib {
  405. struct edac_device_block *block; /* Up Pointer */
  406. struct edac_attrib_spec *spec; /* ptr to module spec entry */
  407. union { /* actual value */
  408. int edac_attrib_int_value;
  409. char edac_attrib_char_value[EDAC_ATTRIB_VALUE_LEN + 1];
  410. } edac_attrib_value;
  411. };
  412. /* device block control structure */
  413. struct edac_device_block {
  414. struct edac_device_instance *instance; /* Up Pointer */
  415. char name[EDAC_DEVICE_NAME_LEN + 1];
  416. struct edac_device_counter counters; /* basic UE and CE counters */
  417. int nr_attribs; /* how many attributes */
  418. struct edac_attrib *attribs; /* this block's attributes */
  419. /* edac sysfs device control */
  420. struct kobject kobj;
  421. struct completion kobj_complete;
  422. };
  423. /* device instance control structure */
  424. struct edac_device_instance {
  425. struct edac_device_ctl_info *ctl; /* Up pointer */
  426. char name[EDAC_DEVICE_NAME_LEN + 4];
  427. struct edac_device_counter counters; /* instance counters */
  428. u32 nr_blocks; /* how many blocks */
  429. struct edac_device_block *blocks; /* block array */
  430. /* edac sysfs device control */
  431. struct kobject kobj;
  432. struct completion kobj_complete;
  433. };
  434. /*
  435. * Abstract edac_device control info structure
  436. *
  437. */
  438. struct edac_device_ctl_info {
  439. /* for global list of edac_device_ctl_info structs */
  440. struct list_head link;
  441. int dev_idx;
  442. /* Per instance controls for this edac_device */
  443. int log_ue; /* boolean for logging UEs */
  444. int log_ce; /* boolean for logging CEs */
  445. int panic_on_ue; /* boolean for panic'ing on an UE */
  446. unsigned poll_msec; /* number of milliseconds to poll interval */
  447. unsigned long delay; /* number of jiffies for poll_msec */
  448. struct sysdev_class *edac_class; /* pointer to class */
  449. /* the internal state of this controller instance */
  450. int op_state;
  451. #define OP_ALLOC 0x100
  452. #define OP_RUNNING_POLL 0x201
  453. #define OP_RUNNING_INTERRUPT 0x202
  454. #define OP_RUNNING_POLL_INTR 0x203
  455. #define OP_OFFLINE 0x300
  456. /* work struct for this instance */
  457. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
  458. struct delayed_work work;
  459. #else
  460. struct work_struct work;
  461. #endif
  462. /* pointer to edac polling checking routine:
  463. * If NOT NULL: points to polling check routine
  464. * If NULL: Then assumes INTERRUPT operation, where
  465. * MC driver will receive events
  466. */
  467. void (*edac_check) (struct edac_device_ctl_info * edac_dev);
  468. struct device *dev; /* pointer to device structure */
  469. const char *mod_name; /* module name */
  470. const char *ctl_name; /* edac controller name */
  471. const char *dev_name; /* pci/platform/etc... name */
  472. void *pvt_info; /* pointer to 'private driver' info */
  473. unsigned long start_time;/* edac_device load start time (jiffies)*/
  474. /* these are for safe removal of mc devices from global list while
  475. * NMI handlers may be traversing list
  476. */
  477. struct rcu_head rcu;
  478. struct completion complete;
  479. /* sysfs top name under 'edac' directory
  480. * and instance name:
  481. * cpu/cpu0/...
  482. * cpu/cpu1/...
  483. * cpu/cpu2/...
  484. * ...
  485. */
  486. char name[EDAC_DEVICE_NAME_LEN + 1];
  487. /* Number of instances supported on this control structure
  488. * and the array of those instances
  489. */
  490. u32 nr_instances;
  491. struct edac_device_instance *instances;
  492. /* Event counters for the this whole EDAC Device */
  493. struct edac_device_counter counters;
  494. /* edac sysfs device control for the 'name'
  495. * device this structure controls
  496. */
  497. struct kobject kobj;
  498. struct completion kobj_complete;
  499. };
  500. /* To get from the instance's wq to the beginning of the ctl structure */
  501. #define to_edac_device_ctl_work(w) \
  502. container_of(w,struct edac_device_ctl_info,work)
  503. /* Function to calc the number of delay jiffies from poll_msec */
  504. static inline void edac_device_calc_delay(
  505. struct edac_device_ctl_info *edac_dev)
  506. {
  507. /* convert from msec to jiffies */
  508. edac_dev->delay = edac_dev->poll_msec * HZ / 1000;
  509. }
  510. /*
  511. * The alloc() and free() functions for the 'edac_device' control info
  512. * structure. A MC driver will allocate one of these for each edac_device
  513. * it is going to control/register with the EDAC CORE.
  514. */
  515. extern struct edac_device_ctl_info *edac_device_alloc_ctl_info(
  516. unsigned sizeof_private,
  517. char *edac_device_name,
  518. unsigned nr_instances,
  519. char *edac_block_name,
  520. unsigned nr_blocks,
  521. unsigned offset_value,
  522. struct edac_attrib_spec *attrib_spec,
  523. unsigned nr_attribs
  524. );
  525. /* The offset value can be:
  526. * -1 indicating no offset value
  527. * 0 for zero-based block numbers
  528. * 1 for 1-based block number
  529. * other for other-based block number
  530. */
  531. #define BLOCK_OFFSET_VALUE_OFF ((unsigned) -1)
  532. extern void edac_device_free_ctl_info( struct edac_device_ctl_info *ctl_info);
  533. #ifdef CONFIG_PCI
  534. /* write all or some bits in a byte-register*/
  535. static inline void pci_write_bits8(struct pci_dev *pdev, int offset, u8 value,
  536. u8 mask)
  537. {
  538. if (mask != 0xff) {
  539. u8 buf;
  540. pci_read_config_byte(pdev, offset, &buf);
  541. value &= mask;
  542. buf &= ~mask;
  543. value |= buf;
  544. }
  545. pci_write_config_byte(pdev, offset, value);
  546. }
  547. /* write all or some bits in a word-register*/
  548. static inline void pci_write_bits16(struct pci_dev *pdev, int offset,
  549. u16 value, u16 mask)
  550. {
  551. if (mask != 0xffff) {
  552. u16 buf;
  553. pci_read_config_word(pdev, offset, &buf);
  554. value &= mask;
  555. buf &= ~mask;
  556. value |= buf;
  557. }
  558. pci_write_config_word(pdev, offset, value);
  559. }
  560. /* write all or some bits in a dword-register*/
  561. static inline void pci_write_bits32(struct pci_dev *pdev, int offset,
  562. u32 value, u32 mask)
  563. {
  564. if (mask != 0xffff) {
  565. u32 buf;
  566. pci_read_config_dword(pdev, offset, &buf);
  567. value &= mask;
  568. buf &= ~mask;
  569. value |= buf;
  570. }
  571. pci_write_config_dword(pdev, offset, value);
  572. }
  573. #endif /* CONFIG_PCI */
  574. extern struct mem_ctl_info * edac_mc_find(int idx);
  575. extern int edac_mc_add_mc(struct mem_ctl_info *mci,int mc_idx);
  576. extern struct mem_ctl_info * edac_mc_del_mc(struct device *dev);
  577. extern int edac_mc_find_csrow_by_page(struct mem_ctl_info *mci,
  578. unsigned long page);
  579. /*
  580. * The no info errors are used when error overflows are reported.
  581. * There are a limited number of error logging registers that can
  582. * be exausted. When all registers are exhausted and an additional
  583. * error occurs then an error overflow register records that an
  584. * error occured and the type of error, but doesn't have any
  585. * further information. The ce/ue versions make for cleaner
  586. * reporting logic and function interface - reduces conditional
  587. * statement clutter and extra function arguments.
  588. */
  589. extern void edac_mc_handle_ce(struct mem_ctl_info *mci,
  590. unsigned long page_frame_number, unsigned long offset_in_page,
  591. unsigned long syndrome, int row, int channel,
  592. const char *msg);
  593. extern void edac_mc_handle_ce_no_info(struct mem_ctl_info *mci,
  594. const char *msg);
  595. extern void edac_mc_handle_ue(struct mem_ctl_info *mci,
  596. unsigned long page_frame_number, unsigned long offset_in_page,
  597. int row, const char *msg);
  598. extern void edac_mc_handle_ue_no_info(struct mem_ctl_info *mci,
  599. const char *msg);
  600. extern void edac_mc_handle_fbd_ue(struct mem_ctl_info *mci,
  601. unsigned int csrow,
  602. unsigned int channel0,
  603. unsigned int channel1,
  604. char *msg);
  605. extern void edac_mc_handle_fbd_ce(struct mem_ctl_info *mci,
  606. unsigned int csrow,
  607. unsigned int channel,
  608. char *msg);
  609. /*
  610. * edac_device APIs
  611. */
  612. extern struct mem_ctl_info *edac_mc_alloc(unsigned sz_pvt, unsigned nr_csrows,
  613. unsigned nr_chans);
  614. extern void edac_mc_free(struct mem_ctl_info *mci);
  615. extern int edac_device_add_device(struct edac_device_ctl_info *edac_dev, int edac_idx);
  616. extern struct edac_device_ctl_info * edac_device_del_device(struct device *dev);
  617. extern void edac_device_handle_ue(struct edac_device_ctl_info *edac_dev,
  618. int inst_nr, int block_nr, const char *msg);
  619. extern void edac_device_handle_ce(struct edac_device_ctl_info *edac_dev,
  620. int inst_nr, int block_nr, const char *msg);
  621. #endif /* _EDAC_CORE_H_ */