/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 protocols/property.c

  • Committer: Suren A. Chilingaryan
  • Date: 2015-10-22 15:08:11 UTC
  • Revision ID: csa@suren.me-20151022150811-1l4cqcygra1phx0k
Fix access to the property-based registers

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
    pcilib_view_t view = addr / access;
18
18
    pcilib_value_t val = {0};
19
19
 
20
 
    if ((view == PCILIB_VIEW_INVALID)||(view >= ctx->num_views)||(addr % access))
21
 
        return PCILIB_ERROR_INVALID_ARGUMENT;
 
20
    if (addr % access) {
 
21
        pcilib_error("Can't perform unaligned access to property register (the address is 0x%lx and alligment requirement is %u)", addr, access);
 
22
        return PCILIB_ERROR_INVALID_ARGUMENT;
 
23
    }
 
24
 
 
25
    if ((view == PCILIB_VIEW_INVALID)||(view >= ctx->num_views))
 
26
        return PCILIB_ERROR_INVALID_ARGUMENT;
 
27
 
 
28
    if ((ctx->views[view]->flags&PCILIB_VIEW_FLAG_REGISTER) == 0) {
 
29
        pcilib_error("Accessing invalid register %u (associated view %u does not provide register functionality)", addr, view);
 
30
        return PCILIB_ERROR_INVALID_REQUEST;
 
31
    }
 
32
 
 
33
    if ((ctx->views[view]->mode&PCILIB_ACCESS_R) == 0) {
 
34
        pcilib_error("Read access is not allowed to register %u (view %u)", addr, view);
 
35
        return PCILIB_ERROR_NOTPERMITED;
 
36
    }
22
37
 
23
38
    err = pcilib_get_property(ctx, ctx->views[view]->name, &val);
24
39
    if (err) return err;
38
53
    pcilib_view_t view = addr / access;
39
54
    pcilib_value_t val = {0};
40
55
 
41
 
    if ((view == PCILIB_VIEW_INVALID)||(view >= ctx->num_views)||(addr % access))
42
 
        return PCILIB_ERROR_INVALID_ARGUMENT;
 
56
    if (addr % access) {
 
57
        pcilib_error("Can't perform unaligned access to property register (the address is 0x%lx and alligment requirement is %u)", addr, access);
 
58
        return PCILIB_ERROR_INVALID_ARGUMENT;
 
59
    }
 
60
 
 
61
    if ((view == PCILIB_VIEW_INVALID)||(view >= ctx->num_views))
 
62
        return PCILIB_ERROR_INVALID_ARGUMENT;
 
63
 
 
64
 
 
65
    if ((ctx->views[view]->flags&PCILIB_VIEW_FLAG_REGISTER) == 0) {
 
66
        pcilib_error("Accessing invalid register %u (associated view %u does not provide register functionality)", addr, view);
 
67
        return PCILIB_ERROR_INVALID_REQUEST;
 
68
    }
 
69
 
 
70
    if ((ctx->views[view]->mode&PCILIB_ACCESS_W) == 0) {
 
71
        pcilib_error("Write access is not allowed to register %u (view %u)", addr, view);
 
72
        return PCILIB_ERROR_NOTPERMITED;
 
73
    }
 
74
 
43
75
 
44
76
    err = pcilib_set_value_from_register_value(ctx, &val, regval);
45
77
    if (err) return err;