/alps/pcitool

To get this branch, use:
bzr branch http://suren.me/webbzr/alps/pcitool
236 by Suren A. Chilingaryan
Big redign of model structures
1
#ifndef _PCILIB_BANK_H
2
#define _PCILIB_BANK_H
3
4
#include <pcilib.h>
5
6
#define PCILIB_REGISTER_BANK_INVALID		((pcilib_register_bank_t)-1)
7
#define PCILIB_REGISTER_BANK0 			0					/**< First BANK to be used in the event engine */
8
#define PCILIB_REGISTER_BANK1 			1
9
#define PCILIB_REGISTER_BANK2 			2
10
#define PCILIB_REGISTER_BANK3 			3
324 by Suren A. Chilingaryan
Documentation update
11
#define PCILIB_REGISTER_BANK_CONF		64					/**< Configuration registers */
12
#define PCILIB_REGISTER_BANK_PROPERTY           65                                      /**< Registers abstracting properties and other computed registers */
321 by Suren A. Chilingaryan
Support computed (property-based) registers
13
#define PCILIB_REGISTER_BANK_DMACONF		96					/**< DMA configuration in the software registers */
324 by Suren A. Chilingaryan
Documentation update
14
#define PCILIB_REGISTER_BANK_DMA		97					/**< First BANK address to be used by DMA engines */
332 by Suren A. Chilingaryan
Provide API calls for register and bank address resolution
15
#define PCILIB_REGISTER_BANK_DMA0		PCILIB_REGISTER_BANK_DMA		/**< First BANK address to be used by DMA engines */
16
#define PCILIB_REGISTER_BANK_DMA1		(PCILIB_REGISTER_BANK_DMA + 1)		/**< Second BANK address to be used by DMA engines */
17
#define PCILIB_REGISTER_BANK_DMA2		(PCILIB_REGISTER_BANK_DMA + 2)		/**< Third BANK address to be used by DMA engines */
18
#define PCILIB_REGISTER_BANK_DMA3		(PCILIB_REGISTER_BANK_DMA + 3)		/**< Fourth BANK address to be used by DMA engines */
236 by Suren A. Chilingaryan
Big redign of model structures
19
#define PCILIB_REGISTER_BANK_DYNAMIC		128					/**< First BANK address to map dynamic XML configuration */
20
#define PCILIB_REGISTER_PROTOCOL_INVALID	((pcilib_register_protocol_t)-1)
21
#define PCILIB_REGISTER_PROTOCOL0		0					/**< First PROTOCOL address to be used in the event engine */
22
#define PCILIB_REGISTER_PROTOCOL_DEFAULT	64					/**< Default memmap based protocol */
275 by Suren A. Chilingaryan
Integration of software registers
23
#define PCILIB_REGISTER_PROTOCOL_SOFTWARE	65					/**< Software registers */
321 by Suren A. Chilingaryan
Support computed (property-based) registers
24
#define PCILIB_REGISTER_PROTOCOL_PROPERTY       66                                      /**< Protocol to access registers interfacing properties */
236 by Suren A. Chilingaryan
Big redign of model structures
25
#define PCILIB_REGISTER_PROTOCOL_DMA		96					/**< First PROTOCOL address to be used by DMA engines */
26
#define PCILIB_REGISTER_PROTOCOL_DYNAMIC	128					/**< First PROTOCOL address to be used by plugins */
27
28
typedef uint8_t pcilib_register_bank_t;						/**< Type holding the bank position within the field listing register banks in the model */
29
typedef uint8_t pcilib_register_bank_addr_t;					/**< Type holding the bank address number */
30
typedef uint8_t pcilib_register_protocol_t;					/**< Type holding the protocol position within the field listing register protocols in the model */
31
typedef uint8_t pcilib_register_protocol_addr_t;				/**< Type holding the protocol address */
32
33
typedef struct pcilib_register_bank_context_s pcilib_register_bank_context_t;
34
303 by Suren A. Chilingaryan
Initial integration of XML support
35
typedef enum {
36
    PCILIB_MODEL_MODIFICATON_FLAGS_DEFAULT = 0,
37
    PCILIB_MODEL_MODIFICATION_FLAG_OVERRIDE = 1,				/**< Instructs to override the existing registers/banks/etc... */
38
    PCILIB_MODEL_MODIFICATION_FLAG_SKIP_EXISTING = 2				/**< If flag is set, pcilib will just skip existing registers/banks/etc instead of reporting a error */
39
} pcilib_model_modification_flags_t;
40
332 by Suren A. Chilingaryan
Provide API calls for register and bank address resolution
41
typedef enum {
42
    PCILIB_ADDRESS_RESOLUTION_FLAGS_DEFAULT = 0,
43
    PCILIB_ADDRESS_RESOLUTION_FLAG_BUS_ADDRESS = 1,				/**< Resolve bus address instead of VA */
44
    PCILIB_ADDRESS_RESOLUTION_FLAG_PHYS_ADDRESS = 2,				/**< Resolve hardware address instead of VA */
45
    PCILIB_ADDRESS_RESOLUTION_MASK_ADDRESS_TYPE = 3,
46
    PCILIB_ADDRESS_RESOLUTION_FLAG_READ_ONLY = 4,				/**< Request read-only memory, in case if read-write resolution is impossible */
47
    PCILIB_ADDRESS_RESOLUTION_FLAG_WRITE_ONLY = 8,				/**< Request write-only resolution, in case if read-write resolution is impossible */
48
    PCILIB_ADDRESS_RESOLUTION_MASK_ACCESS_MODE = 12
49
} pcilib_address_resolution_flags_t;
50
236 by Suren A. Chilingaryan
Big redign of model structures
51
typedef struct {
253 by Suren A. Chilingaryan
Include version information in all API descriptions
52
    pcilib_version_t version;
53
240 by Suren A. Chilingaryan
More structural changes to get ready for stand-alone event engines
54
    pcilib_register_bank_context_t *(*init)(pcilib_t *ctx, pcilib_register_bank_t bank, const char *model, const void *args);			/**< Optional API call to initialize bank context */
275 by Suren A. Chilingaryan
Integration of software registers
55
    void (*free)(pcilib_t *pcilib, pcilib_register_bank_context_t *ctx);									/**< Optional API call to cleanup bank context */
332 by Suren A. Chilingaryan
Provide API calls for register and bank address resolution
56
    uintptr_t (*resolve)(pcilib_t *pcilib, pcilib_register_bank_context_t *ctx, pcilib_address_resolution_flags_t flags, pcilib_register_addr_t addr); /**< Resolves register virtual address (if supported) */
240 by Suren A. Chilingaryan
More structural changes to get ready for stand-alone event engines
57
    int (*read)(pcilib_t *pcilib, pcilib_register_bank_context_t *ctx, pcilib_register_addr_t addr, pcilib_register_value_t *value);		/**< Read from register, mandatory for RO/RW registers */
58
    int (*write)(pcilib_t *pcilib, pcilib_register_bank_context_t *ctx, pcilib_register_addr_t addr, pcilib_register_value_t value);		/**< Write to register, mandatory for WO/RW registers */
236 by Suren A. Chilingaryan
Big redign of model structures
59
} pcilib_register_protocol_api_description_t;
60
61
typedef struct {
240 by Suren A. Chilingaryan
More structural changes to get ready for stand-alone event engines
62
    pcilib_register_protocol_addr_t addr;					/**< Protocol address used in model for addressing the described protocol */
63
    const pcilib_register_protocol_api_description_t *api;			/**< Defines all API functions for protocol */
64
    const char *model;								/**< If NULL, the actually used model is used instead */
65
    const void *args;								/**< Custom protocol-specific arguments. The actual structure may depend on the specified model */
66
    const char *name;								/**< Short protocol name */
67
    const char *description;							/**< A bit longer protocol description */
236 by Suren A. Chilingaryan
Big redign of model structures
68
} pcilib_register_protocol_description_t;
69
70
typedef struct {
240 by Suren A. Chilingaryan
More structural changes to get ready for stand-alone event engines
71
    pcilib_register_bank_addr_t addr;						/**< Bank address used in model for addressing the described register bank */
72
73
    pcilib_register_protocol_addr_t protocol;					/**< Defines a protocol to access registers */
74
    pcilib_bar_t bar;								/**< Specifies the PCI BAR through which an access to the registers is provided (autodetcted if PCILIB_BAR_DETECT is specified) */
75
    uintptr_t read_addr;							/**< protocol specific (normally offset in the BAR of the first address used to read registers) */
76
    uintptr_t write_addr;							/**< protocol specific (normally offset in the BAR of the first address used to write registers) */
77
78
    uint8_t access;								/**< Default register size in bits (or word-size in plain addressing mode) */
324 by Suren A. Chilingaryan
Documentation update
79
    size_t size;								/**< The size of the bank in bytes (i.e. number of registers in plain addressing mode multiplied by access; this does not limit number of register names since indefinite number of names can be provided if bit-fields/views are used) */
240 by Suren A. Chilingaryan
More structural changes to get ready for stand-alone event engines
80
    pcilib_endianess_t raw_endianess;						/**< Specifies endianess in the plain-addressing mode, PCILIB_HOST_ENDIAN have to be specified if no conversion desired. 
81
										Conversion applied after protocol. This value does not get into the account in register-access mode */
82
    pcilib_endianess_t endianess;						/**< Specifies endianess in the register-access mode, this may differ from raw_endianess if multi-word registers are used. 
83
										This is fully independent from raw_endianess. No double conversion is either performed */
84
    
85
    const char *format;								/**< printf format for the registers, either %lu for decimal output or 0x%lx for hexdecimal */
86
    const char *name;								/**< short bank name */
87
    const char *description;							/**< longer bank description */
236 by Suren A. Chilingaryan
Big redign of model structures
88
} pcilib_register_bank_description_t;
89
90
/**
240 by Suren A. Chilingaryan
More structural changes to get ready for stand-alone event engines
91
  * Default mappings: defines virtual address to register mappings, i.e. how 0x9000 in the following command 
92
  * will be mapped to the actual register. By comparing with start and end-addresses, we find to which range 
93
  * 0x9000 belongs to and detect actual bank and offset in it.
94
  * Simple example: pci -r 0x9000
95
  * if we specify range { 0x9000, 0x9100, 10, -0x9000}, the example command we print the value of the first
96
  * register in the bank 10.
236 by Suren A. Chilingaryan
Big redign of model structures
97
  */
