/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/software.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:
12
12
 
13
13
typedef struct pcilib_software_register_bank_context_s pcilib_software_register_bank_context_t;
14
14
 
 
15
/**
 
16
 * structure defining the context of software registers
 
17
 */
15
18
struct pcilib_software_register_bank_context_s {
16
 
    pcilib_register_bank_context_t bank_ctx;     /**< the bank context associated with the software registers */
17
 
 
 
19
    pcilib_register_bank_context_t bank_ctx;    /**< the bank context associated with the software registers */
18
20
    pcilib_kmem_handle_t *kmem;                 /**< the kernel memory for software registers */
19
21
    void *addr;                                 /**< the virtual adress of the allocated kernel memory*/
20
22
};
21
23
 
22
 
/**
23
 
 * pcilib_software_registers_close
24
 
 * this function clear the kernel memory space that could have been allocated for software registers
25
 
 * @param[in] bank_ctx the bank context running that we get from the initialisation function
26
 
 */     
27
24
void pcilib_software_registers_close(pcilib_t *ctx, pcilib_register_bank_context_t *bank_ctx) {
28
25
        if (((pcilib_software_register_bank_context_t*)bank_ctx)->kmem)
29
26
            pcilib_free_kernel_memory(ctx, ((pcilib_software_register_bank_context_t*)bank_ctx)->kmem, PCILIB_KMEM_FLAG_REUSE);
30
27
        free(bank_ctx);
31
28
}
32
29
 
33
 
/**
34
 
 * pcilib_software_registers_open
35
 
 * this function initializes the kernel space memory and stores in it the default values of the registers of the given bank index, if it was not initialized by a concurrent process, and return a bank context containing the adress of this kernel space. It the kernel space memory was already initialized by a concurrent process, then this function just return the bank context with the adress of this kernel space already used
36
 
 * @param[in] ctx the pcilib_t structure running
37
 
 * @param[in] bank the bank index that will permits to get the bank we want registers from
38
 
 * @param[in] model not used
39
 
 * @param[in] args not used
40
 
 * @return a bank context with the adress of the kernel space memory related to it
41
 
 */
42
30
pcilib_register_bank_context_t* pcilib_software_registers_open(pcilib_t *ctx, pcilib_register_bank_t bank, const char* model, const void *args) {
43
31
        int err;
44
32
        pcilib_software_register_bank_context_t *bank_ctx;
59
47
            return NULL;
60
48
        }
61
49
 
 
50
        /*we get a lock to protect the creation of the kernel space for software registers against multiple creations*/
62
51
        lock = pcilib_get_lock(ctx, PCILIB_LOCK_FLAGS_DEFAULT, "softreg/%s", bank_desc->name);
63
52
        if (!lock) {
64
53
            pcilib_software_registers_close(ctx, (pcilib_register_bank_context_t*)bank_ctx);
74
63
            return NULL;
75
64
        }
76
65
 
77
 
 
 
66
        /*creation of the kernel space*/
78
67
        handle = pcilib_alloc_kernel_memory(ctx, PCILIB_KMEM_TYPE_PAGE, 1, PCILIB_KMEM_PAGE_SIZE, 0, PCILIB_KMEM_USE(PCILIB_KMEM_USE_SOFTWARE_REGISTERS, bank_desc->addr), PCILIB_KMEM_FLAG_REUSE|PCILIB_KMEM_FLAG_PERSISTENT);
79
68
        if (!handle) {
80
69
            pcilib_unlock(lock);
98
87
                pcilib_error("Inconsistent software registers are found (only part of required buffers is available)");
99
88
                return NULL;
100
89
            }
101
 
                
 
90
 
 
91
        /* here we fill the software registers with their default value*/               
102
92
            for (i = 0; ctx->model_info.registers[i].name != NULL; i++) {
103
93
                if ((ctx->model_info.registers[i].bank == ctx->banks[bank].addr)&&(ctx->model_info.registers[i].type == PCILIB_REGISTER_STANDARD)) {
104
94
                    *(pcilib_register_value_t*)(bank_ctx->addr + ctx->model_info.registers[i].addr) = ctx->model_info.registers[i].defvalue;
112
102
        return (pcilib_register_bank_context_t*)bank_ctx;
113
103
}
114
104
 
115
 
/**
116
 
 * pcilib_software_registers_read
117
 
 * this function read the value of a said register in the kernel space
118
 
 * @param[in] ctx the pcilib_t structure runnning
119
 
 * @param[in] bank_ctx the bank context that was returned by the initialisation function
120
 
 * @param[in] addr the adress of the register we want to read
121
 
 * @param[out] value the value of the register
122
 
 * @return 0 in case of success
123
 
 */
124
105
int pcilib_software_registers_read(pcilib_t *ctx, pcilib_register_bank_context_t *bank_ctx, pcilib_register_addr_t addr, pcilib_register_value_t *value){
125
106
        if ((addr + sizeof(pcilib_register_value_t)) > bank_ctx->bank->size) {
126
107
            pcilib_error("Trying to access space outside of the define register bank (bank: %s, addr: 0x%lx)", bank_ctx->bank->name, addr);
132
113
        return 0;
133
114
}
134
115
 
135
 
/**
136
 
 * pcilib_software_registers_write
137
 
 * this function write the said value to a said register in the kernel space
138
 
 * @param[in] ctx the pcilib_t structure runnning
139
 
 * @param[in] bank_ctx the bank context that was returned by the initialisation function
140
 
 * @param[in] addr the adress of the register we want to write in
141
 
 * @param[out] value the value we want to write in the register
142
 
 * @return 0 in case of success
143
 
 */
144
116
int pcilib_software_registers_write(pcilib_t *ctx, pcilib_register_bank_context_t *bank_ctx, pcilib_register_addr_t addr, pcilib_register_value_t value) {
145
117
        if ((addr + sizeof(pcilib_register_value_t)) > bank_ctx->bank->size) {
146
118
            pcilib_error("Trying to access space outside of the define register bank (bank: %s, addr: 0x%lx)", bank_ctx->bank->name, addr);