diff options
-rw-r--r-- | models/ipecamera/camera.xml | 167 | ||||
-rwxr-xr-x | models/ipecamera/registers_and_banks.xsd | 7 | ||||
-rw-r--r-- | pcilib/pci.c | 10 | ||||
-rw-r--r-- | pcilib/pci.h | 4 | ||||
-rw-r--r-- | pcilib/xml.c | 200 | ||||
-rw-r--r-- | pcilib/xml.h | 6 | ||||
-rw-r--r-- | pcitool/cli.c | 2 |
7 files changed, 205 insertions, 191 deletions
diff --git a/models/ipecamera/camera.xml b/models/ipecamera/camera.xml index 0188267..288f6a4 100644 --- a/models/ipecamera/camera.xml +++ b/models/ipecamera/camera.xml @@ -3,12 +3,11 @@ <banks> <bank> <bank_description> - <adress>bank 0</adress> <bar>0</bar> <size>128</size> <protocol>default</protocol> - <read_adress>0x9010</read_adress> - <write_adress>0x9000</write_adress> + <read_address>0x9010</read_address> + <write_address>0x9000</write_address> <word_size>8</word_size> <endianess>little</endianess> <format>%lu</format> @@ -17,7 +16,7 @@ </bank_description> <registers> <register> - <adress>1</adress> + <address>1</address> <offset>0</offset> <size>16</size> <default>1088</default> @@ -27,7 +26,7 @@ <description>test</description> </register> <register> - <adress>3</adress> + <address>3</address> <offset>0</offset> <size>16</size> <default>0</default> @@ -36,7 +35,7 @@ <name>cmosis_start1</name> </register> <register> - <adress>5</adress> + <address>5</address> <offset>0</offset> <size>16</size> <default>0</default> @@ -45,7 +44,7 @@ <name>cmosis_start2</name> </register> <register> - <adress>7</adress> + <address>7</address> <offset>0</offset> <size>16</size> <default>0</default> @@ -54,7 +53,7 @@ <name>cmosis_start3</name> </register> <register> - <adress>9</adress> + <address>9</address> <offset>0</offset> <size>16</size> <default>0</default> @@ -63,7 +62,7 @@ <name>cmosis_start4</name> </register> <register> - <adress>11</adress> + <address>11</address> <offset>0</offset> <size>16</size> <default>0</default> @@ -72,7 +71,7 @@ <name>cmosis_start5</name> </register> <register> - <adress>13</adress> + <address>13</address> <offset>0</offset> <size>16</size> <default>0</default> @@ -81,7 +80,7 @@ <name>cmosis_start6</name> </register> <register> - <adress>15</adress> + <address>15</address> <offset>0</offset> <size>16</size> <default>0</default> @@ -90,7 +89,7 @@ <name>cmosis_start7</name> </register> <register> - <adress>17</adress> + <address>17</address> <offset>0</offset> <size>16</size> <default>0</default> @@ -99,7 +98,7 @@ <name>cmosis_start8</name> </register> <register> - <adress>19</adress> + <address>19</address> <offset>0</offset> <size>16</size> <default>0</default> @@ -108,7 +107,7 @@ <name>cmosis_number_lines1</name> </register> <register> - <adress>21</adress> + <address>21</address> <offset>0</offset> <size>16</size> <default>0</default> @@ -117,7 +116,7 @@ <name>cmosis_number_lines2</name> </register> <register> - <adress>23</adress> + <address>23</address> <offset>0</offset> <size>16</size> <default>0</default> @@ -126,7 +125,7 @@ <name>cmosis_number_lines3</name> </register> <register> - <adress>25</adress> + <address>25</address> <offset>0</offset> <size>16</size> <default>0</default> @@ -135,7 +134,7 @@ <name>cmosis_number_lines4</name> </register> <register> - <adress>27</adress> + <address>27</address> <offset>0</offset> <size>16</size> <default>0</default> @@ -144,7 +143,7 @@ <name>cmosis_number_lines5</name> </register> <register> - <adress>29</adress> + <address>29</address> <offset>0</offset> <size>16</size> <default>0</default> @@ -153,7 +152,7 @@ <name>cmosis_number_lines6</name> </register> <register> - <adress>31</adress> + <address>31</address> <offset>0</offset> <size>16</size> <default>0</default> @@ -162,7 +161,7 @@ <name>cmosis_number_lines7</name> </register> <register> - <adress>33</adress> + <address>33</address> <offset>0</offset> <size>16</size> <default>0</default> @@ -171,7 +170,7 @@ <name>cmosis_number_lines8</name> </register> <register> - <adress>35</adress> + <address>35</address> <offset>0</offset> <size>16</size> <default>0</default> @@ -180,7 +179,7 @@ <name>cmosis_sub_s</name> </register> <register> - <adress>37</adress> + <address>37</address> <offset>0</offset> <size>16</size> <default>0</default> @@ -189,7 +188,7 @@ <name>cmosis_sub_a</name> </register> <register> - <adress>39</adress> + <address>39</address> <offset>0</offset> <size>1</size> <default>1</default> @@ -198,7 +197,7 @@ <name>cmosis_color</name> </register> <register> - <adress>40</adress> + <address>40</address> <offset>0</offset> <size>2</size> <default>0</default> @@ -207,7 +206,7 @@ <name>cmosis_image_flipping</name> </register> <register> - <adress>41</adress> + <address>41</address> <offset>0</offset> <size>2</size> <default>0</default> @@ -216,7 +215,7 @@ <name>cmosis_exp_flags</name> </register> <register> - <adress>42</adress> + <address>42</address> <offset>0</offset> <size>24</size> <default>1088</default> @@ -229,7 +228,7 @@ </views> </register> <register> - <adress>45</adress> + <address>45</address> <offset>0</offset> <size>24</size> <default>1088</default> @@ -238,7 +237,7 @@ <name>cmosis_exp_step</name> </register> <register> - <adress>48</adress> + <address>48</address> <offset>0</offset> <size>24</size> <default>1</default> @@ -247,7 +246,7 @@ <name>cmosis_exp_kp1</name> </register> <register> - <adress>51</adress> + <address>51</address> <offset>0</offset> <size>24</size> <default>1</default> @@ -256,7 +255,7 @@ <name>cmosis_exp_kp2</name> </register> <register> - <adress>54</adress> + <address>54</address> <offset>0</offset> <size>2</size> <default>1</default> @@ -265,7 +264,7 @@ <name>cmosis_nr_slopes</name> </register> <register> - <adress>55</adress> + <address>55</address> <offset>0</offset> <size>8</size> <default>1</default> @@ -274,7 +273,7 @@ <name>cmosis_exp_seq</name> </register> <register> - <adress>56</adress> + <address>56</address> <offset>0</offset> <size>24</size> <default>1088</default> @@ -283,7 +282,7 @@ <name>cmosis_exp_time2</name> </register> <register> - <adress>59</adress> + <address>59</address> <offset>0</offset> <size>24</size> <default>1088</default> @@ -292,7 +291,7 @@ <name>cmosis_exp_step2</name> </register> <register> - <adress>68</adress> + <address>68</address> <offset>0</offset> <size>2</size> <default>1</default> @@ -301,7 +300,7 @@ <name>cmosis_nr_slopes2</name> </register> <register> - <adress>69</adress> + <address>69</address> <offset>0</offset> <size>8</size> <default>1</default> @@ -310,7 +309,7 @@ <name>cmosis_exp_seq2</name> </register> <register> - <adress>70</adress> + <address>70</address> <offset>0</offset> <size>16</size> <default>1</default> @@ -319,7 +318,7 @@ <name>cmosis_number_frames</name> </register> <register> - <adress>72</adress> + <address>72</address> <offset>0</offset> <size>2</size> <default>0</default> @@ -328,7 +327,7 @@ <name>cmosis_output_mode</name> </register> <register> - <adress>78</adress> + <address>78</address> <offset>0</offset> <size>12</size> <default>85</default> @@ -337,7 +336,7 @@ <name>cmosis_training_pattern</name> </register> <register> - <adress>80</adress> + <address>80</address> <offset>0</offset> <size>18</size> <default>0x3FFFF</default> @@ -346,7 +345,7 @@ <name>cmosis_channel_en</name> </register> <register> - <adress>82</adress> + <address>82</address> <offset>0</offset> <size>3</size> <default>7</default> @@ -355,7 +354,7 @@ <name>cmosis_special_82</name> </register> <register> - <adress>89</adress> + <address>89</address> <offset>0</offset> <size>8</size> <default>96</default> @@ -364,7 +363,7 @@ <name>cmosis_vlow2</name> </register> <register> - <adress>90</adress> + <address>90</address> <offset>0</offset> <size>8</size> <default>96</default> @@ -373,7 +372,7 @@ <name>cmosis_vlow3</name> </register> <register> - <adress>100</adress> + <address>100</address> <offset>0</offset> <size>14</size> <default>16260</default> @@ -382,7 +381,7 @@ <name>cmosis_offset</name> </register> <register> - <adress>102</adress> + <address>102</address> <offset>0</offset> <size>2</size> <default>0</default> @@ -391,7 +390,7 @@ <name>cmosis_pga</name> </register> <register> - <adress>103</adress> + <address>103</address> <offset>0</offset> <size>8</size> <default>32</default> @@ -400,7 +399,7 @@ <name>cmosis_adc_gain</name> </register> <register> - <adress>111</adress> + <address>111</address> <offset>0</offset> <size>1</size> <default>1</default> @@ -409,7 +408,7 @@ <name>cmosis_bit_mode</name> </register> <register> - <adress>112</adress> + <address>112</address> <offset>0</offset> <size>2</size> <default>0</default> @@ -418,7 +417,7 @@ <name>cmosis_adc_resolution</name> </register> <register> - <adress>115</adress> + <address>115</address> <offset>0</offset> <size>1</size> <default>1</default> @@ -430,12 +429,11 @@ </bank> <bank> <bank_description> - <adress>bank 1</adress> <bar>0</bar> <size>0x0200</size> <protocol>default</protocol> - <read_adress>0x9000</read_adress> - <write_adress>0x9000</write_adress> + <read_address>0x9000</read_address> + <write_address>0x9000</write_address> <word_size>32</word_size> <endianess>little</endianess> <format>0x%lx</format> @@ -444,7 +442,7 @@ </bank_description> <registers> <register> - <adress>0x00</adress> + <address>0x00</address> <offset>0</offset> <size>32</size> <default>0</default> @@ -453,7 +451,7 @@ <name>spi_conf_input</name> </register> <register> - <adress>0x10</adress> + <address>0x10</address> <offset>0</offset> <size>32</size> <default>0</default> @@ -462,7 +460,7 @@ <name>spi_conf_output</name> </register> <register> - <adress>0x20</adress> + <address>0x20</address> <offset>0</offset> <size>32</size> <default>0</default> @@ -471,7 +469,7 @@ <name>spi_clk_speed</name> </register> <register> - <adress>0x30</adress> + <address>0x30</address> <offset>0</offset> <size>32</size> <default>0</default> @@ -506,7 +504,7 @@ </registers_bits> </register> <register> - <adress>0x40</adress> + <address>0x40</address> <offset>0</offset> <size>32</size> <default>0</default> @@ -523,7 +521,7 @@ </registers_bits> </register> <register> - <adress>0x50</adress> + <address>0x50</address> <offset>0</offset> <size>32</size> <default>0</default> @@ -532,7 +530,7 @@ <name>status</name> </register> <register> - <adress>0x54</adress> + <address>0x54</address> <offset>0</offset> <size>32</size> <default>0</default> @@ -541,7 +539,7 @@ <name>status2</name> </register> <register> - <adress>0x58</adress> + <address>0x58</address> <offset>0</offset> <size>32</size> <default>0</default> @@ -550,7 +548,7 @@ <name>status3</name> </register> <register> - <adress>0x5c</adress> + <address>0x5c</address> <offset>0</offset> <size>32</size> <default>0</default> @@ -559,7 +557,7 @@ <name>fr_status</name> </register> <register> - <adress>0x70</adress> + <address>0x70</address> <offset>0</offset> <size>32</size> <default>0</default> @@ -568,7 +566,7 @@ <name>start_address</name> </register> <register> - <adress>0x74</adress> + <address>0x74</address> <offset>0</offset> <size>32</size> <default>0</default> @@ -577,7 +575,7 @@ <name>end_address</name> </register> <register> - <adress>0x78</adress> + <address>0x78</address> <offset>0</offset> <size>32</size> <default>0</default> @@ -586,7 +584,7 @@ <name>rd_address</name> </register> <register> - <adress>0xa0</adress> + <address>0xa0</address> <offset>0</offset> <size>32</size> <default>0</default> @@ -615,7 +613,7 @@ </registers_bits> </register> <register> - <adress>0xb0</adress> + <address>0xb0</address> <offset>0</offset> <size>32</size> <default>0</default> @@ -638,7 +636,7 @@ </registers_bits> </register> <register> - <adress>0xc0</adress> + <address>0xc0</address> <offset>0</offset> <size>32</size> <default>0</default> @@ -647,7 +645,7 @@ <name>skiped_lines</name> </register> <register> - <adress>0xd0</adress> + <address>0xd0</address> <offset>0</offset> <size>32</size> <default>0</default> @@ -656,7 +654,7 @@ <name>fr_thresholds</name> </register> <register> - <adress>0xd0</adress> + <address>0xd0</address> <offset>0</offset> <size>10</size> <default>0</default> @@ -665,7 +663,7 @@ <name>fr_pixel_thr</name> </register> <register> - <adress>0xd0</adress> + <address>0xd0</address> <offset>10</offset> <size>11</size> <default>0</default> @@ -674,7 +672,7 @@ <name>fr_num_pixel_thr</name> </register> <register> - <adress>0xd0</adress> + <address>0xd0</address> <offset>21</offset> <size>11</size> <default>0</default> @@ -683,7 +681,7 @@ <name>fr_num_lines_thr</name> </register> <register> - <adress>0x100</adress> + <address>0x100</address> <offset>0</offset> <size>32</size> <default>0</default> @@ -692,7 +690,7 @@ <name>rawdata_pkt_addr</name> </register> <register> - <adress>0x110</adress> + <address>0x110</address> <offset>0</offset> <size>32</size> <default>0</default> @@ -736,7 +734,7 @@ </registers_bits> </register> <register> - <adress>0x120</adress> + <address>0x120</address> <offset>0</offset> <size>32</size> <default>0</default> @@ -745,7 +743,7 @@ <name>num_lines</name> </register> <register> - <adress>0x130</adress> + <address>0x130</address> <offset>0</offset> <size>32</size> <default>0</default> @@ -754,7 +752,7 @@ <name>start_line</name> </register> <register> - <adress>0x140</adress> + <address>0x140</address> <offset>0</offset> <size>32</size> <default>0</default> @@ -763,7 +761,7 @@ <name>exp_time</name> </register> <register> - <adress>0x150</adress> + <address>0x150</address> <offset>0</offset> <size>32</size> <default>0</default> @@ -804,7 +802,7 @@ </registers_bits> </register> <register> - <adress>0x160</adress> + <address>0x160</address> <offset>0</offset> <size>32</size> <default>0</default> @@ -813,7 +811,7 @@ <name>write_status</name> </register> <register> - <adress>0x170</adress> + <address>0x170</address> <offset>0</offset> <size>32</size> <default>0</default> @@ -822,7 +820,7 @@ <name>num_triggers</name> </register> <register> - <adress>0x180</adress> + <address>0x180</address> <offset>0</offset> <size>32</size> <default>0x280</default> @@ -834,7 +832,7 @@ </views> </register> <register> - <adress>0x190</adress> + <address>0x190</address> <offset>0</offset> <size>32</size> <default>0</default> @@ -843,7 +841,7 @@ <name>temperature_sample_period</name> </register> <register> - <adress>0x1a0</adress> + <address>0x1a0</address> <offset>0</offset> <size>32</size> <default>0x64</default> @@ -852,7 +850,7 @@ <name>ddr_max_frames</name> </register> <register> - <adress>0x1b0</adress> + <address>0x1b0</address> <offset>0</offset> <size>32</size> <default>0</default> @@ -864,12 +862,11 @@ </bank> <bank> <bank_description> - <adress>DMA bank</adress> <bar>0</bar> <size>0x0200</size> <protocol>default</protocol> - <read_adress>0x0</read_adress> - <write_adress>0x0</write_adress> + <read_address>0x0</read_address> + <write_address>0x0</write_address> <word_size>32</word_size> <endianess>little</endianess> <format>0x%lx</format> diff --git a/models/ipecamera/registers_and_banks.xsd b/models/ipecamera/registers_and_banks.xsd index 10d49b7..234cc05 100755 --- a/models/ipecamera/registers_and_banks.xsd +++ b/models/ipecamera/registers_and_banks.xsd @@ -49,12 +49,11 @@ <xsd:complexType name="bank_description_t"> <xsd:sequence> - <xsd:element name="adress" type="bank_adress_type"/> <xsd:element name="bar" type="bar_type"/> <xsd:element name="size" type="hexa_and_integer64_t"/> <xsd:element name="protocol" type="xsd:string"/> - <xsd:element name="read_adress" type="hex64_t"/> - <xsd:element name="write_adress" type="hex64_t"/> + <xsd:element name="read_address" type="hex64_t"/> + <xsd:element name="write_address" type="hex64_t"/> <xsd:element name="word_size" type="uint8_t"/> <xsd:element name="endianess" type="endianess_type"/> <xsd:element name="format" type="xsd:string"/> @@ -72,7 +71,7 @@ <xsd:complexType name="register_type"> <xsd:sequence> - <xsd:element name="adress" type="hexa_and_integer32_t"/> + <xsd:element name="address" type="hexa_and_integer32_t"/> <xsd:element name="offset" type="uint8_t"/> <xsd:element name="size" type="uint8_t"/> <xsd:element name="default" type="hexa_and_integer32_t"/> diff --git a/pcilib/pci.c b/pcilib/pci.c index 8bbee2f..5f3c8aa 100644 --- a/pcilib/pci.c +++ b/pcilib/pci.c @@ -172,7 +172,12 @@ pcilib_t *pcilib_open(const char *device, const char *model) { if (!ctx->model) ctx->model = strdup(model?model:"pci"); - pcilib_init_xml(ctx, ctx->model); + err = pcilib_init_xml(ctx, ctx->model); + if (err) { + pcilib_error("Error (%i) initializing xml part\n", err); + pcilib_close(ctx); + return NULL; + } ctx->model_info.registers = ctx->registers; ctx->model_info.banks = ctx->banks; @@ -357,6 +362,9 @@ void pcilib_close(pcilib_t *ctx) { } pcilib_free_register_banks(ctx); + + if(ctx->xml_ctx) + pcilib_free_xml(ctx); if (ctx->register_ctx) free(ctx->register_ctx); diff --git a/pcilib/pci.h b/pcilib/pci.h index 40cb4bf..dfbaf9b 100644 --- a/pcilib/pci.h +++ b/pcilib/pci.h @@ -73,9 +73,7 @@ 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* xml_banks; /**<pointer to xml nodes of banks in the xml file*/ - xmlNodePtr* xml_registers; /**< pointer to xml nodes of registers in the xml file*/ - pcilib_xml_context_t* xml_context; /**< context to xml files*/ + pcilib_xml_context_t* xml_ctx; /**< context to xml files*/ pcilib_lock_t *dma_rlock[PCILIB_MAX_DMA_ENGINES]; /**< Per-engine locks to serialize streaming and read operations */ pcilib_lock_t *dma_wlock[PCILIB_MAX_DMA_ENGINES]; /**< Per-engine locks to serialize write operations */ diff --git a/pcilib/xml.c b/pcilib/xml.c index f581b96..8457927 100644 --- a/pcilib/xml.c +++ b/pcilib/xml.c @@ -4,11 +4,11 @@ * * @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 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 in the header file. In a case of a change in xml file, variables that need to be changed other than xpathes, will be indicated in the description of the function. - + * @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. - In case the performance is not good enough, please consider the following : no more configuration file indicating where the files required are, hard code of formulas, and go to complete non evolutive code : get 1 access to xml file and context, and then make recursive descent to get all you need(investigation of libxml2 source code would be so needed to prove it's better to go recursive than just xpath). + In case the performance is not good enough, please consider the following : hard code of formulas */ #define _XOPEN_SOURCE 700 @@ -33,6 +33,14 @@ #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; + /** 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 @@ -59,18 +67,6 @@ pcilib_xml_get_nodeset_from_xpath(xmlXPathContextPtr doc, xmlChar *xpath){ } -/**pcilib_xml_get_bank_node_from_register_node - * this function get the bank xml node from a standards register xml node in the xml file - *@param[in] mynode the register node we want to know the bank - *@return the bank node - */ -static xmlNodePtr -pcilib_xml_get_bank_node_from_register_node(xmlNodePtr mynode){ - return xmlFirstElementChild(xmlFirstElementChild(mynode->parent->parent)); -} - - - /** pcilib_xml_validate * function to validate the xml file against the xsd * @param[in] xml_filename path to the xml file @@ -125,14 +121,13 @@ if(ret!=0) pcilib_warning("\nxml file \"%s\" does not validate against the schem * @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){ +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; - static int i=0; int bar_ok=0; - int k=0, name_found=0; + int k=0; cur=mynode->children; /** we place ourselves in the childrens of the bank node*/ @@ -149,12 +144,8 @@ pcilib_xml_create_bank(pcilib_register_bank_description_t *mybank, xmlNodePtr my mybank->size=(size_t)strtol((char*)value,&ptr,0); }else if(strcasecmp((char*)cur->name,"protocol")==0){ - while(pci->protocols[k].name!=NULL){ - if(strcasecmp(pci->protocols[k].name,(char*)value)==0){ - mybank->protocol=pci->protocols[k].addr; - break; - k++; - } + if((mybank->protocol=pcilib_find_register_protocol_by_name(pci,(char*)value))==PCILIB_REGISTER_PROTOCOL_INVALID){ + mybank->protocol=PCILIB_REGISTER_PROTOCOL_DEFAULT; } }else if(strcasecmp((char*)cur->name,"read_address")==0){ @@ -190,20 +181,23 @@ pcilib_xml_create_bank(pcilib_register_bank_description_t *mybank, xmlNodePtr my } if(bar_ok==0) mybank->bar=PCILIB_BAR_NOBAR; - - while(pci->banks[k].name!=NULL){ - if(strcasecmp(pci->banks[k].name,mybank->name)==0){ - mybank->addr=pci->banks[k].addr; - name_found++; - break; + + 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; } - k++; - } - if(name_found==0) { - mybank->addr=PCILIB_REGISTER_BANK_DYNAMIC + i; - i++; + else mybank->addr=pci->banks[k].addr; + + if(err==0){ + pci->xml_ctx->xml_banks[k]=mynode; } - pci->xml_banks[k]=mynode; + + char buffer[66]; + sprintf(buffer,"%i",mybank->addr); + printf("buffer %s \n",buffer); + xmlNewChild(mynode,NULL, BAD_CAST "address", BAD_CAST buffer); } @@ -222,7 +216,7 @@ pcilib_xml_initialize_banks(pcilib_t* pci,xmlDocPtr doc){ xmlNodeSetPtr nodesetaddress=NULL; xmlNodePtr mynode; xmlXPathContextPtr context; - int i; + int i,err=0; mynode=malloc(sizeof(xmlNode)); if(!(context= xmlXPathNewContext(doc))){ @@ -234,13 +228,16 @@ pcilib_xml_initialize_banks(pcilib_t* pci,xmlDocPtr doc){ if(!(nodesetaddress)) return; if(nodesetaddress->nodeNr==0) return; - pci->xml_banks=calloc(PCILIB_MAX_REGISTER_BANKS+1,sizeof(xmlNodePtr)); - if(!(pci->xml_banks)) pcilib_error("can't create bank xml nodes for pcilib_t struct"); + 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++; + } /** 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); + pcilib_xml_create_bank(&mybank,mynode,doc, pci, err); pcilib_add_register_banks(pci,1,&mybank); } @@ -267,13 +264,24 @@ pcilib_xml_compare_registers(void const *a, void const *b){ * @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){ +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); } +/**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 @@ -281,12 +289,11 @@ void pcilib_xml_arrange_registers(pcilib_register_description_t *registers,int s * @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, xmlChar* type, pcilib_t* pci){ +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; - xmlNodePtr bank=NULL; int i=0; /**we get the children of the register xml nodes, that contains the properties for it*/ @@ -299,7 +306,7 @@ void pcilib_xml_create_register(pcilib_register_description_t *myregister,xmlNod */ 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); @@ -352,39 +359,19 @@ void pcilib_xml_create_register(pcilib_register_description_t *myregister,xmlNod /** make sure we don't get the description from previous registers*/ if(i==0) myregister->description=NULL; - /** we then get properties that can not be parsed as the previous ones*/ - if(strcasecmp((char*)type,"standard")==0){ + if((int)type==(int)type_standard){ myregister->type=PCILIB_REGISTER_STANDARD; - bank=pcilib_xml_get_bank_node_from_register_node(mynode); - while(bank!=NULL){ - value=xmlNodeListGetString(doc,bank->children,1); - if(strcasecmp((char*)bank->name,"name")==0){ - break; - } - bank=bank->next; - } - - int k=0; - - while(pci->banks[k].name!=NULL){ - printf("name %s\n",pci->banks[k].name); - if(strcasecmp(pci->banks[k].name,(char*)value)==0){ - myregister->bank=pci->banks[k].addr; - printf("ok\n"); - break; - } - k++; - } - - }else if(strcasecmp((char*)type,"bits")==0){ + 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(strcasecmp((char*)type,"fifo")==0){ + + }else if((int)type==(int)type_fifo){ /* not implemented yet*/ myregister->type=PCILIB_REGISTER_FIFO; } - + } @@ -403,7 +390,7 @@ void pcilib_xml_initialize_registers(pcilib_t* pci,xmlDocPtr doc){ xmlXPathContextPtr context; pcilib_register_description_t *registers=NULL; pcilib_register_description_t myregister; - int i,j; + int i,j,err=0; context= xmlXPathNewContext(doc); if(!(context= xmlXPathNewContext(doc))){ @@ -418,15 +405,22 @@ void pcilib_xml_initialize_registers(pcilib_t* pci,xmlDocPtr doc){ if(nodesetaddress->nodeNr>0)registers=calloc(nodesetaddress->nodeNr+nodesetsubaddress->nodeNr,sizeof(pcilib_register_description_t)); else return; - pci->xml_registers=calloc(nodesetaddress->nodeNr+nodesetsubaddress->nodeNr,sizeof(xmlNodePtr)); - if(!(pci->xml_registers)) pcilib_warning("can't create registers xml nodes in pcilib_t struct"); + 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,(xmlChar*)"standard",pci); + pcilib_xml_create_register(&myregister,mynode,doc,type_standard,pci); registers[i]=myregister; - pci->xml_registers[i]=mynode; + if(err==0) pci->xml_ctx->xml_registers[pci->xml_ctx->nb_registers+i]=mynode; } j=i; @@ -434,16 +428,17 @@ void pcilib_xml_initialize_registers(pcilib_t* pci,xmlDocPtr doc){ /** 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,(xmlChar*)"standard",pci); - pcilib_xml_create_register(&myregister,mynode,doc,(xmlChar*)"bits",pci); + 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; - pci->xml_registers[i+j]=mynode; + if(err==0) pci->xml_ctx->xml_registers[pci->xml_ctx->nb_registers+i+j]=mynode; } /**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; } @@ -460,7 +455,7 @@ int pcilib_init_xml(pcilib_t* ctx, char* model){ xmlDocPtr* docs; DIR* rep=NULL; struct dirent* file=NULL; - int err; + int err, err_count=0; path=malloc(sizeof(char*)); line=malloc(sizeof(char*)); @@ -469,8 +464,7 @@ int pcilib_init_xml(pcilib_t* ctx, char* model){ /** we first get the env variable corresponding to the place of the xml files*/ path=getenv("PCILIB_MODEL_DIR"); if(path==NULL){ - pcilib_warning("can't find environment variable for xml files"); - return 1; + path=PCILIB_MODEL_DIR; } /** we then open the directory corresponding to the ctx model*/ @@ -478,7 +472,7 @@ int pcilib_init_xml(pcilib_t* ctx, char* model){ 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 1; + return PCILIB_ERROR_NOTINITIALIZED; } /** we iterate through the files of the directory, to get the xml files and the xsd file*/ @@ -497,33 +491,45 @@ int pcilib_init_xml(pcilib_t* ctx, char* model){ if(line_xsd==NULL){ pcilib_warning("no xsd file found"); - return 1; + return PCILIB_ERROR_NOTINITIALIZED; } if(line[0]==NULL){ pcilib_warning("no xml file found"); - return 1; + return PCILIB_ERROR_NOTINITIALIZED; } /** 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; + + 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]); + pcilib_xml_initialize_registers(ctx,docs[k]); + } + else{ + pcilib_error("xml document %s not parsed successdfullly\n",line[k]); + err_count++; } - else pcilib_error("xml document %s not parsed successdfullly\n",line[k]); } } - ctx->xml_context=malloc(sizeof(pcilib_xml_context_t)); - ctx->xml_context->docs=malloc(sizeof(xmlDocPtr)*(i-1)); - ctx->xml_context->docs=docs; + + ctx->xml_ctx->docs=docs; free(pwd); free(line); free(line_xsd); + if(err_count>0) return PCILIB_ERROR_NOTINITIALIZED; return 0; } @@ -531,11 +537,15 @@ int pcilib_init_xml(pcilib_t* ctx, char* model){ * this function free the xml parts of the pcilib_t running, and some libxml ashes * @param[in] pci the pcilib_t running */ -void pcilib_clean_xml(pcilib_t* pci){ - - free(pci->xml_banks); - free(pci->xml_registers); - free(pci->xml_context); +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(); diff --git a/pcilib/xml.h b/pcilib/xml.h index c10a9d3..a88a8f9 100644 --- a/pcilib/xml.h +++ b/pcilib/xml.h @@ -17,6 +17,10 @@ typedef struct{ xmlDocPtr* docs; + xmlNodePtr* xml_banks; /**<pointer to xml nodes of banks in the xml file*/ + xmlNodePtr* xml_registers; /**< pointer to xml nodes of registers in the xml file*/ + unsigned int nb_registers; + unsigned int nb_new_banks; }pcilib_xml_context_t; /** @@ -30,6 +34,6 @@ int pcilib_init_xml(pcilib_t* pci, char* model); * this function free the xml parts of the pcilib_t running, and some libxml ashes * @param[in] pci the pcilib_t running */ -void pcilib_clean_xml(pcilib_t* pci); +void pcilib_free_xml(pcilib_t* pci); #endif /*_XML_*/ diff --git a/pcitool/cli.c b/pcitool/cli.c index 2628eaa..4c21e99 100644 --- a/pcitool/cli.c +++ b/pcitool/cli.c @@ -3395,7 +3395,5 @@ int main(int argc, char **argv) { if (data != argv + optind) free(data); - pcilib_clean_xml(handle); - return err; } |