diff options
-rw-r--r-- | pcilib/pci.c | 24 | ||||
-rw-r--r-- | pcilib/xml.c | 164 | ||||
-rw-r--r-- | pcilib/xml.h | 75 |
3 files changed, 77 insertions, 186 deletions
diff --git a/pcilib/pci.c b/pcilib/pci.c index fa3175d..5d9fedb 100644 --- a/pcilib/pci.c +++ b/pcilib/pci.c @@ -109,10 +109,6 @@ pcilib_t *pcilib_open(const char *device, const char *model) { size_t i; pcilib_t *ctx = malloc(sizeof(pcilib_t)); - pcilib_register_description_t *registers=NULL; - pcilib_register_bank_description_t *banks=NULL; - int number_registers, number_banks; - char *xmlfile; pcilib_xml_read_config(&xmlfile,3); xmlDocPtr doc; @@ -121,14 +117,6 @@ pcilib_t *pcilib_open(const char *device, const char *model) { xmlXPathContextPtr context; context=pcilib_xml_getcontext(doc); - number_registers=pcilib_xml_getnumberregisters(context); - number_banks=pcilib_xml_getnumberbanks(context); - - if(number_registers)registers=calloc((number_registers),sizeof(pcilib_register_description_t)); - else pcilib_error("no registers in the xml file"); - if(number_banks)banks=calloc((number_banks),sizeof(pcilib_register_bank_description_t)); - else pcilib_error("no banks in the xml file"); - if (!model) model = getenv("PCILIB_MODEL"); @@ -192,16 +180,8 @@ pcilib_t *pcilib_open(const char *device, const char *model) { if (!ctx->model) ctx->model = strdup(model?model:"pci"); - if(banks){ - pcilib_xml_initialize_banks(ctx,doc,banks); - pcilib_add_register_banks(ctx,number_banks,banks); - }else pcilib_error("no memory for banks"); - - if(registers){ - pcilib_xml_initialize_registers(ctx,doc,registers); - pcilib_xml_arrange_registers(registers,number_registers); - pcilib_add_registers(ctx,number_registers,registers); - }else pcilib_error("no memory for registers"); + pcilib_xml_initialize_banks(ctx,doc); + pcilib_xml_initialize_registers(ctx,doc); ctx->model_info.registers = ctx->registers; ctx->model_info.banks = ctx->banks; diff --git a/pcilib/xml.c b/pcilib/xml.c index 762f805..68ac42a 100644 --- a/pcilib/xml.c +++ b/pcilib/xml.c @@ -19,6 +19,8 @@ #include <assert.h> #include <Python.h> #include "pci.h" +#include "bank.h" +#include "register.h" //#define VIEW_OK //#define UNIT_OK @@ -260,12 +262,14 @@ void pcilib_xml_create_bank(pcilib_register_bank_description_t *mybank,xmlChar* * @param[in] doc the AST of the xml file. * @param[in,out] mybanks the structure containing the banks. */ -void pcilib_xml_initialize_banks(pcilib_t* pci, 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; xmlChar *adress=NULL,*bar=NULL,*size=NULL,*protocol=NULL,*read_addr=NULL,*write_addr=NULL,*access=NULL,*endianess=NULL,*format=NULL,*name=NULL,*description=NULL; xmlNodePtr mynode; + int number_banks; + pcilib_register_bank_description_t* banks; xmlXPathContextPtr context; context=pcilib_xml_getcontext(doc); @@ -274,10 +278,14 @@ void pcilib_xml_initialize_banks(pcilib_t* pci, xmlDocPtr doc, pcilib_register_b mynode=malloc(sizeof(xmlNode)); + number_banks=pcilib_xml_getnumberbanks(context); + if(number_banks) banks=calloc((number_banks),sizeof(pcilib_register_bank_description_t)); + else return; + xmlXPathObjectPtr temp; - /** we first get the nodes corresponding to the properties we want - * note: here a recursive algorithm may be more efficient but less evolutive*/ + /** we first get the nodes corresponding to the properties we want*/ +/* -----> certainly not necessary if we validate xml each time*/ temp=pcilib_xml_getsetproperty(context,BANK_ADDR_PATH); if(temp!=NULL) nodesetadress=temp->nodesetval; else pcilib_error("there is no adress for banks in the xml"); @@ -342,14 +350,62 @@ void pcilib_xml_initialize_banks(pcilib_t* pci, xmlDocPtr doc, pcilib_register_b /** 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); - mybanks[i]=mybank; + banks[i]=mybank; pci->banks_xml_nodes[i]=mynode; } + + pcilib_add_register_banks(pci,number_banks,banks); +} + +/* + * next 3 functions are for the implementation of a merge sort algorithm + */ +void topdownmerge(pcilib_register_description_t *A, int start, int middle, int end, pcilib_register_description_t *B){ + int i0,i1,j; + i0= start; + i1=middle; + for(j=start;j<end;j++){ + if((i0 < middle) && (i1>=end || A[i0].addr<=A[i1].addr)){ + B[j]=A[i0]; + i0++; + } + else{ + B[j]=A[i1]; + i1++; + } + } } +void copyarray(pcilib_register_description_t *B, int start,int end, pcilib_register_description_t *A){ + int k; + for (k=start; k<end;k++) A[k]=B[k]; +} + +void topdownsplitmerge(pcilib_register_description_t *A, int start, int end, pcilib_register_description_t *B){ + int middle; + if(end-start <2) + return; + + middle =(end+start)/2; + topdownsplitmerge(A,start, middle,B); + topdownsplitmerge(A,middle,end,B); + topdownmerge(A,start,middle,end,B); + copyarray(B,start,end,A); +} +/** 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 consider the adding of registers in order of adress + * @param[in,out] registers the list of registers in : not ranged out: ranged. + * @param[in] size the number of registers. + */ +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)); + topdownsplitmerge(registers,0,size,temp); +} /** pcilib_xml_getnumberregisters * @@ -373,6 +429,7 @@ int pcilib_xml_getnumberregisters(xmlXPathContextPtr doc){ return nodesetadress->nodeNr + nodesetsuboffset->nodeNr; /**<we sum the number of nodes in the first structure to the number of nodes in the second one*/ } + /** pcilib_xml_initialize_registers * * this function create a list of registers from an abstract syntax tree @@ -381,20 +438,28 @@ 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(pcilib_t* pci, 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; xmlNodePtr mynode; xmlNodePtr tempnode; xmlXPathContextPtr context; + int number_registers; + pcilib_register_description_t *registers=NULL; + context=pcilib_xml_getcontext(doc); - mynode=malloc(sizeof(xmlNode)); + + number_registers=pcilib_xml_getnumberregisters(context); + if(number_registers) registers=calloc(number_registers,sizeof(pcilib_register_description_t)); + else return; xmlXPathObjectPtr temp; /** get the sructures containing each property of standard regsiter */ +/* -----> certainly not necessary if we validate xml each time*/ + temp=pcilib_xml_getsetproperty(context,ADRESS_PATH); if(temp!=NULL)nodesetadress=temp->nodesetval; else pcilib_error("no adress for registers found in xml"); @@ -506,57 +571,12 @@ void pcilib_xml_initialize_registers(pcilib_t* pci, xmlDocPtr doc,pcilib_registe registers[i+j]=myregister; pci->registers_xml_nodes[i+j]=mynode; } -} - - -/* - * next 3 functions are for the implementation of a merge sort algorithm - */ -void topdownmerge(pcilib_register_description_t *A, int start, int middle, int end, pcilib_register_description_t *B){ - int i0,i1,j; - i0= start; - i1=middle; - - for(j=start;j<end;j++){ - if((i0 < middle) && (i1>=end || A[i0].addr<=A[i1].addr)){ - B[j]=A[i0]; - i0++; - } - else{ - B[j]=A[i1]; - i1++; - } - } -} -void copyarray(pcilib_register_description_t *B, int start,int end, pcilib_register_description_t *A){ - int k; - for (k=start; k<end;k++) A[k]=B[k]; + pcilib_xml_arrange_registers(registers,number_registers); + pcilib_add_registers(pci,number_registers,registers); } -void topdownsplitmerge(pcilib_register_description_t *A, int start, int end, pcilib_register_description_t *B){ - int middle; - if(end-start <2) - return; - - middle =(end+start)/2; - topdownsplitmerge(A,start, middle,B); - topdownsplitmerge(A,middle,end,B); - topdownmerge(A,start,middle,end,B); - copyarray(B,start,end,A); -} -/** 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 consider the adding of registers in order of adress - * @param[in,out] registers the list of registers in : not ranged out: ranged. - * @param[in] size the number of registers. - */ -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)); - topdownsplitmerge(registers,0,size,temp); -} #include <libxml/xmlschemastypes.h> /** validation @@ -644,44 +664,6 @@ void pcilib_xml_read_config(char** xmlfile, int j){ memset(line,'\0',60); } } -/* to include or not?*/ -/** pcilib_xml_init_nodeset_register_ctx - * - * function to get all registers nodes in a structure and put it in registers context -* @param[in] ctx the register context running. - * -void pcilib_xml_init_nodeset_register_ctx(pcilib_register_context_t *ctx){ - char* xmlfile; - pcilib_xml_read_config(&xmlfile,3); - xmlDocPtr doc; - doc=pcilib_xml_getdoc(xmlfile); - xmlXPathContextPtr context; - context=pcilib_xml_getcontext(doc); - - xmlNodeSetPtr registers; - registers = pcilib_xml_getsetproperty(context, REGISTERS_PATH)->nodesetval; - ctx->registers_nodes=registers; -} - -** pcilib_xml_init_nodeset_bank_ctx - * - *function to get all banks nodes in a structure and put it in banks context -* @param[in] ctx the bank context running. - * -void pcilib_xml_init_nodeset_bank_ctx(pcilib_register_bank_context_t *ctx){ - char* xmlfile; - pcilib_xml_read_config(&xmlfile,3); - xmlDocPtr doc; - doc=pcilib_xml_getdoc(xmlfile); - xmlXPathContextPtr context; - context=pcilib_xml_getcontext(doc); - - xmlNodeSetPtr banks; - banks = pcilib_xml_getsetproperty(context, BANKS_PATH)->nodesetval; - ctx->banks_nodes=banks; - -} -*/ #ifdef VIEW_OK /* pcilib_xml_getnumberformulaviews diff --git a/pcilib/xml.h b/pcilib/xml.h index 3f6d87f..a921b3e 100644 --- a/pcilib/xml.h +++ b/pcilib/xml.h @@ -106,22 +106,7 @@ xmlXPathObjectPtr pcilib_xml_getsetproperty(xmlXPathContextPtr doc, xmlChar *xpa * @param[in] doc the xpath context of the xml file. * @param[out] registers out: the list of the created registers. */ -void pcilib_xml_initialize_registers(pcilib_t* pci, xmlDocPtr doc,pcilib_register_description_t *registers); - -/** - * this function get the numbers of registers in the xml file for further malloc and xml checking. - * @param[in] doc the xpath context of the xml file. - * @return the numbers of registers in xml file. - * @todo see the usage of this function. - */ -int pcilib_xml_getnumberregisters(xmlXPathContextPtr doc); - -/** - * this function rearrange the list of registers to put them in pcilib_open furthermore, using a merge sort algorithm. The merge sort algorithm was chosen as it's fast and stable, however it uses some memory, but it's not limitating here. - * @param[in,out] registers the list of registers in : not ranged out: ranged. - * @param[in] size the number of registers. - */ -void pcilib_xml_arrange_registers(pcilib_register_description_t *registers,int size); +void pcilib_xml_initialize_registers(pcilib_t* pci, xmlDocPtr doc); /** * this functions initialize the structures containing banks, for use in the rest of execution, from the xml file. @@ -129,34 +114,7 @@ void pcilib_xml_arrange_registers(pcilib_register_description_t *registers,int s * @param[in] doc the AST of the xml file. * @param[in,out] mybanks the structure containing the banks. */ -void pcilib_xml_initialize_banks(pcilib_t* pci,xmlDocPtr doc, pcilib_register_bank_description_t* mybanks); - -/** - * this function create a bank from the informations gathered in the xml. - * @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); -*/ - -/** - * this function get the numbers of banks in the xml file for further malloc and xml checking. - * @param[in] doc the Xpath context of the xml file. - * @return the number of banks. - *@todo see the usage of this function. - */ -int pcilib_xml_getnumberbanks(xmlXPathContextPtr doc); +void pcilib_xml_initialize_banks(pcilib_t* pci,xmlDocPtr doc); /** * this function read the config file of the pcitool tool to give back the pwd of diverse files like the xml file to treat, the xsd file, the pythonscript file, the units xml file, the units xsd file. @@ -179,33 +137,4 @@ void validation(); */ xmlXPathContextPtr pcilib_xml_getcontext(xmlDocPtr doc); -/** -* this function is used to register the xpath object containing all registers node in registers context. -* @param[in] ctx the register context running. -*/ -void pcilib_xml_init_nodeset_register_ctx(pcilib_register_context_t *ctx); - -/** -* this function is used to register the xpath object containing all bankss node in banks context. -* @param[in] ctx the bank context running. -*/ -void pcilib_xml_init_nodeset_bank_ctx(pcilib_register_bank_context_t *ctx); - -/** - * this function create a register structure from the results of xml parsing. - * @param[out] myregister the register we want to create - * @param[in] adress the adress of the future register - * @param[in] offset the offset of the future register - * @param[in] size the size of the future register - * @param[in] defvalue the defaut value of the future register - * @param[in] rwmask the rwmask of the future register - * @param[in] mode the mode of the future register - * @param[in] type the type of the future register - * @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);*/ - #endif /*_XML_*/ |