blob: c3ab81428c6624ffaf7e93612f42654e7c570176 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Tony Jonesee959b02008-02-22 00:13:36 +01002 * attribute_container.h - a generic container for all classes
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * Copyright (c) 2005 - James Bottomley <James.Bottomley@steeleye.com>
5 *
6 * This file is licensed under GPLv2
7 */
8
9#ifndef _ATTRIBUTE_CONTAINER_H_
10#define _ATTRIBUTE_CONTAINER_H_
11
12#include <linux/device.h>
13#include <linux/list.h>
James Bottomley53c165e2005-08-22 10:06:19 -050014#include <linux/klist.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
16struct attribute_container {
17 struct list_head node;
James Bottomley53c165e2005-08-22 10:06:19 -050018 struct klist containers;
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 struct class *class;
David Brownella4dbd672009-06-24 10:06:31 -070020 const struct attribute_group *grp;
Tony Jonesee959b02008-02-22 00:13:36 +010021 struct device_attribute **attrs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 int (*match)(struct attribute_container *, struct device *);
23#define ATTRIBUTE_CONTAINER_NO_CLASSDEVS 0x01
24 unsigned long flags;
25};
26
27static inline int
28attribute_container_no_classdevs(struct attribute_container *atc)
29{
30 return atc->flags & ATTRIBUTE_CONTAINER_NO_CLASSDEVS;
31}
32
33static inline void
34attribute_container_set_no_classdevs(struct attribute_container *atc)
35{
36 atc->flags |= ATTRIBUTE_CONTAINER_NO_CLASSDEVS;
37}
38
39int attribute_container_register(struct attribute_container *cont);
James Bottomley2f3edc62008-04-02 10:05:48 -050040int __must_check attribute_container_unregister(struct attribute_container *cont);
Linus Torvalds1da177e2005-04-16 15:20:36 -070041void attribute_container_create_device(struct device *dev,
42 int (*fn)(struct attribute_container *,
43 struct device *,
Tony Jonesee959b02008-02-22 00:13:36 +010044 struct device *));
Linus Torvalds1da177e2005-04-16 15:20:36 -070045void attribute_container_add_device(struct device *dev,
46 int (*fn)(struct attribute_container *,
47 struct device *,
Tony Jonesee959b02008-02-22 00:13:36 +010048 struct device *));
Linus Torvalds1da177e2005-04-16 15:20:36 -070049void attribute_container_remove_device(struct device *dev,
50 void (*fn)(struct attribute_container *,
51 struct device *,
Tony Jonesee959b02008-02-22 00:13:36 +010052 struct device *));
Linus Torvalds1da177e2005-04-16 15:20:36 -070053void attribute_container_device_trigger(struct device *dev,
54 int (*fn)(struct attribute_container *,
55 struct device *,
Tony Jonesee959b02008-02-22 00:13:36 +010056 struct device *));
Linus Torvalds1da177e2005-04-16 15:20:36 -070057void attribute_container_trigger(struct device *dev,
58 int (*fn)(struct attribute_container *,
59 struct device *));
Tony Jonesee959b02008-02-22 00:13:36 +010060int attribute_container_add_attrs(struct device *classdev);
61int attribute_container_add_class_device(struct device *classdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062int attribute_container_add_class_device_adapter(struct attribute_container *cont,
63 struct device *dev,
Tony Jonesee959b02008-02-22 00:13:36 +010064 struct device *classdev);
65void attribute_container_remove_attrs(struct device *classdev);
66void attribute_container_class_device_del(struct device *classdev);
67struct attribute_container *attribute_container_classdev_to_container(struct device *);
68struct device *attribute_container_find_class_device(struct attribute_container *, struct device *);
69struct device_attribute **attribute_container_classdev_to_attrs(const struct device *classdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71#endif