[PATCH v2 04/12] firmware: scmi: framework for installing additional protocols

Etienne CARRIERE etienne.carriere at st.com
Thu Aug 3 11:57:48 CEST 2023


> From: AKASHI Takahiro <takahiro.akashi at linaro.org>
> Sent: Wednesday, July 26, 2023 10:38
>  
> This framework allows SCMI protocols to be installed and bound to the agent
> so that the agent can manage and utilize them later.
> 
> Signed-off-by: AKASHI Takahiro <takahiro.akashi at linaro.org>
> ---
> v2
> * check for availability of protocols

Reviewed-by: Etienne Carriere <etienne.carriere at foss.st.com>
with 2 minor comments and with .per_device_plat_auto value set
by this patch instead of from patch v2 01/12.

> ---
>  drivers/firmware/scmi/scmi_agent-uclass.c | 100 +++++++++++++++++++++-
>  include/scmi_agent-uclass.h               |  15 +++-
>  include/scmi_agent.h                      |  14 +++
>  3 files changed, 125 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/firmware/scmi/scmi_agent-uclass.c b/drivers/firmware/scmi/scmi_agent-uclass.c
> index 8693e4c447b7..2244fcf487e8 100644
> --- a/drivers/firmware/scmi/scmi_agent-uclass.c
> +++ b/drivers/firmware/scmi/scmi_agent-uclass.c
> @@ -38,6 +38,86 @@ static const struct error_code scmi_linux_errmap[] = {
>          { .scmi = SCMI_PROTOCOL_ERROR, .errno = -EPROTO, },
>  };
>  
> +/*
> + * NOTE: The only one instance should exist according to
> + * the current specification and device tree bindings.
> + */
> +struct udevice *scmi_agent;
> +
> +struct udevice *scmi_get_protocol(struct udevice *dev,
> +                                 enum scmi_std_protocol id)
> +{
> +       struct scmi_agent_priv *priv;
> +       struct udevice *proto;
> +
> +       priv = dev_get_uclass_plat(dev);
> +       if (!priv) {
> +               dev_err(dev, "No priv data found\n");
> +               return NULL;
> +       }
> +
> +       switch (id) {
> +       case SCMI_PROTOCOL_ID_CLOCK:
> +               proto = priv->clock_dev;
> +               break;
> +       case SCMI_PROTOCOL_ID_RESET_DOMAIN:
> +               proto = priv->resetdom_dev;
> +               break;
> +       case SCMI_PROTOCOL_ID_VOLTAGE_DOMAIN:
> +               proto = priv->voltagedom_dev;
> +               break;
> +       default:
> +               dev_err(dev, "Protocol not supported\n");
> +               proto = NULL;
> +               break;
> +       }
> +       if (proto && device_probe(proto))
> +               dev_err(dev, "Probe failed\n");
> +
> +       return proto;
> +}
> +
> +/**
> + * scmi_add_protocol - add protocol to agent
> + * @dev:       SCMI agent device
> + * @proto_id:  SCMI protocol ID
> + * @proto:     SCMI protocol device
> + *
> + * Associate the protocol instance, @proto, to the agent, @dev,
> + * for later use.
> + *
> + * Return:     0 on success, error code otherwise
> + */
> +static int scmi_add_protocol(struct udevice *dev,
> +                            enum scmi_std_protocol proto_id,
> +                            struct udevice *proto)
> +{
> +       struct scmi_agent_priv *priv;
> +
> +       priv = dev_get_uclass_plat(dev);
> +       if (!priv) {
> +               dev_err(dev, "No priv data found\n");
> +               return -ENODEV;
> +       }
> +
> +       switch (proto_id) {
> +       case SCMI_PROTOCOL_ID_CLOCK:
> +               priv->clock_dev = proto;
> +               break;
> +       case SCMI_PROTOCOL_ID_RESET_DOMAIN:
> +               priv->resetdom_dev = proto;
> +               break;
> +       case SCMI_PROTOCOL_ID_VOLTAGE_DOMAIN:
> +               priv->voltagedom_dev = proto;
> +               break;
> +       default:
> +               dev_err(dev, "Protocol not supported\n");
> +               return -EPROTO;
> +       }
> +
> +       return 0;
> +}
> +
>  int scmi_to_linux_errno(s32 scmi_code)
>  {
>          int n;
> @@ -156,12 +236,14 @@ int devm_scmi_process_msg(struct udevice *dev, struct scmi_msg *msg)
>   */
>  static int scmi_bind_protocols(struct udevice *dev)
>  {
> +       struct udevice *agent;
>          int ret = 0;
>          ofnode node;
>          const char *name;
> +       struct driver *drv;
> +       struct udevice *proto;
>  
>          dev_for_each_subnode(node, dev) {
> -               struct driver *drv = NULL;
>                  u32 protocol_id;
>  
>                  if (!ofnode_is_enabled(node))
> @@ -170,6 +252,7 @@ static int scmi_bind_protocols(struct udevice *dev)
>                  if (ofnode_read_u32(node, "reg", &protocol_id))
>                          continue;
>  
> +               drv = NULL;
>                  name = ofnode_get_name(node);
>                  switch (protocol_id) {
>                  case SCMI_PROTOCOL_ID_CLOCK:
> @@ -200,11 +283,22 @@ static int scmi_bind_protocols(struct udevice *dev)
>                          continue;
>                  }
>  
> -               ret = device_bind(dev, drv, name, NULL, node, NULL);
> -               if (ret)
> +               ret = device_bind(dev, drv, name, NULL, node, &proto);
> +               if (ret) {
> +                       dev_err(dev, "failed to bind %s protocol\n", drv->name);
>                          break;
> +               }
> +               ret = scmi_add_protocol(dev, protocol_id, proto);
> +               if (ret) {
> +                       dev_err(dev, "failed to add protocol: %s, ret: %d\n",
> +                               proto->name, ret);
> +                       break;
> +               }
>          }
>  
> +       if (!ret)
> +               scmi_agent = dev;
> +
>          return ret;
>  }
>  
> diff --git a/include/scmi_agent-uclass.h b/include/scmi_agent-uclass.h
> index b1c93532c0ea..f9e7d3f51de1 100644
> --- a/include/scmi_agent-uclass.h
> +++ b/include/scmi_agent-uclass.h
> @@ -5,10 +5,23 @@
>  #ifndef _SCMI_AGENT_UCLASS_H
>  #define _SCMI_AGENT_UCLASS_H
>  
> -struct udevice;
> +#include <dm/device.h>
> +
>  struct scmi_msg;
>  struct scmi_channel;
>  
> +/**
> + * struct scmi_agent_priv - private data maintained by agent instance
> + * @clock_dev:         SCMI clock protocol device
> + * @clock_dev:         SCMI reset domain protocol device
> + * @clock_dev:         SCMI voltage domain protocol device
> + */
> +struct scmi_agent_priv {
> +       struct udevice *clock_dev;
> +       struct udevice *resetdom_dev;
> +       struct udevice *voltagedom_dev;

Nitpicking: typo on @clock_dev, fixed in next patch v2 05/12 of the series.
Could be squashed here.


> +};
> +
>  /**
>   * struct scmi_transport_ops - The functions that a SCMI transport layer must implement.
>   */
> diff --git a/include/scmi_agent.h b/include/scmi_agent.h
> index 577892029ff8..a5e7cf0592bc 100644
> --- a/include/scmi_agent.h
> +++ b/include/scmi_agent.h
> @@ -11,6 +11,7 @@
>  #define SCMI_AGENT_H
>  
>  #include <asm/types.h>
> +#include <scmi_protocols.h>

Should swap the 2 lines.

BR,
Etienne

>  
>  struct udevice;
>  struct scmi_channel;
> @@ -74,6 +75,19 @@ int devm_scmi_of_get_channel(struct udevice *dev);
>   */
>  int devm_scmi_process_msg(struct udevice *dev, struct scmi_msg *msg);
>  
> +/**
> + * scmi_get_protocol() - get protocol instance
> + *
> + * @dev:       SCMI agent device
> + * @id:                SCMI protocol ID
> + *
> + * Obtain the device instance for given protocol ID, @id.
> + *
> + * Return:     Pointer to the device if found, null otherwise
> + */
> +struct udevice *scmi_get_protocol(struct udevice *dev,
> +                                 enum scmi_std_protocol id);
> +
>  /**
>   * scmi_to_linux_errno() - Convert an SCMI error code into a Linux errno code
>   *
> -- 
> 2.41.0
> 


More information about the U-Boot mailing list