From a740fcee56bd456a759e03526df476e1791fb2bd Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Wed, 29 Apr 2015 05:25:08 +0200 Subject: Create dummy register context --- pcilib/pci.c | 13 ++++++++----- pcilib/pci.h | 4 +--- pcilib/register.c | 10 ++++++++++ pcilib/register.h | 3 +-- tests/new_device.sh | 5 ++++- 5 files changed, 24 insertions(+), 11 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); diff --git a/tests/new_device.sh b/tests/new_device.sh index 3545321..e3f8f8a 100755 --- a/tests/new_device.sh +++ b/tests/new_device.sh @@ -1,3 +1,6 @@ #! /bin/bash -echo "10ee 6028" > /sys/bus/pci/drivers/pciDriver/new_id +#Add new device to the driver +#echo "10ee 6028" > /sys/bus/pci/drivers/pciDriver/new_id +#Enable bus mastering +#setpci -s 03:00.0 4.w=0x07 -- cgit v1.2.3