accel/ivpu: Move recovery work to system_unbound_wq
[drm/drm-misc.git] / tools / lib / thermal / include / thermal.h
blob818ecdfb46e509e871e2257ed7f61130d7c236bb
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /* Copyright (C) 2022, Linaro Ltd - Daniel Lezcano <daniel.lezcano@linaro.org> */
3 #ifndef __LIBTHERMAL_H
4 #define __LIBTHERMAL_H
6 #include <linux/thermal.h>
7 #include <sys/types.h>
9 #ifndef LIBTHERMAL_API
10 #define LIBTHERMAL_API __attribute__((visibility("default")))
11 #endif
13 #ifndef THERMAL_THRESHOLD_WAY_UP
14 #define THERMAL_THRESHOLD_WAY_UP 0x1
15 #endif
17 #ifndef THERMAL_THRESHOLD_WAY_DOWN
18 #define THERMAL_THRESHOLD_WAY_DOWN 0x2
19 #endif
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
25 struct thermal_sampling_ops {
26 int (*tz_temp)(int tz_id, int temp, void *arg);
29 struct thermal_events_ops {
30 int (*tz_create)(const char *name, int tz_id, void *arg);
31 int (*tz_delete)(int tz_id, void *arg);
32 int (*tz_enable)(int tz_id, void *arg);
33 int (*tz_disable)(int tz_id, void *arg);
34 int (*trip_high)(int tz_id, int trip_id, int temp, void *arg);
35 int (*trip_low)(int tz_id, int trip_id, int temp, void *arg);
36 int (*trip_add)(int tz_id, int trip_id, int type, int temp, int hyst, void *arg);
37 int (*trip_change)(int tz_id, int trip_id, int type, int temp, int hyst, void *arg);
38 int (*trip_delete)(int tz_id, int trip_id, void *arg);
39 int (*cdev_add)(const char *name, int cdev_id, int max_state, void *arg);
40 int (*cdev_delete)(int cdev_id, void *arg);
41 int (*cdev_update)(int cdev_id, int cur_state, void *arg);
42 int (*gov_change)(int tz_id, const char *gov_name, void *arg);
43 int (*threshold_add)(int tz_id, int temperature, int direction, void *arg);
44 int (*threshold_delete)(int tz_id, int temperature, int direction, void *arg);
45 int (*threshold_flush)(int tz_id, void *arg);
46 int (*threshold_up)(int tz_id, int temp, int prev_temp, void *arg);
47 int (*threshold_down)(int tz_id, int temp, int prev_temp, void *arg);
50 struct thermal_ops {
51 struct thermal_sampling_ops sampling;
52 struct thermal_events_ops events;
55 struct thermal_trip {
56 int id;
57 int type;
58 int temp;
59 int hyst;
62 struct thermal_threshold {
63 int temperature;
64 int direction;
67 struct thermal_zone {
68 int id;
69 int temp;
70 char name[THERMAL_NAME_LENGTH];
71 char governor[THERMAL_NAME_LENGTH];
72 struct thermal_trip *trip;
73 struct thermal_threshold *thresholds;
76 struct thermal_cdev {
77 int id;
78 char name[THERMAL_NAME_LENGTH];
79 int max_state;
80 int min_state;
81 int cur_state;
84 typedef enum {
85 THERMAL_ERROR = -1,
86 THERMAL_SUCCESS = 0,
87 } thermal_error_t;
89 struct thermal_handler;
91 typedef int (*cb_tz_t)(struct thermal_zone *, void *);
93 typedef int (*cb_tt_t)(struct thermal_trip *, void *);
95 typedef int (*cb_tc_t)(struct thermal_cdev *, void *);
97 typedef int (*cb_th_t)(struct thermal_threshold *, void *);
99 LIBTHERMAL_API int for_each_thermal_zone(struct thermal_zone *tz, cb_tz_t cb, void *arg);
101 LIBTHERMAL_API int for_each_thermal_trip(struct thermal_trip *tt, cb_tt_t cb, void *arg);
103 LIBTHERMAL_API int for_each_thermal_cdev(struct thermal_cdev *cdev, cb_tc_t cb, void *arg);
105 LIBTHERMAL_API int for_each_thermal_threshold(struct thermal_threshold *th, cb_th_t cb, void *arg);
107 LIBTHERMAL_API struct thermal_zone *thermal_zone_find_by_name(struct thermal_zone *tz,
108 const char *name);
110 LIBTHERMAL_API struct thermal_zone *thermal_zone_find_by_id(struct thermal_zone *tz, int id);
112 LIBTHERMAL_API struct thermal_zone *thermal_zone_discover(struct thermal_handler *th);
114 LIBTHERMAL_API struct thermal_handler *thermal_init(struct thermal_ops *ops);
116 LIBTHERMAL_API void thermal_exit(struct thermal_handler *th);
119 * Netlink thermal events
121 LIBTHERMAL_API thermal_error_t thermal_events_exit(struct thermal_handler *th);
123 LIBTHERMAL_API thermal_error_t thermal_events_init(struct thermal_handler *th);
125 LIBTHERMAL_API thermal_error_t thermal_events_handle(struct thermal_handler *th, void *arg);
127 LIBTHERMAL_API int thermal_events_fd(struct thermal_handler *th);
130 * Netlink thermal commands
132 LIBTHERMAL_API thermal_error_t thermal_cmd_exit(struct thermal_handler *th);
134 LIBTHERMAL_API thermal_error_t thermal_cmd_init(struct thermal_handler *th);
136 LIBTHERMAL_API thermal_error_t thermal_cmd_get_tz(struct thermal_handler *th,
137 struct thermal_zone **tz);
139 LIBTHERMAL_API thermal_error_t thermal_cmd_get_cdev(struct thermal_handler *th,
140 struct thermal_cdev **tc);
142 LIBTHERMAL_API thermal_error_t thermal_cmd_get_trip(struct thermal_handler *th,
143 struct thermal_zone *tz);
145 LIBTHERMAL_API thermal_error_t thermal_cmd_get_governor(struct thermal_handler *th,
146 struct thermal_zone *tz);
148 LIBTHERMAL_API thermal_error_t thermal_cmd_get_temp(struct thermal_handler *th,
149 struct thermal_zone *tz);
151 LIBTHERMAL_API thermal_error_t thermal_cmd_threshold_get(struct thermal_handler *th,
152 struct thermal_zone *tz);
154 LIBTHERMAL_API thermal_error_t thermal_cmd_threshold_add(struct thermal_handler *th,
155 struct thermal_zone *tz,
156 int temperature,
157 int direction);
159 LIBTHERMAL_API thermal_error_t thermal_cmd_threshold_delete(struct thermal_handler *th,
160 struct thermal_zone *tz,
161 int temperature,
162 int direction);
164 LIBTHERMAL_API thermal_error_t thermal_cmd_threshold_flush(struct thermal_handler *th,
165 struct thermal_zone *tz);
168 * Netlink thermal samples
170 LIBTHERMAL_API thermal_error_t thermal_sampling_exit(struct thermal_handler *th);
172 LIBTHERMAL_API thermal_error_t thermal_sampling_init(struct thermal_handler *th);
174 LIBTHERMAL_API thermal_error_t thermal_sampling_handle(struct thermal_handler *th, void *arg);
176 LIBTHERMAL_API int thermal_sampling_fd(struct thermal_handler *th);
178 #endif /* __LIBTHERMAL_H */
180 #ifdef __cplusplus
182 #endif