/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-04-28 04:09:21 UTC
  • Revision ID: csa@suren.me-20150428040921-fjyahuk824lihv1i
Initial support for event engines

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include "tools.h"
21
21
#include "error.h"
22
22
#include "model.h"
 
23
#include "plugin.h"
23
24
 
24
25
static int pcilib_detect_model(pcilib_t *ctx, const char *model) {
25
26
    int i, j;
26
27
 
27
 
        // Registers & Banks must be copied!
 
28
    const pcilib_model_description_t *model_info = NULL;
 
29
    const pcilib_board_info_t *board_info = pcilib_get_board_info(ctx);
28
30
 
29
 
    if (model) {
30
 
            // Check for DMA models
 
31
    model_info = pcilib_find_plugin_model(ctx, board_info->vendor_id, board_info->device_id, model);
 
32
    if (model_info) {
 
33
        memcpy(&ctx->model_info, model_info, sizeof(pcilib_model_description_t));
 
34
        memcpy(&ctx->dma, model_info->dma, sizeof(pcilib_dma_description_t));
 
35
    } else if (model) {
 
36
            // If not found, check for DMA models
31
37
        for (i = 0; pcilib_dma[i].name; i++) {
32
38
            if (!strcasecmp(model, pcilib_dma[i].name))
33
39
                break;
34
40
        }
35
41
 
36
42
        if (pcilib_dma[i].api) {
 
43
            model_info = &ctx->model_info;
37
44
            memcpy(&ctx->dma, &pcilib_dma[i], sizeof(pcilib_dma_description_t));
38
45
            ctx->model_info.dma = &ctx->dma;
39
 
 
40
 
            if (pcilib_dma[i].banks)
41
 
                pcilib_add_register_banks(ctx, 0, pcilib_dma[i].banks);
42
 
            
43
 
            if (pcilib_dma[i].registers)
44
 
                pcilib_add_registers(ctx, 0, pcilib_dma[i].registers);
45
 
 
46
 
            if (pcilib_dma[i].engines) {
47
 
                for (j = 0; pcilib_dma[i].engines[j].addr_bits; j++)
48
 
                memcpy(ctx->engines, pcilib_dma[i].engines, j * sizeof(pcilib_dma_engine_description_t));
 
46
        }
 
47
    }
 
48
 
 
49
            // Precedens of register configuration: DMA/Event Initialization (top), XML, Event Description, DMA Description (least)
 
50
    if (model_info) {
 
51
        const pcilib_dma_description_t *dma = model_info->dma;
 
52
 
 
53
        if (dma) {
 
54
            if (dma->banks)
 
55
                pcilib_add_register_banks(ctx, 0, dma->banks);
 
56
 
 
57
            if (dma->registers)
 
58
                pcilib_add_registers(ctx, 0, dma->registers);
 
59
 
 
60
            if (dma->engines) {
 
61
                for (j = 0; dma->engines[j].addr_bits; j++);
 
62
                memcpy(ctx->engines, dma->engines, j * sizeof(pcilib_dma_engine_description_t));
49
63
                ctx->num_engines = j;
50
64
            } else
51
65
                ctx->dma.engines = ctx->engines;
52
 
 
53
 
            return 0;
54
66
        }
55
67
 
56
 
        // Check for XML models (DMA + XML registers)
 
68
        if (model_info->protocols)
 
69
            pcilib_add_register_protocols(ctx, 0, model_info->protocols);
 
70
                
 
71
        if (model_info->banks)
 
72
            pcilib_add_register_banks(ctx, 0, model_info->banks);
57
73
 
58
 
        // Check for specified model
59
 
        
60
 
        // Iterate other all other models
 
74
        if (model_info->registers)
 
75
            pcilib_add_registers(ctx, 0, model_info->registers);
 
76
                
 
77
        if (model_info->ranges)
 
78
            pcilib_add_register_ranges(ctx, 0, model_info->ranges);
61
79
    }
62
80
 
 
81
    // Load XML registers
 
82
 
63
83
    // Check for all installed models
64
84
    // memcpy(&ctx->model_info, model, sizeof(pcilib_model_description_t));
65
85
    // how we reconcile the banks from event model and dma description? The banks specified in the DMA description should override corresponding banks of events...
66
86
 
67
87
 
68
 
    if (model)
 
88
    if ((model)&&(!model_info)/*&&(no xml)*/)
69
89
        return PCILIB_ERROR_NOTFOUND;
70
90
 
71
 
        // Otherwise, simple pci access (all model members are set to NULL)
72
 
 
73
91
    return 0;
74
92
}
75
93
 
113
131
        
114
132
        for (i = 0; pcilib_protocols[i].api; i++);
115
133
        memcpy(ctx->protocols, pcilib_protocols, i * sizeof(pcilib_register_protocol_description_t));
116
 
 
117
 
        ctx->model_info.registers = ctx->registers;
118
 
        ctx->model_info.banks = ctx->banks;
119
 
        ctx->model_info.protocols = ctx->protocols;
120
 
        ctx->model_info.ranges = ctx->ranges;
 
134
        ctx->num_protocols = i;
121
135
 
122
136
        err = pcilib_detect_model(ctx, model);
123
137
        if (err) {
131
145
            return NULL;
132
146
        }
133
147
 
 
148
        ctx->model_info.registers = ctx->registers;
 
149
        ctx->model_info.banks = ctx->banks;
 
150
        ctx->model_info.protocols = ctx->protocols;
 
151
        ctx->model_info.ranges = ctx->ranges;
 
152
 
 
153
 
134
154
        err = pcilib_init_register_banks(ctx);
135
155
        if (err) {
136
156
            pcilib_error("Error (%i) initializing regiser banks\n", err);
451
471
 
452
472
        pcilib_free_register_banks(ctx);
453
473
        
 
474
        if (ctx->event_plugin)
 
475
            pcilib_plugin_close(ctx->event_plugin);
 
476
        
454
477
        if (ctx->kmem_list) {
455
478
            pcilib_warning("Not all kernel buffers are properly cleaned");
456
479