Thomas Gleixner | 8266496 | 2019-06-01 10:08:51 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 3 | * attribute_container.h - a generic container for all classes |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
| 5 | * Copyright (c) 2005 - James Bottomley <James.Bottomley@steeleye.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef _ATTRIBUTE_CONTAINER_H_ |
| 9 | #define _ATTRIBUTE_CONTAINER_H_ |
| 10 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/list.h> |
James Bottomley | 53c165e | 2005-08-22 10:06:19 -0500 | [diff] [blame] | 12 | #include <linux/klist.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | |
Paul Gortmaker | 313162d | 2012-01-30 11:46:54 -0500 | [diff] [blame] | 14 | struct device; |
| 15 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | struct attribute_container { |
| 17 | struct list_head node; |
James Bottomley | 53c165e | 2005-08-22 10:06:19 -0500 | [diff] [blame] | 18 | struct klist containers; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | struct class *class; |
David Brownell | a4dbd67 | 2009-06-24 10:06:31 -0700 | [diff] [blame] | 20 | const struct attribute_group *grp; |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 21 | struct device_attribute **attrs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | int (*match)(struct attribute_container *, struct device *); |
| 23 | #define ATTRIBUTE_CONTAINER_NO_CLASSDEVS 0x01 |
| 24 | unsigned long flags; |
| 25 | }; |
| 26 | |
| 27 | static inline int |
| 28 | attribute_container_no_classdevs(struct attribute_container *atc) |
| 29 | { |
| 30 | return atc->flags & ATTRIBUTE_CONTAINER_NO_CLASSDEVS; |
| 31 | } |
| 32 | |
| 33 | static inline void |
| 34 | attribute_container_set_no_classdevs(struct attribute_container *atc) |
| 35 | { |
| 36 | atc->flags |= ATTRIBUTE_CONTAINER_NO_CLASSDEVS; |
| 37 | } |
| 38 | |
| 39 | int attribute_container_register(struct attribute_container *cont); |
James Bottomley | 2f3edc69 | 2008-04-02 10:05:48 -0500 | [diff] [blame] | 40 | int __must_check attribute_container_unregister(struct attribute_container *cont); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | void attribute_container_create_device(struct device *dev, |
| 42 | int (*fn)(struct attribute_container *, |
| 43 | struct device *, |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 44 | struct device *)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | void attribute_container_add_device(struct device *dev, |
| 46 | int (*fn)(struct attribute_container *, |
| 47 | struct device *, |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 48 | struct device *)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | void attribute_container_remove_device(struct device *dev, |
| 50 | void (*fn)(struct attribute_container *, |
| 51 | struct device *, |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 52 | struct device *)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | void attribute_container_device_trigger(struct device *dev, |
| 54 | int (*fn)(struct attribute_container *, |
| 55 | struct device *, |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 56 | struct device *)); |
Gabriel Krisman Bertazi | 7c1ef33 | 2020-01-06 13:58:15 -0500 | [diff] [blame] | 57 | int attribute_container_device_trigger_safe(struct device *dev, |
| 58 | int (*fn)(struct attribute_container *, |
| 59 | struct device *, |
| 60 | struct device *), |
| 61 | int (*undo)(struct attribute_container *, |
| 62 | struct device *, |
| 63 | struct device *)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | void attribute_container_trigger(struct device *dev, |
| 65 | int (*fn)(struct attribute_container *, |
| 66 | struct device *)); |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 67 | int attribute_container_add_attrs(struct device *classdev); |
| 68 | int attribute_container_add_class_device(struct device *classdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | int attribute_container_add_class_device_adapter(struct attribute_container *cont, |
| 70 | struct device *dev, |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 71 | struct device *classdev); |
| 72 | void attribute_container_remove_attrs(struct device *classdev); |
| 73 | void attribute_container_class_device_del(struct device *classdev); |
| 74 | struct attribute_container *attribute_container_classdev_to_container(struct device *); |
| 75 | struct device *attribute_container_find_class_device(struct attribute_container *, struct device *); |
| 76 | struct device_attribute **attribute_container_classdev_to_attrs(const struct device *classdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
| 78 | #endif |