transport_class.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * transport_class.h - a generic container for all transport classes
  3. *
  4. * Copyright (c) 2005 - James Bottomley <James.Bottomley@steeleye.com>
  5. *
  6. * This file is licensed under GPLv2
  7. */
  8. #ifndef _TRANSPORT_CLASS_H_
  9. #define _TRANSPORT_CLASS_H_
  10. #include <linux/device.h>
  11. #include <linux/bug.h>
  12. #include <linux/attribute_container.h>
  13. struct transport_container;
  14. struct transport_class {
  15. struct class class;
  16. int (*setup)(struct transport_container *, struct device *,
  17. struct device *);
  18. int (*configure)(struct transport_container *, struct device *,
  19. struct device *);
  20. int (*remove)(struct transport_container *, struct device *,
  21. struct device *);
  22. };
  23. #define DECLARE_TRANSPORT_CLASS(cls, nm, su, rm, cfg) \
  24. struct transport_class cls = { \
  25. .class = { \
  26. .name = nm, \
  27. }, \
  28. .setup = su, \
  29. .remove = rm, \
  30. .configure = cfg, \
  31. }
  32. struct anon_transport_class {
  33. struct transport_class tclass;
  34. struct attribute_container container;
  35. };
  36. #define DECLARE_ANON_TRANSPORT_CLASS(cls, mtch, cfg) \
  37. struct anon_transport_class cls = { \
  38. .tclass = { \
  39. .configure = cfg, \
  40. }, \
  41. . container = { \
  42. .match = mtch, \
  43. }, \
  44. }
  45. #define class_to_transport_class(x) \
  46. container_of(x, struct transport_class, class)
  47. struct transport_container {
  48. struct attribute_container ac;
  49. const struct attribute_group *statistics;
  50. };
  51. #define attribute_container_to_transport_container(x) \
  52. container_of(x, struct transport_container, ac)
  53. void transport_remove_device(struct device *);
  54. void transport_add_device(struct device *);
  55. void transport_setup_device(struct device *);
  56. void transport_configure_device(struct device *);
  57. void transport_destroy_device(struct device *);
  58. static inline void
  59. transport_register_device(struct device *dev)
  60. {
  61. transport_setup_device(dev);
  62. transport_add_device(dev);
  63. }
  64. static inline void
  65. transport_unregister_device(struct device *dev)
  66. {
  67. transport_remove_device(dev);
  68. transport_destroy_device(dev);
  69. }
  70. static inline int transport_container_register(struct transport_container *tc)
  71. {
  72. return attribute_container_register(&tc->ac);
  73. }
  74. static inline void transport_container_unregister(struct transport_container *tc)
  75. {
  76. if (unlikely(attribute_container_unregister(&tc->ac)))
  77. BUG();
  78. }
  79. int transport_class_register(struct transport_class *);
  80. int anon_transport_class_register(struct anon_transport_class *);
  81. void transport_class_unregister(struct transport_class *);
  82. void anon_transport_class_unregister(struct anon_transport_class *);
  83. #endif