summaryrefslogtreecommitdiffstats
path: root/pcilib/pci.c
diff options
context:
space:
mode:
Diffstat (limited to 'pcilib/pci.c')
-rw-r--r--pcilib/pci.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/pcilib/pci.c b/pcilib/pci.c
index 62ac92d..f043257 100644
--- a/pcilib/pci.c
+++ b/pcilib/pci.c
@@ -25,6 +25,7 @@
#include "model.h"
#include "plugin.h"
#include "bar.h"
+#include "xml.h"
#include "locking.h"
static int pcilib_detect_model(pcilib_t *ctx, const char *model) {
@@ -107,6 +108,26 @@ pcilib_t *pcilib_open(const char *device, const char *model) {
int err;
size_t i;
pcilib_t *ctx = malloc(sizeof(pcilib_t));
+
+ pcilib_register_description_t *registers=NULL;
+ pcilib_register_bank_description_t *banks=NULL;
+ int number_registers, number_banks;
+
+ char *xmlfile;
+ pcilib_xml_read_config(&xmlfile,3);
+ xmlDocPtr doc;
+ doc=pcilib_xml_getdoc(xmlfile);
+
+ xmlXPathContextPtr context;
+ context=pcilib_xml_getcontext(doc);
+
+ number_registers=pcilib_xml_getnumberregisters(context);
+ number_banks=pcilib_xml_getnumberbanks(context);
+
+ if(number_registers)registers=calloc((number_registers),sizeof(pcilib_register_description_t));
+ else pcilib_error("no registers in the xml file");
+ if(number_banks)banks=calloc((number_banks),sizeof(pcilib_register_bank_description_t));
+ else pcilib_error("no banks in the xml file");
if (!model)
model = getenv("PCILIB_MODEL");
@@ -171,6 +192,17 @@ pcilib_t *pcilib_open(const char *device, const char *model) {
if (!ctx->model)
ctx->model = strdup(model?model:"pci");
+ if(banks){
+ pcilib_xml_initialize_banks(doc,banks);
+ pcilib_add_register_banks(ctx,number_banks,banks);
+ }else pcilib_error("no memory for banks");
+
+ if(registers){
+ pcilib_xml_initialize_registers(doc,registers);
+ pcilib_xml_arrange_registers(registers,number_registers);
+ pcilib_add_registers(ctx,number_registers,registers);
+ }else pcilib_error("no memory for registers");
+
ctx->model_info.registers = ctx->registers;
ctx->model_info.banks = ctx->banks;
ctx->model_info.protocols = ctx->protocols;
@@ -182,6 +214,7 @@ pcilib_t *pcilib_open(const char *device, const char *model) {
pcilib_close(ctx);
return NULL;
}
+
err = pcilib_init_event_engine(ctx);
if (err) {
@@ -277,6 +310,7 @@ int pcilib_map_data_space(pcilib_t *ctx, uintptr_t addr) {
char *pcilib_resolve_register_address(pcilib_t *ctx, pcilib_bar_t bar, uintptr_t addr) {
if (bar == PCILIB_BAR_DETECT) {
+ printf("bar = PCILIB_BAR_DETECT\n");
// First checking the default register bar
size_t offset = addr - ctx->board_info.bar_start[ctx->reg_bar];
if ((addr > ctx->board_info.bar_start[ctx->reg_bar])&&(offset < ctx->board_info.bar_length[ctx->reg_bar])) {
@@ -291,6 +325,7 @@ char *pcilib_resolve_register_address(pcilib_t *ctx, pcilib_bar_t bar, uintptr_t
// Otherwise trying to detect
bar = pcilib_detect_bar(ctx, addr, 1);
if (bar != PCILIB_BAR_INVALID) {
+ printf("bar pas ainvalid\n");
size_t offset = addr - ctx->board_info.bar_start[bar];
if ((offset < ctx->board_info.bar_length[bar])&&(ctx->bar_space[bar])) {
if (!ctx->bar_space[bar]) {
@@ -301,16 +336,21 @@ char *pcilib_resolve_register_address(pcilib_t *ctx, pcilib_bar_t bar, uintptr_t
}
}
} else {
+ printf("bar internal :%i\n",bar);
+ // printf("bar invalid\n");
if (!ctx->bar_space[bar]) {
pcilib_error("The requested bar (%i) is not mapped", bar);
return NULL;
}
if (addr < ctx->board_info.bar_length[bar]) {
+ printf("path1\n");
+ // printf("apres: %s\n",ctx->bar_space[bar] + addr);
return ctx->bar_space[bar] + addr + (ctx->board_info.bar_start[bar] & ctx->page_mask);
}
if ((addr >= ctx->board_info.bar_start[bar])&&(addr < (ctx->board_info.bar_start[bar] + ctx->board_info.bar_length[ctx->reg_bar]))) {
+ printf("path2\n");
return ctx->bar_space[bar] + (addr - ctx->board_info.bar_start[bar]) + (ctx->board_info.bar_start[bar] & ctx->page_mask);
}
}