summaryrefslogtreecommitdiffstats
path: root/pcilib/xml.c
diff options
context:
space:
mode:
authorzilio nicolas <nicolas.zilio@kit.edu>2015-08-27 11:09:21 +0200
committerzilio nicolas <nicolas.zilio@kit.edu>2015-08-27 11:09:21 +0200
commitd3678e0fcb489eba625347d1209bd8a179153ae0 (patch)
treeec3b968b1290ef2184c1eceb6ed6d9e1dbefc23d /pcilib/xml.c
parent1e5f0b6d5e02c0dc11bedefa92fc3c5bb406845a (diff)
downloadpcitool-d3678e0fcb489eba625347d1209bd8a179153ae0.tar.gz
pcitool-d3678e0fcb489eba625347d1209bd8a179153ae0.tar.bz2
pcitool-d3678e0fcb489eba625347d1209bd8a179153ae0.tar.xz
pcitool-d3678e0fcb489eba625347d1209bd8a179153ae0.zip
put xml nodes pointers for banks and registers in pcilib_t, compil ok
Diffstat (limited to 'pcilib/xml.c')
-rw-r--r--pcilib/xml.c200
1 files changed, 103 insertions, 97 deletions
diff --git a/pcilib/xml.c b/pcilib/xml.c
index 205b563..762f805 100644
--- a/pcilib/xml.c
+++ b/pcilib/xml.c
@@ -18,7 +18,7 @@
#include <string.h>
#include <assert.h>
#include <Python.h>
-
+#include "pci.h"
//#define VIEW_OK
//#define UNIT_OK
@@ -90,9 +90,8 @@ xmlXPathContextPtr pcilib_xml_getcontext(xmlDocPtr doc){
* @param[in] bank the bank of the future register
* @param[in] name the name of the future register
* @param[in] description the description of the future register
- * @param[in] node the current xmlNode in the xml of the future register
*/
-void pcilib_xml_create_register(pcilib_register_description_t *myregister,xmlChar* adress, xmlChar *offset, xmlChar *size, xmlChar *defvalue, xmlChar *rwmask, xmlChar *mode, xmlChar *type, xmlChar *bank, xmlChar *name, xmlChar *description, xmlNodePtr node){
+void pcilib_xml_create_register(pcilib_register_description_t *myregister,xmlChar* adress, xmlChar *offset, xmlChar *size, xmlChar *defvalue, xmlChar *rwmask, xmlChar *mode, xmlChar *type, xmlChar *bank, xmlChar *name, xmlChar *description){
char* ptr;
@@ -153,8 +152,6 @@ void pcilib_xml_create_register(pcilib_register_description_t *myregister,xmlCha
myregister->name=(char*)name;
myregister->description=(char*)description;
- /*should we include those xmlnodes?*/
- //myregister->xmlNode=node;
}
/** pcilib_xml_getnumberbanks
@@ -172,6 +169,90 @@ int pcilib_xml_getnumberbanks(xmlXPathContextPtr doc){
return nodesetadress->nodeNr; /**< we then return the number of said nodes */
}
+/** pcilib_xml_create_bank
+ *
+ * this function create a bank structure from the results of xml parsing
+ * @param[out] mybank the created bank.
+ * @param[in] adress the adress of the bank that will be created.
+ * @param[in] bar the bar of the bank that will be created.
+ * @param[in] size the size of the bank that will be created.
+ * @param[in] protocol the protocol of the bank that will be created.
+ * @param[in] read_addr the read adress for protocol of the bank that will be created.
+ * @param[in] write_addr the write adress for the protocol of the bank that will be created.
+ * @param[in] access the word size of the bank that will be created.
+ * @param[in] endianess the endianess of the bank that will be created.
+ * @param[in] format the format of the bank that will be created.
+ * @param[in] name the name of the bank that will be created.
+ * @param[in] description the description of the bank that will be created.
+ */
+void pcilib_xml_create_bank(pcilib_register_bank_description_t *mybank,xmlChar* adress, xmlChar *bar, xmlChar *size, xmlChar *protocol, xmlChar *read_addr, xmlChar *write_addr, xmlChar *access, xmlChar *endianess, xmlChar *format, xmlChar *name,xmlChar *description){
+
+ char* ptr;
+
+ /** we recreate each sub property of banks' structure given the results of xml parsing
+ note : strtol is used here to get hexadecimal and decimal values from the xml file as well*/
+
+ if (strcmp((char*)adress,"bank 0")==0){
+ mybank->addr=PCILIB_REGISTER_BANK0;
+ }else if (strcmp((char*)adress,"bank 1")==0){
+ mybank->addr=PCILIB_REGISTER_BANK1;
+ }else if (strcmp((char*)adress,"bank 2")==0){
+ mybank->addr=PCILIB_REGISTER_BANK2;
+ }else if (strcmp((char*)adress,"bank 3")==0){
+ mybank->addr=PCILIB_REGISTER_BANK3;
+ }else if (strcmp((char*)adress,"DMA bank")==0){
+ mybank->addr=PCILIB_REGISTER_BANK_DMA;
+ }else if (strcmp((char*)adress,"DMAconf bank")==0){
+ mybank->addr=PCILIB_REGISTER_BANK_DMACONF;
+ }else if (strcmp((char*)adress,"dynamic bank")==0){
+ mybank->addr=PCILIB_REGISTER_BANK_DYNAMIC;
+ }else{
+ mybank->addr=PCILIB_REGISTER_BANK_INVALID;
+ }
+
+ if(strcmp((char*)bar,"0")==0){
+ mybank->bar=PCILIB_BAR0;
+ }else if(strcmp((char*)bar,"1")==0){
+ mybank->bar=PCILIB_BAR1;
+ }else if(strcmp((char*)bar,"no_bar")==0){
+ mybank->bar=PCILIB_BAR_NOBAR;
+ }else{
+ mybank->bar=PCILIB_BAR_INVALID;
+ }
+
+ mybank->bar=(pcilib_bar_t)strtol((char*)bar,&ptr,0);
+ mybank->size=(size_t)strtol((char*)size,&ptr,0);
+
+ if(strcmp((char*)protocol,"default")==0){
+ mybank->protocol=PCILIB_REGISTER_PROTOCOL_DEFAULT;
+ }else if(strcmp((char*)protocol,"0")==0){
+ mybank->protocol=PCILIB_REGISTER_PROTOCOL0;
+ }else if(strcmp((char*)protocol,"dma")==0){
+ mybank->protocol=PCILIB_REGISTER_PROTOCOL_DMA;
+ }else if(strcmp((char*)protocol,"dynamic")==0){
+ mybank->protocol=PCILIB_REGISTER_PROTOCOL_DYNAMIC;
+ }else if (strcmp((char*)protocol,"software")==0){
+ mybank->protocol=PCILIB_REGISTER_PROTOCOL_SOFTWARE;
+ }else mybank->protocol=PCILIB_REGISTER_PROTOCOL_INVALID;
+
+ mybank->read_addr=(uintptr_t)strtol((char*)read_addr,&ptr,0);
+ mybank->write_addr=(uintptr_t)strtol((char*)write_addr,&ptr,0);
+ mybank->access=(uint8_t)strtol((char*)access,&ptr,0);
+
+ if(strcmp((char*)endianess,"little")==0){
+ mybank->endianess=PCILIB_LITTLE_ENDIAN;
+ }else if(strcmp((char*)endianess,"big")==0){
+ mybank->endianess=PCILIB_BIG_ENDIAN;
+ }else if(strcmp((char*)endianess,"host")==0){
+ mybank->endianess=PCILIB_HOST_ENDIAN;
+ }
+ mybank->format=(char*)format;
+ mybank->raw_endianess=mybank->endianess;
+
+ mybank->name=(char*)name;
+ mybank->description=(char*)description;
+}
+
/** pcilib_xml_initialize_banks
*
* function to create the structures to store the banks from the AST
@@ -179,7 +260,7 @@ int pcilib_xml_getnumberbanks(xmlXPathContextPtr doc){
* @param[in] doc the AST of the xml file.
* @param[in,out] mybanks the structure containing the banks.
*/
-void pcilib_xml_initialize_banks(xmlDocPtr doc, pcilib_register_bank_description_t* mybanks){
+void pcilib_xml_initialize_banks(pcilib_t* pci, xmlDocPtr doc, pcilib_register_bank_description_t* mybanks){
pcilib_register_bank_description_t mybank;
xmlNodeSetPtr nodesetadress=NULL,nodesetbar=NULL,nodesetsize=NULL,nodesetprotocol=NULL,nodesetread_addr=NULL,nodesetwrite_addr=NULL,nodesetaccess=NULL,nodesetendianess=NULL,nodesetformat=NULL,nodesetname=NULL,nodesetdescription=NULL;
@@ -239,7 +320,10 @@ void pcilib_xml_initialize_banks(xmlDocPtr doc, pcilib_register_bank_description
temp=pcilib_xml_getsetproperty(context,BANK_DESCRIPTION_PATH);
if(temp!=NULL)nodesetdescription=temp->nodesetval;
-
+
+ pci->banks_xml_nodes=calloc(nodesetadress->nodeNr,sizeof(xmlNodePtr));
+ if(!(pci->banks_xml_nodes)) pcilib_warning("can't create bank xml nodes for pcilib_t struct");
+
for(i=0;i<nodesetadress->nodeNr;i++){
/** we then get each node from the structures above*/
adress=xmlNodeListGetString(doc,nodesetadress->nodeTab[i]->xmlChildrenNode, 1);
@@ -255,99 +339,16 @@ void pcilib_xml_initialize_banks(xmlDocPtr doc, pcilib_register_bank_description
description=xmlNodeListGetString(doc,nodesetdescription->nodeTab[i]->xmlChildrenNode, 1);
mynode=nodesetadress->nodeTab[i]->parent;
+
/** the following function will create the given structure for banks*/
- pcilib_xml_create_bank(&mybank,adress,bar,size,protocol,read_addr,write_addr,access,endianess,format, name, description,mynode);
+ pcilib_xml_create_bank(&mybank,adress,bar,size,protocol,read_addr,write_addr,access,endianess,format, name, description);
mybanks[i]=mybank;
+ pci->banks_xml_nodes[i]=mynode;
+
}
}
-/** pcilib_xml_create_bank
- *
- * this function create a bank structure from the results of xml parsing
- * @param[out] mybank the created bank.
- * @param[in] adress the adress of the bank that will be created.
- * @param[in] bar the bar of the bank that will be created.
- * @param[in] size the size of the bank that will be created.
- * @param[in] protocol the protocol of the bank that will be created.
- * @param[in] read_addr the read adress for protocol of the bank that will be created.
- * @param[in] write_addr the write adress for the protocol of the bank that will be created.
- * @param[in] access the word size of the bank that will be created.
- * @param[in] endianess the endianess of the bank that will be created.
- * @param[in] format the format of the bank that will be created.
- * @param[in] name the name of the bank that will be created.
- * @param[in] description the description of the bank that will be created.
- * @param[in] node the xmlNodeptr referring to the bank_description node of the bank that will be created.
- */
-void pcilib_xml_create_bank(pcilib_register_bank_description_t *mybank,xmlChar* adress, xmlChar *bar, xmlChar *size, xmlChar *protocol, xmlChar *read_addr, xmlChar *write_addr, xmlChar *access, xmlChar *endianess, xmlChar *format, xmlChar *name,xmlChar *description, xmlNodePtr node){
-
- char* ptr;
-
- /** we recreate each sub property of banks' structure given the results of xml parsing
- note : strtol is used here to get hexadecimal and decimal values from the xml file as well*/
-
- if (strcmp((char*)adress,"bank 0")==0){
- mybank->addr=PCILIB_REGISTER_BANK0;
- }else if (strcmp((char*)adress,"bank 1")==0){
- mybank->addr=PCILIB_REGISTER_BANK1;
- }else if (strcmp((char*)adress,"bank 2")==0){
- mybank->addr=PCILIB_REGISTER_BANK2;
- }else if (strcmp((char*)adress,"bank 3")==0){
- mybank->addr=PCILIB_REGISTER_BANK3;
- }else if (strcmp((char*)adress,"DMA bank")==0){
- mybank->addr=PCILIB_REGISTER_BANK_DMA;
- }else if (strcmp((char*)adress,"DMAconf bank")==0){
- mybank->addr=PCILIB_REGISTER_BANK_DMACONF;
- }else if (strcmp((char*)adress,"dynamic bank")==0){
- mybank->addr=PCILIB_REGISTER_BANK_DYNAMIC;
- }else{
- mybank->addr=PCILIB_REGISTER_BANK_INVALID;
- }
-
- if(strcmp((char*)bar,"0")==0){
- mybank->bar=PCILIB_BAR0;
- }else if(strcmp((char*)bar,"1")==0){
- mybank->bar=PCILIB_BAR1;
- }else if(strcmp((char*)bar,"no_bar")==0){
- mybank->bar=PCILIB_BAR_NOBAR;
- }else{
- mybank->bar=PCILIB_BAR_INVALID;
- }
-
- mybank->bar=(pcilib_bar_t)strtol((char*)bar,&ptr,0);
- mybank->size=(size_t)strtol((char*)size,&ptr,0);
-
- if(strcmp((char*)protocol,"default")==0){
- mybank->protocol=PCILIB_REGISTER_PROTOCOL_DEFAULT;
- }else if(strcmp((char*)protocol,"0")==0){
- mybank->protocol=PCILIB_REGISTER_PROTOCOL0;
- }else if(strcmp((char*)protocol,"dma")==0){
- mybank->protocol=PCILIB_REGISTER_PROTOCOL_DMA;
- }else if(strcmp((char*)protocol,"dynamic")==0){
- mybank->protocol=PCILIB_REGISTER_PROTOCOL_DYNAMIC;
- }else if (strcmp((char*)protocol,"software")==0){
- mybank->protocol=PCILIB_REGISTER_PROTOCOL_SOFTWARE;
- }else mybank->protocol=PCILIB_REGISTER_PROTOCOL_INVALID;
-
- mybank->read_addr=(uintptr_t)strtol((char*)read_addr,&ptr,0);
- mybank->write_addr=(uintptr_t)strtol((char*)write_addr,&ptr,0);
- mybank->access=(uint8_t)strtol((char*)access,&ptr,0);
-
- if(strcmp((char*)endianess,"little")==0){
- mybank->endianess=PCILIB_LITTLE_ENDIAN;
- }else if(strcmp((char*)endianess,"big")==0){
- mybank->endianess=PCILIB_BIG_ENDIAN;
- }else if(strcmp((char*)endianess,"host")==0){
- mybank->endianess=PCILIB_HOST_ENDIAN;
- }
- mybank->format=(char*)format;
- mybank->raw_endianess=mybank->endianess;
-
- mybank->name=(char*)name;
- mybank->description=(char*)description;
- /* to include or not?*/
- //mybank->xmlNode=node;
-}
/** pcilib_xml_getnumberregisters
@@ -380,7 +381,7 @@ int pcilib_xml_getnumberregisters(xmlXPathContextPtr doc){
* @param[in] doc the xpath context of the xml file.
* @param[in,out] registers in: initialized list out: the list of the created registers.
*/
-void pcilib_xml_initialize_registers(xmlDocPtr doc,pcilib_register_description_t *registers){
+void pcilib_xml_initialize_registers(pcilib_t* pci, xmlDocPtr doc,pcilib_register_description_t *registers){
xmlNodeSetPtr nodesetadress=NULL,nodesetoffset=NULL,nodesetdefvalue=NULL,nodesetrwmask=NULL,nodesetsize=NULL,nodesetmode=NULL,nodesetname=NULL;
xmlChar *adress=NULL,*offset=NULL,*defvalue=NULL,*rwmask=NULL,*size=NULL,*mode=NULL,*name=NULL,*bank=NULL,*type=NULL,*description=NULL;
@@ -446,6 +447,9 @@ void pcilib_xml_initialize_registers(xmlDocPtr doc,pcilib_register_description_t
pcilib_register_description_t myregister;
int i,j;
+
+ pci->registers_xml_nodes=calloc(nodesetadress->nodeNr+nodesetsuboffset->nodeNr,sizeof(xmlNodePtr));
+ if(!(pci->registers_xml_nodes)) pcilib_warning("can't create registers xml nodes in pcilib_t struct");
for(i=0;i<nodesetadress->nodeNr;i++){
/** get each sub property of each standard registers*/
@@ -467,8 +471,9 @@ void pcilib_xml_initialize_registers(xmlDocPtr doc,pcilib_register_description_t
}
mynode=nodesetadress->nodeTab[i]->parent;
/**creation of a register with the given previous properties*/
- pcilib_xml_create_register(&myregister,adress,offset,size,defvalue,rwmask,mode, type, bank, name, description,mynode);
+ pcilib_xml_create_register(&myregister,adress,offset,size,defvalue,rwmask,mode, type, bank, name, description);
registers[i]=myregister;
+ pci->registers_xml_nodes[i]=mynode;
}
j=i;
@@ -497,8 +502,9 @@ void pcilib_xml_initialize_registers(xmlDocPtr doc,pcilib_register_description_t
}
mynode=nodesetsuboffset->nodeTab[i]->parent;
/** creation of a bits register given the previous properties*/
- pcilib_xml_create_register(&myregister,subadress,suboffset,subsize,subdefvalue,subrwmask,submode, subtype, subbank, subname, subdescription,mynode);
+ pcilib_xml_create_register(&myregister,subadress,suboffset,subsize,subdefvalue,subrwmask,submode, subtype, subbank, subname, subdescription);
registers[i+j]=myregister;
+ pci->registers_xml_nodes[i+j]=mynode;
}
}