/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-24 02:28:45 UTC
  • mfrom: (305.1.19 views)
  • Revision ID: csa@suren.me-20150924022845-p7hc8lh8v0q48g0r
Finalyze XML support and provide initial support for views (only descriptions so far)

Show diffs side-by-side

added added

removed removed

Lines of Context:
139
139
        }
140
140
 
141
141
        ctx->alloc_reg = PCILIB_DEFAULT_REGISTER_SPACE;
 
142
        ctx->alloc_views = PCILIB_DEFAULT_VIEW_SPACE;
 
143
        ctx->alloc_units = PCILIB_DEFAULT_UNIT_SPACE;
142
144
        ctx->registers = (pcilib_register_description_t *)malloc(PCILIB_DEFAULT_REGISTER_SPACE * sizeof(pcilib_register_description_t));
143
145
        ctx->register_ctx = (pcilib_register_context_t *)malloc(PCILIB_DEFAULT_REGISTER_SPACE * sizeof(pcilib_register_context_t));
 
146
        ctx->views = (pcilib_view_description_t**)malloc(PCILIB_DEFAULT_VIEW_SPACE * sizeof(pcilib_view_description_t*));
 
147
        ctx->units = (pcilib_unit_description_t*)malloc(PCILIB_DEFAULT_UNIT_SPACE * sizeof(pcilib_unit_description_t));
144
148
        
145
 
        if ((!ctx->registers)||(!ctx->register_ctx)) {
 
149
        if ((!ctx->registers)||(!ctx->register_ctx)||(!ctx->views)||(!ctx->units)) {
146
150
            pcilib_error("Error allocating memory for register model");
147
151
            pcilib_close(ctx);
148
152
            return NULL;
149
153
        }
150
154
        
 
155
        
151
156
        memset(ctx->registers, 0, sizeof(pcilib_register_description_t));
 
157
        memset(ctx->units, 0, sizeof(pcilib_unit_t));
 
158
        memset(ctx->views, 0, sizeof(pcilib_view_t));
152
159
        memset(ctx->banks, 0, sizeof(pcilib_register_bank_description_t));
153
160
        memset(ctx->ranges, 0, sizeof(pcilib_register_range_t));
154
161
 
191
198
        ctx->model_info.banks = ctx->banks;
192
199
        ctx->model_info.protocols = ctx->protocols;
193
200
        ctx->model_info.ranges = ctx->ranges;
 
201
        ctx->model_info.views = (const pcilib_view_description_t**)ctx->views;
 
202
        ctx->model_info.units = ctx->units;
194
203
 
195
204
        err = pcilib_init_register_banks(ctx);
196
205
        if (err) {
350
359
 
351
360
 
352
361
void pcilib_close(pcilib_t *ctx) {
353
 
    pcilib_bar_t i;
 
362
    int i;
 
363
    pcilib_bar_t bar;
354
364
 
355
365
    if (ctx) {
356
366
        pcilib_dma_engine_t dma;
370
380
 
371
381
        pcilib_free_register_banks(ctx);
372
382
 
373
 
        pcilib_free_xml(ctx);
374
 
        
375
 
        if (ctx->register_ctx)
 
383
        if (ctx->register_ctx) {
 
384
            pcilib_register_t reg;
 
385
            for (reg = 0; reg < ctx->num_reg; reg++) {
 
386
                if (ctx->register_ctx[reg].views)
 
387
                    free(ctx->register_ctx[reg].views);
 
388
            }
376
389
            free(ctx->register_ctx);
 
390
        }
377
391
 
378
392
        if (ctx->event_plugin)
379
393
            pcilib_plugin_close(ctx->event_plugin);
389
403
            }
390
404
        }
391
405
        
392
 
        for (i = 0; i < PCILIB_MAX_BARS; i++) {
393
 
            if (ctx->bar_space[i]) {
394
 
                char *ptr = ctx->bar_space[i];
395
 
                ctx->bar_space[i] = NULL;
396
 
                pcilib_unmap_bar(ctx, i, ptr);
 
406
        for (bar = 0; bar < PCILIB_MAX_BARS; bar++) {
 
407
            if (ctx->bar_space[bar]) {
 
408
                char *ptr = ctx->bar_space[bar];
 
409
                ctx->bar_space[bar] = NULL;
 
410
                pcilib_unmap_bar(ctx, bar, ptr);
397
411
            }
398
412
        }
399
413
        
400
414
        if (ctx->pci_cfg_space_fd >= 0)
401
415
            close(ctx->pci_cfg_space_fd);
402
416
 
 
417
        if (ctx->units);
 
418
            free(ctx->units);
 
419
 
 
420
        if (ctx->views) {
 
421
            for (i = 0; ctx->views[i]; i++)
 
422
                free(ctx->views[i]);
 
423
            free(ctx->views);
 
424
        }
 
425
 
403
426
        if (ctx->registers)
404
427
            free(ctx->registers);
405
428
        
406
429
        if (ctx->model)
407
430
            free(ctx->model);
408
431
 
 
432
        pcilib_free_xml(ctx);
 
433
 
409
434
        if (ctx->handle >= 0)
410
435
            close(ctx->handle);
411
436