edac_pci.h 6.8 KB

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