Commit 5f2ea10a authored by Nikunj Kela's avatar Nikunj Kela Committed by Sudeep Holla
Browse files

firmware: arm_scmi: Augment SMC/HVC to allow optional parameters



This change adds support for passing shmem channel address as parameters
in smc/hvc call. The address is split into 4KB-page and offset.
This is useful when multiple scmi instances are using same smc-id
and firmware needs to distinguish among the instances.

Signed-off-by: default avatarNikunj Kela <quic_nkela@quicinc.com>
Reviewed-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Link: https://lore.kernel.org/r/20230506182428.25343-3-quic_nkela@quicinc.com


Signed-off-by: default avatarSudeep Holla <sudeep.holla@arm.com>
parent 8f9d530c
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -2914,6 +2914,7 @@ static const struct of_device_id scmi_of_match[] = {
#endif
#endif
#ifdef CONFIG_ARM_SCMI_TRANSPORT_SMC
#ifdef CONFIG_ARM_SCMI_TRANSPORT_SMC
	{ .compatible = "arm,scmi-smc", .data = &scmi_smc_desc},
	{ .compatible = "arm,scmi-smc", .data = &scmi_smc_desc},
	{ .compatible = "arm,scmi-smc-param", .data = &scmi_smc_desc},
#endif
#endif
#ifdef CONFIG_ARM_SCMI_TRANSPORT_VIRTIO
#ifdef CONFIG_ARM_SCMI_TRANSPORT_VIRTIO
	{ .compatible = "arm,scmi-virtio", .data = &scmi_virtio_desc},
	{ .compatible = "arm,scmi-virtio", .data = &scmi_virtio_desc},
+29 −1
Original line number Original line Diff line number Diff line
@@ -20,6 +20,23 @@


#include "common.h"
#include "common.h"


/*
 * The shmem address is split into 4K page and offset.
 * This is to make sure the parameters fit in 32bit arguments of the
 * smc/hvc call to keep it uniform across smc32/smc64 conventions.
 * This however limits the shmem address to 44 bit.
 *
 * These optional parameters can be used to distinguish among multiple
 * scmi instances that are using the same smc-id.
 * The page parameter is passed in r1/x1/w1 register and the offset parameter
 * is passed in r2/x2/w2 register.
 */

#define SHMEM_SIZE (SZ_4K)
#define SHMEM_SHIFT 12
#define SHMEM_PAGE(x) (_UL((x) >> SHMEM_SHIFT))
#define SHMEM_OFFSET(x) ((x) & (SHMEM_SIZE - 1))

/**
/**
 * struct scmi_smc - Structure representing a SCMI smc transport
 * struct scmi_smc - Structure representing a SCMI smc transport
 *
 *
@@ -30,6 +47,8 @@
 * @inflight: Atomic flag to protect access to Tx/Rx shared memory area.
 * @inflight: Atomic flag to protect access to Tx/Rx shared memory area.
 *	      Used when operating in atomic mode.
 *	      Used when operating in atomic mode.
 * @func_id: smc/hvc call function id
 * @func_id: smc/hvc call function id
 * @param_page: 4K page number of the shmem channel
 * @param_offset: Offset within the 4K page of the shmem channel
 */
 */


struct scmi_smc {
struct scmi_smc {
@@ -40,6 +59,8 @@ struct scmi_smc {
#define INFLIGHT_NONE	MSG_TOKEN_MAX
#define INFLIGHT_NONE	MSG_TOKEN_MAX
	atomic_t inflight;
	atomic_t inflight;
	u32 func_id;
	u32 func_id;
	u32 param_page;
	u32 param_offset;
};
};


static irqreturn_t smc_msg_done_isr(int irq, void *data)
static irqreturn_t smc_msg_done_isr(int irq, void *data)
@@ -137,6 +158,10 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
	if (ret < 0)
	if (ret < 0)
		return ret;
		return ret;


	if (of_device_is_compatible(dev->of_node, "arm,scmi-smc-param")) {
		scmi_info->param_page = SHMEM_PAGE(res.start);
		scmi_info->param_offset = SHMEM_OFFSET(res.start);
	}
	/*
	/*
	 * If there is an interrupt named "a2p", then the service and
	 * If there is an interrupt named "a2p", then the service and
	 * completion of a message is signaled by an interrupt rather than by
	 * completion of a message is signaled by an interrupt rather than by
@@ -179,6 +204,8 @@ static int smc_send_message(struct scmi_chan_info *cinfo,
{
{
	struct scmi_smc *scmi_info = cinfo->transport_info;
	struct scmi_smc *scmi_info = cinfo->transport_info;
	struct arm_smccc_res res;
	struct arm_smccc_res res;
	unsigned long page = scmi_info->param_page;
	unsigned long offset = scmi_info->param_offset;


	/*
	/*
	 * Channel will be released only once response has been
	 * Channel will be released only once response has been
@@ -188,7 +215,8 @@ static int smc_send_message(struct scmi_chan_info *cinfo,


	shmem_tx_prepare(scmi_info->shmem, xfer, cinfo);
	shmem_tx_prepare(scmi_info->shmem, xfer, cinfo);


	arm_smccc_1_1_invoke(scmi_info->func_id, 0, 0, 0, 0, 0, 0, 0, &res);
	arm_smccc_1_1_invoke(scmi_info->func_id, page, offset, 0, 0, 0, 0, 0,
			     &res);


	/* Only SMCCC_RET_NOT_SUPPORTED is valid error code */
	/* Only SMCCC_RET_NOT_SUPPORTED is valid error code */
	if (res.a0) {
	if (res.a0) {