summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Lezcano <daniel.lezcano@linaro.org>2021-06-09 11:36:31 +0200
committerDaniel Lezcano <daniel.lezcano@linaro.org>2021-06-09 11:36:31 +0200
commit59ae6cbe1100124c55ac247750960af0691457fc (patch)
treef030faee6c48faca8a2c7fa24ebc462d4d52fbc5
parent430f92610a3329a053b3514d20258c87aa5ddd5f (diff)
Reorganize the includes
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
-rw-r--r--include/libthermal.h128
-rw-r--r--include/thermal.h241
-rw-r--r--src/commands.c6
-rw-r--r--src/events.c20
-rw-r--r--src/thermal.h46
5 files changed, 187 insertions, 254 deletions
diff --git a/include/libthermal.h b/include/libthermal.h
new file mode 100644
index 0000000..17a2111
--- /dev/null
+++ b/include/libthermal.h
@@ -0,0 +1,128 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+#ifndef __LIBTHERMAL_H
+#define __LIBTHERMAL_H
+
+#include <linux/thermal.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef THERMAL_NAME_LENGTH
+#define THERMAL_NAME_LENGTH 64
+#endif
+
+struct thermal_sampling_ops {
+ int (*tz_temp)(int tz_id, int temp, void *arg);
+};
+
+struct thermal_events_ops {
+ int (*tz_create)(const char *name, int tz_id, void *arg);
+ int (*tz_delete)(int tz_id, void *arg);
+ int (*tz_enable)(int tz_id, void *arg);
+ int (*tz_disable)(int tz_id, void *arg);
+ int (*trip_high)(int tz_id, int trip_id, int temp, void *arg);
+ int (*trip_low)(int tz_id, int trip_id, int temp, void *arg);
+ int (*trip_add)(int tz_id, int trip_id, int type, int temp, int hyst, void *arg);
+ int (*trip_change)(int tz_id, int trip_id, int type, int temp, int hyst, void *arg);
+ int (*trip_delete)(int tz_id, int trip_id, void *arg);
+ int (*cdev_add)(const char *name, int cdev_id, int max_state, void *arg);
+ int (*cdev_delete)(int cdev_id, void *arg);
+ int (*cdev_update)(int cdev_id, int cur_state, void *arg);
+ int (*gov_change)(int tz_id, const char *gov_name, void *arg);
+};
+
+struct thermal_ops {
+ struct thermal_sampling_ops sampling;
+ struct thermal_events_ops events;
+};
+
+struct thermal_trip {
+ int id;
+ int type;
+ int temp;
+ int hyst;
+};
+
+struct thermal_zone {
+ int id;
+ int temp;
+ char name[THERMAL_NAME_LENGTH];
+ char governor[THERMAL_NAME_LENGTH];
+ struct thermal_trip *trip;
+};
+
+struct thermal_cdev {
+ int id;
+ char name[THERMAL_NAME_LENGTH];
+ int max_state;
+ int min_state;
+ int cur_state;
+};
+
+struct thermal_handler;
+
+typedef int (*cb_tz_t)(struct thermal_zone *, void *);
+
+typedef int (*cb_tt_t)(struct thermal_trip *, void *);
+
+typedef int (*cb_tc_t)(struct thermal_cdev *, void *);
+
+int for_each_thermal_zone(struct thermal_zone *tz, cb_tz_t cb, void *arg);
+
+int for_each_thermal_trip(struct thermal_trip *tt, cb_tt_t cb, void *arg);
+
+int for_each_thermal_cdev(struct thermal_cdev *cdev, cb_tc_t cb, void *arg);
+
+struct thermal_zone *thermal_zone_find_by_name(struct thermal_zone *tz,
+ const char *name);
+
+struct thermal_zone *thermal_zone_find_by_id(struct thermal_zone *tz, int id);
+
+struct thermal_zone *thermal_zone_discover(struct thermal_handler *th);
+
+struct thermal_handler *thermal_init(struct thermal_ops *ops);
+
+/*
+ * Netlink thermal events
+ */
+extern int thermal_events_init(struct thermal_handler *th);
+
+extern int thermal_events_handle(struct thermal_handler *th, void *arg);
+
+extern int thermal_events_fd(struct thermal_handler *th);
+
+/*
+ * Netlink thermal commands
+ */
+extern int thermal_cmd_init(struct thermal_handler *th);
+
+extern int thermal_cmd_get_tz(struct thermal_handler *th,
+ struct thermal_zone **tz);
+
+extern int thermal_cmd_get_cdev(struct thermal_handler *th,
+ struct thermal_cdev **tc);
+
+extern int thermal_cmd_get_trip(struct thermal_handler *th,
+ struct thermal_zone *tz);
+
+extern int thermal_cmd_get_governor(struct thermal_handler *th,
+ struct thermal_zone *tz);
+
+extern int thermal_cmd_get_temp(struct thermal_handler *th,
+ struct thermal_zone *tz);
+
+/*
+ * Netlink thermal samples
+ */
+extern int thermal_sampling_init(struct thermal_handler *th);
+
+extern int thermal_sampling_handle(struct thermal_handler *th, void *arg);
+
+extern int thermal_sampling_fd(struct thermal_handler *th);
+
+#endif /* __LIBTHERMAL_H */
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/include/thermal.h b/include/thermal.h
deleted file mode 100644
index 0acc3d0..0000000
--- a/include/thermal.h
+++ /dev/null
@@ -1,241 +0,0 @@
-/* SPDX-License-Identifier: LGPL-2.1+ */
-#ifndef __THERMAL_H
-#define __THERMAL_H
-
-#include <netlink/netlink.h>
-#include <netlink/genl/genl.h>
-#include <netlink/genl/mngt.h>
-#include <netlink/genl/ctrl.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define __maybe_unused __attribute__((__unused__))
-
-#ifndef THERMAL_NAME_LENGTH
-#define THERMAL_NAME_LENGTH 64
-#endif
-
-struct thermal_sampling_ops {
- int (*tz_temp)(int tz_id, int temp, void *arg);
-};
-
-struct thermal_events_ops {
- int (*tz_create)(const char *name, int tz_id, void *arg);
- int (*tz_delete)(int tz_id, void *arg);
- int (*tz_enable)(int tz_id, void *arg);
- int (*tz_disable)(int tz_id, void *arg);
- int (*trip_high)(int tz_id, int trip_id, int temp, void *arg);
- int (*trip_low)(int tz_id, int trip_id, int temp, void *arg);
- int (*trip_add)(int tz_id, int trip_id, int type, int temp, int hyst, void *arg);
- int (*trip_change)(int tz_id, int trip_id, int type, int temp, int hyst, void *arg);
- int (*trip_delete)(int tz_id, int trip_id, void *arg);
- int (*cdev_add)(const char *name, int cdev_id, int max_state, void *arg);
- int (*cdev_delete)(int cdev_id, void *arg);
- int (*cdev_update)(int cdev_id, int cur_state, void *arg);
- int (*gov_change)(int tz_id, const char *gov_name, void *arg);
-};
-
-struct thermal_ops {
- struct thermal_sampling_ops sampling;
- struct thermal_events_ops events;
-};
-
-struct thermal_trip {
- int id;
- int type;
- int temp;
- int hyst;
-};
-
-struct thermal_zone {
- int id;
- int temp;
- char name[THERMAL_NAME_LENGTH];
- char governor[THERMAL_NAME_LENGTH];
- struct thermal_trip *trip;
-};
-
-struct thermal_cdev {
- int id;
- char name[THERMAL_NAME_LENGTH];
- int max_state;
- int min_state;
- int cur_state;
-};
-
-struct thermal_handler {
- int done;
- int error;
- struct thermal_ops *ops;
- struct nl_msg *msg;
- struct nl_sock *sk_event;
- struct nl_sock *sk_sampling;
- struct nl_sock *sk_cmd;
- struct nl_cb *cb_cmd;
- struct nl_cb *cb_event;
- struct nl_cb *cb_sampling;
-};
-
-struct thermal_handler_param {
- struct thermal_handler *th;
- void *arg;
-};
-
-typedef int (*cb_tz_t)(struct thermal_zone *, void *);
-
-typedef int (*cb_tt_t)(struct thermal_trip *, void *);
-
-typedef int (*cb_tc_t)(struct thermal_cdev *, void *);
-
-int for_each_thermal_zone(struct thermal_zone *tz, cb_tz_t cb, void *arg);
-
-int for_each_thermal_trip(struct thermal_trip *tt, cb_tt_t cb, void *arg);
-
-int for_each_thermal_cdev(struct thermal_cdev *cdev, cb_tc_t cb, void *arg);
-
-struct thermal_zone *thermal_zone_find_by_name(struct thermal_zone *tz,
- const char *name);
-
-struct thermal_zone *thermal_zone_find_by_id(struct thermal_zone *tz, int id);
-
-struct thermal_zone *thermal_zone_discover(struct thermal_handler *th);
-
-struct thermal_handler *thermal_init(struct thermal_ops *ops);
-
-/*
- * Netlink thermal events
- */
-extern int thermal_events_init(struct thermal_handler *th);
-
-extern int thermal_events_handle(struct thermal_handler *th, void *arg);
-
-extern int thermal_events_fd(struct thermal_handler *th);
-
-/*
- * Netlink thermal commands
- */
-extern int thermal_cmd_init(struct thermal_handler *th);
-
-extern int thermal_cmd_get_tz(struct thermal_handler *th,
- struct thermal_zone **tz);
-
-extern int thermal_cmd_get_cdev(struct thermal_handler *th,
- struct thermal_cdev **tc);
-
-extern int thermal_cmd_get_trip(struct thermal_handler *th,
- struct thermal_zone *tz);
-
-extern int thermal_cmd_get_governor(struct thermal_handler *th,
- struct thermal_zone *tz);
-
-extern int thermal_cmd_get_temp(struct thermal_handler *th,
- struct thermal_zone *tz);
-
-/*
- * Netlink thermal samples
- */
-extern int thermal_sampling_init(struct thermal_handler *th);
-
-extern int thermal_sampling_handle(struct thermal_handler *th, void *arg);
-
-extern int thermal_sampling_fd(struct thermal_handler *th);
-
-/*
- * Low level netlink
- */
-extern int nl_subscribe_thermal(struct nl_sock *nl_sock, struct nl_cb *nl_cb,
- const char *group);
-
-extern int nl_thermal_connect(struct nl_sock **nl_sock, struct nl_cb **nl_cb);
-
-extern void nl_thermal_disconnect(struct nl_sock *nl_sock, struct nl_cb *nl_cb);
-
-extern int nl_send_msg(struct nl_sock *sock, struct nl_cb *nl_cb, struct nl_msg *msg,
- int (*rx_handler)(struct nl_msg *, void *),
- void *data);
-
-#endif /* __THERMAL_H */
-
-/*
- * The netlink notification for thermal is new and the thermal uapi
- * may be not installed yet. Provide the default values, so we can go
- * forward until the linux-headers are available.
- */
-
-/* Adding event notification support elements */
-#define THERMAL_GENL_FAMILY_NAME "thermal"
-#define THERMAL_GENL_VERSION 0x01
-#define THERMAL_GENL_SAMPLING_GROUP_NAME "sampling"
-#define THERMAL_GENL_EVENT_GROUP_NAME "event"
-
-/* Attributes of thermal_genl_family */
-enum thermal_genl_attr {
- THERMAL_GENL_ATTR_UNSPEC,
- THERMAL_GENL_ATTR_TZ,
- THERMAL_GENL_ATTR_TZ_ID,
- THERMAL_GENL_ATTR_TZ_TEMP,
- THERMAL_GENL_ATTR_TZ_TRIP,
- THERMAL_GENL_ATTR_TZ_TRIP_ID,
- THERMAL_GENL_ATTR_TZ_TRIP_TYPE,
- THERMAL_GENL_ATTR_TZ_TRIP_TEMP,
- THERMAL_GENL_ATTR_TZ_TRIP_HYST,
- THERMAL_GENL_ATTR_TZ_MODE,
- THERMAL_GENL_ATTR_TZ_NAME,
- THERMAL_GENL_ATTR_TZ_CDEV_WEIGHT,
- THERMAL_GENL_ATTR_TZ_GOV,
- THERMAL_GENL_ATTR_TZ_GOV_NAME,
- THERMAL_GENL_ATTR_CDEV,
- THERMAL_GENL_ATTR_CDEV_ID,
- THERMAL_GENL_ATTR_CDEV_CUR_STATE,
- THERMAL_GENL_ATTR_CDEV_MAX_STATE,
- THERMAL_GENL_ATTR_CDEV_NAME,
- THERMAL_GENL_ATTR_GOV_NAME,
-
- __THERMAL_GENL_ATTR_MAX,
-};
-#define THERMAL_GENL_ATTR_MAX (__THERMAL_GENL_ATTR_MAX - 1)
-
-enum thermal_genl_sampling {
- THERMAL_GENL_SAMPLING_TEMP,
- __THERMAL_GENL_SAMPLING_MAX,
-};
-#define THERMAL_GENL_SAMPLING_MAX (__THERMAL_GENL_SAMPLING_MAX - 1)
-
-/* Events of thermal_genl_family */
-enum thermal_genl_event {
- THERMAL_GENL_EVENT_UNSPEC,
- THERMAL_GENL_EVENT_TZ_CREATE,/* Thermal zone creation */
- THERMAL_GENL_EVENT_TZ_DELETE,/* Thermal zone deletion */
- THERMAL_GENL_EVENT_TZ_DISABLE,/* Thermal zone disabed */
- THERMAL_GENL_EVENT_TZ_ENABLE,/* Thermal zone enabled */
- THERMAL_GENL_EVENT_TZ_TRIP_HIGH,/* Trip point crossed the way up */
- THERMAL_GENL_EVENT_TZ_TRIP_LOW,/* Trip point crossed the way down */
- THERMAL_GENL_EVENT_TZ_TRIP_CHANGE,/* Trip point changed */
- THERMAL_GENL_EVENT_TZ_TRIP_ADD,/* Trip point added */
- THERMAL_GENL_EVENT_TZ_TRIP_DELETE,/* Trip point deleted */
- THERMAL_GENL_EVENT_TZ_CDEV_ADD, /* Cdev bound to the thermal zone */
- THERMAL_GENL_EVENT_TZ_CDEV_DELETE,/* Cdev unbound */
- THERMAL_GENL_EVENT_TZ_CDEV_UPDATE,/* Cdev state updated */
- THERMAL_GENL_EVENT_TZ_GOV_CHANGE,/* Governor policy changed */
- __THERMAL_GENL_EVENT_MAX,
-};
-#define THERMAL_GENL_EVENT_MAX (__THERMAL_GENL_EVENT_MAX - 1)
-
-/* Commands supported by the thermal_genl_family */
-enum thermal_genl_cmd {
- THERMAL_GENL_CMD_UNSPEC,
- THERMAL_GENL_CMD_TZ_GET,/* List thermal zones id */
- THERMAL_GENL_CMD_TZ_GET_TRIP,/* List of thermal trips */
- THERMAL_GENL_CMD_TZ_GET_TEMP,/* Get the thermal zone temperature */
- THERMAL_GENL_CMD_TZ_GET_GOV,/* Get the thermal zone governor */
- THERMAL_GENL_CMD_TZ_GET_MODE,/* Get the thermal zone mode */
- THERMAL_GENL_CMD_CDEV_GET,/* List of cdev id */
- __THERMAL_GENL_CMD_MAX,
-};
-#define THERMAL_GENL_CMD_MAX (__THERMAL_GENL_CMD_MAX - 1)
-
-#ifdef __cplusplus
-}
-#endif
diff --git a/src/commands.c b/src/commands.c
index cf81a3b..1a930d7 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -200,7 +200,7 @@ static int handle_netlink(__maybe_unused struct nl_cache_ops *unused,
{
switch (cmd->c_id) {
- case THERMAL_GENL_CMD_TZ_GET:
+ case THERMAL_GENL_CMD_TZ_GET_ID:
parse_tz_get(info, arg);
break;
@@ -229,7 +229,7 @@ static int handle_netlink(__maybe_unused struct nl_cache_ops *unused,
static struct genl_cmd thermal_cmds[] = {
{
- .c_id = THERMAL_GENL_CMD_TZ_GET,
+ .c_id = THERMAL_GENL_CMD_TZ_GET_ID,
.c_name = "List thermal zones",
.c_msg_parser = handle_netlink,
.c_maxattr = THERMAL_GENL_ATTR_MAX,
@@ -309,7 +309,7 @@ static int thermal_genl_auto(struct thermal_handler *th, int id, int cmd,
int thermal_cmd_get_tz(struct thermal_handler *th, struct thermal_zone **tz)
{
- return thermal_genl_auto(th, -1, THERMAL_GENL_CMD_TZ_GET,
+ return thermal_genl_auto(th, -1, THERMAL_GENL_CMD_TZ_GET_ID,
NLM_F_DUMP | NLM_F_ACK, tz);
}
diff --git a/src/events.c b/src/events.c
index 49fa227..eb49a3c 100644
--- a/src/events.c
+++ b/src/events.c
@@ -66,7 +66,7 @@ static int handle_thermal_event(struct nl_msg *n, void *arg)
return ops->trip_delete(nla_get_u32(attrs[THERMAL_GENL_ATTR_TZ_ID]),
nla_get_u32(attrs[THERMAL_GENL_ATTR_TZ_TRIP_ID]), arg);
- case THERMAL_GENL_EVENT_TZ_TRIP_HIGH:
+ case THERMAL_GENL_EVENT_TZ_TRIP_UP:
/* return th->ops->trip_high(nla_get_u32(attrs[THERMAL_GENL_ATTR_TZ_ID]),
nla_get_u32(attrs[THERMAL_GENL_ATTR_TZ_TRIP_ID]),
nla_get_u32(attrs[THERMAL_GENL_ATTR_TZ_TEMP])); */
@@ -74,22 +74,22 @@ static int handle_thermal_event(struct nl_msg *n, void *arg)
nla_get_u32(attrs[THERMAL_GENL_ATTR_TZ_TRIP_ID]), -1, arg);
- case THERMAL_GENL_EVENT_TZ_TRIP_LOW:
+ case THERMAL_GENL_EVENT_TZ_TRIP_DOWN:
/* return th->ops->trip_low(nla_get_u32(attrs[THERMAL_GENL_ATTR_TZ_ID]), */
/* nla_get_u32(attrs[THERMAL_GENL_ATTR_TZ_TRIP_ID]), */
/* nla_get_u32(attrs[THERMAL_GENL_ATTR_TZ_TEMP])); */
return ops->trip_low(nla_get_u32(attrs[THERMAL_GENL_ATTR_TZ_ID]),
nla_get_u32(attrs[THERMAL_GENL_ATTR_TZ_TRIP_ID]), -1, arg);
- case THERMAL_GENL_EVENT_TZ_CDEV_ADD:
+ case THERMAL_GENL_EVENT_CDEV_ADD:
return ops->cdev_add(nla_get_string(attrs[THERMAL_GENL_ATTR_CDEV_NAME]),
nla_get_u32(attrs[THERMAL_GENL_ATTR_CDEV_ID]),
nla_get_u32(attrs[THERMAL_GENL_ATTR_CDEV_MAX_STATE]), arg);
- case THERMAL_GENL_EVENT_TZ_CDEV_DELETE:
+ case THERMAL_GENL_EVENT_CDEV_DELETE:
return ops->cdev_delete(nla_get_u32(attrs[THERMAL_GENL_ATTR_CDEV_ID]), arg);
- case THERMAL_GENL_EVENT_TZ_CDEV_UPDATE:
+ case THERMAL_GENL_EVENT_CDEV_STATE_UPDATE:
return ops->cdev_update(nla_get_u32(attrs[THERMAL_GENL_ATTR_CDEV_ID]),
nla_get_u32(attrs[THERMAL_GENL_ATTR_CDEV_CUR_STATE]), arg);
@@ -107,14 +107,14 @@ static void thermal_events_ops_init(struct thermal_events_ops *ops)
enabled_ops[THERMAL_GENL_EVENT_TZ_DELETE] = !!ops->tz_delete;
enabled_ops[THERMAL_GENL_EVENT_TZ_DISABLE] = !!ops->tz_disable;
enabled_ops[THERMAL_GENL_EVENT_TZ_ENABLE] = !!ops->tz_enable;
- enabled_ops[THERMAL_GENL_EVENT_TZ_TRIP_HIGH] = !!ops->trip_high;
- enabled_ops[THERMAL_GENL_EVENT_TZ_TRIP_LOW] = !!ops->trip_low;
+ enabled_ops[THERMAL_GENL_EVENT_TZ_TRIP_UP] = !!ops->trip_high;
+ enabled_ops[THERMAL_GENL_EVENT_TZ_TRIP_DOWN] = !!ops->trip_low;
enabled_ops[THERMAL_GENL_EVENT_TZ_TRIP_CHANGE] = !!ops->trip_change;
enabled_ops[THERMAL_GENL_EVENT_TZ_TRIP_ADD] = !!ops->trip_add;
enabled_ops[THERMAL_GENL_EVENT_TZ_TRIP_DELETE] = !!ops->trip_delete;
- enabled_ops[THERMAL_GENL_EVENT_TZ_CDEV_ADD] = !!ops->cdev_add;
- enabled_ops[THERMAL_GENL_EVENT_TZ_CDEV_DELETE] = !!ops->cdev_delete;
- enabled_ops[THERMAL_GENL_EVENT_TZ_CDEV_UPDATE] = !!ops->cdev_update;
+ enabled_ops[THERMAL_GENL_EVENT_CDEV_ADD] = !!ops->cdev_add;
+ enabled_ops[THERMAL_GENL_EVENT_CDEV_DELETE] = !!ops->cdev_delete;
+ enabled_ops[THERMAL_GENL_EVENT_CDEV_STATE_UPDATE] = !!ops->cdev_update;
enabled_ops[THERMAL_GENL_EVENT_TZ_GOV_CHANGE] = !!ops->gov_change;
}
diff --git a/src/thermal.h b/src/thermal.h
new file mode 100644
index 0000000..798a8cc
--- /dev/null
+++ b/src/thermal.h
@@ -0,0 +1,46 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+#ifndef __THERMAL_H
+#define __THERMAL_H
+
+#include <netlink/netlink.h>
+#include <netlink/genl/genl.h>
+#include <netlink/genl/mngt.h>
+#include <netlink/genl/ctrl.h>
+
+#include "libthermal.h"
+
+#define __maybe_unused __attribute__((__unused__))
+
+struct thermal_handler {
+ int done;
+ int error;
+ struct thermal_ops *ops;
+ struct nl_msg *msg;
+ struct nl_sock *sk_event;
+ struct nl_sock *sk_sampling;
+ struct nl_sock *sk_cmd;
+ struct nl_cb *cb_cmd;
+ struct nl_cb *cb_event;
+ struct nl_cb *cb_sampling;
+};
+
+struct thermal_handler_param {
+ struct thermal_handler *th;
+ void *arg;
+};
+
+/*
+ * Low level netlink
+ */
+extern int nl_subscribe_thermal(struct nl_sock *nl_sock, struct nl_cb *nl_cb,
+ const char *group);
+
+extern int nl_thermal_connect(struct nl_sock **nl_sock, struct nl_cb **nl_cb);
+
+extern void nl_thermal_disconnect(struct nl_sock *nl_sock, struct nl_cb *nl_cb);
+
+extern int nl_send_msg(struct nl_sock *sock, struct nl_cb *nl_cb, struct nl_msg *msg,
+ int (*rx_handler)(struct nl_msg *, void *),
+ void *data);
+
+#endif /* __THERMAL_H */