From d3678e0fcb489eba625347d1209bd8a179153ae0 Mon Sep 17 00:00:00 2001 From: zilio nicolas Date: Thu, 27 Aug 2015 11:09:21 +0200 Subject: put xml nodes pointers for banks and registers in pcilib_t, compil ok --- pcilib/CMakeLists.txt | 6 +- pcilib/bank.h | 1 - pcilib/pci.c | 8 +- pcilib/pci.h | 3 + pcilib/register.h | 1 - pcilib/xml.c | 200 ++++++++++++++++++++++++++------------------------ pcilib/xml.h | 13 ++-- 7 files changed, 121 insertions(+), 111 deletions(-) (limited to 'pcilib') diff --git a/pcilib/CMakeLists.txt b/pcilib/CMakeLists.txt index 774ebe9..428f898 100644 --- a/pcilib/CMakeLists.txt +++ b/pcilib/CMakeLists.txt @@ -5,8 +5,10 @@ include_directories( ${CMAKE_SOURCE_DIR}/pcilib ) -set(HEADERS pcilib.h pci.h export.h bar.h fifo.h model.h bank.h register.h kmem.h irq.h locking.h lock.h dma.h event.h plugin.h tools.h error.h debug.h env.h version.h config.h) -add_library(pcilib SHARED pci.c export.c bar.c fifo.c model.c bank.c register.c kmem.c irq.c locking.c lock.c dma.c event.c plugin.c tools.c error.c debug.c env.c ) +set(HEADERS pcilib.h pci.h export.h bar.h fifo.h model.h bank.h register.h +kmem.h irq.h locking.h lock.h dma.h event.h plugin.h tools.h error.h debug.h +env.h version.h config.h xml.h) +add_library(pcilib SHARED pci.c export.c bar.c fifo.c model.c bank.c register.c kmem.c irq.c locking.c lock.c dma.c event.c plugin.c tools.c error.c debug.c env.c xml.c) target_link_libraries(pcilib dma protocols ${CMAKE_THREAD_LIBS_INIT} ${UFODECODE_LIBRARIES} ${CMAKE_DL_LIBS} ${EXTRA_SYSTEM_LIBS} ${XMLLIB_LIBRARIES} ${PYTHON_LIBRARIES}) add_dependencies(pcilib dma protocols) diff --git a/pcilib/bank.h b/pcilib/bank.h index e2174e9..8074197 100644 --- a/pcilib/bank.h +++ b/pcilib/bank.h @@ -62,7 +62,6 @@ typedef struct { const char *format; /**< printf format for the registers, either %lu for decimal output or 0x%lx for hexdecimal */ const char *name; /**< short bank name */ const char *description; /**< longer bank description */ - /* use it or not?*/ /*xmlNodePtr xmlNode;*/ /**model = strdup(model?model:"pci"); if(banks){ - pcilib_xml_initialize_banks(doc,banks); - pcilib_add_register_banks(ctx,number_banks,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(doc,registers); - pcilib_xml_arrange_registers(registers,number_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"); diff --git a/pcilib/pci.h b/pcilib/pci.h index 340abd3..e3ed1c5 100644 --- a/pcilib/pci.h +++ b/pcilib/pci.h @@ -25,6 +25,7 @@ #include "model.h" #include "export.h" #include "locking.h" +#include typedef struct { uint8_t max_link_speed, link_speed; @@ -71,6 +72,8 @@ struct pcilib_s { pcilib_register_bank_context_t *bank_ctx[PCILIB_MAX_REGISTER_BANKS]; /**< Contexts for registers banks if required by register protocol */ pcilib_dma_context_t *dma_ctx; /**< DMA context */ pcilib_context_t *event_ctx; /**< Implmentation context */ + xmlNodePtr* banks_xml_nodes; /** #include #include - +#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;inodeNr;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;inodeNr;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; } } diff --git a/pcilib/xml.h b/pcilib/xml.h index f5833aa..3f6d87f 100644 --- a/pcilib/xml.h +++ b/pcilib/xml.h @@ -26,7 +26,7 @@ #include "register.h" #include "model.h" #include "bank.h" - +#include "pci.h" //#include #define REGISTERS_PATH ((xmlChar*)"/model/banks/bank/registers/register") /**