From a0fe5cdea15bca52d3b101a88c11cb160ef08b2f Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Thu, 22 Oct 2015 15:57:59 +0200 Subject: Documentation update --- pcilib/pci.c | 124 ++--------------------------------------------------------- 1 file changed, 3 insertions(+), 121 deletions(-) (limited to 'pcilib/pci.c') diff --git a/pcilib/pci.c b/pcilib/pci.c index ae892a2..4b8b8bb 100644 --- a/pcilib/pci.c +++ b/pcilib/pci.c @@ -107,7 +107,6 @@ static int pcilib_detect_model(pcilib_t *ctx, const char *model) { pcilib_t *pcilib_open(const char *device, const char *model) { int err, xmlerr; - size_t i; pcilib_t *ctx = malloc(sizeof(pcilib_t)); if (!model) @@ -167,10 +166,9 @@ pcilib_t *pcilib_open(const char *device, const char *model) { 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)); - ctx->num_protocols = i; + pcilib_add_register_protocols(ctx, PCILIB_MODEL_MODIFICATON_FLAGS_DEFAULT, 0, pcilib_standard_register_protocols, NULL); + pcilib_add_register_banks(ctx, PCILIB_MODEL_MODIFICATON_FLAGS_DEFAULT, 0, pcilib_standard_register_banks, NULL); + pcilib_add_registers(ctx, PCILIB_MODEL_MODIFICATON_FLAGS_DEFAULT, 0, pcilib_standard_registers, NULL); err = pcilib_detect_model(ctx, model); if ((err)&&(err != PCILIB_ERROR_NOTFOUND)) { @@ -248,122 +246,6 @@ pcilib_context_t *pcilib_get_implementation_context(pcilib_t *ctx) { } -int pcilib_map_data_space(pcilib_t *ctx, uintptr_t addr) { - int err; - pcilib_bar_t i; - - if (!ctx->data_bar_mapped) { - const pcilib_board_info_t *board_info = pcilib_get_board_info(ctx); - if (!board_info) return PCILIB_ERROR_FAILED; - - err = pcilib_map_register_space(ctx); - if (err) { - pcilib_error("Error mapping register space"); - return err; - } - - int data_bar = -1; - - for (i = 0; i < PCILIB_MAX_BARS; i++) { - if ((ctx->bar_space[i])||(!board_info->bar_length[i])) continue; - - if (addr) { - if (board_info->bar_start[i] == addr) { - data_bar = i; - break; - } - } else { - if (data_bar >= 0) { - data_bar = -1; - break; - } - - data_bar = i; - } - } - - - if (data_bar < 0) { - if (addr) pcilib_error("Unable to find the specified data space (%lx)", addr); - else pcilib_error("Unable to find the data space"); - return PCILIB_ERROR_NOTFOUND; - } - - ctx->data_bar = data_bar; - - if (!ctx->bar_space[data_bar]) { - char *data_space = pcilib_map_bar(ctx, data_bar); - if (data_space) ctx->bar_space[data_bar] = data_space; - else { - pcilib_error("Unable to map the data space"); - return PCILIB_ERROR_FAILED; - } - } - - ctx->data_bar_mapped = 0; - } - - return 0; -} - -char *pcilib_resolve_register_address(pcilib_t *ctx, pcilib_bar_t bar, uintptr_t addr) { - if (bar == PCILIB_BAR_DETECT) { - // 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])) { - if (!ctx->bar_space[ctx->reg_bar]) { - pcilib_error("The register bar is not mapped"); - return NULL; - } - - return ctx->bar_space[ctx->reg_bar] + offset + (ctx->board_info.bar_start[ctx->reg_bar] & ctx->page_mask); - } - - // Otherwise trying to detect - bar = pcilib_detect_bar(ctx, addr, 1); - if (bar != PCILIB_BAR_INVALID) { - 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]) { - pcilib_error("The requested bar (%i) is not mapped", bar); - return NULL; - } - return ctx->bar_space[bar] + offset + (ctx->board_info.bar_start[bar] & ctx->page_mask); - } - } - } else { - 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]) { - 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]))) { - return ctx->bar_space[bar] + (addr - ctx->board_info.bar_start[bar]) + (ctx->board_info.bar_start[bar] & ctx->page_mask); - } - } - - return NULL; -} - -char *pcilib_resolve_data_space(pcilib_t *ctx, uintptr_t addr, size_t *size) { - int err; - - err = pcilib_map_data_space(ctx, addr); - if (err) { - pcilib_error("Failed to map the specified address space (%lx)", addr); - return NULL; - } - - if (size) *size = ctx->board_info.bar_length[ctx->data_bar]; - - return ctx->bar_space[ctx->data_bar] + (ctx->board_info.bar_start[ctx->data_bar] & ctx->page_mask); -} - - void pcilib_close(pcilib_t *ctx) { pcilib_bar_t bar; -- cgit v1.2.3