[Pdbg] [PATCH 15/17] libpdbg: Add sbefifo_transport hardware unit
Amitay Isaacs
amitay at ozlabs.org
Thu Oct 31 17:34:26 AEDT 2019
Signed-off-by: Amitay Isaacs <amitay at ozlabs.org>
---
libpdbg/hwunit.h | 7 ++++++
libpdbg/sbefifo.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 62 insertions(+)
diff --git a/libpdbg/hwunit.h b/libpdbg/hwunit.h
index 06e5fca..bf5f39d 100644
--- a/libpdbg/hwunit.h
+++ b/libpdbg/hwunit.h
@@ -65,6 +65,13 @@ struct mem {
};
#define target_to_mem(x) container_of(x, struct mem, target)
+struct sbefifo_transport {
+ struct pdbg_target target;
+ int (*msg)(struct sbefifo_transport *, uint8_t *, uint32_t, uint8_t *, uint32_t *);
+ int fd;
+};
+#define target_to_sbefifo_transport(x) container_of(x, struct sbefifo_transport, target)
+
struct sbefifo {
struct pdbg_target target;
int (*istep)(struct sbefifo *, uint32_t major, uint32_t minor);
diff --git a/libpdbg/sbefifo.c b/libpdbg/sbefifo.c
index 9e3532b..2f19be3 100644
--- a/libpdbg/sbefifo.c
+++ b/libpdbg/sbefifo.c
@@ -219,6 +219,49 @@ static int sbefifo_probe(struct pdbg_target *target)
return 0;
}
+static int sbefifo_transport_msg(struct sbefifo_transport *sft,
+ uint8_t *buf, uint32_t buflen,
+ uint8_t *out, uint32_t *outlen)
+{
+ ssize_t n;
+
+ assert(buflen > 0);
+ assert(*outlen > 0);
+
+ n = write(sft->fd, buf, buflen);
+ if (n < 0)
+ return errno;
+
+ if (n != buflen)
+ return EIO;
+
+ n = read(sft->fd, out, *outlen);
+ if (n < 0)
+ return errno;
+
+ *outlen = n;
+ return 0;
+}
+
+static int sbefifo_transport_probe(struct pdbg_target *target)
+{
+ struct sbefifo_transport *sft = target_to_sbefifo_transport(target);
+ const char *sbefifo_path;
+ int rc;
+
+ sbefifo_path = pdbg_target_property(target, "device-path", NULL);
+ assert(sbefifo_path);
+
+ sft->fd = open(sbefifo_path, O_RDWR | O_SYNC);
+ if (sft->fd == -1) {
+ rc = errno;
+ PR_ERROR("Unable to open sbefifo driver %s\n", sbefifo_path);
+ return rc;
+ }
+
+ return 0;
+}
+
struct mem sbefifo_mem = {
.target = {
.name = "SBE FIFO Chip-op based memory access",
@@ -246,9 +289,21 @@ struct sbefifo kernel_sbefifo = {
};
DECLARE_HW_UNIT(kernel_sbefifo);
+struct sbefifo_transport kernel_sft = {
+ .target = {
+ .name = "Kernel based FSI SBE FIFO",
+ .compatible = "ibm,kernel-sbefifo-transport",
+ .class = "sbefifo_transport",
+ .probe = sbefifo_transport_probe,
+ },
+ .msg = sbefifo_transport_msg,
+};
+DECLARE_HW_UNIT(kernel_sft);
+
__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_mem_hw_unit);
}
--
2.21.0
More information about the Pdbg
mailing list