tools/lib/thermal/events.c

Source file repositories/reference/linux-study-clean/tools/lib/thermal/events.c

File Facts

System
Linux kernel
Corpus path
tools/lib/thermal/events.c
Extension
.c
Size
7169 bytes
Lines
194
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: LGPL-2.1+
// Copyright (C) 2022, Linaro Ltd - Daniel Lezcano <daniel.lezcano@linaro.org>
#include <linux/netlink.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>


#include <thermal.h>
#include "thermal_nl.h"

/*
 * Optimization: fill this array to tell which event we do want to pay
 * attention to. That happens at init time with the ops
 * structure. Each ops will enable the event and the general handler
 * will be able to discard the event if there is not ops associated
 * with it.
 */
static int enabled_ops[__THERMAL_GENL_EVENT_MAX];

static int handle_thermal_event(struct nl_msg *n, void *arg)
{
	struct nlmsghdr *nlh = nlmsg_hdr(n);
	struct genlmsghdr *genlhdr = genlmsg_hdr(nlh);
	struct nlattr *attrs[THERMAL_GENL_ATTR_MAX + 1];
	struct thermal_handler_param *thp = arg;
	struct thermal_events_ops *ops = &thp->th->ops->events;

	genlmsg_parse(nlh, 0, attrs, THERMAL_GENL_ATTR_MAX, NULL);

	arg = thp->arg;

	/*
	 * This is an event we don't care of, bail out.
	 */
	if (!enabled_ops[genlhdr->cmd])
		return THERMAL_SUCCESS;

	switch (genlhdr->cmd) {

	case THERMAL_GENL_EVENT_TZ_CREATE:
		return ops->tz_create(nla_get_string(attrs[THERMAL_GENL_ATTR_TZ_NAME]),
				      nla_get_u32(attrs[THERMAL_GENL_ATTR_TZ_ID]), arg);

	case THERMAL_GENL_EVENT_TZ_DELETE:
		return ops->tz_delete(nla_get_u32(attrs[THERMAL_GENL_ATTR_TZ_ID]), arg);

	case THERMAL_GENL_EVENT_TZ_ENABLE:
		return ops->tz_enable(nla_get_u32(attrs[THERMAL_GENL_ATTR_TZ_ID]), arg);

	case THERMAL_GENL_EVENT_TZ_DISABLE:
		return ops->tz_disable(nla_get_u32(attrs[THERMAL_GENL_ATTR_TZ_ID]), arg);

	case THERMAL_GENL_EVENT_TZ_TRIP_CHANGE:
		return ops->trip_change(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_TRIP_TYPE]),
					nla_get_u32(attrs[THERMAL_GENL_ATTR_TZ_TRIP_TEMP]),
					nla_get_u32(attrs[THERMAL_GENL_ATTR_TZ_TRIP_HYST]), arg);

	case THERMAL_GENL_EVENT_TZ_TRIP_ADD:
		return ops->trip_add(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_TRIP_TYPE]),
				     nla_get_u32(attrs[THERMAL_GENL_ATTR_TZ_TRIP_TEMP]),
				     nla_get_u32(attrs[THERMAL_GENL_ATTR_TZ_TRIP_HYST]), arg);

	case THERMAL_GENL_EVENT_TZ_TRIP_DELETE:
		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_UP:
		return 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]), arg);

	case THERMAL_GENL_EVENT_TZ_TRIP_DOWN:
		return 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]), arg);

	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_CDEV_DELETE:
		return ops->cdev_delete(nla_get_u32(attrs[THERMAL_GENL_ATTR_CDEV_ID]), arg);

	case THERMAL_GENL_EVENT_CDEV_STATE_UPDATE:

Annotation

Implementation Notes