Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1efbc7e9 authored by Gaurav Singh's avatar Gaurav Singh Committed by Gerrit - the friendly Code Review server
Browse files

Firmware: arm_scmi: initial support for plh vendor protocol



The perf lock hardening protocol is intended for the management
of perf lock hardening on RIMPS.
The commands in this protocol provide functionality to configure
plh details, plh tunables, configuring the log levels and
debugging support.

Change-Id: I9f5292ee3e32a038160e66d38ec15637a55458fd
Signed-off-by: default avatarGaurav Singh <sgaurav@codeaurora.org>
parent 8c86f959
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -39,6 +39,17 @@ config QTI_SCMI_MEMLAT_PROTOCOL
	  This driver defines the comands or message ID's used for this
	  communication and also exposes the ops used by clients.

config QTI_SCMI_PLH_PROTOCOL
	tristate "Qualcomm Technologies, Inc. SCMI PLH vendor Protocol"
	depends on ARM_SCMI_PROTOCOL && QCOM_RIMPS && QGKI
	help
	  System Control and Management Interface (SCMI) plh vendor protocol
	  this protocol provides interface to communicate with micro controller
	  which is executing the plh algorithm

	  This driver defines the comands or message ID's used for this
	  communication and also exposes the ops used by clients.

config ARM_SCMI_POWER_DOMAIN
	tristate "SCMI power domain driver"
	depends on ARM_SCMI_PROTOCOL || (COMPILE_TEST && OF)
+1 −0
Original line number Diff line number Diff line
@@ -5,3 +5,4 @@ scmi-driver-y = driver.o
scmi-protocols-y = base.o clock.o perf.o power.o reset.o sensors.o
obj-$(CONFIG_ARM_SCMI_POWER_DOMAIN) += scmi_pm_domain.o
obj-$(CONFIG_QTI_SCMI_MEMLAT_PROTOCOL) += memlat_vendor.o
obj-$(CONFIG_QTI_SCMI_PLH_PROTOCOL) += plh_vendor.o
+136 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (c) 2020, The Linux Foundation. All rights reserved.
 */

#include "common.h"

#define SCMI_VENDOR_MSG_MAX_TX_SIZE		(100) /* in bytes */
#define SCMI_VENDOR_MSG_START			(3)
#define SCMI_VENDOR_MSG_PLH_START		(16)

enum scmi_plh_protocol_cmd {
	PERF_LOCK_SET_LOG_LEVEL = SCMI_VENDOR_MSG_START,
	PERF_LOCK_SCROLL_INIT_IPC_FREQ_TBL_MSG_ID = SCMI_VENDOR_MSG_PLH_START,
	PERF_LOCK_SCROLL_START_MSG_ID,
	PERF_LOCK_SCROLL_STOP_MSG_ID,
	PERF_LOCK_MAX_MSG_ID,
};


static int scmi_plh_scroll_init_ipc_freq_tbl(const struct scmi_handle *handle,
			u16 *p_init_args, u16 init_len)
{
	int ret, i = 0;
	struct scmi_xfer *t;
	uint32_t *msg, msg_size, msg_val, align_init_len = init_len;

	if (init_len % 2)
		align_init_len += 1; /* align in multiple of u32 */

	msg_size = align_init_len * sizeof(*p_init_args);

	if (msg_size > SCMI_VENDOR_MSG_MAX_TX_SIZE)
		return -EINVAL;

	ret = scmi_xfer_get_init(handle, PERF_LOCK_SCROLL_INIT_IPC_FREQ_TBL_MSG_ID,
				SCMI_PROTOCOL_PLH,
				(msg_size), sizeof(uint32_t), &t);
	if (ret)
		return ret;

	msg = t->tx.buf;

	for (i = 0; i < init_len/2 ; i++) {
		msg_val = *p_init_args++;
		msg_val |= ((*p_init_args++) << 16);
		*msg++ = cpu_to_le32(msg_val);
	}

	if (init_len % 2)
		*msg = cpu_to_le32(*p_init_args);

	ret = scmi_do_xfer(handle, t);
	scmi_xfer_put(handle, t);
	return ret;
}


static int scmi_send_start_stop(const struct scmi_handle *handle,
			u16 fps, u32 msg_id)
{
	int ret = 0;
	struct scmi_xfer *t;
	uint32_t *msg;

	ret = scmi_xfer_get_init(handle, msg_id,
				SCMI_PROTOCOL_PLH,
				sizeof(*msg), sizeof(uint32_t), &t);
	if (ret)
		return ret;

	msg = t->tx.buf;
	*msg = cpu_to_le32(fps);
	ret = scmi_do_xfer(handle, t);
	scmi_xfer_put(handle, t);
	return ret;
}

