attribute_container.h 2.47 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1
/*
2
 * attribute_container.h - a generic container for all classes
Linus Torvalds's avatar
Linus Torvalds committed
3 4 5 6 7 8 9 10 11 12
 *
 * Copyright (c) 2005 - James Bottomley <James.Bottomley@steeleye.com>
 *
 * This file is licensed under GPLv2
 */

#ifndef _ATTRIBUTE_CONTAINER_H_
#define _ATTRIBUTE_CONTAINER_H_

#include <linux/list.h>
13
#include <linux/klist.h>
Linus Torvalds's avatar
Linus Torvalds committed
14

15 16
struct device;

Linus Torvalds's avatar
Linus Torvalds committed
17 18
struct attribute_container {
	struct list_head	node;
19
	struct klist		containers;
Linus Torvalds's avatar
Linus Torvalds committed
20
	struct class		*class;
21
	const struct attribute_group *grp;
22
	struct device_attribute **attrs;
Linus Torvalds's avatar
Linus Torvalds committed
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
	int (*match)(struct attribute_container *, struct device *);
#define	ATTRIBUTE_CONTAINER_NO_CLASSDEVS	0x01
	unsigned long		flags;
};

static inline int
attribute_container_no_classdevs(struct attribute_container *atc)
{
	return atc->flags & ATTRIBUTE_CONTAINER_NO_CLASSDEVS;
}

static inline void
attribute_container_set_no_classdevs(struct attribute_container *atc)
{
	atc->flags |= ATTRIBUTE_CONTAINER_NO_CLASSDEVS;
}

int attribute_container_register(struct attribute_container *cont);
41
int __must_check attribute_container_unregister(struct attribute_container *cont);
Linus Torvalds's avatar
Linus Torvalds committed
42 43 44
void attribute_container_create_device(struct device *dev,
				       int (*fn)(struct attribute_container *,
						 struct device *,
45
						 struct device *));
Linus Torvalds's avatar
Linus Torvalds committed
46 47 48
void attribute_container_add_device(struct device *dev,
				    int (*fn)(struct attribute_container *,
					      struct device *,
49
					      struct device *));
Linus Torvalds's avatar
Linus Torvalds committed
50 51 52
void attribute_container_remove_device(struct device *dev,
				       void (*fn)(struct attribute_container *,
						  struct device *,
53
						  struct device *));
Linus Torvalds's avatar
Linus Torvalds committed
54 55 56
void attribute_container_device_trigger(struct device *dev, 
					int (*fn)(struct attribute_container *,
						  struct device *,
57
						  struct device *));
Linus Torvalds's avatar
Linus Torvalds committed
58 59 60
void attribute_container_trigger(struct device *dev, 
				 int (*fn)(struct attribute_container *,
					   struct device *));
61 62
int attribute_container_add_attrs(struct device *classdev);
int attribute_container_add_class_device(struct device *classdev);
Linus Torvalds's avatar
Linus Torvalds committed
63 64
int attribute_container_add_class_device_adapter(struct attribute_container *cont,
						 struct device *dev,
65 66 67 68 69 70
						 struct device *classdev);
void attribute_container_remove_attrs(struct device *classdev);
void attribute_container_class_device_del(struct device *classdev);
struct attribute_container *attribute_container_classdev_to_container(struct device *);
struct device *attribute_container_find_class_device(struct attribute_container *, struct device *);
struct device_attribute **attribute_container_classdev_to_attrs(const struct device *classdev);
Linus Torvalds's avatar
Linus Torvalds committed
71 72

#endif