edac_pci.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /*
  2. * Defines, structures, APIs for edac_pci and edac_pci_sysfs
  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. * Please look at Documentation/driver-api/edac.rst for more info about
  19. * EDAC core structs and functions.
  20. */
  21. #ifndef _EDAC_PCI_H_
  22. #define _EDAC_PCI_H_
  23. #include <linux/device.h>
  24. #include <linux/edac.h>
  25. #include <linux/kobject.h>
  26. #include <linux/list.h>
  27. #include <linux/pci.h>
  28. #include <linux/types.h>
  29. #include <linux/workqueue.h>
  30. #ifdef CONFIG_PCI
  31. struct edac_pci_counter {
  32. atomic_t pe_count;
  33. atomic_t npe_count;
  34. };
  35. /*
  36. * Abstract edac_pci control info structure
  37. *
  38. */
  39. struct edac_pci_ctl_info {
  40. /* for global list of edac_pci_ctl_info structs */
  41. struct list_head link;
  42. int pci_idx;
  43. /* the internal state of this controller instance */
  44. int op_state;
  45. /* work struct for this instance */
  46. struct delayed_work work;
  47. /* pointer to edac polling checking routine:
  48. * If NOT NULL: points to polling check routine
  49. * If NULL: Then assumes INTERRUPT operation, where
  50. * MC driver will receive events
  51. */
  52. void (*edac_check) (struct edac_pci_ctl_info * edac_dev);
  53. struct device *dev; /* pointer to device structure */
  54. const char *mod_name; /* module name */
  55. const char *ctl_name; /* edac controller name */
  56. const char *dev_name; /* pci/platform/etc... name */
  57. void *pvt_info; /* pointer to 'private driver' info */
  58. unsigned long start_time; /* edac_pci load start time (jiffies) */
  59. /* sysfs top name under 'edac' directory
  60. * and instance name:
  61. * cpu/cpu0/...
  62. * cpu/cpu1/...
  63. * cpu/cpu2/...
  64. * ...
  65. */
  66. char name[EDAC_DEVICE_NAME_LEN + 1];
  67. /* Event counters for the this whole EDAC Device */
  68. struct edac_pci_counter counters;
  69. /* edac sysfs device control for the 'name'
  70. * device this structure controls
  71. */
  72. struct kobject kobj;
  73. };
  74. #define to_edac_pci_ctl_work(w) \
  75. container_of(w, struct edac_pci_ctl_info,work)
  76. /* write all or some bits in a byte-register*/
  77. static inline void pci_write_bits8(struct pci_dev *pdev, int offset, u8 value,
  78. u8 mask)
  79. {
  80. if (mask != 0xff) {
  81. u8 buf;
  82. pci_read_config_byte(pdev, offset, &buf);
  83. value &= mask;
  84. buf &= ~mask;
  85. value |= buf;
  86. }
  87. pci_write_config_byte(pdev, offset, value);
  88. }
  89. /* write all or some bits in a word-register*/
  90. static inline void pci_write_bits16(struct pci_dev *pdev, int offset,
  91. u16 value, u16 mask)
  92. {
  93. if (mask != 0xffff) {
  94. u16 buf;
  95. pci_read_config_word(pdev, offset, &buf);
  96. value &= mask;
  97. buf &= ~mask;
  98. value |= buf;
  99. }
  100. pci_write_config_word(pdev, offset, value);
  101. }
  102. /*
  103. * pci_write_bits32
  104. *
  105. * edac local routine to do pci_write_config_dword, but adds
  106. * a mask parameter. If mask is all ones, ignore the mask.
  107. * Otherwise utilize the mask to isolate specified bits
  108. *
  109. * write all or some bits in a dword-register
  110. */
  111. static inline void pci_write_bits32(struct pci_dev *pdev, int offset,
  112. u32 value, u32 mask)
  113. {
  114. if (mask != 0xffffffff) {
  115. u32 buf;
  116. pci_read_config_dword(pdev, offset, &buf);
  117. value &= mask;
  118. buf &= ~mask;
  119. value |= buf;
  120. }
  121. pci_write_config_dword(pdev, offset, value);
  122. }
  123. #endif /* CONFIG_PCI */
  124. /*
  125. * edac_pci APIs
  126. */
  127. /**
  128. * edac_pci_alloc_ctl_info:
  129. * The alloc() function for the 'edac_pci' control info
  130. * structure.
  131. *
  132. * @sz_pvt: size of the private info at struct &edac_pci_ctl_info
  133. * @edac_pci_name: name of the PCI device
  134. *
  135. * The chip driver will allocate one of these for each
  136. * edac_pci it is going to control/register with the EDAC CORE.
  137. *
  138. * Returns: a pointer to struct &edac_pci_ctl_info on success; %NULL otherwise.
  139. */
  140. extern struct edac_pci_ctl_info *edac_pci_alloc_ctl_info(unsigned int sz_pvt,
  141. const char *edac_pci_name);
  142. /**
  143. * edac_pci_free_ctl_info():
  144. * Last action on the pci control structure.
  145. *
  146. * @pci: pointer to struct &edac_pci_ctl_info
  147. *
  148. * Calls the remove sysfs information, which will unregister
  149. * this control struct's kobj. When that kobj's ref count
  150. * goes to zero, its release function will be call and then
  151. * kfree() the memory.
  152. */
  153. extern void edac_pci_free_ctl_info(struct edac_pci_ctl_info *pci);
  154. /**
  155. * edac_pci_alloc_index: Allocate a unique PCI index number
  156. *
  157. * Returns:
  158. * allocated index number
  159. *
  160. */
  161. extern int edac_pci_alloc_index(void);
  162. /**
  163. * edac_pci_add_device(): Insert the 'edac_dev' structure into the
  164. * edac_pci global list and create sysfs entries associated with
  165. * edac_pci structure.
  166. *
  167. * @pci: pointer to the edac_device structure to be added to the list
  168. * @edac_idx: A unique numeric identifier to be assigned to the
  169. * 'edac_pci' structure.
  170. *
  171. * Returns:
  172. * 0 on Success, or an error code on failure
  173. */
  174. extern int edac_pci_add_device(struct edac_pci_ctl_info *pci, int edac_idx);
  175. /**
  176. * edac_pci_del_device()
  177. * Remove sysfs entries for specified edac_pci structure and
  178. * then remove edac_pci structure from global list
  179. *
  180. * @dev:
  181. * Pointer to 'struct device' representing edac_pci structure
  182. * to remove
  183. *
  184. * Returns:
  185. * Pointer to removed edac_pci structure,
  186. * or %NULL if device not found
  187. */
  188. extern struct edac_pci_ctl_info *edac_pci_del_device(struct device *dev);
  189. /**
  190. * edac_pci_create_generic_ctl()
  191. * A generic constructor for a PCI parity polling device
  192. * Some systems have more than one domain of PCI busses.
  193. * For systems with one domain, then this API will
  194. * provide for a generic poller.
  195. *
  196. * @dev: pointer to struct &device;
  197. * @mod_name: name of the PCI device
  198. *
  199. * This routine calls the edac_pci_alloc_ctl_info() for
  200. * the generic device, with default values
  201. *
  202. * Returns: Pointer to struct &edac_pci_ctl_info on success, %NULL on
  203. * failure.
  204. */
  205. extern struct edac_pci_ctl_info *edac_pci_create_generic_ctl(
  206. struct device *dev,
  207. const char *mod_name);
  208. /**
  209. * edac_pci_release_generic_ctl
  210. * The release function of a generic EDAC PCI polling device
  211. *
  212. * @pci: pointer to struct &edac_pci_ctl_info
  213. */
  214. extern void edac_pci_release_generic_ctl(struct edac_pci_ctl_info *pci);
  215. /**
  216. * edac_pci_create_sysfs
  217. * Create the controls/attributes for the specified EDAC PCI device
  218. *
  219. * @pci: pointer to struct &edac_pci_ctl_info
  220. */
  221. extern int edac_pci_create_sysfs(struct edac_pci_ctl_info *pci);
  222. /**
  223. * edac_pci_remove_sysfs()
  224. * remove the controls and attributes for this EDAC PCI device
  225. *
  226. * @pci: pointer to struct &edac_pci_ctl_info
  227. */
  228. extern void edac_pci_remove_sysfs(struct edac_pci_ctl_info *pci);
  229. #endif