Commit 612e460d authored by Lucas Russo's avatar Lucas Russo

libs/libllio/*: use operation pointer instead of enum name

This will make it easier to declare a new operation
and use it. In the previous way, we had to manually
add the operation to the enumeration.
parent a18feeb9
......@@ -36,6 +36,9 @@ typedef ssize_t (*write_dma_fp)(llio_t *self, uint64_t offs, size_t size, uint32
/* typedef int (*read_info_fp)(struct _llio_t *self, struct _llio_dev_info_t *dev_info); moved to dev_io */
typedef struct {
const char *name; /* LLIO device name */
/* Operations */
open_fp open; /* Open device */
release_fp release; /* Release device */
read_16_fp read_16; /* Read 16-bit data */
......@@ -60,7 +63,7 @@ typedef struct {
/************************************************************/
/* Creates a new instance of the Low-level I/O */
llio_t * llio_new (char *name, char *endpoint, llio_type_e type, int verbose);
llio_t * llio_new (char *name, char *endpoint, const llio_ops_t *reg_ops, int verbose);
/* Destroy an instance of the Low-level I/O */
llio_err_e llio_destroy (llio_t **self_p);
......@@ -83,7 +86,7 @@ llio_err_e llio_set_dev_handler (llio_t *self, void *dev_handler);
/* Get dev handler */
void *llio_get_dev_handler (llio_t *self);
/* Get type */
llio_type_e llio_get_type (llio_t *self);
const char *llio_get_ops_name (llio_t *self);
/* Set SDB prefix ADDR */
llio_err_e llio_set_sdb_prefix_addr (llio_t *self, uint64_t sdb_prefix_addr);
/* Get SDB prefix ADDR */
......
......@@ -32,13 +32,12 @@
/* LLIO class object */
struct _llio_t {
llio_type_e type; /* Device type (PCIe, Ethnernet, or other) */
void *dev_handler; /* Generic pointer to a device handler. This
must be cast to a specific type by the
devices functions */
char *name; /* Identification of this llio instance */
int verbose; /* Print activity to stdout */
uint64_t sdb_prefix_addr; /* SDB prefix address. Used to read/write to the
uint64_t sdb_prefix_addr; /* SDB prefix address. Used to read/write to the
SDB address space. To be set by the specific ops */
/* Endpoint to connect to */
......@@ -48,14 +47,14 @@ struct _llio_t {
};
/* Register Low-level operations to llio instance. Helpper function */
static llio_err_e _llio_register_ops (llio_type_e type, const llio_ops_t **llio_ops);
static llio_err_e _llio_register_ops (const llio_ops_t **ops, const llio_ops_t *reg_ops);
/* Unregister Low-level operations to llio instance. Helpper function */
static llio_err_e _llio_unregister_ops (const llio_ops_t **ops);
/* Get open endpoint status */
static bool _llio_get_endpoint_open (llio_t *self);
/* Creates a new instance of the Low-level I/O */
llio_t * llio_new (char *name, char *endpoint, llio_type_e type, int verbose)
llio_t * llio_new (char *name, char *endpoint, const llio_ops_t *reg_ops, int verbose)
{
assert (name);
assert (endpoint);
......@@ -64,7 +63,6 @@ llio_t * llio_new (char *name, char *endpoint, llio_type_e type, int verbose)
ASSERT_ALLOC(self, err_self_alloc);
/* Initialize Low-level IO type */
self->type = type;
self->dev_handler = NULL; /* This is set by the device functions */
self->name = strdup (name);
ASSERT_ALLOC(self->name, err_name_alloc);
......@@ -84,12 +82,9 @@ llio_t * llio_new (char *name, char *endpoint, llio_type_e type, int verbose)
ASSERT_ALLOC(self->dev_info, err_dev_info_alloc); Moved to dev_io */
/* Initilialize llio_ops */
/* self->ops = (llio_ops_t *) zmalloc (sizeof *self->ops); */
/* ASSERT_ALLOC(self->ops, err_ops_alloc); */
/* Nullify every ops field to indicate a non-implemented function */
/* *self->ops = (const llio_ops_t) {0}; */
self->ops = NULL;
/* Attach Low-level operation to instance of llio */
_llio_register_ops (type, &self->ops);
_llio_register_ops (&self->ops, reg_ops);
DBE_DEBUG (DBG_LL_IO | DBG_LVL_INFO, "[ll_io] Created instance of llio\n");
return self;
......@@ -191,9 +186,14 @@ void *llio_get_dev_handler (llio_t *self)
return self->dev_handler;
}
llio_type_e llio_get_type (llio_t *self)
const char *llio_get_ops_name (llio_t *self)
{
return self->type;
assert (self);
if (self->ops == NULL) {
return NULL;
}
return self->ops->name;
}
llio_err_e llio_set_sdb_prefix_addr (llio_t *self, uint64_t sdb_prefix_addr)
......@@ -219,26 +219,9 @@ static bool _llio_get_endpoint_open (llio_t *self)
/**************** Helper Functions ***************/
/* Register Low-level operations to llio instance. Helpper function */
static llio_err_e _llio_register_ops (llio_type_e type, const llio_ops_t **ops)
static llio_err_e _llio_register_ops (const llio_ops_t **ops, const llio_ops_t *reg_ops)
{
switch (type) {
case GENERIC_DEV:
*ops = NULL;
return LLIO_ERR_INV_FUNC_PARAM;
case PCIE_DEV:
*ops = &llio_ops_pcie;
break;
case ETH_DEV:
*ops = &llio_ops_eth;
break;
default:
*ops = NULL;
return LLIO_ERR_INV_FUNC_PARAM;
}
*ops = reg_ops;
DBE_DEBUG (DBG_LL_IO | DBG_LVL_INFO, "[ll_io] Ops set\n");
return LLIO_SUCCESS;
}
......
......@@ -475,6 +475,7 @@ static ssize_t _eth_recvall (int fd, uint8_t *buf, size_t len)
}
const llio_ops_t llio_ops_eth = {
.name = "ETH", /* Operations name */
.open = eth_open, /* Open device */
.release = eth_release, /* Release device */
.read_16 = eth_read_16, /* Read 16-bit data */
......
......@@ -188,7 +188,7 @@ static int pcie_open (llio_t *self, llio_endpoint_t *endpoint)
DBE_DEBUG (DBG_LL_IO | DBG_LVL_INFO,
"[ll_io_pcie] Opened PCIe device located at %s\n",
llio_get_endpoint_name (self));
/* Set SDB prefix adress */
llio_set_sdb_prefix_addr (self, BAR4_ADDR);
......@@ -653,6 +653,7 @@ static ssize_t _pcie_reset_fpga (llio_t *self)
}
const llio_ops_t llio_ops_pcie = {
.name = "PCIE", /* Operations name */
.open = pcie_open, /* Open device */
.release = pcie_release, /* Release device */
.read_16 = NULL, /* Read 16-bit data */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment