tools/lib/thermal/commands.c

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

File Facts

System
Linux kernel
Corpus path
tools/lib/thermal/commands.c
Extension
.c
Size
13881 bytes
Lines
512
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

struct cmd_param {
	int tz_id;
	int temp;
	int direction;
};

typedef int (*cmd_cb_t)(struct nl_msg *, struct cmd_param *);

static int thermal_genl_tz_id_encode(struct nl_msg *msg, struct cmd_param *p)
{
	if (nla_put_u32(msg, THERMAL_GENL_ATTR_TZ_ID, p->tz_id))
		return -1;

	return 0;
}

static int thermal_genl_threshold_encode(struct nl_msg *msg, struct cmd_param *p)
{
	if (thermal_genl_tz_id_encode(msg, p))
		return -1;

	if (nla_put_u32(msg, THERMAL_GENL_ATTR_THRESHOLD_TEMP, p->temp))
		return -1;

	if (nla_put_u32(msg, THERMAL_GENL_ATTR_THRESHOLD_DIRECTION, p->direction))
		return -1;

	return 0;
}

static thermal_error_t thermal_genl_auto(struct thermal_handler *th, cmd_cb_t cmd_cb,
					 struct cmd_param *param,
					 int cmd, int flags, void *arg)
{
	thermal_error_t ret = THERMAL_ERROR;
	struct nl_msg *msg;
	void *hdr;

	msg = nlmsg_alloc();
	if (!msg)
		return THERMAL_ERROR;

	hdr = genlmsg_put(msg, NL_AUTO_PORT, NL_AUTO_SEQ, thermal_cmd_ops.o_id,
			  0, flags, cmd, THERMAL_GENL_VERSION);
	if (!hdr)
		goto out;

	if (cmd_cb && cmd_cb(msg, param))
		goto out;

	if (nl_send_msg(th->sk_cmd, th->cb_cmd, msg, genl_handle_msg, arg))
		goto out;

	ret = THERMAL_SUCCESS;
out:
	nlmsg_free(msg);

	return ret;
}

thermal_error_t thermal_cmd_get_tz(struct thermal_handler *th, struct thermal_zone **tz)
{
	return thermal_genl_auto(th, NULL, NULL, THERMAL_GENL_CMD_TZ_GET_ID,
				 NLM_F_DUMP | NLM_F_ACK, tz);
}

thermal_error_t thermal_cmd_get_cdev(struct thermal_handler *th, struct thermal_cdev **tc)
{
	return thermal_genl_auto(th, NULL, NULL, THERMAL_GENL_CMD_CDEV_GET,
				 NLM_F_DUMP | NLM_F_ACK, tc);
}

thermal_error_t thermal_cmd_get_trip(struct thermal_handler *th, struct thermal_zone *tz)
{
	struct cmd_param p = { .tz_id = tz->id };

	return thermal_genl_auto(th, thermal_genl_tz_id_encode, &p,
				 THERMAL_GENL_CMD_TZ_GET_TRIP, 0, tz);
}

thermal_error_t thermal_cmd_get_governor(struct thermal_handler *th, struct thermal_zone *tz)
{
	struct cmd_param p = { .tz_id = tz->id };

	return thermal_genl_auto(th, thermal_genl_tz_id_encode, &p,
				 THERMAL_GENL_CMD_TZ_GET_GOV, 0, tz);
}

thermal_error_t thermal_cmd_get_temp(struct thermal_handler *th, struct thermal_zone *tz)
{

Annotation

Implementation Notes