[Pdbg] [PATCH v2 2/6] libsbefifo: Add connect api with transport callback
Amitay Isaacs
amitay at ozlabs.org
Thu Oct 24 12:53:27 AEDT 2019
When sbefifo library is initialized with transport callback, instead of
reading/writing the chip-op data from the sbefifo device, it will use
the transport callback to write request and read reply from sbefifo.
Signed-off-by: Amitay Isaacs <amitay at ozlabs.org>
---
libsbefifo/connect.c | 25 +++++++++++++++++++++++++
libsbefifo/libsbefifo.h | 3 +++
2 files changed, 28 insertions(+)
diff --git a/libsbefifo/connect.c b/libsbefifo/connect.c
index 08194e1..927ddc1 100644
--- a/libsbefifo/connect.c
+++ b/libsbefifo/connect.c
@@ -53,6 +53,31 @@ int sbefifo_connect(const char *fifo_path, struct sbefifo_context **out)
return 0;
}
+int sbefifo_connect_transport(sbefifo_transport_fn transport_func,
+ void *priv,
+ struct sbefifo_context **out)
+{
+ struct sbefifo_context *sctx;
+
+ if (!transport_func)
+ return EINVAL;
+
+ sctx = malloc(sizeof(struct sbefifo_context));
+ if (!sctx) {
+ fprintf(stderr, "Memory allocation error\n");
+ return ENOMEM;
+ }
+
+ *sctx = (struct sbefifo_context) {
+ .fd = -1,
+ .transport_func = transport_func,
+ .priv = priv,
+ };
+
+ *out = sctx;
+ return 0;
+}
+
void sbefifo_disconnect(struct sbefifo_context *sctx)
{
if (sctx->fd != -1)
diff --git a/libsbefifo/libsbefifo.h b/libsbefifo/libsbefifo.h
index 2963450..8ddb057 100644
--- a/libsbefifo/libsbefifo.h
+++ b/libsbefifo/libsbefifo.h
@@ -56,6 +56,9 @@ typedef int (*sbefifo_transport_fn)(uint8_t *request_buf,
void *priv);
int sbefifo_connect(const char *fifo_path, struct sbefifo_context **out);
+int sbefifo_connect_transport(sbefifo_transport_fn transport_func,
+ void *priv,
+ struct sbefifo_context **out);
void sbefifo_disconnect(struct sbefifo_context *sctx);
uint32_t sbefifo_ffdc_get(struct sbefifo_context *sctx, const uint8_t **ffdc, uint32_t *ffdc_len);
--
2.21.0
More information about the Pdbg
mailing list