Re: [RFC PATCH 3/8] firmware: arm_scmi: add common infrastructure and support for base protocol

2017-06-07 Thread Roy Franz
On Wed, Jun 7, 2017 at 9:10 AM, Sudeep Holla  wrote:
> The base protocol describes the properties of the implementation and
> provide generic error management. The base protocol provides commands
> to describe protocol version, discover implementation specific
> attributes and vendor/sub-vendor identification, list of protocols
> implemented and the various agents are in the system including OSPM
> and the platform. It also supports registering for notifications of
> platform errors.
>
> This protocol is mandatory. This patch adds support for the same along
> with some basic infrastructure to add support for other protocols.
>
> Signed-off-by: Sudeep Holla 
> ---
>  drivers/firmware/arm_scmi/Makefile |   2 +-
>  drivers/firmware/arm_scmi/base.c   | 290 
> +
>  drivers/firmware/arm_scmi/common.h |  46 ++
>  drivers/firmware/arm_scmi/driver.c |  67 +
>  include/linux/scmi_protocol.h  |  28 
>  5 files changed, 432 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/firmware/arm_scmi/base.c
>
> diff --git a/drivers/firmware/arm_scmi/Makefile 
> b/drivers/firmware/arm_scmi/Makefile
> index 58e94c95e523..21d01d1d6b9c 100644
> --- a/drivers/firmware/arm_scmi/Makefile
> +++ b/drivers/firmware/arm_scmi/Makefile
> @@ -1,2 +1,2 @@
>  obj-$(CONFIG_ARM_SCMI_PROTOCOL)= arm_scmi.o
> -arm_scmi-y = driver.o
> +arm_scmi-y = base.o driver.o
> diff --git a/drivers/firmware/arm_scmi/base.c 
> b/drivers/firmware/arm_scmi/base.c
> new file mode 100644
> index ..1191a409ea73
> --- /dev/null
> +++ b/drivers/firmware/arm_scmi/base.c
> @@ -0,0 +1,290 @@
> +/*
> + * System Control and Management Interface (SCMI) Base Protocol
> + *
> + * Copyright (C) 2017 ARM Ltd.
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms and conditions of the GNU General Public License,
> + * version 2, as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope it will be useful, but WITHOUT
> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
> + * more details.
> + *
> + * You should have received a copy of the GNU General Public License along
> + * with this program. If not, see .
> + */
> +
> +#include "common.h"
> +
> +enum scmi_base_protocol_cmd {
> +   BASE_DISCOVER_VENDOR = 0x3,
> +   BASE_DISCOVER_SUB_VENDOR = 0x4,
> +   BASE_DISCOVER_IMPLEMENT_VERSION = 0x5,
> +   BASE_DISCOVER_LIST_PROTOCOLS = 0x6,
> +   BASE_DISCOVER_AGENT = 0x7,
> +   BASE_NOTIFY_ERRORS = 0x8,
> +};
> +
> +struct scmi_msg_resp_base_attributes {
> +   u8 num_protocols;
> +   u8 num_agents;
> +   __le16 reserved;
> +} __packed;
> +
> +/**
> + * scmi_base_attributes_get() - gets the implementation details
> + * that are associated with the base protocol.
> + *
> + * @handle - SCMI entity handle
> + *
> + * Return: 0 on success, else appropriate SCMI error.
> + */
> +static int scmi_base_attributes_get(struct scmi_handle *handle)
> +{
> +   int ret;
> +   struct scmi_xfer *t;
> +   struct scmi_msg_resp_base_attributes *attr_info;
> +   struct scmi_revision_info *rev = handle->version;
> +
> +   ret = scmi_one_xfer_init(handle, PROTOCOL_ATTRIBUTES,
> +SCMI_PROTOCOL_BASE, 0, sizeof(*attr_info), 
> &t);
> +   if (ret)
> +   return ret;
> +
> +   ret = scmi_do_xfer(handle, t);
> +   if (!ret) {
> +   attr_info = (struct scmi_msg_resp_base_attributes *)t->rx.buf;
> +   rev->num_protocols = attr_info->num_protocols;
> +   rev->num_agents = attr_info->num_agents;
> +   }
> +
> +   scmi_put_one_xfer(handle, t);
> +   return ret;
> +}
> +
> +/**
> + * scmi_base_vendor_id_get() - gets vendor/subvendor identifier ASCII string.
> + *
> + * @handle - SCMI entity handle
> + * @sub_vendor - specify true if sub-vendor ID is needed
> + *
> + * Return: 0 on success, else appropriate SCMI error.
> + */
> +static int scmi_base_vendor_id_get(struct scmi_handle *handle, bool 
> sub_vendor)
> +{
> +   u8 cmd;
> +   int ret, size;
> +   char *vendor_id;
> +   struct scmi_xfer *t;
> +   struct scmi_revision_info *rev = handle->version;
> +
> +   if (sub_vendor) {
> +   cmd = BASE_DISCOVER_SUB_VENDOR;
> +   vendor_id = rev->sub_vendor_id;
> +   size = ARRAY_SIZE(rev->sub_vendor_id);
> +   } else {
> +   cmd = BASE_DISCOVER_VENDOR;
> +   vendor_id = rev->vendor_id;
> +   size = ARRAY_SIZE(rev->vendor_id);
> +   }
> +
> +   ret = scmi_one_xfer_init(handle, cmd, SCMI_PROTOCOL_BASE, 0, size, 
> &t);
> +   if (ret)
> +   return ret;
> +
> +   ret = scmi_do_xfer(handle, t);
> +   if (!ret)
> +   me

[RFC PATCH 3/8] firmware: arm_scmi: add common infrastructure and support for base protocol

2017-06-07 Thread Sudeep Holla
The base protocol describes the properties of the implementation and
provide generic error management. The base protocol provides commands
to describe protocol version, discover implementation specific
attributes and vendor/sub-vendor identification, list of protocols
implemented and the various agents are in the system including OSPM
and the platform. It also supports registering for notifications of
platform errors.

This protocol is mandatory. This patch adds support for the same along
with some basic infrastructure to add support for other protocols.

Signed-off-by: Sudeep Holla 
---
 drivers/firmware/arm_scmi/Makefile |   2 +-
 drivers/firmware/arm_scmi/base.c   | 290 +
 drivers/firmware/arm_scmi/common.h |  46 ++
 drivers/firmware/arm_scmi/driver.c |  67 +
 include/linux/scmi_protocol.h  |  28 
 5 files changed, 432 insertions(+), 1 deletion(-)
 create mode 100644 drivers/firmware/arm_scmi/base.c

diff --git a/drivers/firmware/arm_scmi/Makefile 
b/drivers/firmware/arm_scmi/Makefile
index 58e94c95e523..21d01d1d6b9c 100644
--- a/drivers/firmware/arm_scmi/Makefile
+++ b/drivers/firmware/arm_scmi/Makefile
@@ -1,2 +1,2 @@
 obj-$(CONFIG_ARM_SCMI_PROTOCOL)= arm_scmi.o
-arm_scmi-y = driver.o
+arm_scmi-y = base.o driver.o
diff --git a/drivers/firmware/arm_scmi/base.c b/drivers/firmware/arm_scmi/base.c
new file mode 100644
index ..1191a409ea73
--- /dev/null
+++ b/drivers/firmware/arm_scmi/base.c
@@ -0,0 +1,290 @@
+/*
+ * System Control and Management Interface (SCMI) Base Protocol
+ *
+ * Copyright (C) 2017 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see .
+ */
+
+#include "common.h"
+
+enum scmi_base_protocol_cmd {
+   BASE_DISCOVER_VENDOR = 0x3,
+   BASE_DISCOVER_SUB_VENDOR = 0x4,
+   BASE_DISCOVER_IMPLEMENT_VERSION = 0x5,
+   BASE_DISCOVER_LIST_PROTOCOLS = 0x6,
+   BASE_DISCOVER_AGENT = 0x7,
+   BASE_NOTIFY_ERRORS = 0x8,
+};
+
+struct scmi_msg_resp_base_attributes {
+   u8 num_protocols;
+   u8 num_agents;
+   __le16 reserved;
+} __packed;
+
+/**
+ * scmi_base_attributes_get() - gets the implementation details
+ * that are associated with the base protocol.
+ *
+ * @handle - SCMI entity handle
+ *
+ * Return: 0 on success, else appropriate SCMI error.
+ */
+static int scmi_base_attributes_get(struct scmi_handle *handle)
+{
+   int ret;
+   struct scmi_xfer *t;
+   struct scmi_msg_resp_base_attributes *attr_info;
+   struct scmi_revision_info *rev = handle->version;
+
+   ret = scmi_one_xfer_init(handle, PROTOCOL_ATTRIBUTES,
+SCMI_PROTOCOL_BASE, 0, sizeof(*attr_info), &t);
+   if (ret)
+   return ret;
+
+   ret = scmi_do_xfer(handle, t);
+   if (!ret) {
+   attr_info = (struct scmi_msg_resp_base_attributes *)t->rx.buf;
+   rev->num_protocols = attr_info->num_protocols;
+   rev->num_agents = attr_info->num_agents;
+   }
+
+   scmi_put_one_xfer(handle, t);
+   return ret;
+}
+
+/**
+ * scmi_base_vendor_id_get() - gets vendor/subvendor identifier ASCII string.
+ *
+ * @handle - SCMI entity handle
+ * @sub_vendor - specify true if sub-vendor ID is needed
+ *
+ * Return: 0 on success, else appropriate SCMI error.
+ */
+static int scmi_base_vendor_id_get(struct scmi_handle *handle, bool sub_vendor)
+{
+   u8 cmd;
+   int ret, size;
+   char *vendor_id;
+   struct scmi_xfer *t;
+   struct scmi_revision_info *rev = handle->version;
+
+   if (sub_vendor) {
+   cmd = BASE_DISCOVER_SUB_VENDOR;
+   vendor_id = rev->sub_vendor_id;
+   size = ARRAY_SIZE(rev->sub_vendor_id);
+   } else {
+   cmd = BASE_DISCOVER_VENDOR;
+   vendor_id = rev->vendor_id;
+   size = ARRAY_SIZE(rev->vendor_id);
+   }
+
+   ret = scmi_one_xfer_init(handle, cmd, SCMI_PROTOCOL_BASE, 0, size, &t);
+   if (ret)
+   return ret;
+
+   ret = scmi_do_xfer(handle, t);
+   if (!ret)
+   memcpy(vendor_id, t->rx.buf, size);
+
+   scmi_put_one_xfer(handle, t);
+   return ret;
+}
+
+/**
+ * scmi_base_implementation_version_get() - gets a vendor-specific
+ * implementation 32-bit version. The format of the version number is
+ * vendor-specific
+ *
+ * @handle - SCMI entity handle
+ *
+ * Return: 0 on succes