From 18e672c04c6b12d51b13f4cf32b9c197245407d6 Mon Sep 17 00:00:00 2001 From: zilio nicolas Date: Fri, 12 Jun 2015 16:56:21 +0200 Subject: added soft_reg --- protocols/CMakeLists.txt | 4 +- protocols/software_registers.c | 90 ++++++++++++++++++++++++++++++++++++++++++ protocols/software_registers.h | 58 +++++++++++++++++++++++++++ 3 files changed, 150 insertions(+), 2 deletions(-) create mode 100644 protocols/software_registers.c create mode 100644 protocols/software_registers.h diff --git a/protocols/CMakeLists.txt b/protocols/CMakeLists.txt index 3c1d75b..2299061 100644 --- a/protocols/CMakeLists.txt +++ b/protocols/CMakeLists.txt @@ -3,6 +3,6 @@ include_directories( ${CMAKE_SOURCE_DIR}/pcilib ) -set(HEADERS ${HEADERS} default.h) +set(HEADERS ${HEADERS} default.h software_registers.h) -add_library(protocols STATIC default.c) +add_library(protocols STATIC default.c software_registers.c) diff --git a/protocols/software_registers.c b/protocols/software_registers.c new file mode 100644 index 0000000..d3c390f --- /dev/null +++ b/protocols/software_registers.c @@ -0,0 +1,90 @@ +#include +#include +#include + +#include "model.h" +#include "error.h" +#include "kmem.h" +#include "pcilib.h" +#include "pci.h" + + +/** + * pcilib_software_registers_open + * this function initializes the kernel space memory and stores in it the default values of the registers of the given bank index, if it was not initialized by a concurrent process, and return a bank context containing the adress of this kernel space. It the kernel space memory was already initialized by a concurrent process, then this function just return the bank context with the adress of this kernel space already used + *@param[in] ctx the pcilib_t structure running + * @param[in] bank the bank index that will permits to get the bank we want registers from + * @param[in] model not used + * @param[in] args not used + *@return a bank context with the adress of the kernel space memory related to it + */ +pcilib_register_bank_context_t* pcilib_software_registers_open(pcilib_t *ctx, pcilib_register_bank_t bank,const char* model, const void *args){ + pcilib_register_bank_context_t* bank_ctx; + pcilib_register_value_t *init=NULL; + pcilib_kmem_handle_t *test; + int i; + int j; + + bank_ctx=calloc(1,sizeof(pcilib_register_bank_context_t)); + bank_ctx->bank=ctx->banks + bank; + + test=pcilib_alloc_kernel_memory(ctx, 0, 0, 0, 0,PCILIB_KMEM_USE_STANDARD,PCILIB_KMEM_FLAG_REUSE|PCILIB_KMEM_FLAG_PERSISTENT); + if (!test)pcilib_error("allocation of kernel memory for registers has failed"); + + if(pcilib_kmem_is_reused(ctx,test)== PCILIB_KMEM_REUSE_ALLOCATED){ + bank_ctx->bank_software_register_adress=test; + }else{ + bank_ctx->bank_software_register_adress=test; + init=test; + j=0; + while(ctx->model_info.registers[j].name!=NULL){ + if(ctx->model_info.registers[j].bank==(ctx->banks + bank).addr){ + pcilib_write_register_by_id(ctx,ctx->model_info.registers[j],ctx->model_info.registers[j].defvalue); + } + j++; + } + } + return bank_ctx; +} + + +/** + * pcilib_software_registers_close + * this function clear the kernel memory space that could have been allocated for software registers + * @param[in] bank_ctx the bank context running that we get from the initialisation function + */ +void pcilib_software_registers_close(pcilib_register_bank_context_t *bank_ctx){ + int err=1; + + err=pcilib_clean_kernel_memory(bank_ctx->ctx, 0, 0); + + if(err) pcilib_error("Error closing register kernel space"); +} + +/** + * pcilib_software_registers_read + * this function read the value of a said register in the kernel space + * @param[in] ctx the pcilib_t structure runnning + * @param[in] bank_ctx the bank context that was returned by the initialisation function + * @param[in] addr the adress of the register we want to read + *@param[out] value the value of the register + * @return 0 in case of success + */ +int pcilib_software_registers_read(pcilib_t *ctx, pcilib_register_bank_context_t *bank_ctx,pcilib_register_addr_t addr, pcilib_register_value_t *value){ + *value= *(pcilib_register_value_t*) bank_ctx->bank_software_register_adress+addr; + return 0; +} + +/** + * pcilib_software_registers_write + * this function write the said value to a said register in the kernel space + * @param[in] ctx the pcilib_t structure runnning + * @param[in] bank_ctx the bank context that was returned by the initialisation function + * @param[in] addr the adress of the register we want to write in + *@param[out] value the value we want to write in the register + * @return 0 in case of success + */ +int pcilib_software_registers_write(pcilib_t *ctx, pcilib_register_bank_context_t *bank_ctx, pcilib_register_addr_t addr, pcilib_register_value_t value){ + *(pcilib_register_value_t*)(bank_ctx->bank_software_register_adress+addr)=value; + return 0; +} diff --git a/protocols/software_registers.h b/protocols/software_registers.h new file mode 100644 index 0000000..f31e292 --- /dev/null +++ b/protocols/software_registers.h @@ -0,0 +1,58 @@ +/** + * @file software_registers.h + * @skip author nicolas zilio, nicolas.zilio@hotmail.fr + * @brief header file for implementation of the protocol with registers registered in the kernel space. + */ + +#ifndef _PCILIB_SOFTREG_PROT +#define _PCILIB_SOFTREG_PROT + +#include "pcilib.h" +#include "version.h" +#include "model.h" + +/** + * this function initialize the kernel space memory for the use of software register. it initializes the kernel space memory and stores in it the default values of the registers of the given bank index, if it was not initialized by a concurrent process, and return a bank context containing the adress of this kernel space. If the kernel space memory was already initialized by a concurrent process, then this function just return the bank context with the adress of this kernel space already used + *@param[in] ctx the pcilib_t structure running + * @param[in] bank the bank index that will permits to get the bank we want registers from + * @param[in] model not used + * @param[in] args not used + *@return a bank context with the adress of the kernel space memory related to it + */ +pcilib_register_bank_context_t* pcilib_software_registers_open(pcilib_t *ctx, pcilib_register_bank_t bank, const char* model, const void *args); + +/** + * this function clear the kernel memory space that could have been allocated for software registers. + * @param[in] bank_ctx the bank context running that we get from the initialisation function + */ +void pcilib_software_registers_close(pcilib_register_bank_context_t *bank_ctx); + +/** + * this function read the value of a said register in the kernel space. + * @param[in] ctx the pcilib_t structure runnning + * @param[in] bank_ctx the bank context that was returned by the initialisation function + * @param[in] addr the adress of the register we want to read + *@param[out] value the value of the register + * @return 0 in case of success + */ +int pcilib_software_registers_read(pcilib_t *ctx, pcilib_register_bank_context_t* bank_ctx,pcilib_register_addr_t addr, pcilib_register_value_t *value); + +/** + * this function write the said value to a said register in the kernel space + * @param[in] ctx the pcilib_t structure runnning + * @param[in] bank_ctx the bank context that was returned by the initialisation function + * @param[in] addr the adress of the register we want to write in + *@param[out] value the value we want to write in the register + * @return 0 in case of success + */ +int pcilib_software_registers_write(pcilib_t *ctx,pcilib_register_bank_context_t* bank_ctx, pcilib_register_addr_t addr, pcilib_register_value_t value); + +#ifdef _PCILIB_EXPORT_C +/** + * new protocol addition to the protocol api. + */ +const pcilib_register_protocol_api_description_t pcilib_register_software_register_protocol_api = + { PCILIB_VERSION, pcilib_software_registers_open, pcilib_software_registers_close,pcilib_software_registers_read, pcilib_software_registers_write }; /**< we add there the protocol to the list of possible protocols*/ +#endif /* _PCILIB_EXPORT_C */ + +#endif /* _PCILIB_SOFTREG_PROT*/ -- cgit v1.2.3 From 51ec836689e0d9e2d27f2fa4579ff1088513dacf Mon Sep 17 00:00:00 2001 From: zilio nicolas Date: Fri, 12 Jun 2015 19:08:55 +0200 Subject: some modifications --- dma/ipe.h | 4 ++++ pcilib/bank.h | 9 ++++++++- pcilib/export.c | 3 ++- pcilib/model.h | 2 +- protocols/software_registers.c | 7 ++----- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/dma/ipe.h b/dma/ipe.h index 44fbc99..e341a53 100644 --- a/dma/ipe.h +++ b/dma/ipe.h @@ -39,6 +39,7 @@ static const pcilib_dma_engine_description_t ipe_dma_engines[] = { static const pcilib_register_bank_description_t ipe_dma_banks[] = { { PCILIB_REGISTER_BANK_DMA, PCILIB_REGISTER_PROTOCOL_DEFAULT, PCILIB_BAR0, 0, 0, 32, 0x0200, PCILIB_LITTLE_ENDIAN, PCILIB_LITTLE_ENDIAN, "0x%lx", "dma", "DMA Registers"}, + { PCILIB_REGISTER_BANK0, PCILIB_REGISTER_PROTOCOL_SOFTWARE_REGISTERS, PCILIB_BAR1, 0, 0, 32, 0x0003, PCILIB_LITTLE_ENDIAN, PCILIB_LITTLE_ENDIAN, "0x%lx", "test", "test Registers"}, { 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL } }; @@ -77,6 +78,9 @@ static const pcilib_register_description_t ipe_dma_registers[] = { {0x0058, 0, 32, 0, 0x00000000, PCILIB_REGISTER_RW , PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK_DMA, "last_descriptor_read", "Last descriptor read by the host"}, {0x005C, 0, 32, 0, 0x00000000, PCILIB_REGISTER_RW , PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK_DMA, "desc_mem_addr", "Number of descriptors configured"}, {0x0060, 0, 32, 0, 0x00000000, PCILIB_REGISTER_RW , PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK_DMA, "update_thresh", "Update threshold of progress register"}, + {0x0001, 0, 32, 0x1, 0x00000000, PCILIB_REGISTER_RW , PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "test1", "ister"}, + {0x0002, 0, 32, 0, 0x00000000, PCILIB_REGISTER_RW , PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "test2", "ter"}, + {0x0003, 0, 32, 0x020, 0x00000000, PCILIB_REGISTER_RW , PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "test3", "er"}, {0, 0, 0, 0, 0x00000000, 0, 0, 0, NULL, NULL} }; #endif /* _PCILIB_EXPORT_C */ diff --git a/pcilib/bank.h b/pcilib/bank.h index 943c389..bc45ec4 100644 --- a/pcilib/bank.h +++ b/pcilib/bank.h @@ -2,6 +2,8 @@ #define _PCILIB_BANK_H #include +#include +#include #define PCILIB_REGISTER_BANK_INVALID ((pcilib_register_bank_t)-1) #define PCILIB_REGISTER_BANK0 0 /**< First BANK to be used in the event engine */ @@ -13,6 +15,7 @@ #define PCILIB_REGISTER_PROTOCOL_INVALID ((pcilib_register_protocol_t)-1) #define PCILIB_REGISTER_PROTOCOL0 0 /**< First PROTOCOL address to be used in the event engine */ #define PCILIB_REGISTER_PROTOCOL_DEFAULT 64 /**< Default memmap based protocol */ +#define PCILIB_REGISTER_PROTOCOL_KERNEL 32 /**< Protocol with registers registered in kernel directly*/ #define PCILIB_REGISTER_PROTOCOL_DMA 96 /**< First PROTOCOL address to be used by DMA engines */ #define PCILIB_REGISTER_PROTOCOL_DYNAMIC 128 /**< First PROTOCOL address to be used by plugins */ @@ -28,7 +31,7 @@ typedef struct { pcilib_version_t version; pcilib_register_bank_context_t *(*init)(pcilib_t *ctx, pcilib_register_bank_t bank, const char *model, const void *args); /**< Optional API call to initialize bank context */ - void (*free)(pcilib_register_bank_context_t *ctx); /**< Optional API call to cleanup bank context */ + void (*free)(pcilib_register_bank_context_t *bank_ctx); /**< Optional API call to cleanup bank context */ int (*read)(pcilib_t *pcilib, pcilib_register_bank_context_t *ctx, pcilib_register_addr_t addr, pcilib_register_value_t *value); /**< Read from register, mandatory for RO/RW registers */ int (*write)(pcilib_t *pcilib, pcilib_register_bank_context_t *ctx, pcilib_register_addr_t addr, pcilib_register_value_t value); /**< Write to register, mandatory for WO/RW registers */ } pcilib_register_protocol_api_description_t; @@ -60,6 +63,7 @@ typedef struct { const char *format; /**< printf format for the registers, either %lu for decimal output or 0x%lx for hexdecimal */ const char *name; /**< short bank name */ const char *description; /**< longer bank description */ + xmlNodePtr xmlNode; /** #include - typedef struct { const pcilib_version_t interface_version; @@ -24,6 +23,7 @@ typedef struct { const char *name; const char *description; + } pcilib_model_description_t; diff --git a/protocols/software_registers.c b/protocols/software_registers.c index d3c390f..68655e0 100644 --- a/protocols/software_registers.c +++ b/protocols/software_registers.c @@ -20,9 +20,7 @@ */ pcilib_register_bank_context_t* pcilib_software_registers_open(pcilib_t *ctx, pcilib_register_bank_t bank,const char* model, const void *args){ pcilib_register_bank_context_t* bank_ctx; - pcilib_register_value_t *init=NULL; pcilib_kmem_handle_t *test; - int i; int j; bank_ctx=calloc(1,sizeof(pcilib_register_bank_context_t)); @@ -35,11 +33,10 @@ pcilib_register_bank_context_t* pcilib_software_registers_open(pcilib_t *ctx, pc bank_ctx->bank_software_register_adress=test; }else{ bank_ctx->bank_software_register_adress=test; - init=test; j=0; while(ctx->model_info.registers[j].name!=NULL){ - if(ctx->model_info.registers[j].bank==(ctx->banks + bank).addr){ - pcilib_write_register_by_id(ctx,ctx->model_info.registers[j],ctx->model_info.registers[j].defvalue); + if(ctx->model_info.registers[j].bank==(ctx->banks+bank)->addr){ + pcilib_write_register_by_id(ctx,ctx->model_info.registers[j].addr,ctx->model_info.registers[j].defvalue); } j++; } -- cgit v1.2.3 From 8f194817bf33fef401093868fbbbf25a0588d00d Mon Sep 17 00:00:00 2001 From: zilio nicolas Date: Mon, 15 Jun 2015 12:04:07 +0200 Subject: ready to run tests --- pcilib/bank.h | 1 + 1 file changed, 1 insertion(+) diff --git a/pcilib/bank.h b/pcilib/bank.h index bc45ec4..df4df83 100644 --- a/pcilib/bank.h +++ b/pcilib/bank.h @@ -18,6 +18,7 @@ #define PCILIB_REGISTER_PROTOCOL_KERNEL 32 /**< Protocol with registers registered in kernel directly*/ #define PCILIB_REGISTER_PROTOCOL_DMA 96 /**< First PROTOCOL address to be used by DMA engines */ #define PCILIB_REGISTER_PROTOCOL_DYNAMIC 128 /**< First PROTOCOL address to be used by plugins */ +#define PCILIB_REGISTER_PROTOCOL_SOFTWARE_REGISTERS 32 typedef uint8_t pcilib_register_bank_t; /**< Type holding the bank position within the field listing register banks in the model */ typedef uint8_t pcilib_register_bank_addr_t; /**< Type holding the bank address number */ -- cgit v1.2.3 From 907559d880de032deb31aa5e648c11029bbf9cce Mon Sep 17 00:00:00 2001 From: zilio nicolas Date: Thu, 18 Jun 2015 19:47:17 +0200 Subject: new version of software_registers --- dma/ipe.h | 8 +++--- pcilib/bank.h | 3 +-- pcilib/pcilib.h | 1 + protocols/software_registers.c | 55 +++++++++++++++++++++++++++++++----------- 4 files changed, 47 insertions(+), 20 deletions(-) diff --git a/dma/ipe.h b/dma/ipe.h index e341a53..cf773d8 100644 --- a/dma/ipe.h +++ b/dma/ipe.h @@ -39,7 +39,7 @@ static const pcilib_dma_engine_description_t ipe_dma_engines[] = { static const pcilib_register_bank_description_t ipe_dma_banks[] = { { PCILIB_REGISTER_BANK_DMA, PCILIB_REGISTER_PROTOCOL_DEFAULT, PCILIB_BAR0, 0, 0, 32, 0x0200, PCILIB_LITTLE_ENDIAN, PCILIB_LITTLE_ENDIAN, "0x%lx", "dma", "DMA Registers"}, - { PCILIB_REGISTER_BANK0, PCILIB_REGISTER_PROTOCOL_SOFTWARE_REGISTERS, PCILIB_BAR1, 0, 0, 32, 0x0003, PCILIB_LITTLE_ENDIAN, PCILIB_LITTLE_ENDIAN, "0x%lx", "test", "test Registers"}, + { PCILIB_REGISTER_BANK_DMA + 1, PCILIB_REGISTER_PROTOCOL_SOFTWARE_REGISTERS, PCILIB_BARUNDEF, 0, 0, 32, 0x0003, PCILIB_LITTLE_ENDIAN, PCILIB_LITTLE_ENDIAN, "0x%lx", "test", "test Registers"}, { 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL } }; @@ -78,9 +78,9 @@ static const pcilib_register_description_t ipe_dma_registers[] = { {0x0058, 0, 32, 0, 0x00000000, PCILIB_REGISTER_RW , PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK_DMA, "last_descriptor_read", "Last descriptor read by the host"}, {0x005C, 0, 32, 0, 0x00000000, PCILIB_REGISTER_RW , PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK_DMA, "desc_mem_addr", "Number of descriptors configured"}, {0x0060, 0, 32, 0, 0x00000000, PCILIB_REGISTER_RW , PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK_DMA, "update_thresh", "Update threshold of progress register"}, - {0x0001, 0, 32, 0x1, 0x00000000, PCILIB_REGISTER_RW , PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "test1", "ister"}, - {0x0002, 0, 32, 0, 0x00000000, PCILIB_REGISTER_RW , PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "test2", "ter"}, - {0x0003, 0, 32, 0x020, 0x00000000, PCILIB_REGISTER_RW , PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "test3", "er"}, + {0x0001, 0, 32, 0x1, 0x00000000, PCILIB_REGISTER_RW , PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK_DMA +1, "test1", "ister"}, + {0x0002, 0, 32, 0, 0x00000000, PCILIB_REGISTER_RW , PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK_DMA +1, "test2", "ter"}, + {0x0003, 0, 32, 0x020, 0x00000000, PCILIB_REGISTER_RW , PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK_DMA +1, "test3", "er"}, {0, 0, 0, 0, 0x00000000, 0, 0, 0, NULL, NULL} }; #endif /* _PCILIB_EXPORT_C */ diff --git a/pcilib/bank.h b/pcilib/bank.h index df4df83..dfd2adb 100644 --- a/pcilib/bank.h +++ b/pcilib/bank.h @@ -15,7 +15,6 @@ #define PCILIB_REGISTER_PROTOCOL_INVALID ((pcilib_register_protocol_t)-1) #define PCILIB_REGISTER_PROTOCOL0 0 /**< First PROTOCOL address to be used in the event engine */ #define PCILIB_REGISTER_PROTOCOL_DEFAULT 64 /**< Default memmap based protocol */ -#define PCILIB_REGISTER_PROTOCOL_KERNEL 32 /**< Protocol with registers registered in kernel directly*/ #define PCILIB_REGISTER_PROTOCOL_DMA 96 /**< First PROTOCOL address to be used by DMA engines */ #define PCILIB_REGISTER_PROTOCOL_DYNAMIC 128 /**< First PROTOCOL address to be used by plugins */ #define PCILIB_REGISTER_PROTOCOL_SOFTWARE_REGISTERS 32 @@ -88,7 +87,7 @@ struct pcilib_register_bank_context_s { const pcilib_register_bank_description_t *bank; /**< Corresponding bank description */ const pcilib_register_protocol_api_description_t *api; /**< API functions */ xmlNodeSetPtr banks_nodes; - void *bank_software_register_adress; + void *kmem_base_address; pcilib_t *ctx; }; diff --git a/pcilib/pcilib.h b/pcilib/pcilib.h index 6d241c6..6c1d592 100644 --- a/pcilib/pcilib.h +++ b/pcilib/pcilib.h @@ -87,6 +87,7 @@ typedef struct { #define PCILIB_BAR_INVALID ((pcilib_bar_t)-1) #define PCILIB_BAR0 0 #define PCILIB_BAR1 1 +#define PCILIB_BARUNDEF -1 #define PCILIB_DMA_ENGINE_INVALID ((pcilib_dma_engine_t)-1) #define PCILIB_DMA_ENGINE_ALL ((pcilib_dma_engine_t)-1) #define PCILIB_DMA_FLAGS_DEFAULT ((pcilib_dma_flags_t)0) diff --git a/protocols/software_registers.c b/protocols/software_registers.c index 68655e0..ab5d31d 100644 --- a/protocols/software_registers.c +++ b/protocols/software_registers.c @@ -8,6 +8,7 @@ #include "pcilib.h" #include "pci.h" +#include /** * pcilib_software_registers_open @@ -20,27 +21,39 @@ */ pcilib_register_bank_context_t* pcilib_software_registers_open(pcilib_t *ctx, pcilib_register_bank_t bank,const char* model, const void *args){ pcilib_register_bank_context_t* bank_ctx; - pcilib_kmem_handle_t *test; + pcilib_kmem_handle_t *handle; int j; + /* the protocol thing is here to make sure to avoid segfault in write_registers_internal, but is not useful as it is now*/ + pcilib_register_protocol_t protocol; + protocol = pcilib_find_register_protocol_by_addr(ctx, ctx->banks[bank].protocol); bank_ctx=calloc(1,sizeof(pcilib_register_bank_context_t)); bank_ctx->bank=ctx->banks + bank; + bank_ctx->ctx=ctx; + bank_ctx->api=ctx->protocols[protocol].api; + ctx->bank_ctx[bank]=bank_ctx; + + handle=pcilib_alloc_kernel_memory(ctx, PCILIB_KMEM_TYPE_PAGE, 1, 0, 1,PCILIB_KMEM_USE_STANDARD,PCILIB_KMEM_FLAG_REUSE|PCILIB_KMEM_FLAG_PERSISTENT); + + if (!handle)pcilib_error("allocation of kernel memory for registers has failed"); - test=pcilib_alloc_kernel_memory(ctx, 0, 0, 0, 0,PCILIB_KMEM_USE_STANDARD,PCILIB_KMEM_FLAG_REUSE|PCILIB_KMEM_FLAG_PERSISTENT); - if (!test)pcilib_error("allocation of kernel memory for registers has failed"); + bank_ctx->kmem_base_address=handle; - if(pcilib_kmem_is_reused(ctx,test)== PCILIB_KMEM_REUSE_ALLOCATED){ - bank_ctx->bank_software_register_adress=test; - }else{ - bank_ctx->bank_software_register_adress=test; + if(pcilib_kmem_is_reused(ctx,handle)!= PCILIB_KMEM_REUSE_ALLOCATED){ j=0; while(ctx->model_info.registers[j].name!=NULL){ if(ctx->model_info.registers[j].bank==(ctx->banks+bank)->addr){ - pcilib_write_register_by_id(ctx,ctx->model_info.registers[j].addr,ctx->model_info.registers[j].defvalue); + /* !!!!!warning!!!!! + hey suren, + you may check here too :the programm seems to always go this path, so pcilib_write_register_by_id always write the original value, kmem_is_reused working? + */ + pcilib_write_register_by_id(ctx,j,ctx->model_info.registers[j].defvalue); + } j++; } } + return bank_ctx; } @@ -51,11 +64,11 @@ pcilib_register_bank_context_t* pcilib_software_registers_open(pcilib_t *ctx, pc * @param[in] bank_ctx the bank context running that we get from the initialisation function */ void pcilib_software_registers_close(pcilib_register_bank_context_t *bank_ctx){ - int err=1; - - err=pcilib_clean_kernel_memory(bank_ctx->ctx, 0, 0); + /*!!!!! to check!!!! - if(err) pcilib_error("Error closing register kernel space"); + ps: i am using uint32_t to calculate registers adress, may it change in the future? should we define some #define? + */ + pcilib_free_kernel_memory(bank_ctx->ctx,bank_ctx->kmem_base_address, 0); } /** @@ -68,7 +81,14 @@ void pcilib_software_registers_close(pcilib_register_bank_context_t *bank_ctx){ * @return 0 in case of success */ int pcilib_software_registers_read(pcilib_t *ctx, pcilib_register_bank_context_t *bank_ctx,pcilib_register_addr_t addr, pcilib_register_value_t *value){ - *value= *(pcilib_register_value_t*) bank_ctx->bank_software_register_adress+addr; + int i; + void* base_addr; + + base_addr=pcilib_kmem_get_block_ua(ctx,bank_ctx->kmem_base_address,0); + for(i=0;ctx->registers[i].name!=NULL;i++){ + if(ctx->registers[i].addr==addr) break; + } + *value=*(pcilib_register_value_t*)(base_addr+i*sizeof(uint32_t)); return 0; } @@ -82,6 +102,13 @@ int pcilib_software_registers_read(pcilib_t *ctx, pcilib_register_bank_context_t * @return 0 in case of success */ int pcilib_software_registers_write(pcilib_t *ctx, pcilib_register_bank_context_t *bank_ctx, pcilib_register_addr_t addr, pcilib_register_value_t value){ - *(pcilib_register_value_t*)(bank_ctx->bank_software_register_adress+addr)=value; + int i; + void* base_addr; + + base_addr=pcilib_kmem_get_block_ua(ctx,bank_ctx->kmem_base_address,0); + for(i=0;ctx->registers[i].name!=NULL;i++){ + if(ctx->registers[i].addr==addr) break; + } + *(pcilib_register_value_t*)(base_addr+i*sizeof(uint32_t))=value; return 0; } -- cgit v1.2.3