/*1* Defines, structures, APIs for edac_core module2*3* (C) 2007 Linux Networx (http://lnxi.com)4* This file may be distributed under the terms of the5* GNU General Public License.6*7* Written by Thayne Harbaugh8* Based on work by Dan Hollis <goemon at anime dot net> and others.9* http://www.anime.net/~goemon/linux-ecc/10*11* NMI handling support added by12* Dave Peterson <[email protected]> <[email protected]>13*14* Refactored for multi-source files:15* Doug Thompson <[email protected]>16*17*/1819#ifndef _EDAC_CORE_H_20#define _EDAC_CORE_H_2122#include <linux/kernel.h>23#include <linux/types.h>24#include <linux/module.h>25#include <linux/spinlock.h>26#include <linux/smp.h>27#include <linux/pci.h>28#include <linux/time.h>29#include <linux/nmi.h>30#include <linux/rcupdate.h>31#include <linux/completion.h>32#include <linux/kobject.h>33#include <linux/platform_device.h>34#include <linux/sysdev.h>35#include <linux/workqueue.h>3637#define EDAC_MC_LABEL_LEN 3138#define EDAC_DEVICE_NAME_LEN 3139#define EDAC_ATTRIB_VALUE_LEN 1540#define MC_PROC_NAME_MAX_LEN 74142#if PAGE_SHIFT < 2043#define PAGES_TO_MiB(pages) ((pages) >> (20 - PAGE_SHIFT))44#define MiB_TO_PAGES(mb) ((mb) << (20 - PAGE_SHIFT))45#else /* PAGE_SHIFT > 20 */46#define PAGES_TO_MiB(pages) ((pages) << (PAGE_SHIFT - 20))47#define MiB_TO_PAGES(mb) ((mb) >> (PAGE_SHIFT - 20))48#endif4950#define edac_printk(level, prefix, fmt, arg...) \51printk(level "EDAC " prefix ": " fmt, ##arg)5253#define edac_mc_printk(mci, level, fmt, arg...) \54printk(level "EDAC MC%d: " fmt, mci->mc_idx, ##arg)5556#define edac_mc_chipset_printk(mci, level, prefix, fmt, arg...) \57printk(level "EDAC " prefix " MC%d: " fmt, mci->mc_idx, ##arg)5859#define edac_device_printk(ctl, level, fmt, arg...) \60printk(level "EDAC DEVICE%d: " fmt, ctl->dev_idx, ##arg)6162#define edac_pci_printk(ctl, level, fmt, arg...) \63printk(level "EDAC PCI%d: " fmt, ctl->pci_idx, ##arg)6465/* prefixes for edac_printk() and edac_mc_printk() */66#define EDAC_MC "MC"67#define EDAC_PCI "PCI"68#define EDAC_DEBUG "DEBUG"6970extern const char *edac_mem_types[];7172#ifdef CONFIG_EDAC_DEBUG73extern int edac_debug_level;7475#define edac_debug_printk(level, fmt, arg...) \76do { \77if (level <= edac_debug_level) \78edac_printk(KERN_DEBUG, EDAC_DEBUG, \79"%s: " fmt, __func__, ##arg); \80} while (0)8182#define debugf0( ... ) edac_debug_printk(0, __VA_ARGS__ )83#define debugf1( ... ) edac_debug_printk(1, __VA_ARGS__ )84#define debugf2( ... ) edac_debug_printk(2, __VA_ARGS__ )85#define debugf3( ... ) edac_debug_printk(3, __VA_ARGS__ )86#define debugf4( ... ) edac_debug_printk(4, __VA_ARGS__ )8788#else /* !CONFIG_EDAC_DEBUG */8990#define debugf0( ... )91#define debugf1( ... )92#define debugf2( ... )93#define debugf3( ... )94#define debugf4( ... )9596#endif /* !CONFIG_EDAC_DEBUG */9798#define PCI_VEND_DEV(vend, dev) PCI_VENDOR_ID_ ## vend, \99PCI_DEVICE_ID_ ## vend ## _ ## dev100101#define edac_dev_name(dev) (dev)->dev_name102103/* memory devices */104enum dev_type {105DEV_UNKNOWN = 0,106DEV_X1,107DEV_X2,108DEV_X4,109DEV_X8,110DEV_X16,111DEV_X32, /* Do these parts exist? */112DEV_X64 /* Do these parts exist? */113};114115#define DEV_FLAG_UNKNOWN BIT(DEV_UNKNOWN)116#define DEV_FLAG_X1 BIT(DEV_X1)117#define DEV_FLAG_X2 BIT(DEV_X2)118#define DEV_FLAG_X4 BIT(DEV_X4)119#define DEV_FLAG_X8 BIT(DEV_X8)120#define DEV_FLAG_X16 BIT(DEV_X16)121#define DEV_FLAG_X32 BIT(DEV_X32)122#define DEV_FLAG_X64 BIT(DEV_X64)123124/* memory types */125enum mem_type {126MEM_EMPTY = 0, /* Empty csrow */127MEM_RESERVED, /* Reserved csrow type */128MEM_UNKNOWN, /* Unknown csrow type */129MEM_FPM, /* Fast page mode */130MEM_EDO, /* Extended data out */131MEM_BEDO, /* Burst Extended data out */132MEM_SDR, /* Single data rate SDRAM */133MEM_RDR, /* Registered single data rate SDRAM */134MEM_DDR, /* Double data rate SDRAM */135MEM_RDDR, /* Registered Double data rate SDRAM */136MEM_RMBS, /* Rambus DRAM */137MEM_DDR2, /* DDR2 RAM */138MEM_FB_DDR2, /* fully buffered DDR2 */139MEM_RDDR2, /* Registered DDR2 RAM */140MEM_XDR, /* Rambus XDR */141MEM_DDR3, /* DDR3 RAM */142MEM_RDDR3, /* Registered DDR3 RAM */143};144145#define MEM_FLAG_EMPTY BIT(MEM_EMPTY)146#define MEM_FLAG_RESERVED BIT(MEM_RESERVED)147#define MEM_FLAG_UNKNOWN BIT(MEM_UNKNOWN)148#define MEM_FLAG_FPM BIT(MEM_FPM)149#define MEM_FLAG_EDO BIT(MEM_EDO)150#define MEM_FLAG_BEDO BIT(MEM_BEDO)151#define MEM_FLAG_SDR BIT(MEM_SDR)152#define MEM_FLAG_RDR BIT(MEM_RDR)153#define MEM_FLAG_DDR BIT(MEM_DDR)154#define MEM_FLAG_RDDR BIT(MEM_RDDR)155#define MEM_FLAG_RMBS BIT(MEM_RMBS)156#define MEM_FLAG_DDR2 BIT(MEM_DDR2)157#define MEM_FLAG_FB_DDR2 BIT(MEM_FB_DDR2)158#define MEM_FLAG_RDDR2 BIT(MEM_RDDR2)159#define MEM_FLAG_XDR BIT(MEM_XDR)160#define MEM_FLAG_DDR3 BIT(MEM_DDR3)161#define MEM_FLAG_RDDR3 BIT(MEM_RDDR3)162163/* chipset Error Detection and Correction capabilities and mode */164enum edac_type {165EDAC_UNKNOWN = 0, /* Unknown if ECC is available */166EDAC_NONE, /* Doesn't support ECC */167EDAC_RESERVED, /* Reserved ECC type */168EDAC_PARITY, /* Detects parity errors */169EDAC_EC, /* Error Checking - no correction */170EDAC_SECDED, /* Single bit error correction, Double detection */171EDAC_S2ECD2ED, /* Chipkill x2 devices - do these exist? */172EDAC_S4ECD4ED, /* Chipkill x4 devices */173EDAC_S8ECD8ED, /* Chipkill x8 devices */174EDAC_S16ECD16ED, /* Chipkill x16 devices */175};176177#define EDAC_FLAG_UNKNOWN BIT(EDAC_UNKNOWN)178#define EDAC_FLAG_NONE BIT(EDAC_NONE)179#define EDAC_FLAG_PARITY BIT(EDAC_PARITY)180#define EDAC_FLAG_EC BIT(EDAC_EC)181#define EDAC_FLAG_SECDED BIT(EDAC_SECDED)182#define EDAC_FLAG_S2ECD2ED BIT(EDAC_S2ECD2ED)183#define EDAC_FLAG_S4ECD4ED BIT(EDAC_S4ECD4ED)184#define EDAC_FLAG_S8ECD8ED BIT(EDAC_S8ECD8ED)185#define EDAC_FLAG_S16ECD16ED BIT(EDAC_S16ECD16ED)186187/* scrubbing capabilities */188enum scrub_type {189SCRUB_UNKNOWN = 0, /* Unknown if scrubber is available */190SCRUB_NONE, /* No scrubber */191SCRUB_SW_PROG, /* SW progressive (sequential) scrubbing */192SCRUB_SW_SRC, /* Software scrub only errors */193SCRUB_SW_PROG_SRC, /* Progressive software scrub from an error */194SCRUB_SW_TUNABLE, /* Software scrub frequency is tunable */195SCRUB_HW_PROG, /* HW progressive (sequential) scrubbing */196SCRUB_HW_SRC, /* Hardware scrub only errors */197SCRUB_HW_PROG_SRC, /* Progressive hardware scrub from an error */198SCRUB_HW_TUNABLE /* Hardware scrub frequency is tunable */199};200201#define SCRUB_FLAG_SW_PROG BIT(SCRUB_SW_PROG)202#define SCRUB_FLAG_SW_SRC BIT(SCRUB_SW_SRC)203#define SCRUB_FLAG_SW_PROG_SRC BIT(SCRUB_SW_PROG_SRC)204#define SCRUB_FLAG_SW_TUN BIT(SCRUB_SW_SCRUB_TUNABLE)205#define SCRUB_FLAG_HW_PROG BIT(SCRUB_HW_PROG)206#define SCRUB_FLAG_HW_SRC BIT(SCRUB_HW_SRC)207#define SCRUB_FLAG_HW_PROG_SRC BIT(SCRUB_HW_PROG_SRC)208#define SCRUB_FLAG_HW_TUN BIT(SCRUB_HW_TUNABLE)209210/* FIXME - should have notify capabilities: NMI, LOG, PROC, etc */211212/* EDAC internal operation states */213#define OP_ALLOC 0x100214#define OP_RUNNING_POLL 0x201215#define OP_RUNNING_INTERRUPT 0x202216#define OP_RUNNING_POLL_INTR 0x203217#define OP_OFFLINE 0x300218219/*220* There are several things to be aware of that aren't at all obvious:221*222*223* SOCKETS, SOCKET SETS, BANKS, ROWS, CHIP-SELECT ROWS, CHANNELS, etc..224*225* These are some of the many terms that are thrown about that don't always226* mean what people think they mean (Inconceivable!). In the interest of227* creating a common ground for discussion, terms and their definitions228* will be established.229*230* Memory devices: The individual chip on a memory stick. These devices231* commonly output 4 and 8 bits each. Grouping several232* of these in parallel provides 64 bits which is common233* for a memory stick.234*235* Memory Stick: A printed circuit board that aggregates multiple236* memory devices in parallel. This is the atomic237* memory component that is purchaseable by Joe consumer238* and loaded into a memory socket.239*240* Socket: A physical connector on the motherboard that accepts241* a single memory stick.242*243* Channel: Set of memory devices on a memory stick that must be244* grouped in parallel with one or more additional245* channels from other memory sticks. This parallel246* grouping of the output from multiple channels are247* necessary for the smallest granularity of memory access.248* Some memory controllers are capable of single channel -249* which means that memory sticks can be loaded250* individually. Other memory controllers are only251* capable of dual channel - which means that memory252* sticks must be loaded as pairs (see "socket set").253*254* Chip-select row: All of the memory devices that are selected together.255* for a single, minimum grain of memory access.256* This selects all of the parallel memory devices across257* all of the parallel channels. Common chip-select rows258* for single channel are 64 bits, for dual channel 128259* bits.260*261* Single-Ranked stick: A Single-ranked stick has 1 chip-select row of memory.262* Motherboards commonly drive two chip-select pins to263* a memory stick. A single-ranked stick, will occupy264* only one of those rows. The other will be unused.265*266* Double-Ranked stick: A double-ranked stick has two chip-select rows which267* access different sets of memory devices. The two268* rows cannot be accessed concurrently.269*270* Double-sided stick: DEPRECATED TERM, see Double-Ranked stick.271* A double-sided stick has two chip-select rows which272* access different sets of memory devices. The two273* rows cannot be accessed concurrently. "Double-sided"274* is irrespective of the memory devices being mounted275* on both sides of the memory stick.276*277* Socket set: All of the memory sticks that are required for278* a single memory access or all of the memory sticks279* spanned by a chip-select row. A single socket set280* has two chip-select rows and if double-sided sticks281* are used these will occupy those chip-select rows.282*283* Bank: This term is avoided because it is unclear when284* needing to distinguish between chip-select rows and285* socket sets.286*287* Controller pages:288*289* Physical pages:290*291* Virtual pages:292*293*294* STRUCTURE ORGANIZATION AND CHOICES295*296*297*298* PS - I enjoyed writing all that about as much as you enjoyed reading it.299*/300301struct channel_info {302int chan_idx; /* channel index */303u32 ce_count; /* Correctable Errors for this CHANNEL */304char label[EDAC_MC_LABEL_LEN + 1]; /* DIMM label on motherboard */305struct csrow_info *csrow; /* the parent */306};307308struct csrow_info {309unsigned long first_page; /* first page number in dimm */310unsigned long last_page; /* last page number in dimm */311unsigned long page_mask; /* used for interleaving -312* 0UL for non intlv313*/314u32 nr_pages; /* number of pages in csrow */315u32 grain; /* granularity of reported error in bytes */316int csrow_idx; /* the chip-select row */317enum dev_type dtype; /* memory device type */318u32 ue_count; /* Uncorrectable Errors for this csrow */319u32 ce_count; /* Correctable Errors for this csrow */320enum mem_type mtype; /* memory csrow type */321enum edac_type edac_mode; /* EDAC mode for this csrow */322struct mem_ctl_info *mci; /* the parent */323324struct kobject kobj; /* sysfs kobject for this csrow */325326/* channel information for this csrow */327u32 nr_channels;328struct channel_info *channels;329};330331struct mcidev_sysfs_group {332const char *name; /* group name */333const struct mcidev_sysfs_attribute *mcidev_attr; /* group attributes */334};335336struct mcidev_sysfs_group_kobj {337struct list_head list; /* list for all instances within a mc */338339struct kobject kobj; /* kobj for the group */340341const struct mcidev_sysfs_group *grp; /* group description table */342struct mem_ctl_info *mci; /* the parent */343};344345/* mcidev_sysfs_attribute structure346* used for driver sysfs attributes and in mem_ctl_info347* sysfs top level entries348*/349struct mcidev_sysfs_attribute {350/* It should use either attr or grp */351struct attribute attr;352const struct mcidev_sysfs_group *grp; /* Points to a group of attributes */353354/* Ops for show/store values at the attribute - not used on group */355ssize_t (*show)(struct mem_ctl_info *,char *);356ssize_t (*store)(struct mem_ctl_info *, const char *,size_t);357};358359/* MEMORY controller information structure360*/361struct mem_ctl_info {362struct list_head link; /* for global list of mem_ctl_info structs */363364struct module *owner; /* Module owner of this control struct */365366unsigned long mtype_cap; /* memory types supported by mc */367unsigned long edac_ctl_cap; /* Mem controller EDAC capabilities */368unsigned long edac_cap; /* configuration capabilities - this is369* closely related to edac_ctl_cap. The370* difference is that the controller may be371* capable of s4ecd4ed which would be listed372* in edac_ctl_cap, but if channels aren't373* capable of s4ecd4ed then the edac_cap would374* not have that capability.375*/376unsigned long scrub_cap; /* chipset scrub capabilities */377enum scrub_type scrub_mode; /* current scrub mode */378379/* Translates sdram memory scrub rate given in bytes/sec to the380internal representation and configures whatever else needs381to be configured.382*/383int (*set_sdram_scrub_rate) (struct mem_ctl_info * mci, u32 bw);384385/* Get the current sdram memory scrub rate from the internal386representation and converts it to the closest matching387bandwidth in bytes/sec.388*/389int (*get_sdram_scrub_rate) (struct mem_ctl_info * mci);390391392/* pointer to edac checking routine */393void (*edac_check) (struct mem_ctl_info * mci);394395/*396* Remaps memory pages: controller pages to physical pages.397* For most MC's, this will be NULL.398*/399/* FIXME - why not send the phys page to begin with? */400unsigned long (*ctl_page_to_phys) (struct mem_ctl_info * mci,401unsigned long page);402int mc_idx;403int nr_csrows;404struct csrow_info *csrows;405/*406* FIXME - what about controllers on other busses? - IDs must be407* unique. dev pointer should be sufficiently unique, but408* BUS:SLOT.FUNC numbers may not be unique.409*/410struct device *dev;411const char *mod_name;412const char *mod_ver;413const char *ctl_name;414const char *dev_name;415char proc_name[MC_PROC_NAME_MAX_LEN + 1];416void *pvt_info;417u32 ue_noinfo_count; /* Uncorrectable Errors w/o info */418u32 ce_noinfo_count; /* Correctable Errors w/o info */419u32 ue_count; /* Total Uncorrectable Errors for this MC */420u32 ce_count; /* Total Correctable Errors for this MC */421unsigned long start_time; /* mci load start time (in jiffies) */422423struct completion complete;424425/* edac sysfs device control */426struct kobject edac_mci_kobj;427428/* list for all grp instances within a mc */429struct list_head grp_kobj_list;430431/* Additional top controller level attributes, but specified432* by the low level driver.433*434* Set by the low level driver to provide attributes at the435* controller level, same level as 'ue_count' and 'ce_count' above.436* An array of structures, NULL terminated437*438* If attributes are desired, then set to array of attributes439* If no attributes are desired, leave NULL440*/441const struct mcidev_sysfs_attribute *mc_driver_sysfs_attributes;442443/* work struct for this MC */444struct delayed_work work;445446/* the internal state of this controller instance */447int op_state;448};449450/*451* The following are the structures to provide for a generic452* or abstract 'edac_device'. This set of structures and the453* code that implements the APIs for the same, provide for454* registering EDAC type devices which are NOT standard memory.455*456* CPU caches (L1 and L2)457* DMA engines458* Core CPU swithces459* Fabric switch units460* PCIe interface controllers461* other EDAC/ECC type devices that can be monitored for462* errors, etc.463*464* It allows for a 2 level set of hiearchry. For example:465*466* cache could be composed of L1, L2 and L3 levels of cache.467* Each CPU core would have its own L1 cache, while sharing468* L2 and maybe L3 caches.469*470* View them arranged, via the sysfs presentation:471* /sys/devices/system/edac/..472*473* mc/ <existing memory device directory>474* cpu/cpu0/.. <L1 and L2 block directory>475* /L1-cache/ce_count476* /ue_count477* /L2-cache/ce_count478* /ue_count479* cpu/cpu1/.. <L1 and L2 block directory>480* /L1-cache/ce_count481* /ue_count482* /L2-cache/ce_count483* /ue_count484* ...485*486* the L1 and L2 directories would be "edac_device_block's"487*/488489struct edac_device_counter {490u32 ue_count;491u32 ce_count;492};493494/* forward reference */495struct edac_device_ctl_info;496struct edac_device_block;497498/* edac_dev_sysfs_attribute structure499* used for driver sysfs attributes in mem_ctl_info500* for extra controls and attributes:501* like high level error Injection controls502*/503struct edac_dev_sysfs_attribute {504struct attribute attr;505ssize_t (*show)(struct edac_device_ctl_info *, char *);506ssize_t (*store)(struct edac_device_ctl_info *, const char *, size_t);507};508509/* edac_dev_sysfs_block_attribute structure510*511* used in leaf 'block' nodes for adding controls/attributes512*513* each block in each instance of the containing control structure514* can have an array of the following. The show and store functions515* will be filled in with the show/store function in the516* low level driver.517*518* The 'value' field will be the actual value field used for519* counting520*/521struct edac_dev_sysfs_block_attribute {522struct attribute attr;523ssize_t (*show)(struct kobject *, struct attribute *, char *);524ssize_t (*store)(struct kobject *, struct attribute *,525const char *, size_t);526struct edac_device_block *block;527528unsigned int value;529};530531/* device block control structure */532struct edac_device_block {533struct edac_device_instance *instance; /* Up Pointer */534char name[EDAC_DEVICE_NAME_LEN + 1];535536struct edac_device_counter counters; /* basic UE and CE counters */537538int nr_attribs; /* how many attributes */539540/* this block's attributes, could be NULL */541struct edac_dev_sysfs_block_attribute *block_attributes;542543/* edac sysfs device control */544struct kobject kobj;545};546547/* device instance control structure */548struct edac_device_instance {549struct edac_device_ctl_info *ctl; /* Up pointer */550char name[EDAC_DEVICE_NAME_LEN + 4];551552struct edac_device_counter counters; /* instance counters */553554u32 nr_blocks; /* how many blocks */555struct edac_device_block *blocks; /* block array */556557/* edac sysfs device control */558struct kobject kobj;559};560561562/*563* Abstract edac_device control info structure564*565*/566struct edac_device_ctl_info {567/* for global list of edac_device_ctl_info structs */568struct list_head link;569570struct module *owner; /* Module owner of this control struct */571572int dev_idx;573574/* Per instance controls for this edac_device */575int log_ue; /* boolean for logging UEs */576int log_ce; /* boolean for logging CEs */577int panic_on_ue; /* boolean for panic'ing on an UE */578unsigned poll_msec; /* number of milliseconds to poll interval */579unsigned long delay; /* number of jiffies for poll_msec */580581/* Additional top controller level attributes, but specified582* by the low level driver.583*584* Set by the low level driver to provide attributes at the585* controller level, same level as 'ue_count' and 'ce_count' above.586* An array of structures, NULL terminated587*588* If attributes are desired, then set to array of attributes589* If no attributes are desired, leave NULL590*/591struct edac_dev_sysfs_attribute *sysfs_attributes;592593/* pointer to main 'edac' class in sysfs */594struct sysdev_class *edac_class;595596/* the internal state of this controller instance */597int op_state;598/* work struct for this instance */599struct delayed_work work;600601/* pointer to edac polling checking routine:602* If NOT NULL: points to polling check routine603* If NULL: Then assumes INTERRUPT operation, where604* MC driver will receive events605*/606void (*edac_check) (struct edac_device_ctl_info * edac_dev);607608struct device *dev; /* pointer to device structure */609610const char *mod_name; /* module name */611const char *ctl_name; /* edac controller name */612const char *dev_name; /* pci/platform/etc... name */613614void *pvt_info; /* pointer to 'private driver' info */615616unsigned long start_time; /* edac_device load start time (jiffies) */617618struct completion removal_complete;619620/* sysfs top name under 'edac' directory621* and instance name:622* cpu/cpu0/...623* cpu/cpu1/...624* cpu/cpu2/...625* ...626*/627char name[EDAC_DEVICE_NAME_LEN + 1];628629/* Number of instances supported on this control structure630* and the array of those instances631*/632u32 nr_instances;633struct edac_device_instance *instances;634635/* Event counters for the this whole EDAC Device */636struct edac_device_counter counters;637638/* edac sysfs device control for the 'name'639* device this structure controls640*/641struct kobject kobj;642};643644/* To get from the instance's wq to the beginning of the ctl structure */645#define to_edac_mem_ctl_work(w) \646container_of(w, struct mem_ctl_info, work)647648#define to_edac_device_ctl_work(w) \649container_of(w,struct edac_device_ctl_info,work)650651/*652* The alloc() and free() functions for the 'edac_device' control info653* structure. A MC driver will allocate one of these for each edac_device654* it is going to control/register with the EDAC CORE.655*/656extern struct edac_device_ctl_info *edac_device_alloc_ctl_info(657unsigned sizeof_private,658char *edac_device_name, unsigned nr_instances,659char *edac_block_name, unsigned nr_blocks,660unsigned offset_value,661struct edac_dev_sysfs_block_attribute *block_attributes,662unsigned nr_attribs,663int device_index);664665/* The offset value can be:666* -1 indicating no offset value667* 0 for zero-based block numbers668* 1 for 1-based block number669* other for other-based block number670*/671#define BLOCK_OFFSET_VALUE_OFF ((unsigned) -1)672673extern void edac_device_free_ctl_info(struct edac_device_ctl_info *ctl_info);674675#ifdef CONFIG_PCI676677struct edac_pci_counter {678atomic_t pe_count;679atomic_t npe_count;680};681682/*683* Abstract edac_pci control info structure684*685*/686struct edac_pci_ctl_info {687/* for global list of edac_pci_ctl_info structs */688struct list_head link;689690int pci_idx;691692struct sysdev_class *edac_class; /* pointer to class */693694/* the internal state of this controller instance */695int op_state;696/* work struct for this instance */697struct delayed_work work;698699/* pointer to edac polling checking routine:700* If NOT NULL: points to polling check routine701* If NULL: Then assumes INTERRUPT operation, where702* MC driver will receive events703*/704void (*edac_check) (struct edac_pci_ctl_info * edac_dev);705706struct device *dev; /* pointer to device structure */707708const char *mod_name; /* module name */709const char *ctl_name; /* edac controller name */710const char *dev_name; /* pci/platform/etc... name */711712void *pvt_info; /* pointer to 'private driver' info */713714unsigned long start_time; /* edac_pci load start time (jiffies) */715716struct completion complete;717718/* sysfs top name under 'edac' directory719* and instance name:720* cpu/cpu0/...721* cpu/cpu1/...722* cpu/cpu2/...723* ...724*/725char name[EDAC_DEVICE_NAME_LEN + 1];726727/* Event counters for the this whole EDAC Device */728struct edac_pci_counter counters;729730/* edac sysfs device control for the 'name'731* device this structure controls732*/733struct kobject kobj;734struct completion kobj_complete;735};736737#define to_edac_pci_ctl_work(w) \738container_of(w, struct edac_pci_ctl_info,work)739740/* write all or some bits in a byte-register*/741static inline void pci_write_bits8(struct pci_dev *pdev, int offset, u8 value,742u8 mask)743{744if (mask != 0xff) {745u8 buf;746747pci_read_config_byte(pdev, offset, &buf);748value &= mask;749buf &= ~mask;750value |= buf;751}752753pci_write_config_byte(pdev, offset, value);754}755756/* write all or some bits in a word-register*/757static inline void pci_write_bits16(struct pci_dev *pdev, int offset,758u16 value, u16 mask)759{760if (mask != 0xffff) {761u16 buf;762763pci_read_config_word(pdev, offset, &buf);764value &= mask;765buf &= ~mask;766value |= buf;767}768769pci_write_config_word(pdev, offset, value);770}771772/*773* pci_write_bits32774*775* edac local routine to do pci_write_config_dword, but adds776* a mask parameter. If mask is all ones, ignore the mask.777* Otherwise utilize the mask to isolate specified bits778*779* write all or some bits in a dword-register780*/781static inline void pci_write_bits32(struct pci_dev *pdev, int offset,782u32 value, u32 mask)783{784if (mask != 0xffffffff) {785u32 buf;786787pci_read_config_dword(pdev, offset, &buf);788value &= mask;789buf &= ~mask;790value |= buf;791}792793pci_write_config_dword(pdev, offset, value);794}795796#endif /* CONFIG_PCI */797798extern struct mem_ctl_info *edac_mc_alloc(unsigned sz_pvt, unsigned nr_csrows,799unsigned nr_chans, int edac_index);800extern int edac_mc_add_mc(struct mem_ctl_info *mci);801extern void edac_mc_free(struct mem_ctl_info *mci);802extern struct mem_ctl_info *edac_mc_find(int idx);803extern struct mem_ctl_info *find_mci_by_dev(struct device *dev);804extern struct mem_ctl_info *edac_mc_del_mc(struct device *dev);805extern int edac_mc_find_csrow_by_page(struct mem_ctl_info *mci,806unsigned long page);807808/*809* The no info errors are used when error overflows are reported.810* There are a limited number of error logging registers that can811* be exausted. When all registers are exhausted and an additional812* error occurs then an error overflow register records that an813* error occurred and the type of error, but doesn't have any814* further information. The ce/ue versions make for cleaner815* reporting logic and function interface - reduces conditional816* statement clutter and extra function arguments.817*/818extern void edac_mc_handle_ce(struct mem_ctl_info *mci,819unsigned long page_frame_number,820unsigned long offset_in_page,821unsigned long syndrome, int row, int channel,822const char *msg);823extern void edac_mc_handle_ce_no_info(struct mem_ctl_info *mci,824const char *msg);825extern void edac_mc_handle_ue(struct mem_ctl_info *mci,826unsigned long page_frame_number,827unsigned long offset_in_page, int row,828const char *msg);829extern void edac_mc_handle_ue_no_info(struct mem_ctl_info *mci,830const char *msg);831extern void edac_mc_handle_fbd_ue(struct mem_ctl_info *mci, unsigned int csrow,832unsigned int channel0, unsigned int channel1,833char *msg);834extern void edac_mc_handle_fbd_ce(struct mem_ctl_info *mci, unsigned int csrow,835unsigned int channel, char *msg);836837/*838* edac_device APIs839*/840extern int edac_device_add_device(struct edac_device_ctl_info *edac_dev);841extern struct edac_device_ctl_info *edac_device_del_device(struct device *dev);842extern void edac_device_handle_ue(struct edac_device_ctl_info *edac_dev,843int inst_nr, int block_nr, const char *msg);844extern void edac_device_handle_ce(struct edac_device_ctl_info *edac_dev,845int inst_nr, int block_nr, const char *msg);846extern int edac_device_alloc_index(void);847848/*849* edac_pci APIs850*/851extern struct edac_pci_ctl_info *edac_pci_alloc_ctl_info(unsigned int sz_pvt,852const char *edac_pci_name);853854extern void edac_pci_free_ctl_info(struct edac_pci_ctl_info *pci);855856extern void edac_pci_reset_delay_period(struct edac_pci_ctl_info *pci,857unsigned long value);858859extern int edac_pci_alloc_index(void);860extern int edac_pci_add_device(struct edac_pci_ctl_info *pci, int edac_idx);861extern struct edac_pci_ctl_info *edac_pci_del_device(struct device *dev);862863extern struct edac_pci_ctl_info *edac_pci_create_generic_ctl(864struct device *dev,865const char *mod_name);866867extern void edac_pci_release_generic_ctl(struct edac_pci_ctl_info *pci);868extern int edac_pci_create_sysfs(struct edac_pci_ctl_info *pci);869extern void edac_pci_remove_sysfs(struct edac_pci_ctl_info *pci);870871/*872* edac misc APIs873*/874extern char *edac_op_state_to_string(int op_state);875876#endif /* _EDAC_CORE_H_ */877878879