Commit 776b6c8a authored by Cristian Marussi's avatar Cristian Marussi Committed by Sudeep Holla
Browse files

firmware: arm_scmi: Dynamically allocate implemented protocols array

Move away from a statically allocated array for holding the current set of
protocols implemented by the platform in favour of allocating it
dynamically based on the number of protocols effectively advertised by the
platform via BASE protocol exchanges.

While at that, rectify the BASE_DISCOVER_LIST_PROTOCOLS loop iterations to
terminate only when a number of protocols equal to the advertised ones has
been received, instead of looping till the platform returns no more
protocols descriptors. This new behaviour is better compliant with the
specification and it has been tested to work equally well against an SCMI
stack running on top of an official SCP firmware on a JUNO board.

Link: https://lore.kernel.org/r/20220330150551.2573938-6-cristian.marussi@arm.com


Signed-off-by: default avatarCristian Marussi <cristian.marussi@arm.com>
Signed-off-by: default avatarSudeep Holla <sudeep.holla@arm.com>
parent 3b0041f6
Loading
Loading
Loading
Loading
+10 −7
Original line number Diff line number Diff line
@@ -178,6 +178,7 @@ scmi_base_implementation_list_get(const struct scmi_protocol_handle *ph,
	__le32 *num_skip, *num_ret;
	u32 tot_num_ret = 0, loop_num_ret;
	struct device *dev = ph->dev;
	struct scmi_revision_info *rev = ph->get_priv(ph);

	ret = ph->xops->xfer_get_init(ph, BASE_DISCOVER_LIST_PROTOCOLS,
				      sizeof(*num_skip), 0, &t);
@@ -203,8 +204,9 @@ scmi_base_implementation_list_get(const struct scmi_protocol_handle *ph,
		if (!loop_num_ret)
			break;

		if (loop_num_ret > MAX_PROTOCOLS_IMP - tot_num_ret) {
			dev_err(dev, "No. of Protocol > MAX_PROTOCOLS_IMP");
		if (loop_num_ret > rev->num_protocols - tot_num_ret) {
			dev_err(dev,
				"No. Returned protocols > Total protocols.\n");
			break;
		}

@@ -232,7 +234,7 @@ scmi_base_implementation_list_get(const struct scmi_protocol_handle *ph,
		tot_num_ret += loop_num_ret;

		ph->xops->reset_rx_to_maxsz(ph, t);
	} while (loop_num_ret);
	} while (tot_num_ret < rev->num_protocols);

	ph->xops->xfer_put(ph, t);

@@ -375,10 +377,6 @@ static int scmi_base_protocol_init(const struct scmi_protocol_handle *ph)
	if (ret)
		return ret;

	prot_imp = devm_kcalloc(dev, MAX_PROTOCOLS_IMP, sizeof(u8), GFP_KERNEL);
	if (!prot_imp)
		return -ENOMEM;

	rev->major_ver = PROTOCOL_REV_MAJOR(version),
	rev->minor_ver = PROTOCOL_REV_MINOR(version);
	ph->set_priv(ph, rev);
@@ -387,6 +385,11 @@ static int scmi_base_protocol_init(const struct scmi_protocol_handle *ph)
	if (ret)
		return ret;

	prot_imp = devm_kcalloc(dev, rev->num_protocols, sizeof(u8),
				GFP_KERNEL);
	if (!prot_imp)
		return -ENOMEM;

	scmi_base_vendor_id_get(ph, false);
	scmi_base_vendor_id_get(ph, true);
	scmi_base_implementation_version_get(ph);
+0 −1
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@
#define PROTOCOL_REV_MAJOR_MASK	GENMASK(31, 16)
#define PROTOCOL_REV_MAJOR(x)	(u16)(FIELD_GET(PROTOCOL_REV_MAJOR_MASK, (x)))
#define PROTOCOL_REV_MINOR(x)	(u16)(FIELD_GET(PROTOCOL_REV_MINOR_MASK, (x)))
#define MAX_PROTOCOLS_IMP	16
#define MAX_OPPS		16

enum scmi_common_cmd {
+4 −2
Original line number Diff line number Diff line
@@ -128,7 +128,8 @@ struct scmi_protocol_instance {
 *	       usage.
 * @protocols_mtx: A mutex to protect protocols instances initialization.
 * @protocols_imp: List of protocols implemented, currently maximum of
 *	MAX_PROTOCOLS_IMP elements allocated by the base protocol
 *		   scmi_revision_info.num_protocols elements allocated by the
 *		   base protocol
 * @active_protocols: IDR storing device_nodes for protocols actually defined
 *		      in the DT and confirmed as implemented by fw.
 * @atomic_threshold: Optional system wide DT-configured threshold, expressed
@@ -1310,11 +1311,12 @@ scmi_is_protocol_implemented(const struct scmi_handle *handle, u8 prot_id)
{
	int i;
	struct scmi_info *info = handle_to_scmi_info(handle);
	struct scmi_revision_info *rev = handle->version;

	if (!info->protocols_imp)
		return false;

	for (i = 0; i < MAX_PROTOCOLS_IMP; i++)
	for (i = 0; i < rev->num_protocols; i++)
		if (info->protocols_imp[i] == prot_id)
			return true;
	return false;