Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * tmon.h contains data structures and constants used by TMON
0004  *
0005  * Copyright (C) 2012 Intel Corporation. All rights reserved.
0006  *
0007  * Author Name Jacob Pan <jacob.jun.pan@linux.intel.com>
0008  */
0009 
0010 #ifndef TMON_H
0011 #define TMON_H
0012 
0013 #define MAX_DISP_TEMP 125
0014 #define MAX_CTRL_TEMP 105
0015 #define MIN_CTRL_TEMP 40
0016 #define MAX_NR_TZONE 16
0017 #define MAX_NR_CDEV 32
0018 #define MAX_NR_TRIP 16
0019 #define MAX_NR_CDEV_TRIP 12 /* number of cooling devices that can bind
0020                  * to a thermal zone trip.
0021                  */
0022 #define MAX_TEMP_KC 140000
0023 /* starting char position to draw sensor data, such as tz names
0024  * trip point list, etc.
0025  */
0026 #define DATA_LEFT_ALIGN 10
0027 #define NR_LINES_TZDATA 1
0028 #define TMON_LOG_FILE "/var/tmp/tmon.log"
0029 
0030 #include <sys/time.h>
0031 #include <pthread.h>
0032 
0033 extern unsigned long ticktime;
0034 extern double time_elapsed;
0035 extern unsigned long target_temp_user;
0036 extern int dialogue_on;
0037 extern char ctrl_cdev[];
0038 extern pthread_mutex_t input_lock;
0039 extern int tmon_exit;
0040 extern int target_thermal_zone;
0041 /* use fixed size record to simplify data processing and transfer
0042  * TBD: more info to be added, e.g. programmable trip point data.
0043 */
0044 struct thermal_data_record {
0045     struct timeval tv;
0046     unsigned long temp[MAX_NR_TZONE];
0047     double pid_out_pct;
0048 };
0049 
0050 struct cdev_info {
0051     char type[64];
0052     int instance;
0053     unsigned long max_state;
0054     unsigned long cur_state;
0055     unsigned long flag;
0056 };
0057 
0058 enum trip_type {
0059     THERMAL_TRIP_CRITICAL,
0060     THERMAL_TRIP_HOT,
0061     THERMAL_TRIP_PASSIVE,
0062     THERMAL_TRIP_ACTIVE,
0063     NR_THERMAL_TRIP_TYPE,
0064 };
0065 
0066 struct trip_point {
0067     enum trip_type type;
0068     unsigned long temp;
0069     unsigned long hysteresis;
0070     int attribute; /* programmability etc. */
0071 };
0072 
0073 /* thermal zone configuration information, binding with cooling devices could
0074  * change at runtime.
0075  */
0076 struct tz_info {
0077     char type[256]; /* e.g. acpitz */
0078     int instance;
0079     int passive; /* active zone has passive node to force passive mode */
0080     int nr_cdev; /* number of cooling device binded */
0081     int nr_trip_pts;
0082     struct trip_point tp[MAX_NR_TRIP];
0083     unsigned long cdev_binding; /* bitmap for attached cdevs */
0084     /* cdev bind trip points, allow one cdev bind to multiple trips */
0085     unsigned long trip_binding[MAX_NR_CDEV];
0086 };
0087 
0088 struct tmon_platform_data {
0089     int nr_tz_sensor;
0090     int nr_cooling_dev;
0091     /* keep track of instance ids since there might be gaps */
0092     int max_tz_instance;
0093     int max_cdev_instance;
0094     struct tz_info *tzi;
0095     struct cdev_info *cdi;
0096 };
0097 
0098 struct control_ops {
0099     void (*set_ratio)(unsigned long ratio);
0100     unsigned long (*get_ratio)(unsigned long ratio);
0101 
0102 };
0103 
0104 enum cdev_types {
0105     CDEV_TYPE_PROC,
0106     CDEV_TYPE_FAN,
0107     CDEV_TYPE_MEM,
0108     CDEV_TYPE_NR,
0109 };
0110 
0111 /* REVISIT: the idea is to group sensors if possible, e.g. on intel mid
0112  * we have "skin0", "skin1", "sys", "msicdie"
0113  * on DPTF enabled systems, we might have PCH, TSKN, TAMB, etc.
0114  */
0115 enum tzone_types {
0116     TZONE_TYPE_ACPI,
0117     TZONE_TYPE_PCH,
0118     TZONE_TYPE_NR,
0119 };
0120 
0121 /* limit the output of PID controller adjustment */
0122 #define LIMIT_HIGH (95)
0123 #define LIMIT_LOW  (2)
0124 
0125 struct pid_params {
0126     double kp;  /* Controller gain from Dialog Box */
0127     double ki;  /* Time-constant for I action from Dialog Box */
0128     double kd;  /* Time-constant for D action from Dialog Box */
0129     double ts;
0130     double k_lpf;
0131 
0132     double t_target;
0133     double y_k;
0134 };
0135 
0136 extern int init_thermal_controller(void);
0137 extern void controller_handler(const double xk, double *yk);
0138 
0139 extern struct tmon_platform_data ptdata;
0140 extern struct pid_params p_param;
0141 
0142 extern FILE *tmon_log;
0143 extern int cur_thermal_record; /* index to the trec array */
0144 extern struct thermal_data_record trec[];
0145 extern const char *trip_type_name[];
0146 extern unsigned long no_control;
0147 
0148 extern void initialize_curses(void);
0149 extern void show_controller_stats(char *line);
0150 extern void show_title_bar(void);
0151 extern void setup_windows(void);
0152 extern void disable_tui(void);
0153 extern void show_sensors_w(void);
0154 extern void show_data_w(void);
0155 extern void write_status_bar(int x, char *line);
0156 extern void show_control_w();
0157 
0158 extern void show_cooling_device(void);
0159 extern void show_dialogue(void);
0160 extern int update_thermal_data(void);
0161 
0162 extern int probe_thermal_sysfs(void);
0163 extern void free_thermal_data(void);
0164 extern  void resize_handler(int sig);
0165 extern void set_ctrl_state(unsigned long state);
0166 extern void get_ctrl_state(unsigned long *state);
0167 extern void *handle_tui_events(void *arg);
0168 extern int sysfs_set_ulong(char *path, char *filename, unsigned long val);
0169 extern int zone_instance_to_index(int zone_inst);
0170 extern void close_windows(void);
0171 
0172 #define PT_COLOR_DEFAULT    1
0173 #define PT_COLOR_HEADER_BAR 2
0174 #define PT_COLOR_ERROR      3
0175 #define PT_COLOR_RED        4
0176 #define PT_COLOR_YELLOW     5
0177 #define PT_COLOR_GREEN      6
0178 #define PT_COLOR_BRIGHT     7
0179 #define PT_COLOR_BLUE       8
0180 
0181 /* each thermal zone uses 12 chars, 8 for name, 2 for instance, 2 space
0182  * also used to list trip points in forms of AAAC, which represents
0183  * A: Active
0184  * C: Critical
0185  */
0186 #define TZONE_RECORD_SIZE 12
0187 #define TZ_LEFT_ALIGN 32
0188 #define CDEV_NAME_SIZE 20
0189 #define CDEV_FLAG_IN_CONTROL (1 << 0)
0190 
0191 /* dialogue box starts */
0192 #define DIAG_X 48
0193 #define DIAG_Y 8
0194 #define THERMAL_SYSFS "/sys/class/thermal"
0195 #define CDEV "cooling_device"
0196 #define TZONE "thermal_zone"
0197 #define TDATA_LEFT 16
0198 #endif /* TMON_H */