blob: 896c6892f327848ed195f8f7cb7b7181ae353557 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/list.h>
James Bottomley53c165e2005-08-22 10:06:19 -050013#include <linux/klist.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
Paul Gortmaker313162d2012-01-30 11:46:54 -050015struct device;
16
Linus Torvalds1da177e2005-04-16 15:20:36 -070017struct attribute_container {
18 struct list_head node;
James Bottomley53c165e2005-08-22 10:06:19 -050019 struct klist containers;
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 struct class *class;
David Brownella4dbd672009-06-24 10:06:31 -070021 const struct attribute_group *grp;
Tony Jonesee959b02008-02-22 00:13:36 +010022 struct device_attribute **attrs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070023 int (*match)(struct attribute_container *, struct device *);
24#define ATTRIBUTE_CONTAINER_NO_CLASSDEVS 0x01
25 unsigned long flags;
26};
27
28static inline int
29attribute_container_no_classdevs(struct attribute_container *atc)
30{
31 return atc->flags & ATTRIBUTE_CONTAINER_NO_CLASSDEVS;
32}
33
34static inline void
35attribute_container_set_no_classdevs(struct attribute_container *atc)
36{
37 atc->flags |= ATTRIBUTE_CONTAINER_NO_CLASSDEVS;
38}
39
40int attribute_container_register(struct attribute_container *cont);
James Bottomley2f3edc692008-04-02 10:05:48 -050041int __must_check attribute_container_unregister(struct attribute_container *cont);
Linus Torvalds1da177e2005-04-16 15:20:36 -070042void attribute_container_create_device(struct device *dev,
43 int (*fn)(struct attribute_container *,
44 struct device *,
Tony Jonesee959b02008-02-22 00:13:36 +010045 struct device *));
Linus Torvalds1da177e2005-04-16 15:20:36 -070046void attribute_container_add_device(struct device *dev,
47 int (*fn)(struct attribute_container *,
48 struct device *,
Tony Jonesee959b02008-02-22 00:13:36 +010049 struct device *));
Linus Torvalds1da177e2005-04-16 15:20:36 -070050void attribute_container_remove_device(struct device *dev,
51 void (*fn)(struct attribute_container *,
52 struct device *,
Tony Jonesee959b02008-02-22 00:13:36 +010053 struct device *));
Linus Torvalds1da177e2005-04-16 15:20:36 -070054void attribute_container_device_trigger(struct device *dev,
55 int (*fn)(struct attribute_container *,
56 struct device *,
Tony Jonesee959b02008-02-22 00:13:36 +010057 struct device *));
Linus Torvalds1da177e2005-04-16 15:20:36 -070058void attribute_container_trigger(struct device *dev,
59 int (*fn)(struct attribute_container *,
60 struct device *));
Tony Jonesee959b02008-02-22 00:13:36 +010061int attribute_container_add_attrs(struct device *classdev);
62int attribute_container_add_class_device(struct device *classdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063int attribute_container_add_class_device_adapter(struct attribute_container *cont,
64 struct device *dev,
Tony Jonesee959b02008-02-22 00:13:36 +010065 struct device *classdev);
66void attribute_container_remove_attrs(struct device *classdev);
67void attribute_container_class_device_del(struct device *classdev);
68struct attribute_container *attribute_container_classdev_to_container(struct device *);
69struct device *attribute_container_find_class_device(struct attribute_container *, struct device *);
70struct device_attribute **attribute_container_classdev_to_attrs(const struct device *classdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72#endif