/alps/pcitool

To get this branch, use:
bzr branch http://suren.me/webbzr/alps/pcitool
303 by Suren A. Chilingaryan
Initial integration of XML support
1
/**
2
 * @file xml.h
277.2.1 by zilio nicolas
registers and banks support in xml v1. pci -ll works fine, but got segfault on pci -r name and pci -r name gives 0 always. might be due to the order in pci.c ------> ask suren
3
 * @version 1.0
4
 * @brief header file to support of xml configuration.
5
 *
6
 * @details    this file is the header file for the implementation of dynamic registers using xml and several funtionalities for the "pci-tool" line command tool from XML files. the xml part has been implemented using libxml2.
303 by Suren A. Chilingaryan
Initial integration of XML support
7
 *
277.2.1 by zilio nicolas
registers and banks support in xml v1. pci -ll works fine, but got segfault on pci -r name and pci -r name gives 0 always. might be due to the order in pci.c ------> ask suren
8
 *      this code was meant to be evolutive as the XML files evolute. In this meaning, most of the xml parsing is realized with XPath expressions(when it was possible), so that changing the xml xould result mainly in changing the XPAth pathes present here.
9
 * @todo cf compilation chain
10
 */
11
303 by Suren A. Chilingaryan
Initial integration of XML support
12
#ifndef _PCILIB_XML_H
13
#define _PCILIB_XML_H
277.2.1 by zilio nicolas
registers and banks support in xml v1. pci -ll works fine, but got segfault on pci -r name and pci -r name gives 0 always. might be due to the order in pci.c ------> ask suren
14
303 by Suren A. Chilingaryan
Initial integration of XML support
15
#include <pcilib.h>
277.2.16 by zilio nicolas
end of modifications
16
#include <libxml/tree.h>
303 by Suren A. Chilingaryan
Initial integration of XML support
17
#include <libxml/xpath.h>
18
#include <libxml/xmlschemas.h>
19
20
#define PCILIB_MAX_MODEL_FILES 32
21
22
typedef struct pcilib_xml_s pcilib_xml_t;
23
24
struct pcilib_xml_s {
25
    size_t num_files;					/**< Number of currently loaded XML documents */
26
    
27
    xmlDocPtr docs[PCILIB_MAX_MODEL_FILES];		/**< Pointers to parsed XML documents */
28
    xmlXPathContextPtr xpath[PCILIB_MAX_MODEL_FILES];	/**< Per-file XPath context */
29
    
30
    xmlParserCtxtPtr parser;				/**< Pointer to the XML parser context */
322 by Suren A. Chilingaryan
Support multiple XML files per folder
31
    xmlSchemaPtr schema;  				/**< Pointer to the parsed xsd schema */
303 by Suren A. Chilingaryan
Initial integration of XML support
32
    xmlSchemaValidCtxtPtr validator;       		/**< Pointer to the XML validation context */
322 by Suren A. Chilingaryan
Support multiple XML files per folder
33
    xmlSchemaPtr parts_schema; 				/**< Pointer to the parsed xsd schema capable of validating individual XML files - no check for cross-references */
34
    xmlSchemaValidCtxtPtr parts_validator;     		/**< Pointer to the XML validation context capable of validating individual XML files - no check for cross-references */
303 by Suren A. Chilingaryan
Initial integration of XML support
35
36
    xmlNodePtr bank_nodes[PCILIB_MAX_REGISTER_BANKS];	/**< pointer to xml nodes of banks in the xml file */
37
};
38
39
#ifdef __cplusplus
40
extern "C" {
41
#endif
277.2.12 by zilio nicolas
almost finished regarding suren remarks
42
379 by Suren A. Chilingaryan
Support XML configuration of device models
43
/**
44
 * Resolves device model from vendor and device ids using XML configuration
45
 * The association of vendor/device id pairs with model are provided devices.xml under PCILIB_MODEL_DIR
46
 * @param[in,out] ctx 	- pcilib context
47
 * @param[in] vendor_id	- the vendor id
48
 * @param[in] device_id	- the device id
49
 * @return 		- the name of model or NULL on an error and unknown device. It is caller responsibility to free returned string.
50
 */
51
char *pcilib_detect_xml_model(pcilib_t *ctx, unsigned int vendor_id, unsigned int device_id);
52
324 by Suren A. Chilingaryan
Documentation update
53
/** Initializes XML stack and loads a default set of XML files. 
54
 * The default location for XML files is /usr/local/share/pcilib/models/@b{model}.
55
 * This can be altered using CMake PCILIB_MODEL_DIR variable while building or using 
56
 * PCILIB_MODEL_DIR environmental variable dynamicly.  More XML files can be added
57
 * later using pcilib_process_xml() call.
58
 *
59
 * @param[in,out] ctx 	- pcilib context
60
 * @param[in] model 	- the name of the model
61
 * @return 		- error or 0 on success
277.2.12 by zilio nicolas
almost finished regarding suren remarks
62
 */
303 by Suren A. Chilingaryan
Initial integration of XML support
63
int pcilib_init_xml(pcilib_t *ctx, const char *model);
64
324 by Suren A. Chilingaryan
Documentation update
65
/** Cleans up memory used by various XML structures
66
 * @param[in] ctx 	- the pcilib_t context
322 by Suren A. Chilingaryan
Support multiple XML files per folder
67
 */
303 by Suren A. Chilingaryan
Initial integration of XML support
68
void pcilib_free_xml(pcilib_t *ctx);
69
324 by Suren A. Chilingaryan
Documentation update
70
/** Processes a bunch of XML files in the specified directory. During the initialization, all XML files
322 by Suren A. Chilingaryan
Support multiple XML files per folder
71
 * in the corresponding model directory will be loaded. This function allows to additionally load XML 
72
 * files from the specified subdirectories of the model directory. I.e. the XML files from the 
324 by Suren A. Chilingaryan
Documentation update
73
 * /usr/local/share/pcilib/models/@b{current_model}/@b{location} will be loaded. As with pcilib_init_xml,
322 by Suren A. Chilingaryan
Support multiple XML files per folder
74
 * the directory can be adjusted using CMake build configuration or PCILIB_MODEL_DIR environmental
75
 * variable.
324 by Suren A. Chilingaryan
Documentation update
76
 * @param[in] ctx 	- pcilib context
77
 * @param[in] location 	- Specifies sub-directory with XML files relative to the model directory.
78
 * @return 		- error or 0 on success
322 by Suren A. Chilingaryan
Support multiple XML files per folder
79
 */
303 by Suren A. Chilingaryan
Initial integration of XML support
80
int pcilib_process_xml(pcilib_t *ctx, const char *location);
81
324 by Suren A. Chilingaryan
Documentation update
82
/** This is an internal function which returns a specified node attribute in the pcilib_value_t structure.
322 by Suren A. Chilingaryan
Support multiple XML files per folder
83
 * This function should not be used directly. Instead subsystem specific calls like pcilib_get_register_attr,
84
 * pcilib_get_property_attr, ...have to be used.
324 by Suren A. Chilingaryan
Documentation update
85
 * @param[in] ctx 	- pcilib context
86
 * @param[in] node 	- LibXML2 node
87
 * @param[in] attr 	- attribute name
88
 * @param[out] val 	- the result will be returned in this variable. Prior to first usage pcilib_value_t variable should be initalized to 0.
89
 * @return 		- error or 0 on success
322 by Suren A. Chilingaryan
Support multiple XML files per folder
90
 */
318 by Suren A. Chilingaryan
Support reading/writting register views by id
91
int pcilib_get_xml_attr(pcilib_t *ctx, pcilib_xml_node_t *node, const char *attr, pcilib_value_t *val);
92
93
303 by Suren A. Chilingaryan
Initial integration of XML support
94
#ifdef __cplusplus
95
}
96
#endif
97
98
#endif /*_PCILIB_XML_H */