static int scmi_plh_scroll_start_cmd(const struct scmi_handle *handle,
			u16 fps)
{
	return scmi_send_start_stop(handle, fps, PERF_LOCK_SCROLL_START_MSG_ID);
}

static int scmi_plh_scroll_stop_cmd(const struct scmi_handle *handle)
{
	return scmi_send_start_stop(handle, 0, PERF_LOCK_SCROLL_STOP_MSG_ID);
}

static int scmi_plh_set_log_level(const struct scmi_handle *handle,
			u16 val)
{
	int ret = 0;
	struct scmi_xfer *t;
	uint32_t *msg;

	ret = scmi_xfer_get_init(handle, PERF_LOCK_SET_LOG_LEVEL,
				SCMI_PROTOCOL_PLH, sizeof(*msg),
				sizeof(uint32_t), &t);
	if (ret)
		return ret;

	msg = t->tx.buf;
	*msg = cpu_to_le32(val);
	ret = scmi_do_xfer(handle, t);
	scmi_xfer_put(handle, t);
	return ret;
}

static struct scmi_plh_vendor_ops plh_ops = {
	.init_splh_ipc_freq_tbl = scmi_plh_scroll_init_ipc_freq_tbl,
	.start_splh = scmi_plh_scroll_start_cmd,
	.stop_splh = scmi_plh_scroll_stop_cmd,
	.set_plh_log_level = scmi_plh_set_log_level,
};

static int scmi_plh_vendor_protocol_init(struct scmi_handle *handle)
{
	u32 version;

	scmi_version_get(handle, SCMI_PROTOCOL_PLH, &version);

	dev_dbg(handle->dev, "PLH version %d.%d\n",
		PROTOCOL_REV_MAJOR(version), PROTOCOL_REV_MINOR(version));

	handle->plh_ops = &plh_ops;

	return 0;
}

static int __init scmi_plh_init(void)
{
	return scmi_protocol_register(SCMI_PROTOCOL_PLH,
				      &scmi_plh_vendor_protocol_init);
}
subsys_initcall(scmi_plh_init);
+26 −0
Original line number Diff line number Diff line
@@ -266,6 +266,26 @@ struct scmi_memlat_vendor_ops {
};
#endif

#ifdef CONFIG_QTI_SCMI_PLH_PROTOCOL
/**
 * struct scmi_plh_vendor_ops - represents the various operations provided
 *	by SCMI PLH Protocol
 *
 * @init_splh_ipc_freq_tbl: initialize scroll plh ipc freq voting table in rimps
 * @start_splh: starts scroll plh in rimps
 * @stop_splh: stops scroll plh in rimps
 * @set_plh_log_level: configure the supported log_level in plh module of rimps
 */
struct scmi_plh_vendor_ops {
	int (*init_splh_ipc_freq_tbl)(const struct scmi_handle *handle,
				u16 *p_init_args, u16 init_len);
	int (*start_splh)(const struct scmi_handle *handle,	u16 fps);
	int (*stop_splh)(const struct scmi_handle *handle);
	int (*set_plh_log_level)(const struct scmi_handle *handle,
				u16 log_level);
};
#endif

/**
 * struct scmi_handle - Handle returned to ARM SCMI clients for usage.
 *
@@ -297,6 +317,9 @@ struct scmi_handle {
	struct scmi_reset_ops *reset_ops;
#ifdef CONFIG_QTI_SCMI_MEMLAT_PROTOCOL
	struct scmi_memlat_vendor_ops *memlat_ops;
#endif
#ifdef CONFIG_QTI_SCMI_PLH_PROTOCOL
	struct scmi_plh_vendor_ops *plh_ops;
#endif
	/* for protocol internal use */
	void *perf_priv;
@@ -317,6 +340,9 @@ enum scmi_std_protocol {
#ifdef CONFIG_QTI_SCMI_MEMLAT_PROTOCOL
	SCMI_PROTOCOL_MEMLAT = 0x80,
#endif
#ifdef CONFIG_QTI_SCMI_PLH_PROTOCOL
	SCMI_PROTOCOL_PLH = 0x81,
#endif
};

struct scmi_device {