1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#ifndef _EDAC_CORE_H_
21#define _EDAC_CORE_H_
22
23#include <linux/kernel.h>
24#include <linux/types.h>
25#include <linux/module.h>
26#include <linux/spinlock.h>
27#include <linux/smp.h>
28#include <linux/pci.h>
29#include <linux/time.h>
30#include <linux/nmi.h>
31#include <linux/rcupdate.h>
32#include <linux/completion.h>
33#include <linux/kobject.h>
34#include <linux/platform_device.h>
35#include <linux/workqueue.h>
36#include <linux/edac.h>
37
38#define EDAC_DEVICE_NAME_LEN 31
39#define EDAC_ATTRIB_VALUE_LEN 15
40
41#if PAGE_SHIFT < 20
42#define PAGES_TO_MiB(pages) ((pages) >> (20 - PAGE_SHIFT))
43#define MiB_TO_PAGES(mb) ((mb) << (20 - PAGE_SHIFT))
44#else
45#define PAGES_TO_MiB(pages) ((pages) << (PAGE_SHIFT - 20))
46#define MiB_TO_PAGES(mb) ((mb) >> (PAGE_SHIFT - 20))
47#endif
48
49#define edac_printk(level, prefix, fmt, arg...) \
50 printk(level "EDAC " prefix ": " fmt, ##arg)
51
52#define edac_mc_printk(mci, level, fmt, arg...) \
53 printk(level "EDAC MC%d: " fmt, mci->mc_idx, ##arg)
54
55#define edac_mc_chipset_printk(mci, level, prefix, fmt, arg...) \
56 printk(level "EDAC " prefix " MC%d: " fmt, mci->mc_idx, ##arg)
57
58#define edac_device_printk(ctl, level, fmt, arg...) \
59 printk(level "EDAC DEVICE%d: " fmt, ctl->dev_idx, ##arg)
60
61#define edac_pci_printk(ctl, level, fmt, arg...) \
62 printk(level "EDAC PCI%d: " fmt, ctl->pci_idx, ##arg)
63
64
65#define EDAC_MC "MC"
66#define EDAC_PCI "PCI"
67#define EDAC_DEBUG "DEBUG"
68
69extern const char *edac_mem_types[];
70
71#ifdef CONFIG_EDAC_DEBUG
72extern int edac_debug_level;
73
74#define edac_dbg(level, fmt, ...) \
75do { \
76 if (level <= edac_debug_level) \
77 edac_printk(KERN_DEBUG, EDAC_DEBUG, \
78 "%s: " fmt, __func__, ##__VA_ARGS__); \
79} while (0)
80
81#else
82
83#define edac_dbg(level, fmt, ...) \
84do { \
85 if (0) \
86 edac_printk(KERN_DEBUG, EDAC_DEBUG, \
87 "%s: " fmt, __func__, ##__VA_ARGS__); \
88} while (0)
89
90#endif
91
92#define PCI_VEND_DEV(vend, dev) PCI_VENDOR_ID_ ## vend, \
93 PCI_DEVICE_ID_ ## vend ## _ ## dev
94
95#define edac_dev_name(dev) (dev)->dev_name
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136struct edac_device_counter {
137 u32 ue_count;
138 u32 ce_count;
139};
140
141
142struct edac_device_ctl_info;
143struct edac_device_block;
144
145
146
147
148
149
150struct edac_dev_sysfs_attribute {
151 struct attribute attr;
152 ssize_t (*show)(struct edac_device_ctl_info *, char *);
153 ssize_t (*store)(struct edac_device_ctl_info *, const char *, size_t);
154};
155
156
157
158
159
160
161
162
163
164
165
166
167
168struct edac_dev_sysfs_block_attribute {
169 struct attribute attr;
170 ssize_t (*show)(struct kobject *, struct attribute *, char *);
171 ssize_t (*store)(struct kobject *, struct attribute *,
172 const char *, size_t);
173 struct edac_device_block *block;
174
175 unsigned int value;
176};
177
178
179struct edac_device_block {
180 struct edac_device_instance *instance;
181 char name[EDAC_DEVICE_NAME_LEN + 1];
182
183 struct edac_device_counter counters;
184
185 int nr_attribs;
186
187
188 struct edac_dev_sysfs_block_attribute *block_attributes;
189
190
191 struct kobject kobj;
192};
193
194
195struct edac_device_instance {
196 struct edac_device_ctl_info *ctl;
197 char name[EDAC_DEVICE_NAME_LEN + 4];
198
199 struct edac_device_counter counters;
200
201 u32 nr_blocks;
202 struct edac_device_block *blocks;
203
204
205 struct kobject kobj;
206};
207
208
209
210
211
212
213struct edac_device_ctl_info {
214
215 struct list_head link;
216
217 struct module *owner;
218
219 int dev_idx;
220
221
222 int log_ue;
223 int log_ce;
224 int panic_on_ue;
225 unsigned poll_msec;
226 unsigned long delay;
227
228
229
230
231
232
233
234
235
236
237
238 struct edac_dev_sysfs_attribute *sysfs_attributes;
239
240
241 struct bus_type *edac_subsys;
242
243
244 int op_state;
245
246 struct delayed_work work;
247
248
249
250
251
252
253 void (*edac_check) (struct edac_device_ctl_info * edac_dev);
254
255 struct device *dev;
256
257 const char *mod_name;
258 const char *ctl_name;
259 const char *dev_name;
260
261 void *pvt_info;
262
263 unsigned long start_time;
264
265 struct completion removal_complete;
266
267
268
269
270
271
272
273
274 char name[EDAC_DEVICE_NAME_LEN + 1];
275
276
277
278
279 u32 nr_instances;
280 struct edac_device_instance *instances;
281
282
283 struct edac_device_counter counters;
284
285
286
287
288 struct kobject kobj;
289};
290
291
292#define to_edac_mem_ctl_work(w) \
293 container_of(w, struct mem_ctl_info, work)
294
295#define to_edac_device_ctl_work(w) \
296 container_of(w,struct edac_device_ctl_info,work)
297
298
299
300
301
302
303extern struct edac_device_ctl_info *edac_device_alloc_ctl_info(
304 unsigned sizeof_private,
305 char *edac_device_name, unsigned nr_instances,
306 char *edac_block_name, unsigned nr_blocks,
307 unsigned offset_value,
308 struct edac_dev_sysfs_block_attribute *block_attributes,
309 unsigned nr_attribs,
310 int device_index);
311
312
313
314
315
316
317
318#define BLOCK_OFFSET_VALUE_OFF ((unsigned) -1)
319
320extern void edac_device_free_ctl_info(struct edac_device_ctl_info *ctl_info);
321
322#ifdef CONFIG_PCI
323
324struct edac_pci_counter {
325 atomic_t pe_count;
326 atomic_t npe_count;
327};
328
329
330
331
332
333struct edac_pci_ctl_info {
334
335 struct list_head link;
336
337 int pci_idx;
338
339 struct bus_type *edac_subsys;
340
341
342 int op_state;
343
344 struct delayed_work work;
345
346
347
348
349
350
351 void (*edac_check) (struct edac_pci_ctl_info * edac_dev);
352
353 struct device *dev;
354
355 const char *mod_name;
356 const char *ctl_name;
357 const char *dev_name;
358
359 void *pvt_info;
360
361 unsigned long start_time;
362
363 struct completion complete;
364
365
366
367
368
369
370
371
372 char name[EDAC_DEVICE_NAME_LEN + 1];
373
374
375 struct edac_pci_counter counters;
376
377
378
379
380 struct kobject kobj;
381 struct completion kobj_complete;
382};
383
384#define to_edac_pci_ctl_work(w) \
385 container_of(w, struct edac_pci_ctl_info,work)
386
387
388static inline void pci_write_bits8(struct pci_dev *pdev, int offset, u8 value,
389 u8 mask)
390{
391 if (mask != 0xff) {
392 u8 buf;
393
394 pci_read_config_byte(pdev, offset, &buf);
395 value &= mask;
396 buf &= ~mask;
397 value |= buf;
398 }
399
400 pci_write_config_byte(pdev, offset, value);
401}
402
403
404static inline void pci_write_bits16(struct pci_dev *pdev, int offset,
405 u16 value, u16 mask)
406{
407 if (mask != 0xffff) {
408 u16 buf;
409
410 pci_read_config_word(pdev, offset, &buf);
411 value &= mask;
412 buf &= ~mask;
413 value |= buf;
414 }
415
416 pci_write_config_word(pdev, offset, value);
417}
418
419
420
421
422
423
424
425
426
427
428static inline void pci_write_bits32(struct pci_dev *pdev, int offset,
429 u32 value, u32 mask)
430{
431 if (mask != 0xffffffff) {
432 u32 buf;
433
434 pci_read_config_dword(pdev, offset, &buf);
435 value &= mask;
436 buf &= ~mask;
437 value |= buf;
438 }
439
440 pci_write_config_dword(pdev, offset, value);
441}
442
443#endif
444
445struct mem_ctl_info *edac_mc_alloc(unsigned mc_num,
446 unsigned n_layers,
447 struct edac_mc_layer *layers,
448 unsigned sz_pvt);
449extern int edac_mc_add_mc_with_groups(struct mem_ctl_info *mci,
450 const struct attribute_group **groups);
451#define edac_mc_add_mc(mci) edac_mc_add_mc_with_groups(mci, NULL)
452extern void edac_mc_free(struct mem_ctl_info *mci);
453
454
455
456
457
458
459
460
461extern bool edac_has_mcs(void);
462
463extern struct mem_ctl_info *edac_mc_find(int idx);
464extern struct mem_ctl_info *find_mci_by_dev(struct device *dev);
465extern struct mem_ctl_info *edac_mc_del_mc(struct device *dev);
466extern int edac_mc_find_csrow_by_page(struct mem_ctl_info *mci,
467 unsigned long page);
468
469void edac_raw_mc_handle_error(const enum hw_event_mc_err_type type,
470 struct mem_ctl_info *mci,
471 struct edac_raw_error_desc *e);
472
473void edac_mc_handle_error(const enum hw_event_mc_err_type type,
474 struct mem_ctl_info *mci,
475 const u16 error_count,
476 const unsigned long page_frame_number,
477 const unsigned long offset_in_page,
478 const unsigned long syndrome,
479 const int top_layer,
480 const int mid_layer,
481 const int low_layer,
482 const char *msg,
483 const char *other_detail);
484
485
486
487
488extern int edac_device_add_device(struct edac_device_ctl_info *edac_dev);
489extern struct edac_device_ctl_info *edac_device_del_device(struct device *dev);
490extern void edac_device_handle_ue(struct edac_device_ctl_info *edac_dev,
491 int inst_nr, int block_nr, const char *msg);
492extern void edac_device_handle_ce(struct edac_device_ctl_info *edac_dev,
493 int inst_nr, int block_nr, const char *msg);
494extern int edac_device_alloc_index(void);
495extern const char *edac_layer_name[];
496
497
498
499
500extern struct edac_pci_ctl_info *edac_pci_alloc_ctl_info(unsigned int sz_pvt,
501 const char *edac_pci_name);
502
503extern void edac_pci_free_ctl_info(struct edac_pci_ctl_info *pci);
504
505extern void edac_pci_reset_delay_period(struct edac_pci_ctl_info *pci,
506 unsigned long value);
507
508extern int edac_pci_alloc_index(void);
509extern int edac_pci_add_device(struct edac_pci_ctl_info *pci, int edac_idx);
510extern struct edac_pci_ctl_info *edac_pci_del_device(struct device *dev);
511
512extern struct edac_pci_ctl_info *edac_pci_create_generic_ctl(
513 struct device *dev,
514 const char *mod_name);
515
516extern void edac_pci_release_generic_ctl(struct edac_pci_ctl_info *pci);
517extern int edac_pci_create_sysfs(struct edac_pci_ctl_info *pci);
518extern void edac_pci_remove_sysfs(struct edac_pci_ctl_info *pci);
519
520
521
522
523extern char *edac_op_state_to_string(int op_state);
524
525#endif
526