tmon.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * tmon.h contains data structures and constants used by TMON
  4. *
  5. * Copyright (C) 2012 Intel Corporation. All rights reserved.
  6. *
  7. * Author Name Jacob Pan <jacob.jun.pan@linux.intel.com>
  8. */
  9. #ifndef TMON_H
  10. #define TMON_H
  11. #define MAX_DISP_TEMP 125
  12. #define MAX_CTRL_TEMP 105
  13. #define MIN_CTRL_TEMP 40
  14. #define MAX_NR_TZONE 16
  15. #define MAX_NR_CDEV 32
  16. #define MAX_NR_TRIP 16
  17. #define MAX_NR_CDEV_TRIP 12 /* number of cooling devices that can bind
  18. * to a thermal zone trip.
  19. */
  20. #define MAX_TEMP_KC 140000
  21. /* starting char position to draw sensor data, such as tz names
  22. * trip point list, etc.
  23. */
  24. #define DATA_LEFT_ALIGN 10
  25. #define NR_LINES_TZDATA 1
  26. #define TMON_LOG_FILE "/var/tmp/tmon.log"
  27. #include <sys/time.h>
  28. #include <pthread.h>
  29. extern unsigned long ticktime;
  30. extern double time_elapsed;
  31. extern unsigned long target_temp_user;
  32. extern int dialogue_on;
  33. extern char ctrl_cdev[];
  34. extern pthread_mutex_t input_lock;
  35. extern int tmon_exit;
  36. extern int target_thermal_zone;
  37. /* use fixed size record to simplify data processing and transfer
  38. * TBD: more info to be added, e.g. programmable trip point data.
  39. */
  40. struct thermal_data_record {
  41. struct timeval tv;
  42. unsigned long temp[MAX_NR_TZONE];
  43. double pid_out_pct;
  44. };
  45. struct cdev_info {
  46. char type[64];
  47. int instance;
  48. unsigned long max_state;
  49. unsigned long cur_state;
  50. unsigned long flag;
  51. };
  52. enum trip_type {
  53. THERMAL_TRIP_CRITICAL,
  54. THERMAL_TRIP_HOT,
  55. THERMAL_TRIP_PASSIVE,
  56. THERMAL_TRIP_ACTIVE,
  57. NR_THERMAL_TRIP_TYPE,
  58. };
  59. struct trip_point {
  60. enum trip_type type;
  61. unsigned long temp;
  62. unsigned long hysteresis;
  63. int attribute; /* programmability etc. */
  64. };
  65. /* thermal zone configuration information, binding with cooling devices could
  66. * change at runtime.
  67. */
  68. struct tz_info {
  69. char type[256]; /* e.g. acpitz */
  70. int instance;
  71. int passive; /* active zone has passive node to force passive mode */
  72. int nr_cdev; /* number of cooling device binded */
  73. int nr_trip_pts;
  74. struct trip_point tp[MAX_NR_TRIP];
  75. unsigned long cdev_binding; /* bitmap for attached cdevs */
  76. /* cdev bind trip points, allow one cdev bind to multiple trips */
  77. unsigned long trip_binding[MAX_NR_CDEV];
  78. };
  79. struct tmon_platform_data {
  80. int nr_tz_sensor;
  81. int nr_cooling_dev;
  82. /* keep track of instance ids since there might be gaps */
  83. int max_tz_instance;
  84. int max_cdev_instance;
  85. struct tz_info *tzi;
  86. struct cdev_info *cdi;
  87. };
  88. struct control_ops {
  89. void (*set_ratio)(unsigned long ratio);
  90. unsigned long (*get_ratio)(unsigned long ratio);
  91. };
  92. enum cdev_types {
  93. CDEV_TYPE_PROC,
  94. CDEV_TYPE_FAN,
  95. CDEV_TYPE_MEM,
  96. CDEV_TYPE_NR,
  97. };
  98. /* REVISIT: the idea is to group sensors if possible, e.g. on intel mid
  99. * we have "skin0", "skin1", "sys", "msicdie"
  100. * on DPTF enabled systems, we might have PCH, TSKN, TAMB, etc.
  101. */
  102. enum tzone_types {
  103. TZONE_TYPE_ACPI,
  104. TZONE_TYPE_PCH,
  105. TZONE_TYPE_NR,
  106. };
  107. /* limit the output of PID controller adjustment */
  108. #define LIMIT_HIGH (95)
  109. #define LIMIT_LOW (2)
  110. struct pid_params {
  111. double kp; /* Controller gain from Dialog Box */
  112. double ki; /* Time-constant for I action from Dialog Box */
  113. double kd; /* Time-constant for D action from Dialog Box */
  114. double ts;
  115. double k_lpf;
  116. double t_target;
  117. double y_k;
  118. };
  119. extern int init_thermal_controller(void);
  120. extern void controller_handler(const double xk, double *yk);
  121. extern struct tmon_platform_data ptdata;
  122. extern struct pid_params p_param;
  123. extern FILE *tmon_log;
  124. extern int cur_thermal_record; /* index to the trec array */
  125. extern struct thermal_data_record trec[];
  126. extern const char *trip_type_name[];
  127. extern unsigned long no_control;
  128. extern void initialize_curses(void);
  129. extern void show_controller_stats(char *line);
  130. extern void show_title_bar(void);
  131. extern void setup_windows(void);
  132. extern void disable_tui(void);
  133. extern void show_sensors_w(void);
  134. extern void show_data_w(void);
  135. extern void write_status_bar(int x, char *line);
  136. extern void show_control_w();
  137. extern void show_cooling_device(void);
  138. extern void show_dialogue(void);
  139. extern int update_thermal_data(void);
  140. extern int probe_thermal_sysfs(void);
  141. extern void free_thermal_data(void);
  142. extern void resize_handler(int sig);
  143. extern void set_ctrl_state(unsigned long state);
  144. extern void get_ctrl_state(unsigned long *state);
  145. extern void *handle_tui_events(void *arg);
  146. extern int sysfs_set_ulong(char *path, char *filename, unsigned long val);
  147. extern int zone_instance_to_index(int zone_inst);
  148. extern void close_windows(void);
  149. #define PT_COLOR_DEFAULT 1
  150. #define PT_COLOR_HEADER_BAR 2
  151. #define PT_COLOR_ERROR 3
  152. #define PT_COLOR_RED 4
  153. #define PT_COLOR_YELLOW 5
  154. #define PT_COLOR_GREEN 6
  155. #define PT_COLOR_BRIGHT 7
  156. #define PT_COLOR_BLUE 8
  157. /* each thermal zone uses 12 chars, 8 for name, 2 for instance, 2 space
  158. * also used to list trip points in forms of AAAC, which represents
  159. * A: Active
  160. * C: Critical
  161. */
  162. #define TZONE_RECORD_SIZE 12
  163. #define TZ_LEFT_ALIGN 32
  164. #define CDEV_NAME_SIZE 20
  165. #define CDEV_FLAG_IN_CONTROL (1 << 0)
  166. /* dialogue box starts */
  167. #define DIAG_X 48
  168. #define DIAG_Y 8
  169. #define THERMAL_SYSFS "/sys/class/thermal"
  170. #define CDEV "cooling_device"
  171. #define TZONE "thermal_zone"
  172. #define TDATA_LEFT 16
  173. #endif /* TMON_H */