attribute_container.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * attribute_container.h - a generic container for all classes
  4. *
  5. * Copyright (c) 2005 - James Bottomley <James.Bottomley@steeleye.com>
  6. */
  7. #ifndef _ATTRIBUTE_CONTAINER_H_
  8. #define _ATTRIBUTE_CONTAINER_H_
  9. #include <linux/list.h>
  10. #include <linux/klist.h>
  11. struct device;
  12. struct attribute_container {
  13. struct list_head node;
  14. struct klist containers;
  15. struct class *class;
  16. const struct attribute_group *grp;
  17. struct device_attribute **attrs;
  18. int (*match)(struct attribute_container *, struct device *);
  19. #define ATTRIBUTE_CONTAINER_NO_CLASSDEVS 0x01
  20. unsigned long flags;
  21. };
  22. static inline int
  23. attribute_container_no_classdevs(struct attribute_container *atc)
  24. {
  25. return atc->flags & ATTRIBUTE_CONTAINER_NO_CLASSDEVS;
  26. }
  27. static inline void
  28. attribute_container_set_no_classdevs(struct attribute_container *atc)
  29. {
  30. atc->flags |= ATTRIBUTE_CONTAINER_NO_CLASSDEVS;
  31. }
  32. int attribute_container_register(struct attribute_container *cont);
  33. int __must_check attribute_container_unregister(struct attribute_container *cont);
  34. void attribute_container_create_device(struct device *dev,
  35. int (*fn)(struct attribute_container *,
  36. struct device *,
  37. struct device *));
  38. void attribute_container_add_device(struct device *dev,
  39. int (*fn)(struct attribute_container *,
  40. struct device *,
  41. struct device *));
  42. void attribute_container_remove_device(struct device *dev,
  43. void (*fn)(struct attribute_container *,
  44. struct device *,
  45. struct device *));
  46. void attribute_container_device_trigger(struct device *dev,
  47. int (*fn)(struct attribute_container *,
  48. struct device *,
  49. struct device *));
  50. int attribute_container_device_trigger_safe(struct device *dev,
  51. int (*fn)(struct attribute_container *,
  52. struct device *,
  53. struct device *),
  54. int (*undo)(struct attribute_container *,
  55. struct device *,
  56. struct device *));
  57. void attribute_container_trigger(struct device *dev,
  58. int (*fn)(struct attribute_container *,
  59. struct device *));
  60. int attribute_container_add_attrs(struct device *classdev);
  61. int attribute_container_add_class_device(struct device *classdev);
  62. int attribute_container_add_class_device_adapter(struct attribute_container *cont,
  63. struct device *dev,
  64. struct device *classdev);
  65. void attribute_container_remove_attrs(struct device *classdev);
  66. void attribute_container_class_device_del(struct device *classdev);
  67. struct attribute_container *attribute_container_classdev_to_container(struct device *);
  68. struct device *attribute_container_find_class_device(struct attribute_container *, struct device *);
  69. struct device_attribute **attribute_container_classdev_to_attrs(const struct device *classdev);
  70. #endif