diff mbox series

[1/3] libsbeinfo: Add GET_TI_INFO chip-op

Message ID 20200506054948.153723-2-amitay@ozlabs.org
State Accepted
Headers show
Series Add new sbefifo chip-op (GET_TI_INFO) | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success Successfully applied on branch master (6c10b68bf774a9fe21affd5ef0b40084cd49800d)
snowpatch_ozlabs/build-multiarch success Test build-multiarch on branch master

Commit Message

Amitay Isaacs May 6, 2020, 5:49 a.m. UTC
Signed-off-by: Amitay Isaacs <amitay@ozlabs.org>
---
 libsbefifo/cmd_mpipl.c       | 57 ++++++++++++++++++++++++++++++++++++
 libsbefifo/libsbefifo.h      |  2 +-
 libsbefifo/sbefifo_private.h |  1 +
 3 files changed, 59 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/libsbefifo/cmd_mpipl.c b/libsbefifo/cmd_mpipl.c
index e397db4..1d32494 100644
--- a/libsbefifo/cmd_mpipl.c
+++ b/libsbefifo/cmd_mpipl.c
@@ -179,3 +179,60 @@  int sbefifo_mpipl_stopclocks(struct sbefifo_context *sctx, uint16_t target_type,
 
 	return rc;
 }
+
+static int sbefifo_mpipl_get_ti_info_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_GET_TI_INFO;
+
+	msg[0] = htobe32(nwords);
+	msg[1] = htobe32(cmd);
+
+	*buf = (uint8_t *)msg;
+	return 0;
+}
+
+static int sbefifo_mpipl_get_ti_info_pull(uint8_t *buf, uint32_t buflen, uint8_t **data, uint32_t *data_len)
+{
+	if (buflen < 4)
+		return EPROTO;
+
+	*data_len = be32toh(*(uint32_t *) &buf[buflen-4]);
+	*data = malloc(*data_len);
+	if (! *data)
+		return ENOMEM;
+
+	memcpy(*data, buf, *data_len);
+	return 0;
+}
+
+int sbefifo_mpipl_get_ti_info(struct sbefifo_context *sctx, uint8_t **data, uint32_t *data_len)
+{
+	uint8_t *msg, *out;
+	uint32_t msg_len, out_len;
+	int rc;
+
+	rc = sbefifo_mpipl_get_ti_info_push(&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_mpipl_get_ti_info_pull(out, out_len, data, data_len);
+	if (out)
+		free(out);
+
+	return rc;
+}
diff --git a/libsbefifo/libsbefifo.h b/libsbefifo/libsbefifo.h
index 5a0f745..2efb25c 100644
--- a/libsbefifo/libsbefifo.h
+++ b/libsbefifo/libsbefifo.h
@@ -124,6 +124,6 @@  int sbefifo_quiesce(struct sbefifo_context *sctx);
 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);
-
+int sbefifo_mpipl_get_ti_info(struct sbefifo_context *sctx, uint8_t **data, uint32_t *data_len);
 
 #endif /* __LIBSBEFIFO_H__ */
diff --git a/libsbefifo/sbefifo_private.h b/libsbefifo/sbefifo_private.h
index ef432c4..d94112f 100644
--- a/libsbefifo/sbefifo_private.h
+++ b/libsbefifo/sbefifo_private.h
@@ -61,6 +61,7 @@ 
 #define SBEFIFO_CMD_ENTER_MPIPL            0x01
 #define SBEFIFO_CMD_CONTINUE_MPIPL         0x02
 #define SBEFIFO_CMD_STOP_CLOCKS            0x03
+#define SBEFIFO_CMD_GET_TI_INFO            0x04
 
 struct sbefifo_context {
 	int fd;