linux/drivers/misc/enclosure.c

// SPDX-License-Identifier: GPL-2.0-only
/*
 * Enclosure Services
 *
 * Copyright (C) 2008 James Bottomley <[email protected]>
 *
**-----------------------------------------------------------------------------
**
**
**-----------------------------------------------------------------------------
*/
#include <linux/device.h>
#include <linux/enclosure.h>
#include <linux/err.h>
#include <linux/list.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/slab.h>

static LIST_HEAD(container_list);
static DEFINE_MUTEX(container_list_lock);
static struct class enclosure_class;

/**
 * enclosure_find - find an enclosure given a parent device
 * @dev:	the parent to match against
 * @start:	Optional enclosure device to start from (NULL if none)
 *
 * Looks through the list of registered enclosures to find all those
 * with @dev as a parent.  Returns NULL if no enclosure is
 * found. @start can be used as a starting point to obtain multiple
 * enclosures per parent (should begin with NULL and then be set to
 * each returned enclosure device). Obtains a reference to the
 * enclosure class device which must be released with put_device().
 * If @start is not NULL, a reference must be taken on it which is
 * released before returning (this allows a loop through all
 * enclosures to exit with only the reference on the enclosure of
 * interest held).  Note that the @dev may correspond to the actual
 * device housing the enclosure, in which case no iteration via @start
 * is required.
 */
struct enclosure_device *enclosure_find(struct device *dev,
					struct enclosure_device *start)
{}
EXPORT_SYMBOL_GPL();

/**
 * enclosure_for_each_device - calls a function for each enclosure
 * @fn:		the function to call
 * @data:	the data to pass to each call
 *
 * Loops over all the enclosures calling the function.
 *
 * Note, this function uses a mutex which will be held across calls to
 * @fn, so it must have non atomic context, and @fn may (although it
 * should not) sleep or otherwise cause the mutex to be held for
 * indefinite periods
 */
int enclosure_for_each_device(int (*fn)(struct enclosure_device *, void *),
			      void *data)
{}
EXPORT_SYMBOL_GPL();

/**
 * enclosure_register - register device as an enclosure
 *
 * @dev:	device containing the enclosure
 * @name:	chosen device name
 * @components:	number of components in the enclosure
 * @cb:         platform call-backs
 *
 * This sets up the device for being an enclosure.  Note that @dev does
 * not have to be a dedicated enclosure device.  It may be some other type
 * of device that additionally responds to enclosure services
 */
struct enclosure_device *
enclosure_register(struct device *dev, const char *name, int components,
		   struct enclosure_component_callbacks *cb)
{}
EXPORT_SYMBOL_GPL();

static struct enclosure_component_callbacks enclosure_null_callbacks;

/**
 * enclosure_unregister - remove an enclosure
 *
 * @edev:	the registered enclosure to remove;
 */
void enclosure_unregister(struct enclosure_device *edev)
{}
EXPORT_SYMBOL_GPL();

#define ENCLOSURE_NAME_SIZE
#define COMPONENT_NAME_SIZE

static void enclosure_link_name(struct enclosure_component *cdev, char *name)
{}

static void enclosure_remove_links(struct enclosure_component *cdev)
{}

static int enclosure_add_links(struct enclosure_component *cdev)
{}

static void enclosure_release(struct device *cdev)
{}

static void enclosure_component_release(struct device *dev)
{}

static struct enclosure_component *
enclosure_component_find_by_name(struct enclosure_device *edev,
				const char *name)
{}

static const struct attribute_group *enclosure_component_groups[];

/**
 * enclosure_component_alloc - prepare a new enclosure component
 * @edev:	the enclosure to add the component
 * @number:	the device number
 * @type:	the type of component being added
 * @name:	an optional name to appear in sysfs (leave NULL if none)
 *
 * The name is optional for enclosures that give their components a unique
 * name.  If not, leave the field NULL and a name will be assigned.
 *
 * Returns a pointer to the enclosure component or an error.
 */
struct enclosure_component *
enclosure_component_alloc(struct enclosure_device *edev,
			  unsigned int number,
			  enum enclosure_component_type type,
			  const char *name)
{}
EXPORT_SYMBOL_GPL();

