[PATCH 01/10] firmware: scmi: implement SCMI base protocol

AKASHI Takahiro takahiro.akashi at linaro.org
Mon Jul 3 02:37:20 CEST 2023


On Thu, Jun 29, 2023 at 08:09:45PM +0100, Simon Glass wrote:
> Hi AKASHI,
> 
> On Wed, 28 Jun 2023 at 01:49, AKASHI Takahiro
> <takahiro.akashi at linaro.org> wrote:
> >
> > SCMI base protocol is mandatory according to the SCMI specification.
> >
> > With this patch, SCMI base protocol can be accessed via SCMI transport
> > layers. All the commands, except SCMI_BASE_NOTIFY_ERRORS, are supported.
> > This is because U-Boot doesn't support interrupts and the current transport
> > layers are not able to handle asynchronous messages properly.
> >
> > Signed-off-by: AKASHI Takahiro <takahiro.akashi at linaro.org>
> > ---
> >  drivers/firmware/scmi/Makefile |   1 +
> >  drivers/firmware/scmi/base.c   | 517 +++++++++++++++++++++++++++++++++
> >  include/dm/uclass-id.h         |   1 +
> >  include/scmi_protocols.h       | 201 ++++++++++++-
> >  4 files changed, 718 insertions(+), 2 deletions(-)
> >  create mode 100644 drivers/firmware/scmi/base.c
> >
> > diff --git a/drivers/firmware/scmi/Makefile b/drivers/firmware/scmi/Makefile
> > index b2ff483c75a1..1a23d4981709 100644
> > --- a/drivers/firmware/scmi/Makefile
> > +++ b/drivers/firmware/scmi/Makefile
> > @@ -1,4 +1,5 @@
> >  obj-y  += scmi_agent-uclass.o
> > +obj-y  += base.o
> >  obj-y  += smt.o
> >  obj-$(CONFIG_SCMI_AGENT_SMCCC)         += smccc_agent.o
> >  obj-$(CONFIG_SCMI_AGENT_MAILBOX)       += mailbox_agent.o
> 
> [..]
> 
> > diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h
> > index 307ad6931ca7..f7a110852321 100644
> > --- a/include/dm/uclass-id.h
> > +++ b/include/dm/uclass-id.h
> > @@ -116,6 +116,7 @@ enum uclass_id {
> >         UCLASS_RNG,             /* Random Number Generator */
> >         UCLASS_RTC,             /* Real time clock device */
> >         UCLASS_SCMI_AGENT,      /* Interface with an SCMI server */
> > +       UCLASS_SCMI_BASE,       /* Interface for SCMI Base protocol */
> >         UCLASS_SCSI,            /* SCSI device */
> >         UCLASS_SERIAL,          /* Serial UART */
> >         UCLASS_SIMPLE_BUS,      /* Bus with child devices */
> > diff --git a/include/scmi_protocols.h b/include/scmi_protocols.h
> > index a220cb2a91ad..769041654534 100644
> > --- a/include/scmi_protocols.h
> > +++ b/include/scmi_protocols.h
> > @@ -15,6 +15,8 @@
> >   * https://developer.arm.com/docs/den0056/b
> >   */
> >
> > +#define SCMI_BASE_NAME_LENGTH_MAX 16
> > +
> >  enum scmi_std_protocol {
> >         SCMI_PROTOCOL_ID_BASE = 0x10,
> >         SCMI_PROTOCOL_ID_POWER_DOMAIN = 0x11,
> > @@ -41,12 +43,207 @@ enum scmi_status_code {
> >  };
> >
> >  /*
> > - * Generic message IDs
> > + * SCMI Base Protocol
> >   */
> > -enum scmi_discovery_id {
> > +#define SCMI_BASE_PROTOCOL_VERSION 0x20000
> > +
> > +enum scmi_base_message_id {
> >         SCMI_PROTOCOL_VERSION = 0x0,
> >         SCMI_PROTOCOL_ATTRIBUTES = 0x1,
> >         SCMI_PROTOCOL_MESSAGE_ATTRIBUTES = 0x2,
> > +       SCMI_BASE_DISCOVER_VENDOR = 0x3,
> > +       SCMI_BASE_DISCOVER_SUB_VENDOR = 0x4,
> > +       SCMI_BASE_DISCOVER_IMPL_VERSION = 0x5,
> > +       SCMI_BASE_DISCOVER_LIST_PROTOCOLS = 0x6,
> > +       SCMI_BASE_DISCOVER_AGENT = 0x7,
> > +       SCMI_BASE_NOTIFY_ERRORS = 0x8,
> > +       SCMI_BASE_SET_DEVICE_PERMISSIONS = 0x9,
> > +       SCMI_BASE_SET_PROTOCOL_PERMISSIONS = 0xa,
> > +       SCMI_BASE_RESET_AGENT_CONFIGURATION = 0xb,
> > +};
> > +
> > +/**
> > + * struct scmi_protocol_version_out - Response for SCMI_PROTOCOL_VERSION
> > + *                                     command
> > + * @status:    SCMI command status
> > + * @version:   Protocol version
> > + */
> > +struct scmi_protocol_version_out {
> > +       s32 status;
> > +       u32 version;
> > +};
> > +
> > +/**
> > + * struct scmi_protocol_attrs_out - Response for SCMI_PROTOCOL_ATTRIBUTES
> > + *                                     command
> > + * @status:    SCMI command status
> > + * @attributes:        Protocol attributes or implementation details
> > + */
> > +struct scmi_protocol_attrs_out {
> > +       s32 status;
> > +       u32 attributes;
> > +};
> > +
> > +#define SCMI_PROTOCOL_ATTRS_NUM_AGENTS(attributes) \
> > +                               (((attributes) & GENMASK(15, 8)) >> 8)
> > +#define SCMI_PROTOCOL_ATTRS_NUM_PROTOCOLS(attributes) \
> > +                               ((attributes) & GENMASK(7, 0))
> > +
> > +/**
> > + * struct scmi_protocol_msg_attrs_out - Response for
> > + *                                     SCMI_PROTOCOL_MESSAGE_ATTRIBUTES command
> > + * @status:    SCMI command status
> > + * @attributes:        Message-specific attributes
> > + */
> > +struct scmi_protocol_msg_attrs_out {
> > +       s32 status;
> > +       u32 attributes;
> > +};
> > +
> > +/**
> > + * struct scmi_base_discover_vendor_out - Response for
> > + *                                       SCMI_BASE_DISCOVER_VENDOR or
> > + *                                       SCMI_BASE_DISCOVER_SUB_VENDOR command
> > + * @status:            SCMI command status
> > + * @vendor_identifier: Identifier of vendor or sub-vendor in string
> > + */
> > +struct scmi_base_discover_vendor_out {
> > +       s32 status;
> > +       u8 vendor_identifier[SCMI_BASE_NAME_LENGTH_MAX];
> > +};
> > +
> > +/**
> > + * struct scmi_base_discover_impl_version_out - Response for
> > + *                                     SCMI_BASE_DISCOVER_IMPL_VERSION command
> > + * @status:            SCMI command status
> > + * @impl_version:      Vendor-specific implementation version
> > + */
> > +struct scmi_base_discover_impl_version_out {
> > +       s32 status;
> > +       u32 impl_version;
> > +};
> > +
> > +/**
> > + * struct scmi_base_discover_list_protocols_out - Response for
> > + *                             SCMI_BASE_DISCOVER_LIST_PROTOCOLS command
> > + * @status:            SCMI command status
> > + * @num_protocols:     Number of protocols in @protocol
> > + * @protocols:         Array of packed protocol ID's
> > + */
> > +struct scmi_base_discover_list_protocols_out {
> > +       s32 status;
> > +       u32 num_protocols;
> > +       u32 protocols[3];
> > +};
> > +
> > +/**
> > + * struct scmi_base_discover_agent_out - Response for
> > + *                                      SCMI_BASE_DISCOVER_AGENT command
> > + * @status:    SCMI command status
> > + * @agent_id:  Identifier of agent
> > + * @name:      Name of agent in string
> > + */
> > +struct scmi_base_discover_agent_out {
> > +       s32 status;
> > +       u32 agent_id;
> > +       u8 name[SCMI_BASE_NAME_LENGTH_MAX];
> > +};
> > +
> > +#define SCMI_BASE_NOTIFY_ERRORS_ENABLE BIT(0)
> > +
> > +/**
> > + * struct scmi_base_set_device_permissions_in - Parameters for
> > + *                                     SCMI_BASE_SET_DEVICE_PERMISSIONS command
> > + * @agent_id:  Identifier of agent
> > + * @device_id: Identifier of device
> > + * @flags:     A set of flags
> > + */
> > +struct scmi_base_set_device_permissions_in {
> > +       u32 agent_id;
> > +       u32 device_id;
> > +       u32 flags;
> > +};
> > +
> > +#define SCMI_BASE_SET_DEVICE_PERMISSIONS_ACCESS BIT(0)
> > +
> > +/**
> > + * struct scmi_base_set_protocol_permissions_in - Parameters for
> > + *                             SCMI_BASE_SET_PROTOCOL_PERMISSIONS command
> > + * @agent_id:          Identifier of agent
> > + * @device_id:         Identifier of device
> > + * @command_id:                Identifier of command
> > + * @flags:             A set of flags
> > + */
> > +struct scmi_base_set_protocol_permissions_in {
> > +       u32 agent_id;
> > +       u32 device_id;
> > +       u32 command_id;
> > +       u32 flags;
> > +};
> > +
> > +#define SCMI_BASE_SET_PROTOCOL_PERMISSIONS_COMMAND GENMASK(7, 0)
> > +#define SCMI_BASE_SET_PROTOCOL_PERMISSIONS_ACCESS BIT(0)
> > +
> > +/**
> > + * struct scmi_base_reset_agent_configuration_in - Parameters for
> > + *                             SCMI_BASE_RESET_AGENT_CONFIGURATION command
> > + * @agent_id:  Identifier of agent
> > + * @flags:     A set of flags
> > + */
> > +struct scmi_base_reset_agent_configuration_in {
> > +       u32 agent_id;
> > +       u32 flags;
> > +};
> > +
> > +#define SCMI_BASE_RESET_ALL_ACCESS_PERMISSIONS BIT(0)
> > +
> > +/**
> > + * struct scmi_base_ops - SCMI base protocol interfaces
> > + * @protocol_version:                  Function pointer for
> > + *                                             PROTOCOL_VERSION
> > + * @protocol_attrs:                    Function pointer for
> > + *                                             PROTOCOL_ATTRIBUTES
> > + * @protocol_message_attrs:            Function pointer for
> > + *                                             PROTOCOL_MESSAGE_ATTRIBUTES
> > + * @base_discover_vendor:              Function pointer for
> > + *                                             BASE_DISCOVER_VENDOR
> > + * @base_discover_sub_vendor:          Function pointer for
> > + *                                             BASE_DISCOVER_SUB_VENDOR
> > + * @base_discover_impl_version:                Function pointer for
> > + *                                             BASE_DISCOVER_IMPLEMENTATION_VERSION
> > + * @base_discover_list_protocols:      Function pointer for
> > + *                                             BASE_DISCOVER_LIST_PROTOCOLS
> > + * @base_discover_agent:               Function pointer for
> > + *                                             BASE_DISCOVER_AGENT
> > + * @base_notify_errors:                        Function pointer for
> > + *                                             BASE_NOTIFY_ERRORS
> > + * @base_set_device_permissions:       Function pointer for
> > + *                                             BASE_SET_DEVICE_PROTOCOLS
> > + * @base_set_protocol_permissions:     Function pointer for
> > + *                                             BASE_SET_PROTOCOL_PERMISSIONS
> > + * @base_reset_agent_configuration:    Function pointer for
> > + *                                             BASE_RESET_AGENT_CONFIGURATION
> > + */
> > +struct scmi_base_ops {
> > +       int (*protocol_version)(struct udevice *dev, u32 *version);
> > +       int (*protocol_attrs)(struct udevice *dev, u32 *num_agents,
> > +                             u32 *num_protocols);
> > +       int (*protocol_message_attrs)(struct udevice *dev, u32 message_id,
> > +                                     u32 *attributes);
> > +       int (*base_discover_vendor)(struct udevice *dev, u8 *vendor);
> > +       int (*base_discover_sub_vendor)(struct udevice *dev, u8 *sub_vendor);
> > +       int (*base_discover_impl_version)(struct udevice *dev, u32 *impl_version);
> > +       int (*base_discover_list_protocols)(struct udevice *dev, u8 **protocols);
> > +       int (*base_discover_agent)(struct udevice *dev, u32 agent_id,
> > +                                  u32 *ret_agent_id, u8 *name);
> > +       int (*base_notify_errors)(struct udevice *dev, u32 enable);
> > +       int (*base_set_device_permissions)(struct udevice *dev, u32 agent_id,
> > +                                          u32 device_id, u32 flags);
> > +       int (*base_set_protocol_permissions)(struct udevice *dev, u32 agent_id,
> > +                                            u32 device_id, u32 command_id,
> > +                                            u32 flags);
> > +       int (*base_reset_agent_configuration)(struct udevice *dev, u32 agent_id,
> > +                                             u32 flags);
> 
> Please can you add full function comments for each of these?

Yes, I will.

Thanks,
-Takahiro Akashi


> >  };
> >
> >  /*
> > --
> > 2.41.0
> >
> 
> Regards,
> Simon


More information about the U-Boot mailing list