[Pdbg] [PATCH 16/17] libpdbg: Add sbefifo chipop method to use sbefifo transport

Amitay Isaacs amitay at ozlabs.org
Thu Oct 31 17:34:27 AEDT 2019


Signed-off-by: Amitay Isaacs <amitay at ozlabs.org>
---
 libpdbg/hwunit.h  |  1 +
 libpdbg/sbefifo.c | 66 +++++++++++++++++++++++++++++++++++------------
 2 files changed, 50 insertions(+), 17 deletions(-)

diff --git a/libpdbg/hwunit.h b/libpdbg/hwunit.h
index bf5f39d..4efea5e 100644
--- a/libpdbg/hwunit.h
+++ b/libpdbg/hwunit.h
@@ -74,6 +74,7 @@ struct sbefifo_transport {
 
 struct sbefifo {
 	struct pdbg_target target;
+	int (*chipop)(struct sbefifo *, uint8_t *, uint32_t, uint8_t **, uint32_t *);
 	int (*istep)(struct sbefifo *, uint32_t major, uint32_t minor);
 	int (*thread_start)(struct sbefifo *, uint32_t core_id, uint32_t thread_id);
 	int (*thread_stop)(struct sbefifo *, uint32_t core_id, uint32_t thread_id);
diff --git a/libpdbg/sbefifo.c b/libpdbg/sbefifo.c
index 2f19be3..b313b67 100644
--- a/libpdbg/sbefifo.c
+++ b/libpdbg/sbefifo.c
@@ -30,6 +30,43 @@ static uint32_t sbefifo_op_ffdc_get(struct sbefifo *sbefifo, const uint8_t **ffd
 	return sbefifo_ffdc_get(sbefifo->sf_ctx, ffdc, ffdc_len);
 }
 
+static int sbefifo_chipop(struct sbefifo *sbefifo,
+			  uint8_t *msg, uint32_t msg_len,
+			  uint8_t **out, uint32_t *out_len)
+{
+	struct sbefifo_transport *sft = target_to_sbefifo_transport(sbefifo->target.parent);
+	uint8_t *buf;
+	size_t buflen;
+	uint32_t len, cmd;
+	int rc;
+
+	assert(msg);
+	assert(msg_len > 0);
+
+	/*
+	 * Allocate extra memory for FFDC (SBEFIFO_MAX_FFDC_SIZE = 0x2000)
+	 * Use *out_len as a hint to expected reply length
+	 */
+	buflen = (*out_len + 0x2000 + 3) & ~(uint32_t)3;
+	buf = malloc(buflen);
+	if (!buf)
+		return ENOMEM;
+
+	/* Command is second word in the message */
+	cmd = be32toh(*(uint32_t *)(msg + 4));
+
+	len = buflen;
+	rc = sft->msg(sft, msg, msg_len, buf, &len);
+	if (rc) {
+		free(buf);
+		return rc;
+	}
+
+	rc = sbefifo_parse_output(sbefifo->sf_ctx, cmd, buf, len, out, out_len);
+	free(buf);
+	return rc;
+}
+
 static int sbefifo_op_istep(struct sbefifo *sbefifo, uint32_t major, uint32_t minor)
 {
 	uint8_t *msg, *out;
@@ -43,7 +80,7 @@ static int sbefifo_op_istep(struct sbefifo *sbefifo, uint32_t major, uint32_t mi
 		return rc;
 
 	out_len = 0;
-	rc = sbefifo_operation(sbefifo->sf_ctx, msg, msg_len, &out, &out_len);
+	rc = sbefifo->chipop(sbefifo, msg, msg_len, &out, &out_len);
 	free(msg);
 	if (rc)
 		return rc;
@@ -83,7 +120,7 @@ static int sbefifo_op_getmem(struct mem *sbefifo_mem,
 		return rc;
 
 	out_len = len + 4;
-	rc = sbefifo_operation(sbefifo->sf_ctx, msg, msg_len, &out, &out_len);
+	rc = sbefifo->chipop(sbefifo, msg, msg_len, &out, &out_len);
 	free(msg);
 	if (rc)
 		return rc;
@@ -129,7 +166,7 @@ static int sbefifo_op_putmem(struct mem *sbefifo_mem,
 		return rc;
 
 	out_len = 4;
-	rc = sbefifo_operation(sbefifo->sf_ctx, msg, msg_len, &out, &out_len);
+	rc = sbefifo->chipop(sbefifo, msg, msg_len, &out, &out_len);
 	free(msg);
 	if (rc)
 		return rc;
@@ -165,7 +202,7 @@ static int sbefifo_op_control(struct sbefifo *sbefifo,
 		return rc;
 
 	out_len = 0;
-	rc = sbefifo_operation(sbefifo->sf_ctx, msg, msg_len, &out, &out_len);
+	rc = sbefifo->chipop(sbefifo, msg, msg_len, &out, &out_len);
 	free(msg);
 	if (rc)
 		return rc;
@@ -204,17 +241,11 @@ static int sbefifo_op_thread_sreset(struct sbefifo *sbefifo,
 static int sbefifo_probe(struct pdbg_target *target)
 {
 	struct sbefifo *sf = target_to_sbefifo(target);
-	const char *sbefifo_path;
 	int rc;
 
-	sbefifo_path = pdbg_target_property(target, "device-path", NULL);
-	assert(sbefifo_path);
-
-	rc = sbefifo_connect(sbefifo_path, &sf->sf_ctx);
-	if (rc) {
-		PR_ERROR("Unable to open sbefifo driver %s\n", sbefifo_path);
+	rc = sbefifo_init(&sf->sf_ctx);
+	if (rc)
 		return rc;
-	}
 
 	return 0;
 }
@@ -273,13 +304,14 @@ struct mem sbefifo_mem = {
 };
 DECLARE_HW_UNIT(sbefifo_mem);
 
-struct sbefifo kernel_sbefifo = {
+struct sbefifo sbefifo = {
 	.target = {
-		.name =	"Kernel based FSI SBE FIFO",
-		.compatible = "ibm,kernel-sbefifo",
+		.name =	"SBE FIFO Chip-op engine",
+		.compatible = "ibm,sbefifo",
 		.class = "sbefifo",
 		.probe = sbefifo_probe,
 	},
+	.chipop = sbefifo_chipop,
 	.istep = sbefifo_op_istep,
 	.thread_start = sbefifo_op_thread_start,
 	.thread_stop = sbefifo_op_thread_stop,
@@ -287,7 +319,7 @@ struct sbefifo kernel_sbefifo = {
 	.thread_sreset = sbefifo_op_thread_sreset,
 	.ffdc_get = sbefifo_op_ffdc_get,
 };
-DECLARE_HW_UNIT(kernel_sbefifo);
+DECLARE_HW_UNIT(sbefifo);
 
 struct sbefifo_transport kernel_sft = {
 	.target = {
@@ -304,6 +336,6 @@ __attribute__((constructor))
 static void register_sbefifo(void)
 {
 	pdbg_hwunit_register(&kernel_sft_hw_unit);
-	pdbg_hwunit_register(&kernel_sbefifo_hw_unit);
+	pdbg_hwunit_register(&sbefifo_hw_unit);
 	pdbg_hwunit_register(&sbefifo_mem_hw_unit);
 }
-- 
2.21.0



More information about the Pdbg mailing list