governor.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * governor.h - internal header for devfreq governors.
  4. *
  5. * Copyright (C) 2011 Samsung Electronics
  6. * MyungJoo Ham <[email protected]>
  7. *
  8. * This header is for devfreq governors in drivers/devfreq/
  9. */
  10. #ifndef _GOVERNOR_H
  11. #define _GOVERNOR_H
  12. #include <linux/devfreq.h>
  13. #define DEVFREQ_NAME_LEN 16
  14. #define to_devfreq(DEV) container_of((DEV), struct devfreq, dev)
  15. /* Devfreq events */
  16. #define DEVFREQ_GOV_START 0x1
  17. #define DEVFREQ_GOV_STOP 0x2
  18. #define DEVFREQ_GOV_UPDATE_INTERVAL 0x3
  19. #define DEVFREQ_GOV_SUSPEND 0x4
  20. #define DEVFREQ_GOV_RESUME 0x5
  21. #define DEVFREQ_MIN_FREQ 0
  22. #define DEVFREQ_MAX_FREQ ULONG_MAX
  23. /*
  24. * Definition of the governor feature flags
  25. * - DEVFREQ_GOV_FLAG_IMMUTABLE
  26. * : This governor is never changeable to other governors.
  27. * - DEVFREQ_GOV_FLAG_IRQ_DRIVEN
  28. * : The devfreq won't schedule the work for this governor.
  29. */
  30. #define DEVFREQ_GOV_FLAG_IMMUTABLE BIT(0)
  31. #define DEVFREQ_GOV_FLAG_IRQ_DRIVEN BIT(1)
  32. /*
  33. * Definition of governor attribute flags except for common sysfs attributes
  34. * - DEVFREQ_GOV_ATTR_POLLING_INTERVAL
  35. * : Indicate polling_interval sysfs attribute
  36. * - DEVFREQ_GOV_ATTR_TIMER
  37. * : Indicate timer sysfs attribute
  38. */
  39. #define DEVFREQ_GOV_ATTR_POLLING_INTERVAL BIT(0)
  40. #define DEVFREQ_GOV_ATTR_TIMER BIT(1)
  41. /**
  42. * struct devfreq_cpu_data - Hold the per-cpu data
  43. * @node: list node
  44. * @dev: reference to cpu device.
  45. * @first_cpu: the cpumask of the first cpu of a policy.
  46. * @opp_table: reference to cpu opp table.
  47. * @cur_freq: the current frequency of the cpu.
  48. * @min_freq: the min frequency of the cpu.
  49. * @max_freq: the max frequency of the cpu.
  50. *
  51. * This structure stores the required cpu_data of a cpu.
  52. * This is auto-populated by the governor.
  53. */
  54. struct devfreq_cpu_data {
  55. struct list_head node;
  56. struct device *dev;
  57. unsigned int first_cpu;
  58. struct opp_table *opp_table;
  59. unsigned int cur_freq;
  60. unsigned int min_freq;
  61. unsigned int max_freq;
  62. };
  63. /**
  64. * struct devfreq_governor - Devfreq policy governor
  65. * @node: list node - contains registered devfreq governors
  66. * @name: Governor's name
  67. * @attrs: Governor's sysfs attribute flags
  68. * @flags: Governor's feature flags
  69. * @get_target_freq: Returns desired operating frequency for the device.
  70. * Basically, get_target_freq will run
  71. * devfreq_dev_profile.get_dev_status() to get the
  72. * status of the device (load = busy_time / total_time).
  73. * @event_handler: Callback for devfreq core framework to notify events
  74. * to governors. Events include per device governor
  75. * init and exit, opp changes out of devfreq, suspend
  76. * and resume of per device devfreq during device idle.
  77. *
  78. * Note that the callbacks are called with devfreq->lock locked by devfreq.
  79. */
  80. struct devfreq_governor {
  81. struct list_head node;
  82. const char name[DEVFREQ_NAME_LEN];
  83. const u64 attrs;
  84. const u64 flags;
  85. int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
  86. int (*event_handler)(struct devfreq *devfreq,
  87. unsigned int event, void *data);
  88. };
  89. void devfreq_monitor_start(struct devfreq *devfreq);
  90. void devfreq_monitor_stop(struct devfreq *devfreq);
  91. void devfreq_monitor_suspend(struct devfreq *devfreq);
  92. void devfreq_monitor_resume(struct devfreq *devfreq);
  93. void devfreq_update_interval(struct devfreq *devfreq, unsigned int *delay);
  94. int devfreq_add_governor(struct devfreq_governor *governor);
  95. int devfreq_remove_governor(struct devfreq_governor *governor);
  96. int devm_devfreq_add_governor(struct device *dev,
  97. struct devfreq_governor *governor);
  98. int devfreq_update_status(struct devfreq *devfreq, unsigned long freq);
  99. int devfreq_update_target(struct devfreq *devfreq, unsigned long freq);
  100. void devfreq_get_freq_range(struct devfreq *devfreq, unsigned long *min_freq,
  101. unsigned long *max_freq);
  102. static inline int devfreq_update_stats(struct devfreq *df)
  103. {
  104. if (!df->profile->get_dev_status)
  105. return -EINVAL;
  106. return df->profile->get_dev_status(df->dev.parent, &df->last_status);
  107. }
  108. #endif /* _GOVERNOR_H */