transport_class.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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/attribute_container.h>
  12. struct transport_class {
  13. struct class class;
  14. int (*setup)(struct device *);
  15. int (*configure)(struct device *);
  16. int (*remove)(struct device *);
  17. };
  18. #define DECLARE_TRANSPORT_CLASS(cls, nm, su, rm, cfg) \
  19. struct transport_class cls = { \
  20. .class = { \
  21. .name = nm, \
  22. }, \
  23. .setup = su, \
  24. .remove = rm, \
  25. .configure = cfg, \
  26. }
  27. struct anon_transport_class {
  28. struct transport_class tclass;
  29. struct attribute_container container;
  30. };
  31. #define DECLARE_ANON_TRANSPORT_CLASS(cls, mtch, cfg) \
  32. struct anon_transport_class cls = { \
  33. .tclass = { \
  34. .configure = cfg, \
  35. }, \
  36. . container = { \
  37. .match = mtch, \
  38. }, \
  39. }
  40. #define class_to_transport_class(x) \
  41. container_of(x, struct transport_class, class)
  42. struct transport_container {
  43. struct attribute_container ac;
  44. struct attribute_group *statistics;
  45. };
  46. #define attribute_container_to_transport_container(x) \
  47. container_of(x, struct transport_container, ac)
  48. void transport_remove_device(struct device *);
  49. void transport_add_device(struct device *);
  50. void transport_setup_device(struct device *);
  51. void transport_configure_device(struct device *);
  52. void transport_destroy_device(struct device *);
  53. static inline void
  54. transport_register_device(struct device *dev)
  55. {
  56. transport_setup_device(dev);
  57. transport_add_device(dev);
  58. }
  59. static inline void
  60. transport_unregister_device(struct device *dev)
  61. {
  62. transport_remove_device(dev);
  63. transport_destroy_device(dev);
  64. }
  65. static inline int transport_container_register(struct transport_container *tc)
  66. {
  67. return attribute_container_register(&tc->ac);
  68. }
  69. static inline int transport_container_unregister(struct transport_container *tc)
  70. {
  71. return attribute_container_unregister(&tc->ac);
  72. }
  73. int transport_class_register(struct transport_class *);
  74. int anon_transport_class_register(struct anon_transport_class *);
  75. void transport_class_unregister(struct transport_class *);
  76. void anon_transport_class_unregister(struct anon_transport_class *);
  77. #endif