tmon.h 5.4 KB

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