interconnect.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2018-2019, Linaro Ltd.
  4. * Author: Georgi Djakov <[email protected]>
  5. */
  6. #ifndef __LINUX_INTERCONNECT_H
  7. #define __LINUX_INTERCONNECT_H
  8. #include <linux/mutex.h>
  9. #include <linux/types.h>
  10. /* macros for converting to icc units */
  11. #define Bps_to_icc(x) ((x) / 1000)
  12. #define kBps_to_icc(x) (x)
  13. #define MBps_to_icc(x) ((x) * 1000)
  14. #define GBps_to_icc(x) ((x) * 1000 * 1000)
  15. #define bps_to_icc(x) (1)
  16. #define kbps_to_icc(x) ((x) / 8 + ((x) % 8 ? 1 : 0))
  17. #define Mbps_to_icc(x) ((x) * 1000 / 8)
  18. #define Gbps_to_icc(x) ((x) * 1000 * 1000 / 8)
  19. struct icc_path;
  20. struct device;
  21. /**
  22. * struct icc_bulk_data - Data used for bulk icc operations.
  23. *
  24. * @path: reference to the interconnect path (internal use)
  25. * @name: the name from the "interconnect-names" DT property
  26. * @avg_bw: average bandwidth in icc units
  27. * @peak_bw: peak bandwidth in icc units
  28. */
  29. struct icc_bulk_data {
  30. struct icc_path *path;
  31. const char *name;
  32. u32 avg_bw;
  33. u32 peak_bw;
  34. };
  35. #if IS_ENABLED(CONFIG_INTERCONNECT)
  36. struct icc_path *icc_get(struct device *dev, const int src_id,
  37. const int dst_id);
  38. struct icc_path *of_icc_get(struct device *dev, const char *name);
  39. struct icc_path *devm_of_icc_get(struct device *dev, const char *name);
  40. int devm_of_icc_bulk_get(struct device *dev, int num_paths, struct icc_bulk_data *paths);
  41. struct icc_path *of_icc_get_by_index(struct device *dev, int idx);
  42. void icc_put(struct icc_path *path);
  43. int icc_enable(struct icc_path *path);
  44. int icc_disable(struct icc_path *path);
  45. int icc_set_bw(struct icc_path *path, u32 avg_bw, u32 peak_bw);
  46. void icc_set_tag(struct icc_path *path, u32 tag);
  47. const char *icc_get_name(struct icc_path *path);
  48. int __must_check of_icc_bulk_get(struct device *dev, int num_paths,
  49. struct icc_bulk_data *paths);
  50. void icc_bulk_put(int num_paths, struct icc_bulk_data *paths);
  51. int icc_bulk_set_bw(int num_paths, const struct icc_bulk_data *paths);
  52. int icc_bulk_enable(int num_paths, const struct icc_bulk_data *paths);
  53. void icc_bulk_disable(int num_paths, const struct icc_bulk_data *paths);
  54. #else
  55. static inline struct icc_path *icc_get(struct device *dev, const int src_id,
  56. const int dst_id)
  57. {
  58. return NULL;
  59. }
  60. static inline struct icc_path *of_icc_get(struct device *dev,
  61. const char *name)
  62. {
  63. return NULL;
  64. }
  65. static inline struct icc_path *devm_of_icc_get(struct device *dev,
  66. const char *name)
  67. {
  68. return NULL;
  69. }
  70. static inline struct icc_path *of_icc_get_by_index(struct device *dev, int idx)
  71. {
  72. return NULL;
  73. }
  74. static inline void icc_put(struct icc_path *path)
  75. {
  76. }
  77. static inline int icc_enable(struct icc_path *path)
  78. {
  79. return 0;
  80. }
  81. static inline int icc_disable(struct icc_path *path)
  82. {
  83. return 0;
  84. }
  85. static inline int icc_set_bw(struct icc_path *path, u32 avg_bw, u32 peak_bw)
  86. {
  87. return 0;
  88. }
  89. static inline void icc_set_tag(struct icc_path *path, u32 tag)
  90. {
  91. }
  92. static inline const char *icc_get_name(struct icc_path *path)
  93. {
  94. return NULL;
  95. }
  96. static inline int of_icc_bulk_get(struct device *dev, int num_paths, struct icc_bulk_data *paths)
  97. {
  98. return 0;
  99. }
  100. static inline int devm_of_icc_bulk_get(struct device *dev, int num_paths,
  101. struct icc_bulk_data *paths)
  102. {
  103. return 0;
  104. }
  105. static inline void icc_bulk_put(int num_paths, struct icc_bulk_data *paths)
  106. {
  107. }
  108. static inline int icc_bulk_set_bw(int num_paths, const struct icc_bulk_data *paths)
  109. {
  110. return 0;
  111. }
  112. static inline int icc_bulk_enable(int num_paths, const struct icc_bulk_data *paths)
  113. {
  114. return 0;
  115. }
  116. static inline void icc_bulk_disable(int num_paths, const struct icc_bulk_data *paths)
  117. {
  118. }
  119. #endif /* CONFIG_INTERCONNECT */
  120. #endif /* __LINUX_INTERCONNECT_H */