source: branch/giet_vm_ioc_drivers/giet_xml/xml_driver.c @ 286

Last change on this file since 286 was 286, checked in by cfuguet, 10 years ago
  • Modifying HBA driver to respect new IOC driver interface.
  • Modifying XML parser and XML driver to manage the HBA controller as an IOC subtype.
  • Property svn:executable set to *
File size: 17.9 KB
Line 
1////////////////////////////////////////////////////////////////////////////
2// File     : xml_driver.c
3// Date     : 04/04/2012
4// Author   : alain greiner
5// Copyright (c) UPMC-LIP6
6////////////////////////////////////////////////////////////////////////////
7// This program translate a binary file containing a MAPPING_INFO
8// data structure to an xml file.
9////////////////////////////////////////////////////////////////////////////
10
11#include  <stdlib.h>
12#include  <fcntl.h>
13#include  <unistd.h>
14#include  <stdio.h>
15#include  <string.h>
16#include  <stdint.h>
17#include  <mapping_info.h>
18
19//////////////////////////////////////////////////////
20void buildXml(mapping_header_t * header, FILE * fpout) {
21    const char * vobj_type[] = 
22    { 
23        "ELF",        // binary code generated by GCC
24        "BLOB",       // binary code generated by GCC
25        "PTAB",       // page table
26        "PERI",       // hardware component
27        "MWMR",       // MWMR channel
28        "LOCK",       // Spin-Lock
29        "BUFFER",     // Any "no intialiasation needed" objects (stacks...)
30        "BARRIER",    // Barrier
31        "CONST",      // Constant
32        "MEMSPACE",   // Memspace
33        "SCHED",      // Scheduler
34    };
35
36    const char * pseg_type[] = 
37    {
38        "RAM",
39        "ROM",
40        "PERI",
41    };
42
43    const char * irq_type[] =
44    {
45        "HARD",
46        "SOFT",
47    };
48
49    const char * isr_type[] =
50    {
51        "ISR_DEFAULT",
52        "ISR_SWITCH",
53        "ISR_TTY",
54        "ISR_DMA",
55        "ISR_IOC",
56        "ISR_TIMER",
57    };
58
59    const char * periph_type[] =
60    {
61        "CMA",
62        "DMA",
63        "FBF",
64        "ICU",
65        "IOB",
66        "IOC",
67        "MMC",
68        "MWR",
69        "NIC",
70        "ROM",
71        "SIM",
72        "TIM",
73        "TTY",
74        "XCU",
75    };
76
77    const char * periph_subtype[] =
78    {
79        "BDV",
80        "HBA",
81        "SPI",
82    };
83
84    const char * port_direction[] =
85    {
86        "TO_COPROC",
87        "FROM_COPROC",
88    };
89
90    const char * mode_str[] = 
91    { 
92        "____",
93        "___U", 
94        "__W_", 
95        "__WU", 
96        "_X__", 
97        "_X_U", 
98        "_XW_", 
99        "_XWU", 
100        "C___", 
101        "C__U", 
102        "C_W_", 
103        "C_WU", 
104        "CX__", 
105        "CX_U", 
106        "CXW_", 
107        "CXWU", 
108    };
109
110    unsigned int vspace_id;
111    unsigned int cluster_id;
112    unsigned int pseg_id;
113    unsigned int vseg_id;
114    unsigned int vobj_id;
115    unsigned int task_id;
116    unsigned int proc_id;
117    unsigned int irq_id;
118    unsigned int coproc_id;
119    unsigned int port_id;
120    unsigned int periph_id;
121
122    mapping_cluster_t * cluster;
123    mapping_pseg_t * pseg;
124    mapping_vspace_t * vspace;
125    mapping_vseg_t * vseg;
126    mapping_vobj_t * vobj;
127    mapping_task_t * task;
128    mapping_proc_t * proc;
129    mapping_irq_t * irq;   
130    mapping_coproc_t * coproc;
131    mapping_cp_port_t * cp_port;
132    mapping_periph_t * periph;
133
134    // computes the base adresss for clusters array,
135    cluster = (mapping_cluster_t *)((char *) header +
136            MAPPING_HEADER_SIZE);
137
138    // computes the base adresss for psegs array,
139    pseg = (mapping_pseg_t *) ((char *) header +
140            MAPPING_HEADER_SIZE +
141            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size);
142
143    // computes the base adresss for vspaces array,
144    vspace = (mapping_vspace_t *) ((char *) header +
145            MAPPING_HEADER_SIZE +
146            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
147            MAPPING_PSEG_SIZE * header->psegs);
148
149    // computes the base adresss for vsegs array,
150    vseg = (mapping_vseg_t *) ((char *) header +
151            MAPPING_HEADER_SIZE +
152            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
153            MAPPING_PSEG_SIZE * header->psegs +
154            MAPPING_VSPACE_SIZE * header->vspaces);
155
156    // computes the base adresss for vobjs array,
157    vobj = (mapping_vobj_t *) ((char *) header +
158            MAPPING_HEADER_SIZE +
159            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
160            MAPPING_PSEG_SIZE * header->psegs +
161            MAPPING_VSPACE_SIZE * header->vspaces +
162            MAPPING_VSEG_SIZE * header->vsegs);
163
164    // computes the base address for tasks array
165    task = (mapping_task_t *) ((char *) header +
166            MAPPING_HEADER_SIZE +
167            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
168            MAPPING_PSEG_SIZE * header->psegs +
169            MAPPING_VSPACE_SIZE * header->vspaces +
170            MAPPING_VOBJ_SIZE * header->vobjs +
171            MAPPING_VSEG_SIZE * header->vsegs);
172
173    // computes the base address for procs array
174    proc = (mapping_proc_t *) ((char *) header +
175            MAPPING_HEADER_SIZE +
176            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
177            MAPPING_PSEG_SIZE * header->psegs +
178            MAPPING_VSPACE_SIZE * header->vspaces +
179            MAPPING_VOBJ_SIZE * header->vobjs +
180            MAPPING_VSEG_SIZE * header->vsegs +
181            MAPPING_TASK_SIZE * header->tasks);
182
183    // computes the base address for irqs array
184    irq = (mapping_irq_t *) ((char *) header +
185            MAPPING_HEADER_SIZE +
186            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
187            MAPPING_PSEG_SIZE * header->psegs +
188            MAPPING_VSPACE_SIZE * header->vspaces +
189            MAPPING_VOBJ_SIZE * header->vobjs +
190            MAPPING_VSEG_SIZE * header->vsegs +
191            MAPPING_TASK_SIZE * header->tasks +
192            MAPPING_PROC_SIZE * header->procs);
193
194    // computes the base address for coprocs array
195    coproc = (mapping_coproc_t *) ((char *) header +
196            MAPPING_HEADER_SIZE +
197            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
198            MAPPING_PSEG_SIZE * header->psegs +
199            MAPPING_VSPACE_SIZE * header->vspaces +
200            MAPPING_VOBJ_SIZE * header->vobjs +
201            MAPPING_VSEG_SIZE * header->vsegs +
202            MAPPING_TASK_SIZE * header->tasks +
203            MAPPING_PROC_SIZE * header->procs +
204            MAPPING_IRQ_SIZE * header->irqs);
205
206    // computes the base address for cp_ports array
207    cp_port = (mapping_cp_port_t *) ((char *) header +
208            MAPPING_HEADER_SIZE +
209            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
210            MAPPING_PSEG_SIZE * header->psegs +
211            MAPPING_VSPACE_SIZE * header->vspaces +
212            MAPPING_VOBJ_SIZE * header->vobjs +
213            MAPPING_VSEG_SIZE * header->vsegs +
214            MAPPING_TASK_SIZE * header->tasks +
215            MAPPING_PROC_SIZE * header->procs +
216            MAPPING_IRQ_SIZE * header->irqs +
217            MAPPING_COPROC_SIZE * header->coprocs);
218
219    // computes the base address for periphs array
220    periph = (mapping_periph_t *) ((char *) header +
221            MAPPING_HEADER_SIZE +
222            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
223            MAPPING_PSEG_SIZE * header->psegs +
224            MAPPING_VSPACE_SIZE * header->vspaces +
225            MAPPING_VOBJ_SIZE * header->vobjs +
226            MAPPING_VSEG_SIZE * header->vsegs +
227            MAPPING_TASK_SIZE * header->tasks +
228            MAPPING_PROC_SIZE * header->procs +
229            MAPPING_IRQ_SIZE * header->irqs +
230            MAPPING_COPROC_SIZE * header->coprocs +
231            MAPPING_CP_PORT_SIZE * header->cp_ports);
232
233    ///////////////////////// header /////////////////////////////////////////////
234
235    fprintf(fpout, "<?xml version = \"1.0\"?>\n\n");
236
237    fprintf(fpout, "<mapping_info signature = \"0x%x\" \n", header->signature);
238    fprintf(fpout, "              name      = \"%s\"   \n", header->name);
239    fprintf(fpout, "              x_size    = \"%d\"   \n", header->x_size);
240    fprintf(fpout, "              y_size    = \"%d\"   \n", header->y_size);
241    fprintf(fpout, "              x_width   = \"%d\"   \n", header->x_width);
242    fprintf(fpout, "              y_width   = \"%d\"   \n", header->y_width);
243    fprintf(fpout, "              vspaces   = \"%d\"   \n", header->vspaces);
244    fprintf(fpout, "              increment = \"%d\" >\n\n", header->vspaces);
245
246    ///////////////////// clusters ///////////////////////////////////////////////
247
248    fprintf( fpout, "    <clusterset>\n");
249    for (cluster_id = 0; cluster_id < (header->x_size * header->y_size); cluster_id++) 
250    {
251        fprintf(fpout, "        <cluster x = \"%d\" y = \"%d\" >\n", 
252                cluster[cluster_id].x, cluster[cluster_id].y );
253
254        ///////////////////// psegs   ////////////////////////////////////////////////
255
256        for (pseg_id = cluster[cluster_id].pseg_offset;
257             pseg_id < cluster[cluster_id].pseg_offset + cluster[cluster_id].psegs;
258             pseg_id++) 
259        {
260            fprintf(fpout, "            <pseg name = \"%s\" ", pseg[pseg_id].name);
261            fprintf(fpout, "type = \"%s\" ", pseg_type[pseg[pseg_id].type]);
262            fprintf(fpout, "base = \"0x%llx\" ", pseg[pseg_id].base);
263            fprintf(fpout, "length = \"0x%llx\" />\n",   pseg[pseg_id].length);
264        }
265
266        ///////////////////// processors /////////////////////////////////////////////
267
268        unsigned int proc_index = 0;
269        for (proc_id = cluster[cluster_id].proc_offset;
270             proc_id < cluster[cluster_id].proc_offset + cluster[cluster_id].procs;
271             proc_id++) 
272        {
273            fprintf(fpout, "            <proc index = \"%d\" >\n", proc_index);
274            for (irq_id = proc[proc_id].irq_offset; 
275                 irq_id < proc[proc_id].irq_offset + proc[proc_id].irqs;
276                 irq_id++) 
277            {
278                fprintf(fpout, "                <irq type = \"%s\" ", irq_type[irq[irq_id].type]);
279                fprintf(fpout, " icuid = \"0x%x\" ", irq[irq_id].icuid);
280                fprintf(fpout, " isr = \"%s\" ", isr_type[irq[irq_id].isr]);
281                fprintf(fpout, " channel = \"0x%x\" />\n", irq[irq_id].channel);
282            }
283            fprintf(fpout, "            </proc>\n" );
284        }
285
286
287        ///////////////////// coprocessors ///////////////////////////////////////////
288
289        for (coproc_id = cluster[cluster_id].coproc_offset;
290             coproc_id < cluster[cluster_id].coproc_offset + cluster[cluster_id].coprocs;
291             coproc_id++) 
292        {
293            fprintf(fpout, "            <coproc name = \"%s\" ", coproc[coproc_id].name);
294            fprintf(fpout, " psegname = \"%s\" >\n", pseg[coproc[coproc_id].psegid].name);
295            for (port_id = coproc[coproc_id].port_offset;
296                 port_id < coproc[coproc_id].port_offset + coproc[coproc_id].ports;
297                 port_id++) 
298            {
299                unsigned int vobj_id = cp_port[port_id].mwmr_vobjid + vspace[cp_port[port_id].vspaceid].vobj_offset; 
300                fprintf(fpout, "             <port direction = \"%s\" ",  port_direction[cp_port[port_id].direction]);
301                fprintf(fpout, " vspacename = \"%s\" ", vspace[cp_port[port_id].vspaceid].name);
302                fprintf(fpout, " vobjname = \"%s\" />\n",  vobj[vobj_id].name);
303            }
304            fprintf(fpout, "            </coproc>\n" );
305        }
306
307        ///////////////////// periphs  ///////////////////////////////////////////////
308
309        for (periph_id = cluster[cluster_id].periph_offset;
310             periph_id < cluster[cluster_id].periph_offset + cluster[cluster_id].periphs;
311             periph_id++) 
312        {
313            fprintf(fpout, "            <periph type = \"%s\" ", periph_type[periph[periph_id].type]);
314
315            if (periph[periph_id].subtype < PERIPH_SUBTYPE_MAX_VALUE) 
316                fprintf(fpout, " subtype = \"%s\" ", periph_subtype[periph[periph_id].subtype]);
317
318            fprintf(fpout, " psegname = \"%s\" ", pseg[periph[periph_id].psegid].name);
319            fprintf(fpout, " channels = \"%d\" />\n",  periph[periph_id].channels);
320        }
321        fprintf(fpout, "        </cluster>\n" );
322    }
323    fprintf(fpout, "    </clusterset>\n\n" );
324
325    /////////////////// globals /////////////////////////////////////////////////
326
327    fprintf(fpout, "    <globalset>\n" );
328    for (vseg_id = 0; vseg_id < header->globals; vseg_id++) 
329    {
330        unsigned int pseg_id = vseg[vseg_id].psegid; 
331
332        fprintf(fpout, "        <vseg name = \"%s\" ", vseg[vseg_id].name);
333        fprintf(fpout, "vbase = \"0x%x\" ", vseg[vseg_id].vbase);
334        fprintf(fpout, "mode  = \"%s\" ", mode_str[vseg[vseg_id].mode]);
335        fprintf(fpout, "clusterid = \"%d\" ", pseg[pseg_id].clusterid);
336        fprintf(fpout, "psegname = \"%s\" ", pseg[pseg_id].name);
337        fprintf(fpout, "ident = \"%d\" >\n", vseg[vseg_id].ident);
338        for (vobj_id = vseg[vseg_id].vobj_offset;
339             vobj_id < (vseg[vseg_id].vobj_offset + vseg[vseg_id].vobjs); 
340             vobj_id++) 
341        {
342            fprintf(fpout, "            <vobj name = \"%s\" ", vobj[vobj_id].name);
343            fprintf(fpout, "type = \"%s\" ", vobj_type[vobj[vobj_id].type]);
344            fprintf(fpout, "length = \"0x%x\" ", vobj[vobj_id].length);
345            fprintf(fpout, "align = \"%d\" ", vobj[vobj_id].align);
346            fprintf(fpout, "init = \"%d\" ", vobj[vobj_id].init);
347            fprintf(fpout, "binpath = \"%s\" />\n", vobj[vobj_id].binpath);
348        }
349        fprintf(fpout, "        </vseg>\n");
350    }
351    fprintf(fpout, "    </globalset>\n" );
352
353    //////////////////// vspaces ////////////////////////////////////////////////
354
355    fprintf( fpout, "\n    <vspaceset>\n\n" );
356    for (vspace_id = 0; vspace_id < header->vspaces; vspace_id++) 
357    {
358        unsigned int func_id = vspace[vspace_id].vobj_offset + vspace[vspace_id].start_offset; 
359        fprintf(fpout, "        <vspace name = \"%s\" ", vspace[vspace_id].name); 
360        fprintf(fpout, " startname = \"%s\" >\n", vobj[func_id].name); 
361
362        //////////////////// vsegs //////////////////////////////////////////////
363
364        for (vseg_id = vspace[vspace_id].vseg_offset;
365             vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs);
366             vseg_id++) 
367        {
368            unsigned int pseg_id    = vseg[vseg_id].psegid; 
369            unsigned int cluster_id = pseg[pseg_id].clusterid;
370            unsigned int x          = cluster_id >> header->y_width;
371            unsigned int y          = cluster_id & ((1<<header->y_width)-1);
372
373            fprintf(fpout, "            <vseg name = \"%s\" ", vseg[vseg_id].name);
374            fprintf(fpout, "vbase = \"0x%x\" ", vseg[vseg_id].vbase);
375            fprintf(fpout, "mode = \"%s\" ", mode_str[vseg[vseg_id].mode]);
376            fprintf(fpout, "x = \"%d\" ", x);
377            fprintf(fpout, "y = \"%d\" ", y);
378            fprintf(fpout, "psegname = \"%s\" ", pseg[pseg_id].name);
379            fprintf(fpout, "ident = \"%d\" >\n", vseg[vseg_id].ident);
380
381            for (vobj_id = vseg[vseg_id].vobj_offset;
382                 vobj_id < (vseg[vseg_id].vobj_offset + vseg[vseg_id].vobjs);
383                 vobj_id++) 
384            {
385                fprintf(fpout, "             <vobj name = \"%s\" ", vobj[vobj_id].name);
386                fprintf(fpout, "type = \"%s\" ", vobj_type[vobj[vobj_id].type]);
387                fprintf(fpout, "length = \"0x%x\" ", vobj[vobj_id].length);
388                fprintf(fpout, "align = \"%d\" ", vobj[vobj_id].align);
389                fprintf(fpout, "init = \"%d\" ", vobj[vobj_id].init);
390                fprintf(fpout, "binpath = \"%s\" />\n", vobj[vobj_id].binpath);
391            }
392            fprintf(fpout, "            </vseg>\n\n");
393        }
394
395        //////////////////// tasks //////////////////////////////////////////////
396
397        for (task_id = vspace[vspace_id].task_offset;
398             task_id < (vspace[vspace_id].task_offset + vspace[vspace_id].tasks);
399             task_id++) 
400        {
401            unsigned int stack_vobj_id = task[task_id].stack_vobjid + vspace[vspace_id].vobj_offset; 
402            unsigned int heap_vobj_id = task[task_id].heap_vobjid + vspace[vspace_id].vobj_offset; 
403            unsigned int cluster_id   = task[task_id].clusterid;
404            unsigned int x            = cluster_id >> header->y_width;
405            unsigned int y            = cluster_id & ((1<<header->y_width)-1);
406
407            fprintf(fpout, "            <task name = \"%s\" ", task[task_id].name);
408            fprintf(fpout, "x = \"%d\" ", x);
409            fprintf(fpout, "y = \"%d\" ", y);
410            fprintf(fpout, "proclocid = \"%d\" ", task[task_id].proclocid);
411            fprintf(fpout, "stackname = \"%s\" ", vobj[stack_vobj_id].name);
412            if (heap_vobj_id != -1) 
413            {
414                fprintf(fpout, "heapname = \"%s\" ", vobj[heap_vobj_id].name);
415            }
416            fprintf(fpout, "startid = \"%d\" ", task[task_id].startid);
417            fprintf(fpout, "usetty = \"%d\" ", task[task_id].use_tty);
418            fprintf(fpout, "usenic = \"%d\" ", task[task_id].use_nic);
419            fprintf(fpout, "usecma = \"%d\" ", task[task_id].use_cma);
420            fprintf(fpout, "usetim = \"%d\" ", task[task_id].use_tim);
421            fprintf(fpout, "usehba = \"%d\" />\n", task[task_id].use_hba);
422        }
423        fprintf(fpout, "        </vspace>\n\n");
424    }
425    fprintf(fpout, "    </vspaceset>\n");
426    fprintf(fpout, "</mapping_info>\n");
427} // end buildXml()
428
429
430/////////////////////////////////////
431int main(int argc, char * argv[]) {
432    if (argc < 2) {
433        printf("Usage: bin2xml <input_file_path> <output_file_path>\n");
434        return 1;
435    }
436
437    unsigned int bin[0x10000]; // 64 K int = 256 Kbytes
438
439    int fdin = open(argv[1], O_RDONLY);
440    if (fdin < 0) {
441        perror("open");
442        exit(1);
443    }
444
445    FILE * fpout = fopen( argv[2], "w");
446    if (fpout == NULL) {
447        perror("open");
448        exit(1);
449    }
450
451    unsigned int length = read(fdin, bin, 0x40000);
452
453    if (length <= 0) {
454        perror("read");
455        exit(1);
456    }
457
458    if (bin[0] == IN_MAPPING_SIGNATURE) {
459        buildXml((mapping_header_t *) bin, fpout);
460    } 
461    else {
462        printf("[ERROR] Wrong file format\n");
463        exit(1);
464    }
465    return 0;
466} // end main()
467
468
469
470// Local Variables:
471// tab-width: 4
472// c-basic-offset: 4
473// c-file-offsets:((innamespace . 0)(inline-open . 0))
474// indent-tabs-mode: nil
475// End:
476// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
477
Note: See TracBrowser for help on using the repository browser.