edac_mc.h 3.8 KB
Newer Older
1
/*
2
 * Defines, structures, APIs for edac_mc module
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 * (C) 2007 Linux Networx (http://lnxi.com)
 * This file may be distributed under the terms of the
 * GNU General Public License.
 *
 * Written by Thayne Harbaugh
 * Based on work by Dan Hollis <goemon at anime dot net> and others.
 *	http://www.anime.net/~goemon/linux-ecc/
 *
 * NMI handling support added by
 *     Dave Peterson <dsp@llnl.gov> <dave_peterson@pobox.com>
 *
 * Refactored for multi-source files:
 *	Doug Thompson <norsk5@xmission.com>
 *
 */

20 21
#ifndef _EDAC_MC_H_
#define _EDAC_MC_H_
22 23 24 25 26 27 28 29 30 31 32 33 34

#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/module.h>
#include <linux/spinlock.h>
#include <linux/smp.h>
#include <linux/pci.h>
#include <linux/time.h>
#include <linux/nmi.h>
#include <linux/rcupdate.h>
#include <linux/completion.h>
#include <linux/kobject.h>
#include <linux/platform_device.h>
35
#include <linux/workqueue.h>
36
#include <linux/edac.h>
37 38

#if PAGE_SHIFT < 20
39 40
#define PAGES_TO_MiB(pages)	((pages) >> (20 - PAGE_SHIFT))
#define MiB_TO_PAGES(mb)	((mb) << (20 - PAGE_SHIFT))
41
#else				/* PAGE_SHIFT > 20 */
42
#define PAGES_TO_MiB(pages)	((pages) << (PAGE_SHIFT - 20))
43
#define MiB_TO_PAGES(mb)	((mb) >> (PAGE_SHIFT - 20))
44 45 46 47 48 49 50 51 52 53 54
#endif

#define edac_printk(level, prefix, fmt, arg...) \
	printk(level "EDAC " prefix ": " fmt, ##arg)

#define edac_mc_printk(mci, level, fmt, arg...) \
	printk(level "EDAC MC%d: " fmt, mci->mc_idx, ##arg)

#define edac_mc_chipset_printk(mci, level, prefix, fmt, arg...) \
	printk(level "EDAC " prefix " MC%d: " fmt, mci->mc_idx, ##arg)

55 56 57
#define edac_device_printk(ctl, level, fmt, arg...) \
	printk(level "EDAC DEVICE%d: " fmt, ctl->dev_idx, ##arg)

58 59 60
#define edac_pci_printk(ctl, level, fmt, arg...) \
	printk(level "EDAC PCI%d: " fmt, ctl->pci_idx, ##arg)

61 62 63 64 65
/* prefixes for edac_printk() and edac_mc_printk() */
#define EDAC_MC "MC"
#define EDAC_PCI "PCI"
#define EDAC_DEBUG "DEBUG"

66
extern const char * const edac_mem_types[];
67

68 69 70
#ifdef CONFIG_EDAC_DEBUG
extern int edac_debug_level;

71
#define edac_dbg(level, fmt, ...)					\
72 73 74 75 76
do {									\
	if (level <= edac_debug_level)					\
		edac_printk(KERN_DEBUG, EDAC_DEBUG,			\
			    "%s: " fmt, __func__, ##__VA_ARGS__);	\
} while (0)
77

78
#else				/* !CONFIG_EDAC_DEBUG */
79

80
#define edac_dbg(level, fmt, ...)					\
81 82 83 84 85
do {									\
	if (0)								\
		edac_printk(KERN_DEBUG, EDAC_DEBUG,			\
			    "%s: " fmt, __func__, ##__VA_ARGS__);	\
} while (0)
86

87
#endif				/* !CONFIG_EDAC_DEBUG */
88 89 90 91

#define PCI_VEND_DEV(vend, dev) PCI_VENDOR_ID_ ## vend, \
	PCI_DEVICE_ID_ ## vend ## _ ## dev

92
#define edac_dev_name(dev) (dev)->dev_name
93

94 95
#define to_mci(k) container_of(k, struct mem_ctl_info, dev)

96
struct mem_ctl_info *edac_mc_alloc(unsigned mc_num,
97 98 99
				   unsigned n_layers,
				   struct edac_mc_layer *layers,
				   unsigned sz_pvt);
100 101 102
extern int edac_mc_add_mc_with_groups(struct mem_ctl_info *mci,
				      const struct attribute_group **groups);
#define edac_mc_add_mc(mci)	edac_mc_add_mc_with_groups(mci, NULL)
103
extern void edac_mc_free(struct mem_ctl_info *mci);
104
extern struct mem_ctl_info *edac_mc_find(int idx);
105
extern struct mem_ctl_info *find_mci_by_dev(struct device *dev);
106
extern struct mem_ctl_info *edac_mc_del_mc(struct device *dev);
107
extern int edac_mc_find_csrow_by_page(struct mem_ctl_info *mci,
108
				      unsigned long page);
109 110 111 112 113

void edac_raw_mc_handle_error(const enum hw_event_mc_err_type type,
			      struct mem_ctl_info *mci,
			      struct edac_raw_error_desc *e);

114 115
void edac_mc_handle_error(const enum hw_event_mc_err_type type,
			  struct mem_ctl_info *mci,
116
			  const u16 error_count,
117 118 119
			  const unsigned long page_frame_number,
			  const unsigned long offset_in_page,
			  const unsigned long syndrome,
120 121 122
			  const int top_layer,
			  const int mid_layer,
			  const int low_layer,
123
			  const char *msg,
124
			  const char *other_detail);
125

126 127 128
/*
 * edac misc APIs
 */
129
extern char *edac_op_state_to_string(int op_state);
130

131
#endif				/* _EDAC_MC_H_ */