[Pdbg] [PATCH 04/17] libsbefifo: Refactor protocol marshalling for scom chipops
Amitay Isaacs
amitay at ozlabs.org
Thu Oct 31 17:34:15 AEDT 2019
Signed-off-by: Amitay Isaacs <amitay at ozlabs.org>
---
libsbefifo/cmd_scom.c | 203 ++++++++++++++++++++++++++++++----------
libsbefifo/libsbefifo.h | 12 +++
2 files changed, 165 insertions(+), 50 deletions(-)
diff --git a/libsbefifo/cmd_scom.c b/libsbefifo/cmd_scom.c
index c0687ef..558c27c 100644
--- a/libsbefifo/cmd_scom.c
+++ b/libsbefifo/cmd_scom.c
@@ -22,79 +22,134 @@
#include "libsbefifo.h"
#include "sbefifo_private.h"
-int sbefifo_scom_get(struct sbefifo_context *sctx, uint64_t addr, uint64_t *value)
+int sbefifo_scom_get_push(uint64_t addr, uint8_t **buf, uint32_t *buflen)
{
- uint8_t *out;
- uint32_t msg[4];
- uint32_t cmd, out_len;
- uint32_t val1, val2;
- int rc;
+ uint8_t *msg;
+ uint32_t nwords, cmd;
+
+ nwords = 4;
+ *buflen = nwords * sizeof(uint32_t);
+ msg = malloc(*buflen);
+ if (!msg)
+ return ENOMEM;
cmd = SBEFIFO_CMD_CLASS_SCOM | SBEFIFO_CMD_GET_SCOM;
- msg[0] = htobe32(4); // number of words
+ msg[0] = htobe32(nwords);
msg[1] = htobe32(cmd);
msg[2] = htobe32(addr >> 32);
msg[3] = htobe32(addr & 0xffffffff);
- out_len = 2 * 4;
- rc = sbefifo_operation(sctx, (uint8_t *)msg, 4 * 4, &out, &out_len);
- if (rc)
- return rc;
+ *buf = (uint8_t *)msg;
+ return 0;
+}
- if (out_len != 2 * 4) {
- free(out);
+int sbefifo_scom_get_pull(uint8_t *buf, uint32_t buflen, uint64_t *value)
+{
+ uint32_t val1, val2;
+
+ if (buflen != 2 * sizeof(uint32_t))
return EPROTO;
- }
- val1 = be32toh(*(uint32_t *) &out[0]);
- val2 = be32toh(*(uint32_t *) &out[4]);
- free(out);
+ val1 = be32toh(*(uint32_t *) &buf[0]);
+ val2 = be32toh(*(uint32_t *) &buf[4]);
*value = ((uint64_t)val1 << 32) | (uint64_t)val2;
-
return 0;
}
-int sbefifo_scom_put(struct sbefifo_context *sctx, uint64_t addr, uint64_t value)
+int sbefifo_scom_get(struct sbefifo_context *sctx, uint64_t addr, uint64_t *value)
{
- uint8_t *out;
- uint32_t msg[6];
- uint32_t cmd, out_len;
+ uint8_t *msg, *out;
+ uint32_t msg_len, out_len;
int rc;
+ rc = sbefifo_scom_get_push(addr, &msg, &msg_len);
+ if (rc)
+ return rc;
+
+ out_len = 2 * sizeof(uint32_t);
+ rc = sbefifo_operation(sctx, msg, msg_len, &out, &out_len);
+ free(msg);
+ if (rc)
+ return rc;
+
+ rc = sbefifo_scom_get_pull(out, out_len, value);
+ if (out)
+ free(out);
+
+ return rc;
+}
+
+int sbefifo_scom_put_push(uint64_t addr, uint64_t value, uint8_t **buf, uint32_t *buflen)
+{
+ uint8_t *msg;
+ uint32_t nwords, cmd;
+
+ nwords = 6;
+ *buflen = nwords * sizeof(uint32_t);
+ msg = malloc(*buflen);
+ if (!msg)
+ return ENOMEM;
+
cmd = SBEFIFO_CMD_CLASS_SCOM | SBEFIFO_CMD_PUT_SCOM;
- msg[0] = htobe32(6); // number of words
+ msg[0] = htobe32(nwords);
msg[1] = htobe32(cmd);
msg[2] = htobe32(addr >> 32);
msg[3] = htobe32(addr & 0xffffffff);
msg[2] = htobe32(value >> 32);
msg[3] = htobe32(value & 0xffffffff);
+ *buf = (uint8_t *)msg;
+ return 0;
+}
+
+int sbefifo_scom_put_pull(uint8_t *buf, uint32_t buflen)
+{
+ if (buflen != 0)
+ return EPROTO;
+
+ return 0;
+}
+
+int sbefifo_scom_put(struct sbefifo_context *sctx, uint64_t addr, uint64_t value)
+{
+ uint8_t *msg, *out;
+ uint32_t msg_len, out_len;
+ int rc;
+
+ rc = sbefifo_scom_put_push(addr, value, &msg, &msg_len);
+ if (rc)
+ return rc;
+
out_len = 0;
- rc = sbefifo_operation(sctx, (uint8_t *)msg, 6 * 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_scom_put_pull(out, out_len);
+ if (out)
free(out);
- return EPROTO;
- }
- return 0;
+ return rc;
}
-int sbefifo_scom_modify(struct sbefifo_context *sctx, uint64_t addr, uint64_t value, uint8_t operand)
+int sbefifo_scom_modify_push(uint64_t addr, uint64_t value, uint8_t operand, uint8_t **buf, uint32_t *buflen)
{
- uint8_t *out;
- uint32_t msg[7];
- uint32_t cmd, out_len;
- int rc;
+ uint32_t *msg;
+ uint32_t nwords, cmd;
+
+ nwords = 7;
+ *buflen = nwords * sizeof(uint32_t);
+ msg = malloc(*buflen);
+ if (!msg)
+ return ENOMEM;
cmd = SBEFIFO_CMD_CLASS_SCOM | SBEFIFO_CMD_MODIFY_SCOM;
- msg[0] = htobe32(7); // number of words
+ msg[0] = htobe32(nwords);
msg[1] = htobe32(cmd);
msg[2] = htobe32(operand);
msg[3] = htobe32(addr >> 32);
@@ -102,29 +157,55 @@ int sbefifo_scom_modify(struct sbefifo_context *sctx, uint64_t addr, uint64_t va
msg[5] = htobe32(value >> 32);
msg[6] = htobe32(value & 0xffffffff);
+ *buf = (uint8_t *)msg;
+ return 0;
+}
+
+int sbefifo_scom_modify_pull(uint8_t *buf, uint32_t buflen)
+{
+ if (buflen != 0)
+ return EPROTO;
+
+ return 0;
+}
+
+int sbefifo_scom_modify(struct sbefifo_context *sctx, uint64_t addr, uint64_t value, uint8_t operand)
+{
+ uint8_t *msg, *out;
+ uint32_t msg_len, out_len;
+ int rc;
+
+ rc = sbefifo_scom_modify_push(addr, value, operand, &msg, &msg_len);
+ if (rc)
+ return rc;
+
out_len = 0;
- rc = sbefifo_operation(sctx, (uint8_t *)msg, 7 * 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_scom_modify_pull(out, out_len);
+ if (out)
free(out);
- return EPROTO;
- }
- return 0;
+ return rc;
}
-int sbefifo_scom_put_mask(struct sbefifo_context *sctx, uint64_t addr, uint64_t value, uint64_t mask)
+int sbefifo_scom_put_mask_push(uint64_t addr, uint64_t value, uint64_t mask, uint8_t **buf, uint32_t *buflen)
{
- uint8_t *out;
- uint32_t msg[8];
- uint32_t cmd, out_len;
- int rc;
+ uint32_t *msg;
+ uint32_t nwords, cmd;
+
+ nwords = 8;
+ *buflen = nwords * sizeof(uint32_t);
+ msg = malloc(*buflen);
+ if (!msg)
+ return ENOMEM;
cmd = SBEFIFO_CMD_CLASS_SCOM | SBEFIFO_CMD_PUT_SCOM_MASK;
- msg[0] = htobe32(8); // number of words
+ msg[0] = htobe32(nwords);
msg[1] = htobe32(cmd);
msg[2] = htobe32(addr >> 32);
msg[3] = htobe32(addr & 0xffffffff);
@@ -133,15 +214,37 @@ int sbefifo_scom_put_mask(struct sbefifo_context *sctx, uint64_t addr, uint64_t
msg[6] = htobe32(mask >> 32);
msg[7] = htobe32(mask & 0xffffffff);
+ *buf = (uint8_t *)msg;
+ return 0;
+}
+
+int sbefifo_scom_put_mask_pull(uint8_t *buf, uint32_t buflen)
+{
+ if (buflen != 0)
+ return EPROTO;
+
+ return 0;
+}
+
+int sbefifo_scom_put_mask(struct sbefifo_context *sctx, uint64_t addr, uint64_t value, uint64_t mask)
+{
+ uint8_t *msg, *out;
+ uint32_t msg_len, out_len;
+ int rc;
+
+ rc = sbefifo_scom_put_mask_push(addr, value, mask, &msg, &msg_len);
+ if (rc)
+ return rc;
+
out_len = 0;
- rc = sbefifo_operation(sctx, (uint8_t *)msg, 8 * 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_scom_put_mask_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 7a2d104..b13caa6 100644
--- a/libsbefifo/libsbefifo.h
+++ b/libsbefifo/libsbefifo.h
@@ -64,6 +64,18 @@ int sbefifo_istep_execute(struct sbefifo_context *sctx, uint8_t major, uint8_t m
#define SBEFIFO_SCOM_OPERAND_AND 2
#define SBEFIFO_SCOM_OPERAND_XOR 3
+int sbefifo_scom_get_push(uint64_t addr, uint8_t **buf, uint32_t *buflen);
+int sbefifo_scom_get_pull(uint8_t *buf, uint32_t buflen, uint64_t *value);
+
+int sbefifo_scom_put_push(uint64_t addr, uint64_t value, uint8_t **buf, uint32_t *buflen);
+int sbefifo_scom_put_pull(uint8_t *buf, uint32_t buflen);
+
+int sbefifo_scom_modify_push(uint64_t addr, uint64_t value, uint8_t operand, uint8_t **buf, uint32_t *buflen);
+int sbefifo_scom_modify_pull(uint8_t *buf, uint32_t buflen);
+
+int sbefifo_scom_put_mask_push(uint64_t addr, uint64_t value, uint64_t mask, uint8_t **buf, uint32_t *buflen);
+int sbefifo_scom_put_mask_pull(uint8_t *buf, uint32_t buflen);
+
int sbefifo_scom_get(struct sbefifo_context *sctx, uint64_t addr, uint64_t *value);
int sbefifo_scom_put(struct sbefifo_context *sctx, uint64_t addr, uint64_t value);
int sbefifo_scom_modify(struct sbefifo_context *sctx, uint64_t addr, uint64_t value, uint8_t operand);
--
2.21.0
More information about the Pdbg
mailing list