2 * Defines, structures, APIs for edac_pci and edac_pci_sysfs
4 * (C) 2007 Linux Networx (http://lnxi.com)
5 * This file may be distributed under the terms of the
6 * GNU General Public License.
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/
12 * NMI handling support added by
13 * Dave Peterson <dsp@llnl.gov> <dave_peterson@pobox.com>
15 * Refactored for multi-source files:
16 * Doug Thompson <norsk5@xmission.com>
18 * Please look at Documentation/driver-api/edac.rst for more info about
19 * EDAC core structs and functions.
25 #include <linux/device.h>
26 #include <linux/edac.h>
27 #include <linux/kobject.h>
28 #include <linux/list.h>
29 #include <linux/pci.h>
30 #include <linux/types.h>
31 #include <linux/workqueue.h>
35 struct edac_pci_counter
{
41 * Abstract edac_pci control info structure
44 struct edac_pci_ctl_info
{
45 /* for global list of edac_pci_ctl_info structs */
46 struct list_head link
;
50 /* the internal state of this controller instance */
52 /* work struct for this instance */
53 struct delayed_work work
;
55 /* pointer to edac polling checking routine:
56 * If NOT NULL: points to polling check routine
57 * If NULL: Then assumes INTERRUPT operation, where
58 * MC driver will receive events
60 void (*edac_check
) (struct edac_pci_ctl_info
* edac_dev
);
62 struct device
*dev
; /* pointer to device structure */
64 const char *mod_name
; /* module name */
65 const char *ctl_name
; /* edac controller name */
66 const char *dev_name
; /* pci/platform/etc... name */
68 void *pvt_info
; /* pointer to 'private driver' info */
70 unsigned long start_time
; /* edac_pci load start time (jiffies) */
72 /* sysfs top name under 'edac' directory
79 char name
[EDAC_DEVICE_NAME_LEN
+ 1];
81 /* Event counters for the this whole EDAC Device */
82 struct edac_pci_counter counters
;
84 /* edac sysfs device control for the 'name'
85 * device this structure controls
90 #define to_edac_pci_ctl_work(w) \
91 container_of(w, struct edac_pci_ctl_info,work)
93 /* write all or some bits in a byte-register*/
94 static inline void pci_write_bits8(struct pci_dev
*pdev
, int offset
, u8 value
,
100 pci_read_config_byte(pdev
, offset
, &buf
);
106 pci_write_config_byte(pdev
, offset
, value
);
109 /* write all or some bits in a word-register*/
110 static inline void pci_write_bits16(struct pci_dev
*pdev
, int offset
,
113 if (mask
!= 0xffff) {
116 pci_read_config_word(pdev
, offset
, &buf
);
122 pci_write_config_word(pdev
, offset
, value
);
128 * edac local routine to do pci_write_config_dword, but adds
129 * a mask parameter. If mask is all ones, ignore the mask.
130 * Otherwise utilize the mask to isolate specified bits
132 * write all or some bits in a dword-register
134 static inline void pci_write_bits32(struct pci_dev
*pdev
, int offset
,
137 if (mask
!= 0xffffffff) {
140 pci_read_config_dword(pdev
, offset
, &buf
);
146 pci_write_config_dword(pdev
, offset
, value
);
149 #endif /* CONFIG_PCI */
156 * edac_pci_alloc_ctl_info:
157 * The alloc() function for the 'edac_pci' control info
160 * @sz_pvt: size of the private info at struct &edac_pci_ctl_info
161 * @edac_pci_name: name of the PCI device
163 * The chip driver will allocate one of these for each
164 * edac_pci it is going to control/register with the EDAC CORE.
166 * Returns: a pointer to struct &edac_pci_ctl_info on success; %NULL otherwise.
168 extern struct edac_pci_ctl_info
*edac_pci_alloc_ctl_info(unsigned int sz_pvt
,
169 const char *edac_pci_name
);
172 * edac_pci_free_ctl_info():
173 * Last action on the pci control structure.
175 * @pci: pointer to struct &edac_pci_ctl_info
177 * Calls the remove sysfs information, which will unregister
178 * this control struct's kobj. When that kobj's ref count
179 * goes to zero, its release function will be call and then
180 * kfree() the memory.
182 extern void edac_pci_free_ctl_info(struct edac_pci_ctl_info
*pci
);
185 * edac_pci_alloc_index: Allocate a unique PCI index number
188 * allocated index number
191 extern int edac_pci_alloc_index(void);
194 * edac_pci_add_device(): Insert the 'edac_dev' structure into the
195 * edac_pci global list and create sysfs entries associated with
196 * edac_pci structure.
198 * @pci: pointer to the edac_device structure to be added to the list
199 * @edac_idx: A unique numeric identifier to be assigned to the
200 * 'edac_pci' structure.
203 * 0 on Success, or an error code on failure
205 extern int edac_pci_add_device(struct edac_pci_ctl_info
*pci
, int edac_idx
);
208 * edac_pci_del_device()
209 * Remove sysfs entries for specified edac_pci structure and
210 * then remove edac_pci structure from global list
213 * Pointer to 'struct device' representing edac_pci structure
217 * Pointer to removed edac_pci structure,
218 * or %NULL if device not found
220 extern struct edac_pci_ctl_info
*edac_pci_del_device(struct device
*dev
);
223 * edac_pci_create_generic_ctl()
224 * A generic constructor for a PCI parity polling device
225 * Some systems have more than one domain of PCI busses.
226 * For systems with one domain, then this API will
227 * provide for a generic poller.
229 * @dev: pointer to struct &device;
230 * @mod_name: name of the PCI device
232 * This routine calls the edac_pci_alloc_ctl_info() for
233 * the generic device, with default values
235 * Returns: Pointer to struct &edac_pci_ctl_info on success, %NULL on
238 extern struct edac_pci_ctl_info
*edac_pci_create_generic_ctl(
240 const char *mod_name
);
243 * edac_pci_release_generic_ctl
244 * The release function of a generic EDAC PCI polling device
246 * @pci: pointer to struct &edac_pci_ctl_info
248 extern void edac_pci_release_generic_ctl(struct edac_pci_ctl_info
*pci
);
251 * edac_pci_create_sysfs
252 * Create the controls/attributes for the specified EDAC PCI device
254 * @pci: pointer to struct &edac_pci_ctl_info
256 extern int edac_pci_create_sysfs(struct edac_pci_ctl_info
*pci
);
259 * edac_pci_remove_sysfs()
260 * remove the controls and attributes for this EDAC PCI device
262 * @pci: pointer to struct &edac_pci_ctl_info
264 extern void edac_pci_remove_sysfs(struct edac_pci_ctl_info
*pci
);