From 60c6bf9f6916b6ae2c05a499675ff54480256ece Mon Sep 17 00:00:00 2001 From: "nicolas.zilio@hotmail.fr" <> Date: Fri, 11 Sep 2015 19:40:33 +0200 Subject: more towards views --- pcilib/pci.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'pcilib/pci.c') diff --git a/pcilib/pci.c b/pcilib/pci.c index b7dcbcd..8c178f6 100644 --- a/pcilib/pci.c +++ b/pcilib/pci.c @@ -139,8 +139,12 @@ pcilib_t *pcilib_open(const char *device, const char *model) { } ctx->alloc_reg = PCILIB_DEFAULT_REGISTER_SPACE; + ctx->alloc_formula_views=PCILIB_DEFAULT_VIEW_SPACE; + ctx->alloc_enum_views=PCILIB_DEFAULT_VIEW_SPACE; ctx->registers = (pcilib_register_description_t *)malloc(PCILIB_DEFAULT_REGISTER_SPACE * sizeof(pcilib_register_description_t)); ctx->register_ctx = (pcilib_register_context_t *)malloc(PCILIB_DEFAULT_REGISTER_SPACE * sizeof(pcilib_register_context_t)); + ctx->enum_views = (pcilib_view_enum2_t *)malloc(PCILIB_DEFAULT_VIEW_SPACE * sizeof(pcilib_view_enum2_t)); + ctx->formula_views = (pcilib_view_formula_t*)malloc(PCILIB_DEFAULT_VIEW_SPACE * sizeof(pcilib_view_formula_t)); if ((!ctx->registers)||(!ctx->register_ctx)) { pcilib_error("Error allocating memory for register model"); @@ -148,12 +152,20 @@ pcilib_t *pcilib_open(const char *device, const char *model) { return NULL; } + if((!ctx->enum_views)||(!ctx->formula_views)){ + pcilib_error("Error allocating memory for views"); + pcilib_close(ctx); + return NULL; + } + 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)); + memset(ctx->enum_views,0,sizeof(pcilib_view_enum2_t)); + memset(ctx->formula_views,0,sizeof(pcilib_view_formula_t)); for (i = 0; pcilib_protocols[i].api; i++); memcpy(ctx->protocols, pcilib_protocols, i * sizeof(pcilib_register_protocol_description_t)); -- cgit v1.2.3 From 2dfb23016c39a331bf5ed4111b630dffa330edbb Mon Sep 17 00:00:00 2001 From: "nicolas.zilio@hotmail.fr" <> Date: Mon, 14 Sep 2015 11:56:38 +0200 Subject: views working fine, units in progress --- pcilib/pci.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'pcilib/pci.c') diff --git a/pcilib/pci.c b/pcilib/pci.c index 8c178f6..2742240 100644 --- a/pcilib/pci.c +++ b/pcilib/pci.c @@ -145,19 +145,24 @@ pcilib_t *pcilib_open(const char *device, const char *model) { ctx->register_ctx = (pcilib_register_context_t *)malloc(PCILIB_DEFAULT_REGISTER_SPACE * sizeof(pcilib_register_context_t)); ctx->enum_views = (pcilib_view_enum2_t *)malloc(PCILIB_DEFAULT_VIEW_SPACE * sizeof(pcilib_view_enum2_t)); ctx->formula_views = (pcilib_view_formula_t*)malloc(PCILIB_DEFAULT_VIEW_SPACE * sizeof(pcilib_view_formula_t)); + ctx->alloc_units=PCILIB_DEFAULT_UNIT_SPACE; + ctx->units=(pcilib_unit_t*)malloc(PCILIB_DEFAULT_UNIT_SPACE * sizeof(pcilib_unit_t)); + + if ((!ctx->registers)||(!ctx->register_ctx)) { pcilib_error("Error allocating memory for register model"); pcilib_close(ctx); return NULL; } - if((!ctx->enum_views)||(!ctx->formula_views)){ - pcilib_error("Error allocating memory for views"); - pcilib_close(ctx); - return NULL; + /* i think we need a better error handling here, because, it's not that a problem to not have views working, but how to block the use if the memory here was not good?, and we could have only one type of views that is working*/ + if((!ctx->enum_views)||(!ctx->formula_views) || (!ctx->units)){ + pcilib_warning("Error allocating memory for views"); } + + 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)); @@ -166,6 +171,7 @@ pcilib_t *pcilib_open(const char *device, const char *model) { memset(ctx->enum_views,0,sizeof(pcilib_view_enum2_t)); memset(ctx->formula_views,0,sizeof(pcilib_view_formula_t)); + memset(ctx->units,0,sizeof(pcilib_unit_t)); for (i = 0; pcilib_protocols[i].api; i++); memcpy(ctx->protocols, pcilib_protocols, i * sizeof(pcilib_register_protocol_description_t)); -- cgit v1.2.3 From de589562bd91cc60ee3e2d739bdd7a03063d38f7 Mon Sep 17 00:00:00 2001 From: "nicolas.zilio@hotmail.fr" <> Date: Mon, 14 Sep 2015 18:18:00 +0200 Subject: first try with pcilib_operation_t --- pcilib/pci.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'pcilib/pci.c') diff --git a/pcilib/pci.c b/pcilib/pci.c index 2742240..946b003 100644 --- a/pcilib/pci.c +++ b/pcilib/pci.c @@ -140,16 +140,16 @@ pcilib_t *pcilib_open(const char *device, const char *model) { ctx->alloc_reg = PCILIB_DEFAULT_REGISTER_SPACE; ctx->alloc_formula_views=PCILIB_DEFAULT_VIEW_SPACE; + ctx->alloc_views=PCILIB_DEFAULT_VIEW_SPACE; ctx->alloc_enum_views=PCILIB_DEFAULT_VIEW_SPACE; ctx->registers = (pcilib_register_description_t *)malloc(PCILIB_DEFAULT_REGISTER_SPACE * sizeof(pcilib_register_description_t)); ctx->register_ctx = (pcilib_register_context_t *)malloc(PCILIB_DEFAULT_REGISTER_SPACE * sizeof(pcilib_register_context_t)); ctx->enum_views = (pcilib_view_enum2_t *)malloc(PCILIB_DEFAULT_VIEW_SPACE * sizeof(pcilib_view_enum2_t)); ctx->formula_views = (pcilib_view_formula_t*)malloc(PCILIB_DEFAULT_VIEW_SPACE * sizeof(pcilib_view_formula_t)); + ctx->views = (pcilib_view_t*)malloc(PCILIB_DEFAULT_VIEW_SPACE * sizeof(pcilib_view_t)); ctx->alloc_units=PCILIB_DEFAULT_UNIT_SPACE; ctx->units=(pcilib_unit_t*)malloc(PCILIB_DEFAULT_UNIT_SPACE * sizeof(pcilib_unit_t)); - - if ((!ctx->registers)||(!ctx->register_ctx)) { pcilib_error("Error allocating memory for register model"); pcilib_close(ctx); @@ -157,7 +157,7 @@ pcilib_t *pcilib_open(const char *device, const char *model) { } /* i think we need a better error handling here, because, it's not that a problem to not have views working, but how to block the use if the memory here was not good?, and we could have only one type of views that is working*/ - if((!ctx->enum_views)||(!ctx->formula_views) || (!ctx->units)){ + if((!ctx->enum_views)||(!ctx->formula_views) || (!ctx->units) || !(ctx->views)){ pcilib_warning("Error allocating memory for views"); } @@ -172,6 +172,7 @@ pcilib_t *pcilib_open(const char *device, const char *model) { memset(ctx->enum_views,0,sizeof(pcilib_view_enum2_t)); memset(ctx->formula_views,0,sizeof(pcilib_view_formula_t)); memset(ctx->units,0,sizeof(pcilib_unit_t)); + memset(ctx->views,0,sizeof(pcilib_view_t)); for (i = 0; pcilib_protocols[i].api; i++); memcpy(ctx->protocols, pcilib_protocols, i * sizeof(pcilib_register_protocol_description_t)); -- cgit v1.2.3 From 6c47064466d8484813741f347e41af1d4ac90f85 Mon Sep 17 00:00:00 2001 From: "nicolas.zilio@hotmail.fr" <> Date: Tue, 15 Sep 2015 11:45:37 +0200 Subject: cleaning --- pcilib/pci.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'pcilib/pci.c') diff --git a/pcilib/pci.c b/pcilib/pci.c index 946b003..b37e817 100644 --- a/pcilib/pci.c +++ b/pcilib/pci.c @@ -139,13 +139,9 @@ pcilib_t *pcilib_open(const char *device, const char *model) { } ctx->alloc_reg = PCILIB_DEFAULT_REGISTER_SPACE; - ctx->alloc_formula_views=PCILIB_DEFAULT_VIEW_SPACE; ctx->alloc_views=PCILIB_DEFAULT_VIEW_SPACE; - ctx->alloc_enum_views=PCILIB_DEFAULT_VIEW_SPACE; ctx->registers = (pcilib_register_description_t *)malloc(PCILIB_DEFAULT_REGISTER_SPACE * sizeof(pcilib_register_description_t)); ctx->register_ctx = (pcilib_register_context_t *)malloc(PCILIB_DEFAULT_REGISTER_SPACE * sizeof(pcilib_register_context_t)); - ctx->enum_views = (pcilib_view_enum2_t *)malloc(PCILIB_DEFAULT_VIEW_SPACE * sizeof(pcilib_view_enum2_t)); - ctx->formula_views = (pcilib_view_formula_t*)malloc(PCILIB_DEFAULT_VIEW_SPACE * sizeof(pcilib_view_formula_t)); ctx->views = (pcilib_view_t*)malloc(PCILIB_DEFAULT_VIEW_SPACE * sizeof(pcilib_view_t)); ctx->alloc_units=PCILIB_DEFAULT_UNIT_SPACE; ctx->units=(pcilib_unit_t*)malloc(PCILIB_DEFAULT_UNIT_SPACE * sizeof(pcilib_unit_t)); @@ -157,7 +153,7 @@ pcilib_t *pcilib_open(const char *device, const char *model) { } /* i think we need a better error handling here, because, it's not that a problem to not have views working, but how to block the use if the memory here was not good?, and we could have only one type of views that is working*/ - if((!ctx->enum_views)||(!ctx->formula_views) || (!ctx->units) || !(ctx->views)){ + if((!ctx->units) || !(ctx->views)){ pcilib_warning("Error allocating memory for views"); } @@ -169,8 +165,6 @@ pcilib_t *pcilib_open(const char *device, const char *model) { memset(ctx->register_ctx, 0, PCILIB_DEFAULT_REGISTER_SPACE * sizeof(pcilib_register_context_t)); - memset(ctx->enum_views,0,sizeof(pcilib_view_enum2_t)); - memset(ctx->formula_views,0,sizeof(pcilib_view_formula_t)); memset(ctx->units,0,sizeof(pcilib_unit_t)); memset(ctx->views,0,sizeof(pcilib_view_t)); -- cgit v1.2.3