/**
 * enclosure_component_register - publishes an initialized enclosure component
 * @ecomp:	component to add
 *
 * Returns 0 on successful registration, releases the component otherwise
 */
int enclosure_component_register(struct enclosure_component *ecomp)
{}
EXPORT_SYMBOL_GPL();

/**
 * enclosure_add_device - add a device as being part of an enclosure
 * @edev:	the enclosure device being added to.
 * @component:	the number of the component
 * @dev:	the device being added
 *
 * Declares a real device to reside in slot (or identifier) @num of an
 * enclosure.  This will cause the relevant sysfs links to appear.
 * This function may also be used to change a device associated with
 * an enclosure without having to call enclosure_remove_device() in
 * between.
 *
 * Returns zero on success or an error.
 */
int enclosure_add_device(struct enclosure_device *edev, int component,
			 struct device *dev)
{}
EXPORT_SYMBOL_GPL();

/**
 * enclosure_remove_device - remove a device from an enclosure
 * @edev:	the enclosure device
 * @dev:	device to remove/put
 *
 * Returns zero on success or an error.
 *
 */
int enclosure_remove_device(struct enclosure_device *edev, struct device *dev)
{}
EXPORT_SYMBOL_GPL();

/*
 * sysfs pieces below
 */

static ssize_t components_show(struct device *cdev,
			       struct device_attribute *attr, char *buf)
{}
static DEVICE_ATTR_RO(components);

static ssize_t id_show(struct device *cdev,
				 struct device_attribute *attr,
				 char *buf)
{}
static DEVICE_ATTR_RO(id);

static struct attribute *enclosure_class_attrs[] =;
ATTRIBUTE_GROUPS();

static struct class enclosure_class =;

static const char *const enclosure_status[] =;

static const char *const enclosure_type[] =;

static ssize_t get_component_fault(struct device *cdev,
				   struct device_attribute *attr, char *buf)
{}

static ssize_t set_component_fault(struct device *cdev,
				   struct device_attribute *attr,
				   const char *buf, size_t count)
{}

static ssize_t get_component_status(struct device *cdev,
				    struct device_attribute *attr,char *buf)
{}

static ssize_t set_component_status(struct device *cdev,
				    struct device_attribute *attr,
				    const char *buf, size_t count)
{}

static ssize_t get_component_active(struct device *cdev,
				    struct device_attribute *attr, char *buf)
{}

static ssize_t set_component_active(struct device *cdev,
				    struct device_attribute *attr,
				    const char *buf, size_t count)
{}

static ssize_t get_component_locate(struct device *cdev,
				    struct device_attribute *attr, char *buf)
{}

static ssize_t set_component_locate(struct device *cdev,
				    struct device_attribute *attr,
				    const char *buf, size_t count)
{}

static ssize_t get_component_power_status(struct device *cdev,
					  struct device_attribute *attr,
					  char *buf)
{}

static ssize_t set_component_power_status(struct device *cdev,
					  struct device_attribute *attr,
					  const char *buf, size_t count)
{}

static ssize_t get_component_type(struct device *cdev,
				  struct device_attribute *attr, char *buf)
{}

static ssize_t get_component_slot(struct device *cdev,
				  struct device_attribute *attr, char *buf)
{}

static DEVICE_ATTR(fault, S_IRUGO | S_IWUSR, get_component_fault,
		    set_component_fault);
static DEVICE_ATTR(status, S_IRUGO | S_IWUSR, get_component_status,
		   set_component_status);
static DEVICE_ATTR(active, S_IRUGO | S_IWUSR, get_component_active,
		   set_component_active);
static DEVICE_ATTR(locate, S_IRUGO | S_IWUSR, get_component_locate,
		   set_component_locate);
static DEVICE_ATTR(power_status, S_IRUGO | S_IWUSR, get_component_power_status,
		   set_component_power_status);
static DEVICE_ATTR(type, S_IRUGO, get_component_type, NULL);
static DEVICE_ATTR(slot, S_IRUGO, get_component_slot, NULL);

static struct attribute *enclosure_component_attrs[] =;
ATTRIBUTE_GROUPS();

static int __init enclosure_init(void)
{}

static void __exit enclosure_exit(void)
{}

module_init();
module_exit(enclosure_exit);

MODULE_AUTHOR();
MODULE_DESCRIPTION();
MODULE_LICENSE();