/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 13:57:59 UTC
  • Revision ID: csa@suren.me-20151022135759-nqs5wowy38tvbw09
Documentation update

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
#include "error.h"
9
9
 
10
10
 
11
 
int pcilib_property_registers_read(pcilib_t *ctx, pcilib_register_bank_context_t *bank, pcilib_register_addr_t addr, pcilib_register_value_t *regval) {
 
11
int pcilib_property_registers_read(pcilib_t *ctx, pcilib_register_bank_context_t *bank_ctx, pcilib_register_addr_t addr, pcilib_register_value_t *regval) {
12
12
    int err;
13
13
 
14
 
    pcilib_view_t view = addr;
 
14
    const pcilib_register_bank_description_t *b = bank_ctx->bank;
 
15
    int access = b->access / 8;
 
16
 
 
17
    pcilib_view_t view = addr / access;
15
18
    pcilib_value_t val = {0};
16
19
 
17
 
    if ((view == PCILIB_VIEW_INVALID)||(view >= ctx->num_views))
 
20
    if ((view == PCILIB_VIEW_INVALID)||(view >= ctx->num_views)||(addr % access))
18
21
        return PCILIB_ERROR_INVALID_ARGUMENT;
19
22
 
20
23
    err = pcilib_get_property(ctx, ctx->views[view]->name, &val);
26
29
}
27
30
 
28
31
 
29
 
int pcilib_property_registers_write(pcilib_t *ctx, pcilib_register_bank_context_t *bank, pcilib_register_addr_t addr, pcilib_register_value_t regval) {
 
32
int pcilib_property_registers_write(pcilib_t *ctx, pcilib_register_bank_context_t *bank_ctx, pcilib_register_addr_t addr, pcilib_register_value_t regval) {
30
33
    int err;
31
34
 
32
 
    pcilib_view_t view = addr;
 
35
    const pcilib_register_bank_description_t *b = bank_ctx->bank;
 
36
    int access = b->access / 8;
 
37
 
 
38
    pcilib_view_t view = addr / access;
33
39
    pcilib_value_t val = {0};
34
40
 
35
 
    if ((view == PCILIB_VIEW_INVALID)||(view >= ctx->num_views))
 
41
    if ((view == PCILIB_VIEW_INVALID)||(view >= ctx->num_views)||(addr % access))
36
42
        return PCILIB_ERROR_INVALID_ARGUMENT;
37
43
 
38
44
    err = pcilib_set_value_from_register_value(ctx, &val, regval);