[Pdbg] [PATCH 11/17] libsbefifo: Refactor protocol marshalling for mpipl chip-ops
Amitay Isaacs
amitay at ozlabs.org
Thu Oct 31 17:34:22 AEDT 2019
Signed-off-by: Amitay Isaacs <amitay at ozlabs.org>
---
libsbefifo/cmd_mpipl.c | 145 +++++++++++++++++++++++++++++++---------
libsbefifo/libsbefifo.h | 9 +++
2 files changed, 121 insertions(+), 33 deletions(-)
diff --git a/libsbefifo/cmd_mpipl.c b/libsbefifo/cmd_mpipl.c
index 9e3d59b..f4d4769 100644
--- a/libsbefifo/cmd_mpipl.c
+++ b/libsbefifo/cmd_mpipl.c
@@ -23,80 +23,159 @@
#include "libsbefifo.h"
#include "sbefifo_private.h"
-int sbefifo_mpipl_enter(struct sbefifo_context *sctx)
+int sbefifo_mpipl_enter_push(uint8_t **buf, uint32_t *buflen)
{
- uint8_t *out;
- uint32_t msg[2];
- uint32_t cmd, out_len;
- int rc;
+ uint32_t *msg;
+ uint32_t nwords, cmd;
+
+ nwords = 2;
+ *buflen = nwords * sizeof(uint32_t);
+ msg = malloc(*buflen);
+ if (!msg)
+ return ENOMEM;
cmd = SBEFIFO_CMD_CLASS_MPIPL | SBEFIFO_CMD_ENTER_MPIPL;
- msg[0] = htobe32(2); // number of words
+ msg[0] = htobe32(nwords);
msg[1] = htobe32(cmd);
+ *buf = (uint8_t *)msg;
+ return 0;
+}
+
+int sbefifo_mpipl_enter_pull(uint8_t *buf, uint32_t buflen)
+{
+ if (buflen != 0)
+ return EPROTO;
+
+ return 0;
+}
+
+int sbefifo_mpipl_enter(struct sbefifo_context *sctx)
+{
+ uint8_t *msg, *out;
+ uint32_t msg_len, out_len;
+ int rc;
+
+ rc = sbefifo_mpipl_enter_push(&msg, &msg_len);
+ if (rc)
+ return rc;
+
out_len = 0;
- rc = sbefifo_operation(sctx, (uint8_t *)msg, 2 * 4, &out, &out_len);
+ rc = sbefifo_operation(sctx, msg, msg_len, &out, &out_len);
+ free(msg);
if (rc)
return rc;
- if (out_len != 0) {
+ rc = sbefifo_mpipl_enter_pull(out, out_len);
+ if (out)
free(out);
+
+ return rc;
+}
+
+int sbefifo_mpipl_continue_push(uint8_t **buf, uint32_t *buflen)
+{
+ uint32_t *msg;
+ uint32_t nwords, cmd;
+
+ nwords = 2;
+ *buflen = nwords * sizeof(uint32_t);
+ msg = malloc(*buflen);
+ if (!msg)
+ return ENOMEM;
+
+ cmd = SBEFIFO_CMD_CLASS_MPIPL | SBEFIFO_CMD_CONTINUE_MPIPL;
+
+ msg[0] = htobe32(nwords);
+ msg[1] = htobe32(cmd);
+
+ *buf = (uint8_t *)msg;
+ return 0;
+}
+
+int sbefifo_mpipl_continue_pull(uint8_t *buf, uint32_t buflen)
+{
+ if (buflen != 0)
return EPROTO;
- }
return 0;
}
int sbefifo_mpipl_continue(struct sbefifo_context *sctx)
{
- uint8_t *out;
- uint32_t msg[2];
- uint32_t cmd, out_len;
+ uint8_t *msg, *out;
+ uint32_t msg_len, out_len;
int rc;
- cmd = SBEFIFO_CMD_CLASS_MPIPL | SBEFIFO_CMD_CONTINUE_MPIPL;
-
- msg[0] = htobe32(2); // number of words
- msg[1] = htobe32(cmd);
+ rc = sbefifo_mpipl_continue_push(&msg, &msg_len);
+ if (rc)
+ return rc;
out_len = 0;
- rc = sbefifo_operation(sctx, (uint8_t *)msg, 2 * 4, &out, &out_len);
+ rc = sbefifo_operation(sctx, msg, msg_len, &out, &out_len);
+ free(msg);
if (rc)
return rc;
- if (out_len != 0) {
+ rc = sbefifo_mpipl_enter_pull(out, out_len);
+ if (out)
free(out);
- return EPROTO;
- }
- return 0;
+ return rc;
}
-int sbefifo_mpipl_stopclocks(struct sbefifo_context *sctx, uint16_t target_type, uint8_t chiplet_id)
+int sbefifo_mpipl_stopclocks_push(uint16_t target_type, uint8_t chiplet_id, uint8_t **buf, uint32_t *buflen)
{
- uint8_t *out;
- uint32_t msg[3];
- uint32_t cmd, out_len;
+ uint32_t *msg;
+ uint32_t nwords, cmd;
uint32_t target;
- int rc;
- cmd = SBEFIFO_CMD_CLASS_GENERIC | SBEFIFO_CMD_STOP_CLOCKS;
+ nwords = 3;
+ *buflen = nwords * sizeof(uint32_t);
+ msg = malloc(*buflen);
+ if (!msg)
+ return ENOMEM;
+
+ cmd = SBEFIFO_CMD_CLASS_MPIPL | SBEFIFO_CMD_STOP_CLOCKS;
+
target = ((uint32_t)target_type << 16) | chiplet_id;
- msg[0] = htobe32(3); // number of words
+ msg[0] = htobe32(nwords);
msg[1] = htobe32(cmd);
msg[2] = htobe32(target);
+ *buf = (uint8_t *)msg;
+ return 0;
+}
+
+int sbefifo_mpipl_stopclocks_pull(uint8_t *buf, uint32_t buflen)
+{
+ if (buflen != 0)
+ return EPROTO;
+
+ return 0;
+}
+
+int sbefifo_mpipl_stopclocks(struct sbefifo_context *sctx, uint16_t target_type, uint8_t chiplet_id)
+{
+ uint8_t *msg, *out;
+ uint32_t msg_len, out_len;
+ int rc;
+
+ rc = sbefifo_mpipl_stopclocks_push(target_type, chiplet_id, &msg, &msg_len);
+ if (rc)
+ return rc;
+
out_len = 0;
- rc = sbefifo_operation(sctx, (uint8_t *)msg, 3 * 4, &out, &out_len);
+ rc = sbefifo_operation(sctx, msg, msg_len, &out, &out_len);
+ free(msg);
if (rc)
return rc;
- if (out_len != 0) {
+ rc = sbefifo_mpipl_stopclocks_pull(out, out_len);
+ if (out)
free(out);
- return EPROTO;
- }
- return 0;
+ return rc;
}
diff --git a/libsbefifo/libsbefifo.h b/libsbefifo/libsbefifo.h
index 417509c..4d45bbf 100644
--- a/libsbefifo/libsbefifo.h
+++ b/libsbefifo/libsbefifo.h
@@ -167,6 +167,15 @@ int sbefifo_get_ffdc(struct sbefifo_context *sctx, uint8_t **ffdc, uint32_t *ffd
int sbefifo_get_capabilities(struct sbefifo_context *sctx, uint32_t *version, char **commit_id, char **release_tag, uint32_t **caps, uint32_t *caps_count);
int sbefifo_quiesce(struct sbefifo_context *sctx);
+int sbefifo_mpipl_enter_push(uint8_t **buf, uint32_t *buflen);
+int sbefifo_mpipl_enter_pull(uint8_t *buf, uint32_t buflen);
+
+int sbefifo_mpipl_continue_push(uint8_t **buf, uint32_t *buflen);
+int sbefifo_mpipl_continue_pull(uint8_t *buf, uint32_t buflen);
+
+int sbefifo_mpipl_stopclocks_push(uint16_t target_type, uint8_t chiplet_id, uint8_t **buf, uint32_t *buflen);
+int sbefifo_mpipl_stopclocks_pull(uint8_t *buf, uint32_t buflen);
+
int sbefifo_mpipl_enter(struct sbefifo_context *sctx);
int sbefifo_mpipl_continue(struct sbefifo_context *sctx);
int sbefifo_mpipl_stopclocks(struct sbefifo_context *sctx, uint16_t target_type, uint8_t chiplet_id);
--
2.21.0
More information about the Pdbg
mailing list