/alps/pcitool

To get this branch, use:
bzr branch http://suren.me/webbzr/alps/pcitool

« back to all changes in this revision

Viewing changes to pcilib/pci.c

  • Committer: Suren A. Chilingaryan
  • Date: 2015-09-10 03:08:04 UTC
  • mfrom: (277.2.17 test_xml)
  • Revision ID: csa@suren.me-20150910030804-djti3wcmk4yubhp7
Initial integration of XML support

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#include "model.h"
27
27
#include "plugin.h"
28
28
#include "bar.h"
 
29
#include "xml.h"
29
30
#include "locking.h"
30
31
 
31
32
static int pcilib_detect_model(pcilib_t *ctx, const char *model) {
59
60
 
60
61
        if (dma) {
61
62
            if (dma->banks)
62
 
                pcilib_add_register_banks(ctx, 0, dma->banks);
 
63
                pcilib_add_register_banks(ctx, PCILIB_MODEL_MODIFICATON_FLAGS_DEFAULT, 0, dma->banks, NULL);
63
64
 
64
65
            if (dma->registers)
65
 
                pcilib_add_registers(ctx, 0, dma->registers);
 
66
                pcilib_add_registers(ctx, PCILIB_MODEL_MODIFICATON_FLAGS_DEFAULT, 0, dma->registers, NULL);
66
67
 
67
68
            if (dma->engines) {
68
69
                for (j = 0; dma->engines[j].addr_bits; j++);
73
74
        }
74
75
 
75
76
        if (model_info->protocols)
76
 
            pcilib_add_register_protocols(ctx, 0, model_info->protocols);
 
77
            pcilib_add_register_protocols(ctx, PCILIB_MODEL_MODIFICATON_FLAGS_DEFAULT, 0, model_info->protocols, NULL);
77
78
                
78
79
        if (model_info->banks)
79
 
            pcilib_add_register_banks(ctx, 0, model_info->banks);
 
80
            pcilib_add_register_banks(ctx, PCILIB_MODEL_MODIFICATON_FLAGS_DEFAULT, 0, model_info->banks, NULL);
80
81
 
81
82
        if (model_info->registers)
82
 
            pcilib_add_registers(ctx, 0, model_info->registers);
 
83
            pcilib_add_registers(ctx, PCILIB_MODEL_MODIFICATON_FLAGS_DEFAULT, 0, model_info->registers, NULL);
83
84
                
84
85
        if (model_info->ranges)
85
 
            pcilib_add_register_ranges(ctx, 0, model_info->ranges);
 
86
            pcilib_add_register_ranges(ctx, PCILIB_MODEL_MODIFICATON_FLAGS_DEFAULT, 0, model_info->ranges);
86
87
    }
87
88
 
88
89
    // Load XML registers
105
106
 
106
107
 
107
108
pcilib_t *pcilib_open(const char *device, const char *model) {
108
 
    int err;
 
109
    int err, xmlerr;
109
110
    size_t i;
110
111
    pcilib_t *ctx = malloc(sizeof(pcilib_t));
111
 
 
 
112
        
112
113
    if (!model)
113
114
        model = getenv("PCILIB_MODEL");
114
115
 
159
160
        ctx->num_protocols = i;
160
161
 
161
162
        err = pcilib_detect_model(ctx, model);
162
 
        if (err) {
 
163
        if ((err)&&(err != PCILIB_ERROR_NOTFOUND)) {
163
164
            const pcilib_board_info_t *board_info = pcilib_get_board_info(ctx);
164
165
            if (board_info)
165
166
                pcilib_error("Error (%i) configuring model %s (%x:%x)", err, (model?model:""), board_info->vendor_id, board_info->device_id);
171
172
 
172
173
        if (!ctx->model)
173
174
            ctx->model = strdup(model?model:"pci");
 
175
        
 
176
        xmlerr = pcilib_init_xml(ctx, ctx->model);
 
177
        if ((xmlerr)&&(xmlerr != PCILIB_ERROR_NOTFOUND)) {
 
178
            pcilib_error("Error (%i) initializing XML subsystem for model %s", xmlerr, ctx->model);
 
179
            pcilib_close(ctx);
 
180
            return NULL;
 
181
        }
174
182
 
 
183
            // We have found neither standard model nor XML
 
184
        if ((err)&&(xmlerr)) {
 
185
            pcilib_error("The specified model (%s) is not available", model);
 
186
            pcilib_close(ctx);
 
187
            return NULL;
 
188
        }
 
189
        
175
190
        ctx->model_info.registers = ctx->registers;
176
191
        ctx->model_info.banks = ctx->banks;
177
192
        ctx->model_info.protocols = ctx->protocols;
354
369
        }
355
370
 
356
371
        pcilib_free_register_banks(ctx);
 
372
 
 
373
        pcilib_free_xml(ctx);
357
374
        
358
375
        if (ctx->register_ctx)
359
376
            free(ctx->register_ctx);