diff mbox series

[14/18] libsbefifo: Add new chip-ops for hw register get/put

Message ID 20200924044236.130586-15-amitay@ozlabs.org
State Superseded
Headers show
Series Add p10 support to libpdbg | expand

Commit Message

Amitay Isaacs Sept. 24, 2020, 4:42 a.m. UTC
Signed-off-by: Amitay Isaacs <amitay@ozlabs.org>
---
 libsbefifo/cmd_register.c    | 131 +++++++++++++++++++++++++++++++++++
 libsbefifo/libsbefifo.h      |   3 +
 libsbefifo/sbefifo_private.h |   2 +
 3 files changed, 136 insertions(+)

Comments

Joel Stanley Sept. 28, 2020, 6:03 a.m. UTC | #1
On Thu, 24 Sep 2020 at 04:43, Amitay Isaacs <amitay@ozlabs.org> wrote:
>
> Signed-off-by: Amitay Isaacs <amitay@ozlabs.org>

Reviewed-by: Joel Stanley <joel@jms.id.au>

> ---
>  libsbefifo/cmd_register.c    | 131 +++++++++++++++++++++++++++++++++++
>  libsbefifo/libsbefifo.h      |   3 +
>  libsbefifo/sbefifo_private.h |   2 +
>  3 files changed, 136 insertions(+)
>
> diff --git a/libsbefifo/cmd_register.c b/libsbefifo/cmd_register.c
> index 060d3dc..6c3f336 100644
> --- a/libsbefifo/cmd_register.c
> +++ b/libsbefifo/cmd_register.c
> @@ -165,3 +165,134 @@ int sbefifo_register_put(struct sbefifo_context *sctx, uint8_t core_id, uint8_t
>
>         return rc;
>  }
> +
> +static int sbefifo_hw_register_get_push(uint8_t target_type, uint8_t instance_id, uint64_t reg_id, uint8_t **buf, uint32_t *buflen)
> +{
> +       uint32_t *msg;
> +       uint32_t nwords, cmd;
> +       uint32_t target;
> +
> +       nwords = 5;
> +       *buflen = nwords * sizeof(uint32_t);
> +       msg = malloc(*buflen);
> +       if (!msg)
> +               return ENOMEM;
> +
> +       cmd = SBEFIFO_CMD_CLASS_REGISTER | SBEFIFO_CMD_GET_HW_REGISTER;
> +
> +       target = ((uint32_t)(target_type & 0xff) << 16) |
> +                ((uint32_t)(instance_id & 0xff));
> +
> +       msg[0] = htobe32(nwords);
> +       msg[1] = htobe32(cmd);
> +       msg[2] = htobe32(target);
> +       msg[3] = htobe32(reg_id >> 32);
> +       msg[4] = htobe32(reg_id & 0xffffffff);
> +
> +       *buf = (uint8_t *)msg;
> +       return 0;
> +}
> +
> +static int sbefifo_hw_register_get_pull(uint8_t *buf, uint32_t buflen, uint64_t *value)
> +{
> +       uint32_t val1, val2;
> +
> +       if (buflen != 8)
> +               return EPROTO;
> +
> +       val1 = be32toh(*(uint32_t *) &buf[0]);
> +       val2 = be32toh(*(uint32_t *) &buf[4]);
> +
> +       *value = ((uint64_t)val1 << 32) | (uint64_t)val2;
> +
> +       return 0;
> +}
> +
> +int sbefifo_hw_register_get(struct sbefifo_context *sctx, uint8_t target_type, uint8_t instance_id, uint64_t reg_id, uint64_t *value)
> +{
> +       uint8_t *msg, *out;
> +       uint32_t msg_len, out_len;
> +       int rc;
> +
> +       if (sctx->proc == SBEFIFO_PROC_P9)
> +               return ENOSYS;
> +
> +       rc = sbefifo_hw_register_get_push(target_type, instance_id, reg_id, &msg, &msg_len);
> +       if (rc)
> +               return rc;
> +
> +       out_len = 8;
> +       rc = sbefifo_operation(sctx, msg, msg_len, &out, &out_len);
> +       free(msg);
> +       if (rc)
> +               return rc;
> +
> +       rc = sbefifo_hw_register_get_pull(out, out_len, value);
> +       if (out)
> +               free(out);
> +
> +       return rc;
> +}
> +
> +static int sbefifo_hw_register_put_push(uint8_t target_type, uint8_t instance_id, uint64_t reg_id, uint64_t value, uint8_t **buf, uint32_t *buflen)
> +{
> +       uint32_t *msg;
> +       uint32_t nwords, cmd;
> +       uint32_t target;
> +
> +       nwords = 7;
> +       *buflen = nwords * sizeof(uint32_t);
> +       msg = malloc(*buflen);
> +       if (!msg)
> +               return ENOMEM;
> +
> +       cmd = SBEFIFO_CMD_CLASS_REGISTER | SBEFIFO_CMD_PUT_HW_REGISTER;
> +
> +       target = ((uint32_t)(target_type & 0xff) << 16) |
> +                ((uint32_t)(instance_id & 0xff));
> +
> +       msg[0] = htobe32(nwords);
> +       msg[1] = htobe32(cmd);
> +       msg[2] = htobe32(target);
> +       msg[3] = htobe32(reg_id >> 32);
> +       msg[4] = htobe32(reg_id & 0xffffffff);
> +       msg[5] = htobe32(value >> 32);
> +       msg[6] = htobe32(value & 0xffffffff);
> +
> +       *buf = (uint8_t *)msg;
> +       return 0;
> +}
> +
> +static int sbefifo_hw_register_put_pull(uint8_t *buf, uint32_t buflen)
> +{
> +       if (buflen != 0)
> +               return EPROTO;
> +
> +       return 0;
> +}
> +
> +int sbefifo_hw_register_put(struct sbefifo_context *sctx, uint8_t target_type, uint8_t instance_id, uint64_t reg_id, uint64_t value)
> +{
> +       uint8_t *msg, *out;
> +       uint32_t msg_len, out_len;
> +       int rc;
> +
> +       if (sctx->proc == SBEFIFO_PROC_P9)
> +               return ENOSYS;
> +
> +       rc = sbefifo_hw_register_put_push(target_type, instance_id, reg_id, value, &msg, &msg_len);
> +       if (rc)
> +               return rc;
> +
> +       out_len = 0;
> +       rc = sbefifo_operation(sctx, msg, msg_len, &out, &out_len);
> +       free(msg);
> +       if (rc)
> +               return rc;
> +
> +       rc = sbefifo_hw_register_put_pull(out, out_len);
> +       if (out)
> +               free(out);
> +
> +       return rc;
> +}
> diff --git a/libsbefifo/libsbefifo.h b/libsbefifo/libsbefifo.h
> index 74ea2b3..6ff39e6 100644
> --- a/libsbefifo/libsbefifo.h
> +++ b/libsbefifo/libsbefifo.h
> @@ -157,6 +157,9 @@ int sbefifo_sram_put(struct sbefifo_context *sctx, uint16_t chiplet_id, uint64_t
>  int sbefifo_register_get(struct sbefifo_context *sctx, uint8_t core_id, uint8_t thread_id, uint8_t reg_type, uint32_t *reg_id, uint8_t reg_count, uint64_t **value);
>  int sbefifo_register_put(struct sbefifo_context *sctx, uint8_t core_id, uint8_t thread_id, uint8_t reg_type, uint32_t *reg_id, uint8_t reg_count, uint64_t *value);
>
> +int sbefifo_hw_register_get(struct sbefifo_context *sctx, uint8_t target_type, uint8_t instance_id, uint64_t reg_id, uint64_t *value);
> +int sbefifo_hw_register_put(struct sbefifo_context *sctx, uint8_t target_type, uint8_t instance_id, uint64_t reg_id, uint64_t value);
> +
>  int sbefifo_control_fast_array(struct sbefifo_context *sctx, uint16_t target_type, uint8_t chiplet_id, uint8_t mode, uint64_t clock_cycle);
>  int sbefifo_control_trace_array(struct sbefifo_context *sctx, uint16_t target_type, uint8_t chiplet_id, uint16_t array_id, uint16_t operation, uint8_t **trace_data, uint32_t *trace_data_len);
>
> diff --git a/libsbefifo/sbefifo_private.h b/libsbefifo/sbefifo_private.h
> index d3f6a8b..e49f673 100644
> --- a/libsbefifo/sbefifo_private.h
> +++ b/libsbefifo/sbefifo_private.h
> @@ -45,6 +45,8 @@
>  #define SBEFIFO_CMD_CLASS_REGISTER       0xA500
>  #define   SBEFIFO_CMD_GET_REGISTER         0x01
>  #define   SBEFIFO_CMD_PUT_REGISTER         0x02
> +#define   SBEFIFO_CMD_GET_HW_REGISTER      0x03
> +#define   SBEFIFO_CMD_PUT_HW_REGISTER      0x04
>
>  #define SBEFIFO_CMD_CLASS_ARRAY          0xA600
>  #define   SBEFIFO_CMD_FAST_ARRAY           0x01
> --
> 2.26.2
>
> --
> Pdbg mailing list
> Pdbg@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/pdbg
diff mbox series

Patch

diff --git a/libsbefifo/cmd_register.c b/libsbefifo/cmd_register.c
index 060d3dc..6c3f336 100644
--- a/libsbefifo/cmd_register.c
+++ b/libsbefifo/cmd_register.c
@@ -165,3 +165,134 @@  int sbefifo_register_put(struct sbefifo_context *sctx, uint8_t core_id, uint8_t
 
 	return rc;
 }
+
+static int sbefifo_hw_register_get_push(uint8_t target_type, uint8_t instance_id, uint64_t reg_id, uint8_t **buf, uint32_t *buflen)
+{
+	uint32_t *msg;
+	uint32_t nwords, cmd;
+	uint32_t target;
+
+	nwords = 5;
+	*buflen = nwords * sizeof(uint32_t);
+	msg = malloc(*buflen);
+	if (!msg)
+		return ENOMEM;
+
+	cmd = SBEFIFO_CMD_CLASS_REGISTER | SBEFIFO_CMD_GET_HW_REGISTER;
+
+	target = ((uint32_t)(target_type & 0xff) << 16) |
+		 ((uint32_t)(instance_id & 0xff));
+
+	msg[0] = htobe32(nwords);
+	msg[1] = htobe32(cmd);
+	msg[2] = htobe32(target);
+	msg[3] = htobe32(reg_id >> 32);
+	msg[4] = htobe32(reg_id & 0xffffffff);
+
+	*buf = (uint8_t *)msg;
+	return 0;
+}
+
+static int sbefifo_hw_register_get_pull(uint8_t *buf, uint32_t buflen, uint64_t *value)
+{
+	uint32_t val1, val2;
+
+	if (buflen != 8)
+		return EPROTO;
+
+	val1 = be32toh(*(uint32_t *) &buf[0]);
+	val2 = be32toh(*(uint32_t *) &buf[4]);
+
+	*value = ((uint64_t)val1 << 32) | (uint64_t)val2;
+
+	return 0;
+}
+
+int sbefifo_hw_register_get(struct sbefifo_context *sctx, uint8_t target_type, uint8_t instance_id, uint64_t reg_id, uint64_t *value)
+{
+	uint8_t *msg, *out;
+	uint32_t msg_len, out_len;
+	int rc;
+
+	if (sctx->proc == SBEFIFO_PROC_P9)
+		return ENOSYS;
+
+	rc = sbefifo_hw_register_get_push(target_type, instance_id, reg_id, &msg, &msg_len);
+	if (rc)
+		return rc;
+
+	out_len = 8;
+	rc = sbefifo_operation(sctx, msg, msg_len, &out, &out_len);
+	free(msg);
+	if (rc)
+		return rc;
+
+	rc = sbefifo_hw_register_get_pull(out, out_len, value);
+	if (out)
+		free(out);
+
+	return rc;
+}
+
+static int sbefifo_hw_register_put_push(uint8_t target_type, uint8_t instance_id, uint64_t reg_id, uint64_t value, uint8_t **buf, uint32_t *buflen)
+{
+	uint32_t *msg;
+	uint32_t nwords, cmd;
+	uint32_t target;
+
+	nwords = 7;
+	*buflen = nwords * sizeof(uint32_t);
+	msg = malloc(*buflen);
+	if (!msg)
+		return ENOMEM;
+
+	cmd = SBEFIFO_CMD_CLASS_REGISTER | SBEFIFO_CMD_PUT_HW_REGISTER;
+
+	target = ((uint32_t)(target_type & 0xff) << 16) |
+		 ((uint32_t)(instance_id & 0xff));
+
+	msg[0] = htobe32(nwords);
+	msg[1] = htobe32(cmd);
+	msg[2] = htobe32(target);
+	msg[3] = htobe32(reg_id >> 32);
+	msg[4] = htobe32(reg_id & 0xffffffff);
+	msg[5] = htobe32(value >> 32);
+	msg[6] = htobe32(value & 0xffffffff);
+
+	*buf = (uint8_t *)msg;
+	return 0;
+}
+
+static int sbefifo_hw_register_put_pull(uint8_t *buf, uint32_t buflen)
+{
+	if (buflen != 0)
+		return EPROTO;
+
+	return 0;
+}
+
+int sbefifo_hw_register_put(struct sbefifo_context *sctx, uint8_t target_type, uint8_t instance_id, uint64_t reg_id, uint64_t value)
+{
+	uint8_t *msg, *out;
+	uint32_t msg_len, out_len;
+	int rc;
+
+	if (sctx->proc == SBEFIFO_PROC_P9)
+		return ENOSYS;
+
+	rc = sbefifo_hw_register_put_push(target_type, instance_id, reg_id, value, &msg, &msg_len);
+	if (rc)
+		return rc;
+
+	out_len = 0;
+	rc = sbefifo_operation(sctx, msg, msg_len, &out, &out_len);
+	free(msg);
+	if (rc)
+		return rc;
+
+	rc = sbefifo_hw_register_put_pull(out, out_len);
+	if (out)
+		free(out);
+
+	return rc;
+}
diff --git a/libsbefifo/libsbefifo.h b/libsbefifo/libsbefifo.h
index 74ea2b3..6ff39e6 100644
--- a/libsbefifo/libsbefifo.h
+++ b/libsbefifo/libsbefifo.h
@@ -157,6 +157,9 @@  int sbefifo_sram_put(struct sbefifo_context *sctx, uint16_t chiplet_id, uint64_t
 int sbefifo_register_get(struct sbefifo_context *sctx, uint8_t core_id, uint8_t thread_id, uint8_t reg_type, uint32_t *reg_id, uint8_t reg_count, uint64_t **value);
 int sbefifo_register_put(struct sbefifo_context *sctx, uint8_t core_id, uint8_t thread_id, uint8_t reg_type, uint32_t *reg_id, uint8_t reg_count, uint64_t *value);
 
+int sbefifo_hw_register_get(struct sbefifo_context *sctx, uint8_t target_type, uint8_t instance_id, uint64_t reg_id, uint64_t *value);
+int sbefifo_hw_register_put(struct sbefifo_context *sctx, uint8_t target_type, uint8_t instance_id, uint64_t reg_id, uint64_t value);
+
 int sbefifo_control_fast_array(struct sbefifo_context *sctx, uint16_t target_type, uint8_t chiplet_id, uint8_t mode, uint64_t clock_cycle);
 int sbefifo_control_trace_array(struct sbefifo_context *sctx, uint16_t target_type, uint8_t chiplet_id, uint16_t array_id, uint16_t operation, uint8_t **trace_data, uint32_t *trace_data_len);
 
diff --git a/libsbefifo/sbefifo_private.h b/libsbefifo/sbefifo_private.h
index d3f6a8b..e49f673 100644
--- a/libsbefifo/sbefifo_private.h
+++ b/libsbefifo/sbefifo_private.h
@@ -45,6 +45,8 @@ 
 #define SBEFIFO_CMD_CLASS_REGISTER       0xA500
 #define   SBEFIFO_CMD_GET_REGISTER         0x01
 #define   SBEFIFO_CMD_PUT_REGISTER         0x02
+#define   SBEFIFO_CMD_GET_HW_REGISTER      0x03
+#define   SBEFIFO_CMD_PUT_HW_REGISTER      0x04
 
 #define SBEFIFO_CMD_CLASS_ARRAY          0xA600
 #define   SBEFIFO_CMD_FAST_ARRAY           0x01