diff options
author | Suren A. Chilingaryan <csa@suren.me> | 2015-04-29 05:25:08 +0200 |
---|---|---|
committer | Suren A. Chilingaryan <csa@suren.me> | 2015-04-29 05:25:08 +0200 |
commit | a740fcee56bd456a759e03526df476e1791fb2bd (patch) | |
tree | 150af9b0b67abee77ae304b6d20516d8673bf52a /pcilib | |
parent | 0f8c3ffba654a5b05fa509f412c0b9d9de931c69 (diff) | |
download | pcitool-a740fcee56bd456a759e03526df476e1791fb2bd.tar.gz pcitool-a740fcee56bd456a759e03526df476e1791fb2bd.tar.bz2 pcitool-a740fcee56bd456a759e03526df476e1791fb2bd.tar.xz pcitool-a740fcee56bd456a759e03526df476e1791fb2bd.zip |
Create dummy register context
Diffstat (limited to 'pcilib')
-rw-r--r-- | pcilib/pci.c | 13 | ||||
-rw-r--r-- | pcilib/pci.h | 4 | ||||
-rw-r--r-- | pcilib/register.c | 10 | ||||
-rw-r--r-- | pcilib/register.h | 3 |
4 files changed, 20 insertions, 10 deletions
diff --git a/pcilib/pci.c b/pcilib/pci.c index 253c439..3769fd4 100644 --- a/pcilib/pci.c +++ b/pcilib/pci.c @@ -113,12 +113,9 @@ pcilib_t *pcilib_open(const char *device, const char *model) { ctx->alloc_reg = PCILIB_DEFAULT_REGISTER_SPACE; ctx->registers = (pcilib_register_description_t *)malloc(PCILIB_DEFAULT_REGISTER_SPACE * sizeof(pcilib_register_description_t)); -/* ctx->banks = (pcilib_register_bank_context_t *)malloc(PCILIB_MAX_BANKS * sizeof(pcilib_register_bank_context_t)); - ctx->ranges = (pcilib_register_range_t *)malloc(PCILIB_MAX_RANGES * sizeof(pcilib_register_range_t)); - ctx->protocols - ctx->engines*/ + ctx->register_ctx = (pcilib_register_context_t *)malloc(PCILIB_DEFAULT_REGISTER_SPACE * sizeof(pcilib_register_context_t)); - if ((!ctx->registers)/*||(!ctx->banks)||(!ctx->ranges)*/) { + if ((!ctx->registers)||(!ctx->register_ctx)) { pcilib_error("Error allocating memory for register model"); pcilib_close(ctx); free(ctx); @@ -128,6 +125,9 @@ pcilib_t *pcilib_open(const char *device, const char *model) { memset(ctx->registers, 0, sizeof(pcilib_register_description_t)); memset(ctx->banks, 0, sizeof(pcilib_register_bank_description_t)); memset(ctx->ranges, 0, sizeof(pcilib_register_range_t)); + + memset(ctx->register_ctx, 0, PCILIB_DEFAULT_REGISTER_SPACE * sizeof(pcilib_register_context_t)); + for (i = 0; pcilib_protocols[i].api; i++); memcpy(ctx->protocols, pcilib_protocols, i * sizeof(pcilib_register_protocol_description_t)); @@ -474,6 +474,9 @@ void pcilib_close(pcilib_t *ctx) { pcilib_free_register_banks(ctx); + if (ctx->register_ctx) + free(ctx->register_ctx); + if (ctx->event_plugin) pcilib_plugin_close(ctx->event_plugin); diff --git a/pcilib/pci.h b/pcilib/pci.h index b53c70b..0775663 100644 --- a/pcilib/pci.h +++ b/pcilib/pci.h @@ -54,13 +54,11 @@ struct pcilib_s { pcilib_dma_description_t dma; /**< Configuration of used DMA implementation */ pcilib_dma_engine_description_t engines[PCILIB_MAX_DMA_ENGINES + 1]; /**< List of engines defined by the DMA implementation */ -// pcilib_register_context_t *register_ctx; /**< Contexts for registers */ + pcilib_register_context_t *register_ctx; /**< Contexts for registers */ pcilib_register_bank_context_t *bank_ctx[PCILIB_MAX_REGISTER_BANKS]; /**< Contexts for registers banks if required by register protocol */ pcilib_dma_context_t *dma_ctx; /**< DMA context */ pcilib_context_t *event_ctx; /**< Implmentation context */ -// pcilib_dma_info_t dma_info; - #ifdef PCILIB_FILE_IO int file_io_handle; #endif /* PCILIB_FILE_IO */ diff --git a/pcilib/register.c b/pcilib/register.c index 586dded..f10e29b 100644 --- a/pcilib/register.c +++ b/pcilib/register.c @@ -21,8 +21,10 @@ int pcilib_add_registers(pcilib_t *ctx, size_t n, const pcilib_register_description_t *registers) { // DS: Overrride existing registers + // Registers identified by addr + offset + size + type or name pcilib_register_description_t *regs; + pcilib_register_context_t *reg_ctx; size_t size; if (!n) { @@ -37,6 +39,14 @@ int pcilib_add_registers(pcilib_t *ctx, size_t n, const pcilib_register_descript ctx->registers = regs; ctx->model_info.registers = regs; + + reg_ctx = (pcilib_register_context_t*)realloc(ctx->registers, size * sizeof(pcilib_register_context_t)); + if (!reg_ctx) return PCILIB_ERROR_MEMORY; + + memset(reg_ctx + ctx->alloc_reg, 0, (size - ctx->alloc_reg) * sizeof(pcilib_register_context_t)); + + ctx->register_ctx = reg_ctx; + ctx->alloc_reg = size; } diff --git a/pcilib/register.h b/pcilib/register.h index 7514943..307e8a1 100644 --- a/pcilib/register.h +++ b/pcilib/register.h @@ -42,11 +42,10 @@ typedef struct { const char *description; /**< Brief description of the register */ } pcilib_register_description_t; -/* + typedef struct { pcilib_register_bank_t bank; } pcilib_register_context_t; -*/ int pcilib_add_registers(pcilib_t *ctx, size_t n, const pcilib_register_description_t *registers); |