summaryrefslogtreecommitdiffstats
path: root/pcilib/xml.c
diff options
context:
space:
mode:
Diffstat (limited to 'pcilib/xml.c')
-rw-r--r--pcilib/xml.c1020
1 files changed, 562 insertions, 458 deletions
diff --git a/pcilib/xml.c b/pcilib/xml.c
index 8457927..73a3deb 100644
--- a/pcilib/xml.c
+++ b/pcilib/xml.c
@@ -1,9 +1,9 @@
/**
* @file pcilib_xml.c
* @version 1.0
- *
+ *
* @brief this file is the main source 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
- *
+ *
* @details registers and banks nodes are parsed using xpath expression, but their properties is get by recursively getting all properties nodes. In this sense, if a property changes, the algorithm has to be changed, but if it's registers or banks nodes, just the xpath expression modification should be enough.
Libxml2 considers blank spaces within the XML as node natively and this code as been produced considering blank spaces in the XML files. In case XML files would not contain blank spaces anymore, please change the code.
@@ -11,434 +11,556 @@
In case the performance is not good enough, please consider the following : hard code of formulas
*/
#define _XOPEN_SOURCE 700
+#define _BSD_SOURCE
+#define _DEFAULT_SOURCE
-
-#define REGISTERS_PATH ((xmlChar*)"/model/banks/bank/registers/register") /**<all standard registers nodes.*/
-#define BITS_REGISTERS_PATH ((xmlChar*)"/model/banks/bank/registers/register/registers_bits/register_bits") /**<all bits registers nodes.*/
-#define BANKS_PATH ((xmlChar*)"/model/banks/bank/bank_description") /**< path to complete nodes of banks.*/
-
-#include "xml.h"
-#include "error.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
-#include "pci.h"
-#include "bank.h"
-#include "register.h"
+#include <dirent.h>
+#include <errno.h>
+#include <alloca.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+
#include <libxml/xmlschemastypes.h>
#include <libxml/tree.h>
#include <libxml/parser.h>
#include <libxml/xpath.h>
#include <libxml/xpathInternals.h>
-#include <dirent.h>
-#include <errno.h>
-#include "config.h"
-typedef enum{
- type_standard,
- type_bits,
- type_fifo
-}pcilib_type_register_t;
+#include "config.h"
+#include "pci.h"
+#include "bank.h"
+#include "register.h"
+#include "xml.h"
+#include "error.h"
-/** pcilib_xml_get_nodeset_from_xpath
- * this function takes a context from an AST and an XPath expression, to produce an object containing the nodes corresponding to the xpath expression
- * @param[in] doc the AST of the xml file
- * @param[in] xpath the xpath expression that will be evaluated
- *@return the nodeset from AST and xpath expression evaluation of the xml file
- */
-static xmlXPathObjectPtr
-pcilib_xml_get_nodeset_from_xpath(xmlXPathContextPtr doc, xmlChar *xpath){
- xmlXPathObjectPtr result;
- result=xmlXPathEvalExpression(xpath, doc); /**<the creation of the resulting object*/
- if(result==NULL){
- pcilib_error("can't parse xpath expression %s",(char*)xpath);
- return NULL;
- }
-
- if(xmlXPathNodeSetIsEmpty(result->nodesetval)){
- pcilib_warning("the parsing of %s xpath expression resulted in an empty nodeset",(char*)xpath);
- xmlXPathFreeObject(result);
- return NULL;
- }
-
- return result;
+#define BANKS_PATH ((xmlChar*)"/model/banks/bank/bank_description") /**< path to complete nodes of banks.*/
+//#define REGISTERS_PATH ((xmlChar*)"/model/banks/bank/registers/register") /**< all standard registers nodes.*/
+//#define BIT_REGISTERS_PATH ((xmlChar*)"/model/banks/bank/registers/register/registers_bits/register_bits") /**< all bits registers nodes.*/
+#define REGISTERS_PATH ((xmlChar*)"../registers/register") /**< all standard registers nodes.*/
+#define BIT_REGISTERS_PATH ((xmlChar*)"./registers_bits/register_bits") /**< all bits registers nodes.*/
+
+static char *pcilib_xml_bank_default_format = "0x%lx";
+
+typedef struct {
+ pcilib_register_description_t base;
+ pcilib_register_value_t min, max;
+} pcilib_xml_register_description_t;
+
+/*
+static xmlNodePtr pcilib_xml_get_parent_bank_node(xmlDocPtr doc, xmlNodePtr node) {
+ xmlNodePtr bank_node;
+ bank_node = node->parent->parent;
+ // bank_description is always a first node according to the XSD schema
+ return xmlFirstElementChild(bank_node);
+
}
-
-/** pcilib_xml_validate
- * function to validate the xml file against the xsd
- * @param[in] xml_filename path to the xml file
- * @param[in] xsd_filename path to the xsd file
- *@return an error code
- */
-static int
-pcilib_xml_validate(char* xml_filename, char* xsd_filename)
-{
-xmlDocPtr doc;
-xmlSchemaPtr schema = NULL;
-xmlSchemaParserCtxtPtr ctxt;
-int ret=1;
-
-/** we first parse the xsd file for AST with validation*/
-ctxt = xmlSchemaNewParserCtxt(xsd_filename);
-schema = xmlSchemaParse(ctxt);
-xmlSchemaFreeParserCtxt(ctxt);
-
-doc = xmlReadFile(xml_filename, NULL, 0);
-
-if (doc == NULL)
-{
- pcilib_error("Could not parse xml document ");
-}
-else
-{
-xmlSchemaValidCtxtPtr ctxt;
-/** validation here*/
-ctxt = xmlSchemaNewValidCtxt(schema);
-ret = xmlSchemaValidateDoc(ctxt, doc);
-xmlSchemaFreeValidCtxt(ctxt);
-xmlFreeDoc(doc);
+static xmlNodePtr pcilib_xml_get_parent_register_node(xmlDocPtr doc, xmlNodePtr node) {
+ return node->parent->parent;
}
+*/
-if(schema != NULL)
-xmlSchemaFree(schema);
-xmlSchemaCleanupTypes();
+static int pcilib_xml_parse_register(pcilib_t *ctx, pcilib_xml_register_description_t *xml_desc, xmlDocPtr doc, xmlNodePtr node, pcilib_register_bank_description_t *bdesc) {
+ pcilib_register_description_t *desc = (pcilib_register_description_t*)xml_desc;
-if(ret!=0) pcilib_warning("\nxml file \"%s\" does not validate against the schema, its register won't be used",xml_filename);
+ xmlNodePtr cur;
+ char *value, *name;
+ char *endptr;
+
+ for (cur = node->children; cur != NULL; cur = cur->next) {
+ if (!cur->children) continue;
+ if (!xmlNodeIsText(cur->children)) continue;
+
+ name = (char*)cur->name;
+ value = (char*)cur->children->content;
+ if (!value) continue;
+
+ if (!strcasecmp((char*)name, "address")) {
+ uintptr_t addr = strtol(value, &endptr, 0);
+ if ((strlen(endptr) > 0)) {
+ pcilib_error("Invalid address (%s) is specified in the XML register description", value);
+ return PCILIB_ERROR_INVALID_DATA;
+ }
+ desc->addr = addr;
+ } else if(!strcasecmp(name, "offset")) {
+ int offset = strtol(value, &endptr, 0);
+ if ((strlen(endptr) > 0)||(offset < 0)||(offset > (8 * sizeof(pcilib_register_value_t)))) {
+ pcilib_error("Invalid offset (%s) is specified in the XML register description", value);
+ return PCILIB_ERROR_INVALID_DATA;
+ }
+ desc->offset = (pcilib_register_size_t)offset;
+ } else if (!strcasecmp(name,"size")) {
+ int size = strtol(value, &endptr, 0);
+ if ((strlen(endptr) > 0)||(size <= 0)||(size > (8 * sizeof(pcilib_register_value_t)))) {
+ pcilib_error("Invalid size (%s) is specified in the XML register description", value);
+ return PCILIB_ERROR_INVALID_DATA;
+ }
+ desc->bits = (pcilib_register_size_t)size;
+ } else if (!strcasecmp(name, "default")) {
+ pcilib_register_value_t val = strtol(value, &endptr, 0);
+ if ((strlen(endptr) > 0)) {
+ pcilib_error("Invalid default value (%s) is specified in the XML register description", value);
+ return PCILIB_ERROR_INVALID_DATA;
+ }
+ desc->defvalue = val;
+ } else if (!strcasecmp(name,"min")) {
+ pcilib_register_value_t min = strtol(value, &endptr, 0);
+ if ((strlen(endptr) > 0)) {
+ pcilib_error("Invalid minimum value (%s) is specified in the XML register description", value);
+ return PCILIB_ERROR_INVALID_DATA;
+ }
+ xml_desc->min = min;
+ } else if (!strcasecmp(name, "max")) {
+ pcilib_register_value_t max = strtol(value, &endptr, 0);
+ if ((strlen(endptr) > 0)) {
+ pcilib_error("Invalid minimum value (%s) is specified in the XML register description", value);
+ return PCILIB_ERROR_INVALID_DATA;
+ }
+ xml_desc->max = max;
+ } else if (!strcasecmp((char*)name,"rwmask")) {
+ if (!strcasecmp(value, "all")) {
+ desc->rwmask = PCILIB_REGISTER_ALL_BITS;
+ } else if (!strcasecmp(value, "none")) {
+ desc->rwmask = 0;
+ } else {
+ uintptr_t mask = strtol(value, &endptr, 0);
+ if ((strlen(endptr) > 0)) {
+ pcilib_error("Invalid mask (%s) is specified in the XML register description", value);
+ return PCILIB_ERROR_INVALID_DATA;
+ }
+ desc->rwmask = mask;
+ }
+ } else if (!strcasecmp(name, "mode")) {
+ if (!strcasecmp(value, "R")) {
+ desc->mode = PCILIB_REGISTER_R;
+ } else if (!strcasecmp(value, "W")) {
+ desc->mode = PCILIB_REGISTER_W;
+ } else if (!strcasecmp(value, "RW")) {
+ desc->mode = PCILIB_REGISTER_RW;
+ } else if (!strcasecmp(value, "W")) {
+ desc->mode = PCILIB_REGISTER_W;
+ } else if (!strcasecmp(value, "RW1C")) {
+ desc->mode = PCILIB_REGISTER_RW1C;
+ } else if (!strcasecmp(value, "W1C")) {
+ desc->mode = PCILIB_REGISTER_W1C;
+ } else {
+ pcilib_error("Invalid access mode (%s) is specified in the XML register description", value);
+ return PCILIB_ERROR_INVALID_DATA;
+ }
+ } else if (!strcasecmp(name, "type")) {
+ if (!strcasecmp(value, "fifo")) {
+ desc->type = PCILIB_REGISTER_FIFO;
+ } else {
+ pcilib_error("Invalid register type (%s) is specified in the XML register description", value);
+ return PCILIB_ERROR_INVALID_DATA;
+ }
+ } else if (!strcasecmp(name,"name")) {
+ desc->name = value;
+ } else if (!strcasecmp(name,"description")) {
+ desc->description = value;
+ }
+ }
- return ret;
+ return 0;
}
+static int pcilib_xml_create_register(pcilib_t *ctx, pcilib_register_bank_t bank, xmlXPathContextPtr xpath, xmlDocPtr doc, xmlNodePtr node) {
+ int err;
+
+ xmlXPathObjectPtr nodes;
+ xmlNodeSetPtr nodeset;
+ pcilib_xml_register_description_t desc = {{0}};
+ pcilib_xml_register_description_t fdesc;
+
+ pcilib_register_t reg;
+
+ desc.base.bank = ctx->banks[bank].addr;
+ desc.base.rwmask = PCILIB_REGISTER_ALL_BITS;
+ desc.base.mode = PCILIB_REGISTER_R;
+ desc.base.type = PCILIB_REGISTER_STANDARD;
+
+ err = pcilib_xml_parse_register(ctx, &desc, doc, node, &ctx->banks[bank]);
+ if (err) {
+ pcilib_error("Error (%i) parsing an XML register", err);
+ return err;
+ }
+
+ err = pcilib_add_registers(ctx, PCILIB_MODEL_MODIFICATION_FLAG_OVERRIDE, 1, &desc.base, &reg);
+ if (err) {
+ pcilib_error("Error (%i) adding a new XML register (%s) to the model", err, desc.base.name);
+ return err;
+ }
-/** pcilib_xml_create_bank
- *
- * this function create a bank structure from a xml bank node
- * @param[out] mybank the created bank.
- * @param[in] my node the xml node used to create the bank
- * @param[in] doc the AST of the xml file, used for used lixbml functions
- */
-static void
-pcilib_xml_create_bank(pcilib_register_bank_description_t *mybank, xmlNodePtr mynode, xmlDocPtr doc, pcilib_t* pci, int err){
-
- char* ptr;
- xmlNodePtr cur;
- xmlChar *value;
- int bar_ok=0;
- int k=0;
+ ctx->register_ctx[reg].xml = node;
+ ctx->register_ctx[reg].min = desc.min;
+ ctx->register_ctx[reg].max = desc.max;
- cur=mynode->children; /** we place ourselves in the childrens of the bank node*/
+ xpath->node = node;
+ nodes = xmlXPathEvalExpression(BIT_REGISTERS_PATH, xpath);
+ xpath->node = NULL;
+
+ if (!nodes) {
+ xmlErrorPtr xmlerr = xmlGetLastError();
- /** we iterate through all children, representing bank properties, to fill the structure*/
- while(cur!=NULL){
- /** we get each time the name of the node, corresponding to one property, and the value of the node*/
- value=xmlNodeListGetString(doc,cur->children,1);
-
- if(strcasecmp((char*)cur->name,"bar")==0){
- mybank->bar=(pcilib_bar_t)(value[0]-'0');
- bar_ok++;
+ if (xmlerr) pcilib_error("Failed to parse XPath expression %s, xmlXPathEvalExpression reported error %d - %s", BIT_REGISTERS_PATH, xmlerr->code, xmlerr->message);
+ else pcilib_error("Failed to parse XPath expression %s", BIT_REGISTERS_PATH);
+ return PCILIB_ERROR_FAILED;
+ }
- }else if(strcasecmp((char*)cur->name,"size")==0){
- mybank->size=(size_t)strtol((char*)value,&ptr,0);
+ nodeset = nodes->nodesetval;
+ if (!xmlXPathNodeSetIsEmpty(nodeset)) {
+ int i;
- }else if(strcasecmp((char*)cur->name,"protocol")==0){
- if((mybank->protocol=pcilib_find_register_protocol_by_name(pci,(char*)value))==PCILIB_REGISTER_PROTOCOL_INVALID){
- mybank->protocol=PCILIB_REGISTER_PROTOCOL_DEFAULT;
- }
+ for (i = 0; i < nodeset->nodeNr; i++) {
+ memset(&fdesc, 0, sizeof(pcilib_xml_register_description_t));
+
+ fdesc.base.bank = desc.base.bank;
+ fdesc.base.addr = desc.base.addr;
+ fdesc.base.mode = desc.base.mode;
+ fdesc.base.rwmask = desc.base.rwmask;
+ fdesc.base.type = PCILIB_REGISTER_BITS;
+
+ err = pcilib_xml_parse_register(ctx, &fdesc, doc, nodeset->nodeTab[i], &ctx->banks[bank]);
+ if (err) {
+ pcilib_error("Error parsing field in the XML register %s", desc.base.name);
+ continue;
+ }
+
+ err = pcilib_add_registers(ctx, PCILIB_MODEL_MODIFICATION_FLAG_OVERRIDE, 1, &fdesc.base, &reg);
+ if (err) {
+ pcilib_error("Error (%i) adding a new XML register (%s) to the model", err, fdesc.base.name);
+ continue;
+ }
+
+ ctx->register_ctx[reg].xml = nodeset->nodeTab[i];
+ ctx->register_ctx[reg].min = fdesc.min;
+ ctx->register_ctx[reg].max = fdesc.max;
+ }
+ }
+ xmlXPathFreeObject(nodes);
- }else if(strcasecmp((char*)cur->name,"read_address")==0){
- mybank->read_addr=(uintptr_t)strtol((char*)value,&ptr,0);
+ return 0;
+}
- }else if(strcasecmp((char*)cur->name,"write_address")==0){
- mybank->write_addr=(uintptr_t)strtol((char*)value,&ptr,0);
-
- }else if(strcasecmp((char*)cur->name,"word_size")==0){
- mybank->access=(uint8_t)strtol((char*)value,&ptr,0);
-
- }else if(strcasecmp((char*)cur->name,"endianess")==0){
- if(strcasecmp((char*)value,"little")==0){
- mybank->endianess=PCILIB_LITTLE_ENDIAN;
- }else if(strcasecmp((char*)value,"big")==0){
- mybank->endianess=PCILIB_BIG_ENDIAN;
- }else if(strcasecmp((char*)value,"host")==0){
- mybank->endianess=PCILIB_HOST_ENDIAN;
- }
- mybank->raw_endianess=mybank->endianess;
-
- }else if(strcasecmp((char*)cur->name,"format")==0){
- mybank->format=(char*)value;
-
- }else if(strcasecmp((char*)cur->name,"name")==0){
- mybank->name=(char*)value;
+static int pcilib_xml_create_bank(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDocPtr doc, xmlNodePtr node) {
+ int err;
- }else if(strcasecmp((char*)cur->name,"description")==0){
- mybank->description=(char*)value;
- }
+ int override = 0;
+ pcilib_register_bank_description_t desc = {0};
+ pcilib_register_bank_t bank;
+ xmlNodePtr cur;
+ char *value, *name;
+ char *endptr;
+
+ xmlXPathObjectPtr nodes;
+ xmlNodeSetPtr nodeset;
+
+
+ desc.format = pcilib_xml_bank_default_format;
+ desc.addr = PCILIB_REGISTER_BANK_DYNAMIC;
+ desc.bar = PCILIB_BAR_NOBAR;
+ desc.size = 0x1000;
+ desc.protocol = PCILIB_REGISTER_PROTOCOL_DEFAULT;
+ desc.access = 32;
+ desc.endianess = PCILIB_HOST_ENDIAN;
+ desc.raw_endianess = PCILIB_HOST_ENDIAN;
+
+ // iterate through all children, representing bank properties, to fill the structure
+ for (cur = node->children; cur != NULL; cur = cur->next) {
+ if (!cur->children) continue;
+ if (!xmlNodeIsText(cur->children)) continue;
+
+ name = (char*)cur->name;
+ value = (char*)cur->children->content;
+ if (!value) continue;
+
+ if (!strcasecmp(name, "bar")) {
+ char bar = value[0]-'0';
+ if ((strlen(value) != 1)||(bar < 0)||(bar > 5)) {
+ pcilib_error("Invalid BAR (%s) is specified in the XML bank description", value);
+ return PCILIB_ERROR_INVALID_DATA;
+ }
+ desc.bar = (pcilib_bar_t)bar;
+ override = 1;
+ } else if (!strcasecmp(name,"size")) {
+ long size = strtol(value, &endptr, 0);
+ if ((strlen(endptr) > 0)||(size<=0)) {
+ pcilib_error("Invalid bank size (%s) is specified in the XML bank description", value);
+ return PCILIB_ERROR_INVALID_DATA;
+ }
+ desc.size = (size_t)size;
+ override = 1;
+ } else if (!strcasecmp(name,"protocol")) {
+ pcilib_register_protocol_t protocol = pcilib_find_register_protocol_by_name(ctx, value);
+ if (protocol == PCILIB_REGISTER_PROTOCOL_INVALID) {
+ pcilib_error("Unsupported protocol (%s) is specified in the XML bank description", value);
+ return PCILIB_ERROR_NOTSUPPORTED;
+ }
+ desc.protocol = ctx->protocols[protocol].addr;
+ override = 1;
+ } else if (!strcasecmp(name,"address")) {
+ uintptr_t addr = strtol(value, &endptr, 0);
+ if ((strlen(endptr) > 0)) {
+ pcilib_error("Invalid address (%s) is specified in the XML bank description", value);
+ return PCILIB_ERROR_INVALID_DATA;
+ }
+ desc.read_addr = addr;
+ desc.write_addr = addr;
+ override = 1;
+ } else if (!strcasecmp(name,"read_address")) {
+ uintptr_t addr = strtol(value, &endptr, 0);
+ if ((strlen(endptr) > 0)) {
+ pcilib_error("Invalid address (%s) is specified in the XML bank description", value);
+ return PCILIB_ERROR_INVALID_DATA;
+ }
+ desc.read_addr = addr;
+ override = 1;
+ } else if (!strcasecmp(name,"write_address")) {
+ uintptr_t addr = strtol(value, &endptr, 0);
+ if ((strlen(endptr) > 0)) {
+ pcilib_error("Invalid address (%s) is specified in the XML bank description", value);
+ return PCILIB_ERROR_INVALID_DATA;
+ }
+ desc.write_addr = addr;
+ override = 1;
+ } else if(strcasecmp((char*)name,"word_size")==0) {
+ int access = strtol(value, &endptr, 0);
+ if ((strlen(endptr) > 0)||(access%8)||(access<=0)||(access>(8 * sizeof(pcilib_register_value_t)))) {
+ pcilib_error("Invalid word size (%s) is specified in the XML bank description", value);
+ return PCILIB_ERROR_INVALID_DATA;
+ }
+ desc.access = access;
+ override = 1;
+ } else if (!strcasecmp(name,"endianess")) {
+ if (!strcasecmp(value,"little")) desc.endianess = PCILIB_LITTLE_ENDIAN;
+ else if (!strcasecmp(value,"big")) desc.endianess = PCILIB_BIG_ENDIAN;
+ else if (!strcasecmp(value,"host")) desc.endianess = PCILIB_HOST_ENDIAN;
+ else {
+ pcilib_error("Invalid endianess (%s) is specified in the XML bank description", value);
+ return PCILIB_ERROR_INVALID_DATA;
+ }
+ override = 1;
+ } else if (!strcasecmp(name,"format")) {
+ desc.format = value;
+ override = 1;
+ } else if (!strcasecmp((char*)name,"name")) {
+ desc.name = value;
+ } else if (!strcasecmp((char*)name,"description")) {
+ desc.description = value;
+ override = 1;
+ } else if (!strcasecmp((char*)name,"override")) {
+ override = 1;
+ }
+ }
- cur=cur->next;
+ err = pcilib_add_register_banks(ctx, override?PCILIB_MODEL_MODIFICATION_FLAG_OVERRIDE:PCILIB_MODEL_MODIFICATION_FLAG_SKIP_EXISTING, 1, &desc, &bank);
+ if (err) {
+ pcilib_error("Error adding register bank (%s) specified in the XML bank description", desc.name);
+ return err;
}
- if(bar_ok==0) mybank->bar=PCILIB_BAR_NOBAR;
+ ctx->xml.bank_nodes[bank] = node;
+ if (ctx->bank_ctx[bank]) {
+ ctx->bank_ctx[bank]->xml = node;
+ }
+
+ xpath->node = node;
+ nodes = xmlXPathEvalExpression(REGISTERS_PATH, xpath);
+ xpath->node = NULL;
+
+ if (!nodes) {
+ xmlErrorPtr xmlerr = xmlGetLastError();
+ if (xmlerr) pcilib_error("Failed to parse XPath expression %s, xmlXPathEvalExpression reported error %d - %s", REGISTERS_PATH, xmlerr->code, xmlerr->message);
+ else pcilib_error("Failed to parse XPath expression %s", REGISTERS_PATH);
+ return PCILIB_ERROR_FAILED;
+ }
- k=(int)pcilib_find_register_bank_by_name(pci,mybank->name);
- if(k==PCILIB_REGISTER_BANK_INVALID){
- mybank->addr=PCILIB_REGISTER_BANK_DYNAMIC + pci->xml_ctx->nb_new_banks;
- pci->xml_ctx->nb_new_banks++;
- k=pci->num_banks+1;
+ nodeset = nodes->nodesetval;
+ if (!xmlXPathNodeSetIsEmpty(nodeset)) {
+ int i;
+ for (i = 0; i < nodeset->nodeNr; i++) {
+ err = pcilib_xml_create_register(ctx, bank, xpath, doc, nodeset->nodeTab[i]);
+ if (err) pcilib_error("Error creating XML registers for bank %s", desc.name);
}
- else mybank->addr=pci->banks[k].addr;
-
- if(err==0){
- pci->xml_ctx->xml_banks[k]=mynode;
}
+ xmlXPathFreeObject(nodes);
- char buffer[66];
- sprintf(buffer,"%i",mybank->addr);
- printf("buffer %s \n",buffer);
- xmlNewChild(mynode,NULL, BAD_CAST "address", BAD_CAST buffer);
+ return 0;
}
-
-
+
/** pcilib_xml_initialize_banks
- *
- * function to create the structures to store the banks from the AST
- * @see pcilib_xml_create_bank(
+ *
+ * function to create the structures to store the banks from the AST
+ * @see pcilib_xml_create_bank
* @param[in] doc the AST of the xml file.
* @param[in] pci the pcilib_t running, which will be filled
*/
-static void
-pcilib_xml_initialize_banks(pcilib_t* pci,xmlDocPtr doc){
- pcilib_register_bank_description_t mybank;
-
- xmlNodeSetPtr nodesetaddress=NULL;
- xmlNodePtr mynode;
- xmlXPathContextPtr context;
- int i,err=0;
-
- mynode=malloc(sizeof(xmlNode));
- if(!(context= xmlXPathNewContext(doc))){
- pcilib_error("can't get an AST from an xml file");
- return;
- }
- /** we get the bank nodes using xpath expression*/
- nodesetaddress=pcilib_xml_get_nodeset_from_xpath(context,BANKS_PATH)->nodesetval;
- if(!(nodesetaddress)) return;
- if(nodesetaddress->nodeNr==0) return;
-
- pci->xml_ctx->xml_banks=calloc(PCILIB_MAX_REGISTER_BANKS+1,sizeof(xmlNodePtr));
- if(!(pci->xml_ctx->xml_banks)){
- pcilib_error("can't create bank xml nodes for pcilib_t struct");
- err++;
- }
+static int pcilib_xml_process_document(pcilib_t *ctx, xmlDocPtr doc, xmlXPathContextPtr xpath) {
+ xmlXPathObjectPtr bank_nodes;
+ xmlNodeSetPtr nodeset;
+
+ bank_nodes = xmlXPathEvalExpression(BANKS_PATH, xpath);
+ if (!bank_nodes) {
+ xmlErrorPtr xmlerr = xmlGetLastError();
+ if (xmlerr) pcilib_error("Failed to parse XPath expression %s, xmlXPathEvalExpression reported error %d - %s", BANKS_PATH, xmlerr->code, xmlerr->message);
+ else pcilib_error("Failed to parse XPath expression %s", BANKS_PATH);
+ return PCILIB_ERROR_FAILED;
+ }
- /** for each of the bank nodes, we create the associated structure, and push it in the pcilib environnement*/
- for(i=0;i<nodesetaddress->nodeNr;i++){
- mynode=nodesetaddress->nodeTab[i];
- pcilib_xml_create_bank(&mybank,mynode,doc, pci, err);
- pcilib_add_register_banks(pci,1,&mybank);
+
+ nodeset = bank_nodes->nodesetval;
+ if (!xmlXPathNodeSetIsEmpty(nodeset)) {
+ int i;
+ for (i = 0; i < nodeset->nodeNr; i++) {
+ pcilib_xml_create_bank(ctx, xpath, doc, nodeset->nodeTab[i]);
}
+ }
+ xmlXPathFreeObject(bank_nodes);
+
+ return 0;
+}
+static int pcilib_xml_load_xsd(pcilib_t *ctx, char *xsd_filename) {
+ int err;
+
+ xmlSchemaParserCtxtPtr ctxt;
+
+ /** we first parse the xsd file for AST with validation*/
+ ctxt = xmlSchemaNewParserCtxt(xsd_filename);
+ if (!ctxt) {
+ xmlErrorPtr xmlerr = xmlGetLastError();
+ if (xmlerr) pcilib_error("xmlSchemaNewParserCtxt reported error %d - %s", xmlerr->code, xmlerr->message);
+ else pcilib_error("Failed to create a parser for XML schemas");
+ return PCILIB_ERROR_FAILED;
+ }
+
+ ctx->xml.schema = xmlSchemaParse(ctxt);
+ if (!ctx->xml.schema) {
+ xmlErrorPtr xmlerr = xmlGetLastError();
+ xmlSchemaFreeParserCtxt(ctxt);
+ if (xmlerr) pcilib_error("Failed to parse XML schema, xmlSchemaParse reported error %d - %s", xmlerr->code, xmlerr->message);
+ else pcilib_error("Failed to parse XML schema");
+ return PCILIB_ERROR_INVALID_DATA;
+ }
+
+ xmlSchemaFreeParserCtxt(ctxt);
+
+ ctx->xml.validator = xmlSchemaNewValidCtxt(ctx->xml.schema);
+ if (!ctx->xml.validator) {
+ xmlErrorPtr xmlerr = xmlGetLastError();
+ if (xmlerr) pcilib_error("xmlSchemaNewValidCtxt reported error %d - %s", xmlerr->code, xmlerr->message);
+ else pcilib_error("Failed to create a validation context");
+ return PCILIB_ERROR_FAILED;
+ }
+
+ err = xmlSchemaSetValidOptions(ctx->xml.validator, XML_SCHEMA_VAL_VC_I_CREATE);
+ if (err) {
+ xmlErrorPtr xmlerr = xmlGetLastError();
+ if (xmlerr) pcilib_error("xmlSchemaSetValidOptions reported error %d - %s", xmlerr->code, xmlerr->message);
+ else pcilib_error("Failed to configure the validation context to populate default attributes");
+ return PCILIB_ERROR_FAILED;
+ }
+ return 0;
}
-/** pcilib_xml_registers_compare
- * function to compare registers by address for sorting registers
- * @param a one hypothetic register
- * @param b one other hypothetic register
- *@return the result of the comparison
- */
-static int
-pcilib_xml_compare_registers(void const *a, void const *b){
- const pcilib_register_description_t *pa=a;
- const pcilib_register_description_t *pb=b;
+static int pcilib_xml_load_file(pcilib_t *ctx, const char *path, const char *name) {
+ int err;
+ char *full_name;
+ xmlDocPtr doc;
+ xmlXPathContextPtr xpath;
- return pa->addr - pb->addr;
-}
+ full_name = (char*)alloca(strlen(path) + strlen(name) + 2);
+ if (!name) {
+ pcilib_error("Error allocating %zu bytes of memory in stack to create a file name", strlen(path) + strlen(name) + 2);
+ return PCILIB_ERROR_MEMORY;
+ }
+ sprintf(full_name, "%s/%s", path, name);
-/** pcilib_xml_arrange_registers
- * after the complete structure containing the registers has been created from the xml, this function rearrange them by address in order to add them in pcilib_open, which don't consider the adding of registers in order of address
- * @param[in,out] registers the list of registers in : not ranged out: ranged.
- * @param[in] size the number of registers.
- */
-static void
-pcilib_xml_arrange_registers(pcilib_register_description_t *registers,int size){
- pcilib_register_description_t* temp;
- temp=malloc(size*sizeof(pcilib_register_description_t));
- qsort(registers,size,sizeof(pcilib_register_description_t),pcilib_xml_compare_registers);
- free(temp);
-}
+ doc = xmlCtxtReadFile(ctx->xml.parser, full_name, NULL, 0);
+ if (!doc) {
+ xmlErrorPtr xmlerr = xmlCtxtGetLastError(ctx->xml.parser);
+ if (xmlerr) pcilib_error("Error parsing %s, xmlCtxtReadFile reported error %d - %s", full_name, xmlerr->code, xmlerr->message);
+ else pcilib_error("Error parsing %s", full_name);
+ return PCILIB_ERROR_INVALID_DATA;
+ }
-/**pcilib_get_bank_address_from_register_node
- *@param[in] node the current register node
- */
-static xmlChar*
-pcilib_get_bank_address_from_register_node(xmlDocPtr doc, xmlNodePtr node){
- xmlChar* temp= xmlNodeListGetString(doc,xmlGetLastChild(xmlFirstElementChild(node->parent->parent))->children,1);
- return temp;
-}
-
-
-/** pcilib_xml_create_register.
- * this function create a register structure from a xml register node.
- * @param[out] myregister the register we want to create
- * @param[in] type the type of the future register, because this property can't be parsed
- * @param[in] doc the AST of the xml file, required for some ibxml2 sub-fonctions
- * @param[in] mynode the xml node to create register from
- */
-void pcilib_xml_create_register(pcilib_register_description_t *myregister,xmlNodePtr mynode, xmlDocPtr doc,pcilib_register_type_t type, pcilib_t* pci){
-
- char* ptr;
- xmlNodePtr cur;
- xmlChar *value=NULL;
- int i=0;
-
- /**we get the children of the register xml nodes, that contains the properties for it*/
- cur=mynode->children;
-
- while(cur!=NULL){
- value=xmlNodeListGetString(doc,cur->children,1);
- /* we iterate throug each children to get the associated property
- note :the use of strtol permits to get as well hexadecimal and decimal values
- */
- if(strcasecmp((char*)cur->name,"address")==0){
- myregister->addr=(pcilib_register_addr_t)strtol((char*)value,&ptr,0);
-
- }else if(strcasecmp((char*)cur->name,"offset")==0){
- myregister->offset=(pcilib_register_size_t)strtol((char*)value,&ptr,0);
-
- }else if(strcasecmp((char*)cur->name,"size")==0){
- myregister->bits=(pcilib_register_size_t)strtol((char*)value,&ptr,0);
-
- }else if(strcasecmp((char*)cur->name,"default")==0){
- myregister->defvalue=(pcilib_register_value_t)strtol((char*)value,&ptr,0);
-
- }else if(strcasecmp((char*)cur->name,"rwmask")==0){
- if(strcasecmp((char*)value,"all bits")==0){
- myregister->rwmask=PCILIB_REGISTER_ALL_BITS;
- }else if(strcasecmp((char*)value,"0")==0){
- myregister->rwmask=0;
- }else{
- myregister->rwmask=(pcilib_register_value_t)strtol((char*)value,&ptr,0);
- }
+ err = xmlSchemaValidateDoc(ctx->xml.validator, doc);
+ if (err) {
+ xmlErrorPtr xmlerr = xmlCtxtGetLastError(ctx->xml.parser);
+ xmlFreeDoc(doc);
+ if (xmlerr) pcilib_error("Error validating %s, xmlSchemaValidateDoc reported error %d - %s", full_name, xmlerr->code, xmlerr->message);
+ else pcilib_error("Error validating %s", full_name);
+ return PCILIB_ERROR_VERIFY;
+ }
- }else if(strcasecmp((char*)cur->name,"mode")==0){
- if(strcasecmp((char*)value,"R")==0){
- myregister->mode=PCILIB_REGISTER_R;
- }else if(strcasecmp((char*)value,"W")==0){
- myregister->mode=PCILIB_REGISTER_W;
- }else if(strcasecmp((char*)value,"RW")==0){
- myregister->mode=PCILIB_REGISTER_RW;
- }else if(strcasecmp((char*)value,"W")==0){
- myregister->mode=PCILIB_REGISTER_W;
- }else if(strcasecmp((char*)value,"RW1C")==0){
- myregister->mode=PCILIB_REGISTER_RW1C;
- }else if(strcasecmp((char*)value,"W1C")==0){
- myregister->mode=PCILIB_REGISTER_W1C;
- }
-
- }else if(strcasecmp((char*)cur->name,"name")==0){
- myregister->name=(char*)value;
-
- }else if(strcasecmp((char*)cur->name,"value_min")==0){
- /* not implemented yet*/ // myregister->value_min=(pcilib_register_value_t)strtol((char*)value,&ptr,0);
-
- }else if(strcasecmp((char*)cur->name,"value_max")==0){
- /* not implemented yet*/ // myregister->value_max=(pcilib_register_value_t)strtol((char*)value,&ptr,0);
-
- }else if(strcasecmp((char*)cur->name,"description")==0){
- i++;
- myregister->description=(char*)value;
- }
-
- cur=cur->next;
+ xpath = xmlXPathNewContext(doc);
+ if (!xpath) {
+ xmlErrorPtr xmlerr = xmlGetLastError();
+ xmlFreeDoc(doc);
+ if (xmlerr) pcilib_error("Document %s: xmlXpathNewContext reported error %d - %s for document %s", full_name, xmlerr->code, xmlerr->message);
+ else pcilib_error("Error creating XPath context for %s", full_name);
+ return PCILIB_ERROR_FAILED;
}
- /** make sure we don't get the description from previous registers*/
- if(i==0) myregister->description=NULL;
+ // This can only partially fail... Therefore we need to keep XML and just return the error...
+ err = pcilib_xml_process_document(ctx, doc, xpath);
- /** we then get properties that can not be parsed as the previous ones*/
- if((int)type==(int)type_standard){
- myregister->type=PCILIB_REGISTER_STANDARD;
- myregister->bank=(pcilib_register_bank_addr_t)strtol((char*)pcilib_get_bank_address_from_register_node(doc,mynode),&ptr,0);
-
- }else if((int)type==(int)type_bits){
- myregister->type=PCILIB_REGISTER_BITS;
-
- }else if((int)type==(int)type_fifo){
- /* not implemented yet*/ myregister->type=PCILIB_REGISTER_FIFO;
- }
-
-
-}
+ if (ctx->xml.num_files == PCILIB_MAX_MODEL_FILES) {
+ xmlFreeDoc(doc);
+ xmlXPathFreeContext(xpath);
+ pcilib_error("Too many XML files for a model, only up to %zu are supported", PCILIB_MAX_MODEL_FILES);
+ return PCILIB_ERROR_TOOBIG;
+ }
-/** pcilib_xml_initialize_registers
- *
- * this function create a list of registers from an abstract syntax tree
- *
- * variables who need change if xml structure change : bank,description, sub_description, sub_address, sub_bank, sub_rwmask (we consider it to be equal to the standard register), sub_defvalue(same to standard register normally)
- * @param[in] doc the xpath context of the xml file.
- * @param[in] pci the pcilib_t struct running, that will get filled
- */
-void pcilib_xml_initialize_registers(pcilib_t* pci,xmlDocPtr doc){
-
- xmlNodeSetPtr nodesetaddress=NULL, nodesetsubaddress=NULL;
- xmlNodePtr mynode;
- xmlXPathContextPtr context;
- pcilib_register_description_t *registers=NULL;
- pcilib_register_description_t myregister;
- int i,j,err=0;
-
- context= xmlXPathNewContext(doc);
- if(!(context= xmlXPathNewContext(doc))){
- pcilib_error("can't get an AST from an xml file");
- return;
- }
-
- /** we first get the nodes of standard and bits registers*/
- nodesetaddress=pcilib_xml_get_nodeset_from_xpath(context,REGISTERS_PATH)->nodesetval;
- nodesetsubaddress=pcilib_xml_get_nodeset_from_xpath(context,BITS_REGISTERS_PATH)->nodesetval;
- if(!(nodesetaddress)) return;
- if(nodesetaddress->nodeNr>0)registers=calloc(nodesetaddress->nodeNr+nodesetsubaddress->nodeNr,sizeof(pcilib_register_description_t));
- else return;
-
- if(pci->xml_ctx->nb_registers==0)
- pci->xml_ctx->xml_registers=calloc(nodesetaddress->nodeNr+nodesetsubaddress->nodeNr,sizeof(xmlNodePtr));
- else
- pci->xml_ctx->xml_registers=realloc(pci->xml_ctx->xml_registers,(pci->xml_ctx->nb_registers+nodesetaddress->nodeNr+nodesetsubaddress->nodeNr)*sizeof(xmlNodePtr));
-
- if(!(pci->xml_ctx->xml_registers)){
- pcilib_warning("can't create registers xml nodes in pcilib_t struct: memory allocation failed");
- err++;
- }
-
- /** we then iterate through standard registers nodes to create registers structures*/
- for(i=0;i<nodesetaddress->nodeNr;i++){
- mynode=nodesetaddress->nodeTab[i];
- pcilib_xml_create_register(&myregister,mynode,doc,type_standard,pci);
- registers[i]=myregister;
- if(err==0) pci->xml_ctx->xml_registers[pci->xml_ctx->nb_registers+i]=mynode;
- }
-
- j=i;
- if(!(nodesetsubaddress)) return;
- /** we then iterate through bits registers nodes to create registers structures*/
- for(i=0;i<nodesetsubaddress->nodeNr;i++){
- mynode=nodesetsubaddress->nodeTab[i];
- pcilib_xml_create_register(&myregister,mynode->parent->parent,doc,type_standard,pci);
- pcilib_xml_create_register(&myregister,mynode,doc,type_bits,pci);
- registers[i+j]=myregister;
- if(err==0) pci->xml_ctx->xml_registers[pci->xml_ctx->nb_registers+i+j]=mynode;
- }
+ ctx->xml.docs[ctx->xml.num_files] = doc;
+ ctx->xml.xpath[ctx->xml.num_files] = xpath;
+ ctx->xml.num_files++;
+
+ return err;
+}
+
+
+int pcilib_process_xml(pcilib_t *ctx, const char *location) {
+ int err;
+
+ DIR *rep;
+ struct dirent *file = NULL;
+ char *model_dir, *model_path;
+
+ model_dir = getenv("PCILIB_MODEL_DIR");
+ if (!model_dir) model_dir = PCILIB_MODEL_DIR;
+
+ model_path = (char*)alloca(strlen(model_dir) + strlen(location) + 2);
+ if (!model_path) return PCILIB_ERROR_MEMORY;
+
+ sprintf(model_path, "%s/%s", model_dir, location);
+
+ rep = opendir(model_path);
+ if (!rep) return PCILIB_ERROR_NOTFOUND;
+
+ while ((file = readdir(rep)) != NULL) {
+ size_t len = strlen(file->d_name);
+ if ((len < 4)||(strcasecmp(file->d_name + len - 4, ".xml"))) continue;
+ if (file->d_type != DT_REG) continue;
- /**we arrange the register for them to be well placed for pci-l*/
- pcilib_xml_arrange_registers(registers,nodesetaddress->nodeNr+nodesetsubaddress->nodeNr);
- /**we fille the pcilib_t struct*/
- pcilib_add_registers(pci,nodesetaddress->nodeNr+nodesetsubaddress->nodeNr,registers);
- pci->xml_ctx->nb_registers+=nodesetaddress->nodeNr+nodesetsubaddress->nodeNr;
+ err = pcilib_xml_load_file(ctx, model_path, file->d_name);
+ if (err) pcilib_error("Error processing XML file %s", file->d_name);
+ }
+
+ closedir(rep);
+
+ return 0;
}
@@ -448,105 +570,87 @@ void pcilib_xml_initialize_registers(pcilib_t* pci,xmlDocPtr doc){
* @param[in] model the current model of ctx
* @return an error code
*/
+int pcilib_init_xml(pcilib_t *ctx, const char *model) {
+ int err;
-int pcilib_init_xml(pcilib_t* ctx, char* model){
- char *path,*pwd, **line, *line_xsd=NULL;
- int i=1,k;
- xmlDocPtr* docs;
- DIR* rep=NULL;
- struct dirent* file=NULL;
- int err, err_count=0;
-
- path=malloc(sizeof(char*));
- line=malloc(sizeof(char*));
- line[0]=NULL;
-
- /** we first get the env variable corresponding to the place of the xml files*/
- path=getenv("PCILIB_MODEL_DIR");
- if(path==NULL){
- path=PCILIB_MODEL_DIR;
- }
-
- /** we then open the directory corresponding to the ctx model*/
- pwd=malloc((strlen(path)+strlen(model))*sizeof(char));
- sprintf(pwd,"%s%s/",path,model);
- if((rep=opendir(pwd))==NULL){
- pcilib_warning("could not open the directory for xml files: error %i\n",errno);
- return PCILIB_ERROR_NOTINITIALIZED;
- }
+ char *model_dir;
+ char *xsd_path;
- /** we iterate through the files of the directory, to get the xml files and the xsd file*/
- while((file=readdir(rep))!=NULL){
- if(strstr(file->d_name,".xml")!=NULL){
- line=realloc(line,i*sizeof(char*));
- line[i-1]=malloc((strlen(file->d_name)+strlen(pwd)+1)*sizeof(char));
- sprintf(line[i-1],"%s%s",pwd,file->d_name); /**< here i wanted to use realpath() function, but it was not working correctly*/
- i++;
- }
- if(strstr(file->d_name,".xsd")!=NULL){
- line_xsd=malloc((strlen(file->d_name)+strlen(pwd))*sizeof(char));
- sprintf(line_xsd,"%s%s",pwd,file->d_name);
- }
- }
+ struct stat st;
- if(line_xsd==NULL){
- pcilib_warning("no xsd file found");
- return PCILIB_ERROR_NOTINITIALIZED;
+ model_dir = getenv("PCILIB_MODEL_DIR");
+ if (!model_dir) model_dir = PCILIB_MODEL_DIR;
+
+ xsd_path = (char*)alloca(strlen(model_dir) + 16);
+ if (!xsd_path) return PCILIB_ERROR_MEMORY;
+
+ sprintf(xsd_path, "%s/model.xsd", model_dir);
+ if (stat(xsd_path, &st)) {
+ pcilib_info("XML models are not present");
+ return PCILIB_ERROR_NOTFOUND;
}
- if(line[0]==NULL){
- pcilib_warning("no xml file found");
- return PCILIB_ERROR_NOTINITIALIZED;
+ ctx->xml.parser = xmlNewParserCtxt();
+ if (!ctx->xml.parser) {
+ xmlErrorPtr xmlerr = xmlGetLastError();
+ if (xmlerr) pcilib_error("xmlNewParserCtxt reported error %d (%s)", xmlerr->code, xmlerr->message);
+ else pcilib_error("Failed to create an XML parser context");
+ return PCILIB_ERROR_FAILED;
}
-
- /** for each xml file, we validate it, and get the registers and the banks*/
- docs=malloc((i-1)*sizeof(xmlDocPtr));
- ctx->xml_ctx=malloc(sizeof(pcilib_xml_context_t));
- ctx->xml_ctx->docs=malloc(sizeof(xmlDocPtr)*(i-1));
- ctx->xml_ctx->nb_registers=0;
- ctx->xml_ctx->nb_new_banks=0;
- if(!(ctx->xml_ctx) || !(ctx->xml_ctx->docs))
- return PCILIB_ERROR_MEMORY;
+ err = pcilib_xml_load_xsd(ctx, xsd_path);
+ if (err) return err;
+
+ return pcilib_process_xml(ctx, model);
+}
+/** pcilib_free_xml
+ * this function free the xml parts of the pcilib_t running, and some libxml ashes
+ * @param[in] pci the pcilib_t running
+*/
+void pcilib_free_xml(pcilib_t *ctx) {
+ int i;
+
+ memset(ctx->xml.bank_nodes, 0, sizeof(ctx->xml.bank_nodes));
+ for (i = 0; i < ctx->num_banks; i++) {
+ if (ctx->bank_ctx[i])
+ ctx->bank_ctx[i]->xml = NULL;
+ }
- for(k=0;k<i-1;k++){
- if((err=pcilib_xml_validate(line[k],line_xsd))==0){
- if((docs[k]=xmlParseFile(line[k]))){
- pcilib_xml_initialize_banks(ctx,docs[k]);
- pcilib_xml_initialize_registers(ctx,docs[k]);
+ for (i = 0; i < ctx->num_reg; i++) {
+ ctx->register_ctx[i].xml = NULL;
+ }
+
+ for (i = 0; i < ctx->xml.num_files; i++) {
+ if (ctx->xml.docs[i]) {
+ xmlFreeDoc(ctx->xml.docs[i]);
+ ctx->xml.docs[i] = NULL;
}
- else{
- pcilib_error("xml document %s not parsed successdfullly\n",line[k]);
- err_count++;
+ if (ctx->xml.xpath[i]) {
+ xmlXPathFreeContext(ctx->xml.xpath[i]);
+ ctx->xml.xpath[i] = NULL;
}
- }
- }
-
- ctx->xml_ctx->docs=docs;
-
- free(pwd);
- free(line);
- free(line_xsd);
+ }
+ ctx->xml.num_files = 0;
- if(err_count>0) return PCILIB_ERROR_NOTINITIALIZED;
- return 0;
-}
+ if (ctx->xml.validator) {
+ xmlSchemaFreeValidCtxt(ctx->xml.validator);
+ ctx->xml.validator = NULL;
+ }
+
+ if (ctx->xml.schema) {
+ xmlSchemaFree(ctx->xml.schema);
+ ctx->xml.schema = NULL;
+
+ }
-/** pcilib_clean_xml
- * this function free the xml parts of the pcilib_t running, and some libxml ashes
- * @param[in] pci the pcilib_t running
+ if (ctx->xml.parser) {
+ xmlFreeParserCtxt(ctx->xml.parser);
+ ctx->xml.parser = NULL;
+ }
+/*
+ xmlSchemaCleanupTypes();
+ xmlCleanupParser();
+ xmlMemoryDump();
*/
-void pcilib_free_xml(pcilib_t* pci){
-
- free(pci->xml_ctx->xml_banks);
- free(pci->xml_ctx->xml_registers);
- pci->xml_ctx->xml_banks=NULL;
- pci->xml_ctx->xml_registers=NULL;
- free(pci->xml_ctx);
- pci->xml_ctx=NULL;
-
- xmlCleanupParser();
- xmlMemoryDump();
-
}