linux/drivers/edac/edac_device.h

/*
 * Defines, structures, APIs for edac_device
 *
 * (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 <[email protected]> <[email protected]>
 *
 * Refactored for multi-source files:
 *	Doug Thompson <[email protected]>
 *
 * Please look at Documentation/driver-api/edac.rst for more info about
 * EDAC core structs and functions.
 */

#ifndef _EDAC_DEVICE_H_
#define _EDAC_DEVICE_H_

#include <linux/device.h>
#include <linux/edac.h>
#include <linux/kobject.h>
#include <linux/list.h>
#include <linux/types.h>
#include <linux/sysfs.h>
#include <linux/workqueue.h>


/*
 * The following are the structures to provide for a generic
 * or abstract 'edac_device'. This set of structures and the
 * code that implements the APIs for the same, provide for
 * registering EDAC type devices which are NOT standard memory.
 *
 * CPU caches (L1 and L2)
 * DMA engines
 * Core CPU switches
 * Fabric switch units
 * PCIe interface controllers
 * other EDAC/ECC type devices that can be monitored for
 * errors, etc.
 *
 * It allows for a 2 level set of hierarchy. For example:
 *
 * cache could be composed of L1, L2 and L3 levels of cache.
 * Each CPU core would have its own L1 cache, while sharing
 * L2 and maybe L3 caches.
 *
 * View them arranged, via the sysfs presentation:
 * /sys/devices/system/edac/..
 *
 *	mc/		<existing memory device directory>
 *	cpu/cpu0/..	<L1 and L2 block directory>
 *		/L1-cache/ce_count
 *			 /ue_count
 *		/L2-cache/ce_count
 *			 /ue_count
 *	cpu/cpu1/..	<L1 and L2 block directory>
 *		/L1-cache/ce_count
 *			 /ue_count
 *		/L2-cache/ce_count
 *			 /ue_count
 *	...
 *
 *	the L1 and L2 directories would be "edac_device_block's"
 */

struct edac_device_counter {};

/* forward reference */
struct edac_device_ctl_info;
struct edac_device_block;

/* edac_dev_sysfs_attribute structure
 *	used for driver sysfs attributes in mem_ctl_info
 *	for extra controls and attributes:
 *		like high level error Injection controls
 */
struct edac_dev_sysfs_attribute {};

/* edac_dev_sysfs_block_attribute structure
 *
 *	used in leaf 'block' nodes for adding controls/attributes
 *
 *	each block in each instance of the containing control structure can
 *	have an array of the following. The show function will be filled in
 *	with the show function in the low level driver.
 */
struct edac_dev_sysfs_block_attribute {};

/* device block control structure */
struct edac_device_block {};

/* device instance control structure */
struct edac_device_instance {};


/*
 * Abstract edac_device control info structure
 *
 */
struct edac_device_ctl_info {};

/* To get from the instance's wq to the beginning of the ctl structure */
#define to_edac_mem_ctl_work(w)

#define to_edac_device_ctl_work(w)

/*
 * The alloc() and free() functions for the 'edac_device' control info
 * structure. A MC driver will allocate one of these for each edac_device
 * it is going to control/register with the EDAC CORE.
 */
extern struct edac_device_ctl_info *edac_device_alloc_ctl_info(
		unsigned sizeof_private,
		char *edac_device_name, unsigned nr_instances,
		char *edac_block_name, unsigned nr_blocks,
		unsigned offset_value,
		int device_index);

/* The offset value can be:
 *	-1 indicating no offset value
 *	0 for zero-based block numbers
 *	1 for 1-based block number
 *	other for other-based block number
 */
#define BLOCK_OFFSET_VALUE_OFF

extern void edac_device_free_ctl_info(struct edac_device_ctl_info *ctl_info);

/**
 * edac_device_add_device - Insert the 'edac_dev' structure into the
 *	 edac_device global list and create sysfs entries associated with
 *	 edac_device structure.
 *
 * @edac_dev: pointer to edac_device structure to be added to the list
 *	'edac_device' structure.
 *
 * Returns:
 *	0 on Success, or an error code on failure
 */
extern int edac_device_add_device(struct edac_device_ctl_info *edac_dev);

/**
 * edac_device_del_device - Remove sysfs entries for specified edac_device
 *	structure and then remove edac_device structure from global list
 *
 * @dev:
 *	Pointer to struct &device representing the edac device
 *	structure to remove.
 *
 * Returns:
 *	Pointer to removed edac_device structure,
 *	or %NULL if device not found.
 */
extern struct edac_device_ctl_info *edac_device_del_device(struct device *dev);

/**
 * edac_device_handle_ce_count - Log correctable errors.
 *
 * @edac_dev: pointer to struct &edac_device_ctl_info
 * @inst_nr: number of the instance where the CE error happened
 * @count: Number of errors to log.
 * @block_nr: number of the block where the CE error happened
 * @msg: message to be printed
 */
void edac_device_handle_ce_count(struct edac_device_ctl_info *edac_dev,
				 unsigned int count, int inst_nr, int block_nr,
				 const char *msg);

/**
 * edac_device_handle_ue_count - Log uncorrectable errors.
 *
 * @edac_dev: pointer to struct &edac_device_ctl_info
 * @inst_nr: number of the instance where the CE error happened
 * @count: Number of errors to log.
 * @block_nr: number of the block where the CE error happened
 * @msg: message to be printed
 */
void edac_device_handle_ue_count(struct edac_device_ctl_info *edac_dev,
				 unsigned int count, int inst_nr, int block_nr,
				 const char *msg);

/**
 * edac_device_handle_ce(): Log a single correctable error
 *
 * @edac_dev: pointer to struct &edac_device_ctl_info
 * @inst_nr: number of the instance where the CE error happened
 * @block_nr: number of the block where the CE error happened
 * @msg: message to be printed
 */
static inline void
edac_device_handle_ce(struct edac_device_ctl_info *edac_dev, int inst_nr,
		      int block_nr, const char *msg)
{}

/**
 * edac_device_handle_ue(): Log a single uncorrectable error
 *
 * @edac_dev: pointer to struct &edac_device_ctl_info
 * @inst_nr: number of the instance where the UE error happened
 * @block_nr: number of the block where the UE error happened
 * @msg: message to be printed
 */
static inline void
edac_device_handle_ue(struct edac_device_ctl_info *edac_dev, int inst_nr,
		      int block_nr, const char *msg)
{}

/**
 * edac_device_alloc_index: Allocate a unique device index number
 *
 * Returns:
 *	allocated index number
 */
extern int edac_device_alloc_index(void);
extern const char *edac_layer_name[];

/* Free the actual struct */
static inline void __edac_device_free_ctl_info(struct edac_device_ctl_info *ci)
{}
#endif