/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-11-19 01:21:30 UTC
  • Revision ID: csa@suren.me-20151119012130-e7qfp7563fqxqhiy
Driver versioning

Show diffs side-by-side

added added

removed removed

Lines of Context:
108
108
pcilib_t *pcilib_open(const char *device, const char *model) {
109
109
    int err, xmlerr;
110
110
    pcilib_t *ctx = malloc(sizeof(pcilib_t));
 
111
    const pcilib_driver_version_t *drv_version;
111
112
        
112
113
    if (!model)
113
114
        model = getenv("PCILIB_MODEL");
123
124
            return NULL;
124
125
        }
125
126
        
 
127
        drv_version = pcilib_get_driver_version(ctx);
 
128
        if (!drv_version) {
 
129
            pcilib_error("Driver verification has failed (%s)", device);
 
130
            free(ctx);
 
131
            return NULL;
 
132
        }
 
133
        
126
134
        ctx->page_mask = (uintptr_t)-1;
127
135
        
128
136
        if ((model)&&(!strcasecmp(model, "maintenance"))) {
224
232
}
225
233
 
226
234
 
 
235
const pcilib_driver_version_t *pcilib_get_driver_version(pcilib_t *ctx) {
 
236
    int ret;
 
237
    
 
238
    if (!ctx->driver_version.version) {
 
239
        ret = ioctl( ctx->handle, PCIDRIVER_IOC_VERSION, &ctx->driver_version );
 
240
        if (ret) {
 
241
            pcilib_error("PCIDRIVER_IOC_DRIVER_VERSION ioctl have failed");
 
242
            return NULL;
 
243
        }
 
244
        
 
245
        if (ctx->driver_version.interface != PCIDRIVER_INTERFACE_VERSION) {
 
246
            pcilib_error("Using pcilib (version: %u.%u.%u, driver interface: 0x%lx) with incompatible driver (version: %u.%u.%u, interface: 0x%lx)", 
 
247
                PCILIB_VERSION_GET_MAJOR(PCILIB_VERSION),
 
248
                PCILIB_VERSION_GET_MINOR(PCILIB_VERSION),
 
249
                PCILIB_VERSION_GET_MICRO(PCILIB_VERSION),
 
250
                PCIDRIVER_INTERFACE_VERSION,
 
251
                PCILIB_VERSION_GET_MAJOR(ctx->driver_version.version),
 
252
                PCILIB_VERSION_GET_MINOR(ctx->driver_version.version),
 
253
                PCILIB_VERSION_GET_MICRO(ctx->driver_version.version),
 
254
                ctx->driver_version.interface
 
255
            );
 
256
            return NULL;
 
257
        }
 
258
    }
 
259
 
 
260
    return &ctx->driver_version;
 
261
}
 
262
 
227
263
const pcilib_board_info_t *pcilib_get_board_info(pcilib_t *ctx) {
228
264
    int ret;
229
265
    
236
272
        
237
273
        ctx->page_mask = pcilib_get_page_mask();
238
274
    }
239
 
    
 
275
 
240
276
    return &ctx->board_info;
241
277
}
242
278
 
432
468
    return &ctx->link_info;
433
469
}
434
470
 
 
471
int pcilib_get_device_state(pcilib_t *ctx, pcilib_device_state_t *state) {
 
472
    int ret = ioctl( ctx->handle, PCIDRIVER_IOC_DEVICE_STATE, state);
 
473
    if (ret < 0) {
 
474
        pcilib_error("PCIDRIVER_IOC_DEVICE_STATE ioctl have failed");
 
475
        return PCILIB_ERROR_FAILED;
 
476
    }
 
477
    return 0;
 
478
}
 
479
 
435
480
int pcilib_set_dma_mask(pcilib_t *ctx, int mask) {
436
 
    if (ioctl( ctx->handle, PCIDRIVER_IOC_SET_DMA_MASK, mask ) < 0)
 
481
    if (ioctl(ctx->handle, PCIDRIVER_IOC_DMA_MASK, mask) < 0)
437
482
        return PCILIB_ERROR_FAILED;
438
483
 
439
484
    return 0;