98
typedef struct {
240 by Suren A. Chilingaryan
More structural changes to get ready for stand-alone event engines
99
    uintptr_t start;								/**< The first virtual address of the register range */
100
    uintptr_t end;								/**< The last virtual address of the register range */
101
    pcilib_register_bank_addr_t bank;						/**< The bank mapped to the specified range */
102
    long addr_shift;								/**< Address shift, i.e. how much we should add/substract to the virtual address to get address in the register bank */
236 by Suren A. Chilingaryan
Big redign of model structures
103
} pcilib_register_range_t;
104
105
106
107
struct pcilib_register_bank_context_s {
240 by Suren A. Chilingaryan
More structural changes to get ready for stand-alone event engines
108
    const pcilib_register_bank_description_t *bank;				/**< Corresponding bank description */
109
    const pcilib_register_protocol_api_description_t *api;			/**< API functions */
303 by Suren A. Chilingaryan
Initial integration of XML support
110
    pcilib_xml_node_t *xml;							/**< Additional XML properties */
236 by Suren A. Chilingaryan
Big redign of model structures
111
};
112
277 by Suren A. Chilingaryan
Keep C++ compilers happy
113
#ifdef __cplusplus
114
extern "C" {
115
#endif
116
315 by Suren A. Chilingaryan
Support properties of arbitrary type
117
/**
118
 * Initalizes context of register banks. This is an internal function and will
119
 * be called automatically when new register banks are added. On error no new
120
 * banks are initalized 
121
 * @param[in,out] ctx - pcilib context
122
 * @return - error or 0 on success
123
 */
236 by Suren A. Chilingaryan
Big redign of model structures
124
int pcilib_init_register_banks(pcilib_t *ctx);
315 by Suren A. Chilingaryan
Support properties of arbitrary type
125
126
/**
127
 * Destroys contexts of register banks. This is an internal function and will
128
 * be called during clean-up. 
129
 * @param[in,out] ctx - pcilib context
130
 * @param[in] start - specifies first bank to clean (used to clean only part of the banks to keep the defined state if pcilib_init_register_banks has failed)
131
 */
132
void pcilib_free_register_banks(pcilib_t *ctx, pcilib_register_bank_t start);
133
134
135
/**
136
 * Use this function to add new register banks into the model or override configuration
137
 * of the existing banks. The function will copy the context of banks structure, but name, 
138
 * description, and other strings in the structure are considered to have static duration 
139
 * and will not be copied. On error no new banks are initalized.
140
 * @param[in,out] ctx - pcilib context
141
 * @param[in] flags - instructs if existing banks should be reported as error (default), overriden or ignored
142
 * @param[in] n - number of banks to initialize. It is OK to pass 0 if banks variable is NULL terminated (last member of banks array have all members set to 0)
143
 * @param[in] banks - bank descriptions
144
 * @param[out] ids - if specified will contain the ids of the newly registered and overriden banks
145
 * @return - error or 0 on success
146
 */
303 by Suren A. Chilingaryan
Initial integration of XML support
147
int pcilib_add_register_banks(pcilib_t *ctx, pcilib_model_modification_flags_t flags, size_t n, const pcilib_register_bank_description_t *banks, pcilib_register_bank_t *ids);
315 by Suren A. Chilingaryan
Support properties of arbitrary type
148
149
/**
150
 * Use this function to add new register protocols into the model. It is error to re-register
151
 * already registered protocols. The function will copy the context of banks structure, but name, 
152
 * description, and other strings in the structure are considered to have static duration 
153
 * and will not be copied. On error no new protocols are initalized.
154
 * @param[in,out] ctx - pcilib context
155
 * @param[in] flags - not used
156
 * @param[in] n - number of protocols to initialize. It is OK to pass 0 if protocols variable is NULL terminated (last member of protocols array have all members set to 0)
157
 * @param[in] protocols - protocol descriptions
158
 * @param[out] ids - if specified will contain the ids of the newly registered protocols
159
 * @return - error or 0 on success
160
 */
303 by Suren A. Chilingaryan
Initial integration of XML support
161
int pcilib_add_register_protocols(pcilib_t *ctx, pcilib_model_modification_flags_t flags, size_t n, const pcilib_register_protocol_description_t *protocols, pcilib_register_protocol_t *ids);
315 by Suren A. Chilingaryan
Support properties of arbitrary type
162
163
/**
164
 * Use this function to add new register ranges into the model. It is error register
165
 * overlapping registered ranges. On error no new ranges are initalized.
166
 * @param[in,out] ctx - pcilib context
167
 * @param[in] flags - not used
168
 * @param[in] n - number of protocols to initialize. It is OK to pass 0 if protocols variable is NULL terminated.
169
 * @param[in] ranges - range descriptions
170
 * @return - error or 0 on success
171
 */
303 by Suren A. Chilingaryan
Initial integration of XML support
172
int pcilib_add_register_ranges(pcilib_t *ctx, pcilib_model_modification_flags_t flags, size_t n, const pcilib_register_range_t *ranges);
236 by Suren A. Chilingaryan
Big redign of model structures
173
361 by Suren A. Chilingaryan
Documentation update
174
/**
175
 * Find the register bank id (offset in \a banks array) corresponding to the specified bank address 
176
 * @param[in,out] ctx	- pcilib context
177
 * @param[in] bank	- the address of register bank
178
 * @return 		- bank id or PCILIB_REGISTER_BANK_INVALID if bank is not found
179
 */
236 by Suren A. Chilingaryan
Big redign of model structures
180
pcilib_register_bank_t pcilib_find_register_bank_by_addr(pcilib_t *ctx, pcilib_register_bank_addr_t bank);
361 by Suren A. Chilingaryan
Documentation update
181
182
/**
183
 * Find the register bank id (offset in \a banks array) corresponding to the specified bank name
184
 * @param[in,out] ctx	- pcilib context
185
 * @param[in] bankname	- the name of register bank
186
 * @return 		- bank id or PCILIB_REGISTER_BANK_INVALID if bank is not found
187
 */
236 by Suren A. Chilingaryan
Big redign of model structures
188
pcilib_register_bank_t pcilib_find_register_bank_by_name(pcilib_t *ctx, const char *bankname);
361 by Suren A. Chilingaryan
Documentation update
189
190
/**
191
 * Find the register bank id (offset in \a banks array) corresponding to the specified bank name or address
192
 * @param[in,out] ctx	- pcilib context
193
 * @param[in] bank	- either the name or the address of the required register bank
194
 * @return 		- bank id or PCILIB_REGISTER_BANK_INVALID if bank is not found
195
 */
236 by Suren A. Chilingaryan
Big redign of model structures
196
pcilib_register_bank_t pcilib_find_register_bank(pcilib_t *ctx, const char *bank);
197
361 by Suren A. Chilingaryan
Documentation update
198
/**
199
 * Find the register protocol id (offset in \a protocols array) corresponding to the specified protocol address 
200
 * @param[in,out] ctx	- pcilib context
201
 * @param[in] protocol	- the address of register protocol
202
 * @return 		- protocol id or PCILIB_REGISTER_PROTOCOL_INVALID if register protocol is not found
203
 */
236 by Suren A. Chilingaryan
Big redign of model structures
204
pcilib_register_protocol_t pcilib_find_register_protocol_by_addr(pcilib_t *ctx, pcilib_register_protocol_addr_t protocol);
361 by Suren A. Chilingaryan
Documentation update
205
206
/**
207
 * Find the register protocol id (offset in \a protocols array) corresponding to the specified protocol name
208
 * @param[in,out] ctx	- pcilib context
209
 * @param[in] name	- the name of register protocol
210
 * @return 		- protocol id or PCILIB_REGISTER_PROTOCOL_INVALID if register protocol is not found
211
 */
236 by Suren A. Chilingaryan
Big redign of model structures
212
pcilib_register_protocol_t pcilib_find_register_protocol_by_name(pcilib_t *ctx, const char *name);
361 by Suren A. Chilingaryan
Documentation update
213
214
/**
215
 * Find the register protocol id (offset in \a protocols array) corresponding to the specified protocol name or address
216
 * @param[in,out] ctx	- pcilib context
217
 * @param[in] name	- either the name or the address of the required register protocol
218
 * @return 		- protocol id or PCILIB_REGISTER_PROTOCOL_INVALID if register protocol is not found
219
 */
236 by Suren A. Chilingaryan
Big redign of model structures
220
pcilib_register_protocol_t pcilib_find_register_protocol(pcilib_t *ctx, const char *name);
221
361 by Suren A. Chilingaryan
Documentation update
222
/**
223
 * Resolves the address of the specified register bank. The address of the register0 in the bank is returned.
224
 *
225
 * All address types (virtual address in process address space, physical address, or bus address) can be resolved.
226
 * The caller has also to specify the requested access mode (read, write, read/write) and the error will be returned
227
 * if the requested access type is not possible.
228
 *
229
 * @param[in,out] ctx	- pcilib context
230
 * @param[in] flags	- specifies the type of required address (virtual, physical, or bus) and the required access (ro/wo/rw)
231
 * @param[in] bank	- the id of register bank
232
 * @return 		- the resolved address or PCILIB_ADDRESS_INVALID on error
233
 */
332 by Suren A. Chilingaryan
Provide API calls for register and bank address resolution
234
uintptr_t pcilib_resolve_bank_address_by_id(pcilib_t *ctx, pcilib_address_resolution_flags_t flags, pcilib_register_bank_t bank);
361 by Suren A. Chilingaryan
Documentation update
235
236
/**
237
 * Resolves the address of the specified register bank. The address of the register0 in the bank is returned.
238
 *
239
 * All address types (virtual address in process address space, physical address, or bus address) can be resolved.
240
 * The caller has also to specify the requested access mode (read, write, read/write) and the error will be returned
241
 * if the requested access type is not possible.
242
 *
243
 * @param[in,out] ctx	- pcilib context
244
 * @param[in] flags	- specifies the type of required address (virtual, physical, or bus) and the required access (ro/wo/rw)
245
 * @param[in] bank	- the name of register bank
246
 * @return 		- the resolved address or PCILIB_ADDRESS_INVALID on error
247
 */
332 by Suren A. Chilingaryan
Provide API calls for register and bank address resolution
248
uintptr_t pcilib_resolve_bank_address(pcilib_t *ctx, pcilib_address_resolution_flags_t flags, const char *bank);
249
361 by Suren A. Chilingaryan
Documentation update
250
/**
251
 * Resolves the address of the specified register.
252
 *
253
 * All address types (virtual address in process address space, physical address, or bus address) can be resolved.
254
 * The caller has also to specify the requested access mode (read, write, read/write) and the error will be returned
255
 * if the requested access type is not possible.
256
 *
257
 * @param[in,out] ctx	- pcilib context
258
 * @param[in] flags	- specifies the type of required address (virtual, physical, or bus) and the required access (ro/wo/rw)
259
 * @param[in] reg	- the id of register
260
 * @return 		- the resolved address or PCILIB_ADDRESS_INVALID on error
261
 */
332 by Suren A. Chilingaryan
Provide API calls for register and bank address resolution
262
uintptr_t pcilib_resolve_register_address_by_id(pcilib_t *ctx, pcilib_address_resolution_flags_t flags, pcilib_register_t reg);
361 by Suren A. Chilingaryan
Documentation update
263
264
/**
265
 * Resolves the address of the specified register.
266
 *
267
 * All address types (virtual address in process address space, physical address, or bus address) can be resolved.
268
 * The caller has also to specify the requested access mode (read, write, read/write) and the error will be returned
269
 * if the requested access type is not possible.
270
 *
271
 * @param[in,out] ctx	- pcilib context
272
 * @param[in] flags	- specifies the type of required address (virtual, physical, or bus) and the required access (ro/wo/rw)
273
 * @param[in] bank	- should specify the bank name if register with the same name may occur in multiple banks, NULL otherwise
274
 * @param[in] regname	- the name of the register
275
 * @return 		- the resolved address or PCILIB_ADDRESS_INVALID on error
276
 */
332 by Suren A. Chilingaryan
Provide API calls for register and bank address resolution
277
uintptr_t pcilib_resolve_register_address(pcilib_t *ctx, pcilib_address_resolution_flags_t flags, const char *bank, const char *regname);
278
361 by Suren A. Chilingaryan
Documentation update
279
/**
280
 * Extracts additional information about the specified register bank. The additional information
281
 * is model-specific and are provided as extra XML attributes in XML-described register bank.
282
 * The available attributes are only restricted by used XSD schema.
283
 * @param[in,out] ctx	- pcilib context
284
 * @param[in] bank	- register bank id
285
 * @param[in] attr	- requested attribute name
286
 * @param[in,out] val	- the value of attribute is returned here (see \ref public_api_value),
287
 *			pcilib_clean_value() will be executed if \a val contains data. Therefore it should be always initialized to 0 before first use
288
 * @return		- error code or 0 on success
289
 */ 
318 by Suren A. Chilingaryan
Support reading/writting register views by id
290
int pcilib_get_register_bank_attr_by_id(pcilib_t *ctx, pcilib_register_bank_t bank, const char *attr, pcilib_value_t *val);
361 by Suren A. Chilingaryan
Documentation update
291
292
/**
293
 * Extracts additional information about the specified register bank. The additional information
294
 * is model-specific and are provided as extra XML attributes in XML-described register bank.
295
 * The available attributes are only restricted by used XSD schema.
296
 * @param[in,out] ctx	- pcilib context
297
 * @param[in] bankname	- the name of register bank
298
 * @param[in] attr	- requested attribute name
299
 * @param[in,out] val	- the value of attribute is returned here (see \ref public_api_value),
300
 *			pcilib_clean_value() will be executed if \a val contains data. Therefore it should be always initialized to 0 before first use
301
 * @return		- error code or 0 on success
302
 */ 
324 by Suren A. Chilingaryan
Documentation update
303
int pcilib_get_register_bank_attr(pcilib_t *ctx, const char *bankname, const char *attr, pcilib_value_t *val);
318 by Suren A. Chilingaryan
Support reading/writting register views by id
304
277 by Suren A. Chilingaryan
Keep C++ compilers happy
305
#ifdef __cplusplus
306
}
307
#endif
308
236 by Suren A. Chilingaryan
Big redign of model structures
309
#endif /* _PCILIB_BANK_H */