Index: soft/giet_vm/giet_python/mapping.py
===================================================================
--- soft/giet_vm/giet_python/mapping.py	(revision 560)
+++ soft/giet_vm/giet_python/mapping.py	(revision 562)
@@ -282,4 +282,5 @@
                 periph,                # peripheral containing IRQ (PIC or XCU)
                 index,                 # peripheral input port index
+                src,                   # interrupt source peripheral
                 isrtype,               # ISR type
                 channel = 0 ):         # channel for multi-channels ISR
@@ -294,4 +295,11 @@
         irq.index = self.total_irqs
         self.total_irqs += 1
+
+        # pointer from the source to the interrupt controller peripheral
+        if src.irq_ctrl == None: src.irq_ctrl = periph
+        if src.irq_ctrl != periph:
+            print '[genmap error] in addIrq():'
+            print '    two different interrupt controller for the same peripheral'
+            sys.exit(1)
 
         return irq
@@ -1171,4 +1179,5 @@
         # to one or several drivers identified by ("major","minor")
 
+        chosen_tty = False
         for cluster in self.clusters:
             x               = cluster.x
@@ -1186,5 +1195,5 @@
                     size = pseg.size
 
-                    s += '  ram_%d_%d: ram@0x%x {\n' % (x, y, pseg.base)
+                    s += '  %s@0x%x {\n' % (pseg.name, pseg.base)
                     s += '    device_type = "memory";\n'
                     s += '    reg = <0x%x  0x%x  0x%x>;\n' % (msb, lsb, size)
@@ -1200,8 +1209,6 @@
                 if ( (periph.ptype == 'XCU') ):
                     found_xcu     = True
-                    xcu           = periph
-                    irq_ctrl_name = 'xcu_%d_%d' % (x, y)
-
-                    s += '  %s: xcu@0x%x {\n'  % (irq_ctrl_name, periph.pseg.base)
+
+                    s += '  %s@0x%x {\n' % (periph.pseg.name, periph.pseg.base)
                     s += '    compatible = "soclib,vci_xicu","soclib,vci_xicu_timer";\n'
                     s += '    interrupt-controller;\n'
@@ -1214,8 +1221,6 @@
                 if ( periph.ptype == 'PIC' ):
                     found_pic     = True
-                    pic           = periph
-                    irq_ctrl_name = 'pic'
-
-                    s += '  %s: pic@0x%x {\n'  % (irq_ctrl_name, periph.pseg.base)
+
+                    s += '  %s@0x%x {\n' % (periph.pseg.name, periph.pseg.base)
                     s += '    compatible = "soclib,vci_iopic";\n'
                     s += '    interrupt-controller;\n'
@@ -1225,13 +1230,10 @@
 
             # we need one interrupt controler in any cluster containing peripherals
-            if ( (found_xcu == False) and 
-                 (found_pic == False) and 
+            if ( (found_xcu == False) and
+                 (found_pic == False) and
                  (len(cluster.periphs) > 0) ):
                 print '[genmap error] in linux_dts()'
                 print '    No XCU/PIC in cluster(%d,%d)' % (x,y)
                 sys.exit(1)
-
-            if ( found_pic == True ): irq_ctrl = pic
-            else:                     irq_ctrl = xcu
 
             # scan all periphs to find TTY and IOC in current cluster
@@ -1241,6 +1243,11 @@
                 size    = periph.pseg.size
 
+                irq_ctrl = periph.irq_ctrl
+                if irq_ctrl != None:
+                    irq_ctrl_name = '%s@0x%x' % (irq_ctrl.pseg.name, irq_ctrl.pseg.base)
+
                 # search TTY (non replicated)
-                if ( periph.ptype == 'TTY' ):
+                if periph.ptype == 'TTY':
+                    assert irq_ctrl != None
 
                     # get HWI index to XCU or PIC (only TTY0 is used by Linux)
@@ -1255,13 +1262,19 @@
                         sys.exit(1)
 
-                    s += '  tty: tty@0x%x {\n' % (periph.pseg.base)
+                    if chosen_tty == False:
+                        chosen_tty = True
+                        s += '  tty:\n'
+
+                    s += '  %s@0x%x {\n' % (periph.pseg.name, periph.pseg.base)
                     s += '    compatible = "soclib,vci_multi_tty";\n'
-                    s += '    interrupt-parent = <&%s>;\n' % (irq_ctrl_name)
+                    s += '    interrupt-parent = <&{/%s}>;\n' % (irq_ctrl_name)
                     s += '    interrupts = <%d>;\n' % hwi_id
                     s += '    reg = <0x%x  0x%x  0x%x>;\n' % (msb, lsb, size)
                     s += '  };\n\n'
 
+
                 # search IOC (non replicated)
                 elif ( periph.ptype == 'IOC' ):
+                    assert irq_ctrl != None
 
                     if ( periph.subtype == 'BDV' ):
@@ -1277,7 +1290,7 @@
                             sys.exit(1)
 
-                        s += '  bdv: bdv@0x%x {\n' % (periph.pseg.base)
+                        s += '  %s@0x%x {\n' % (periph.pseg.name, periph.pseg.base)
                         s += '    compatible = "tsar,vci_block_device";\n'
-                        s += '    interrupt-parent = <&%s>;\n' % (irq_ctrl_name)
+                        s += '    interrupt-parent = <&{/%s}>;\n' % (irq_ctrl_name)
                         s += '    interrupts = <%d>;\n' % hwi_id
                         s += '    reg = <0x%x  0x%x  0x%x>;\n' % (msb, lsb, size)
@@ -1299,5 +1312,4 @@
 
         # clocks
-        s += '  /*** clocks ***/\n\n'
         s += '  clocks {\n'
         s += '    freq: freq@50MHZ {\n'
@@ -1367,6 +1379,7 @@
             y = cluster.y
 
-            # research XCU component
+            # research XCU or PIC component
             found_xcu = False
+            found_pic = False
             for periph in cluster.periphs:
                 if ( (periph.ptype == 'XCU') ):
@@ -1380,7 +1393,7 @@
                     s += '    device_type = "soclib:xicu:root";\n'
                     s += '    reg         = <0x%x  0x%x  0x%x>;\n' % (msb,lsb,size)
-                    s += '    input_lines = <%d>;\n'    % periph.arg
-                    s += '    ipis        = <%d>;\n'    % periph.arg
-                    s += '    timers      = <%d>;\n'    % periph.arg
+                    s += '    input_lines = <%d>;\n'    % periph.arg0
+                    s += '    ipis        = <%d>;\n'    % periph.arg1
+                    s += '    timers      = <%d>;\n'    % periph.arg2
 
                     output_id = 0            # output index from XCU
@@ -1400,7 +1413,4 @@
                     s += '  };\n'
 
-            # research PIC component
-            found_pic = False
-            for periph in cluster.periphs:
                 if ( periph.ptype == 'PIC' ):
                     found_pic = True
@@ -1413,5 +1423,5 @@
                     s += '    device_type = "soclib:pic:root";\n'
                     s += '    reg         = <0x%x  0x%x  0x%x>;\n' % (msb, lsb, size)
-                    s += '    input_lines = <%d>;\n'    % periph.channels
+                    s += '    input_lines = <%d>;\n' % periph.channels
                     s += '  };\n'
 
@@ -1422,7 +1432,4 @@
                 sys.exit(1)
 
-            if ( found_pic == True ):  irq_tgt = pic
-            else:                      irq_tgt = xcu
-
             # get all others peripherals in cluster
             for periph in cluster.periphs:
@@ -1431,6 +1438,14 @@
                 size = periph.pseg.size
 
+                irq_ctrl = periph.irq_ctrl
+                if irq_ctrl != None:
+                    irq_ctrl_name = '%s@0x%x' % (irq_ctrl.pseg.name, irq_ctrl.pseg.base)
+
+                # XCU or PIC have been already parsed
+                if ( periph.ptype == 'XCU' ) or ( periph.ptype == 'PIC' ):
+                    pass
+
                 # research DMA component
-                if ( periph.ptype == 'DMA' ):
+                elif ( periph.ptype == 'DMA' ):
 
                     s += '  %s@0x%x {\n'  % (periph.pseg.name, periph.pseg.base)
@@ -1477,5 +1492,5 @@
                     s += '  %s@0x%x {\n'  % (periph.pseg.name, periph.pseg.base)
                     s += '    device_type = "soclib:mmc";\n'
-                    s += '    irq = <&{/%s@0x%x}  %d>;\n' % (irq_tgt.pseg.name, irq_tgt.pseg.base, irq_in)
+                    s += '    irq = <&{/%s} %d>;\n' % (irq_ctrl_name, irq_in)
                     s += '    reg = <0x%x  0x%x  0x%x>;\n' % (msb, lsb, size)
                     s += '  };\n'
@@ -1487,6 +1502,6 @@
                     s += '    device_type = "soclib:framebuffer";\n'
                     s += '    mode        = <32>;\n'            # bits par pixel
-                    s += '    width       = <%d>;\n'    % periph.arg
-                    s += '    height      = <%d>;\n'    % periph.arg
+                    s += '    width       = <%d>;\n'    % periph.arg0
+                    s += '    height      = <%d>;\n'    % periph.arg1
                     s += '    reg         = <0x%x  0x%x  0x%x>;\n' % (msb, lsb, size)
                     s += '  };\n'
@@ -1499,5 +1514,5 @@
                         # get irq line index associated to bdv
                         irq_in = 0xFFFFFFFF
-                        for irq in irq_tgt.irqs:
+                        for irq in irq_ctrl.irqs:
                             if ( irq.isrtype == 'ISR_BDV' ): irq_in = irq.srcid
                         if ( irq_in == 0xFFFFFFFF ):
@@ -1508,12 +1523,12 @@
                         s += '  %s@0x%x {\n' % (periph.pseg.name, periph.pseg.base)
                         s += '    device_type = "soclib:blockdevice";\n'
-                        s += '    irq = <&{/%s@0x%x} %d>;\n' % (irq_tgt.pseg.name,irq_tgt.pseg.base,irq_in)
+                        s += '    irq = <&{/%s} %d>;\n' % (irq_ctrl_name, irq_in)
                         s += '    reg = <0x%x  0x%x  0x%x>;\n' % (msb, lsb, size)
                         s += '  };\n'
 
                     elif ( periph.subtype == 'HBA' ):
+
                         print '[genmap error] in netbsd_dts()'
                         print '    HBA peripheral not supported by NetBSD'
-                        sys.exit(1)
 
                     elif ( periph.subtype == 'SDC' ):
@@ -1521,5 +1536,5 @@
                         # get irq line index associated to sdc
                         irq_in = 0xFFFFFFFF
-                        for irq in irq_tgt.irqs:
+                        for irq in irq_ctrl.irqs:
                             if ( irq.isrtype == 'ISR_SDC' ): irq_in = irq.srcid
                         if ( irq_in == 0xFFFFFFFF ):
@@ -1530,10 +1545,10 @@
                         s += '  %s@0x%x {\n'  % (periph.pseg.name, periph.pseg.base)
                         s += '    device_type = "soclib:sdc";\n'
-                        s += '    irq = <&{/%s@0x%x} %d>;\n' % (irq_tgt.pseg.name,irq_tgt.pseg.base,irq_in)
+                        s += '    irq = <&{/%s} %d>;\n' % (irq_ctrl_name, irq_in)
                         s += '    reg = <0x%x  0x%x  0x%x>;\n' % (msb, lsb, size)
                         s += '  };\n'
 
                 # research ROM component
-                elif ( periph.ptype == 'ROM' ):
+                elif ( periph.ptype == 'ROM' ) or ( periph.ptype == 'DROM' ):
 
                     s += '  %s@0x%x {\n' % (periph.pseg.name, periph.pseg.base)
@@ -1562,5 +1577,5 @@
                     for channel in xrange( periph.channels ):
                         hwi_id = 0xFFFFFFFF
-                        for irq in irq_tgt.irqs:
+                        for irq in irq_ctrl.irqs:
                             if ( (irq.isrtype == 'ISR_TTY_RX') and (irq.channel == channel) ):
                                 hwi_id = irq.srcid
@@ -1570,5 +1585,5 @@
                             sys.exit(1)
 
-                        name = '%s@0x%x' % (irq_tgt.pseg.name, irq_tgt.pseg.base)
+                        name = '%s' % (irq_ctrl_name)
                         s += '    irq@%d{\n' % channel
                         s += '      device_type = "soclib:periph:irq";\n'
@@ -1600,5 +1615,5 @@
                     for channel in xrange( periph.channels ):
                         hwi_id = 0xFFFFFFFF
-                        for irq in irq_tgt.irqs:
+                        for irq in irq_ctrl.irqs:
                             if ( (irq.isrtype == 'ISR_NIC_RX') and (irq.channel == channel) ):
                                 hwi_id = irq.srcid
@@ -1608,5 +1623,5 @@
                             sys.exit(1)
 
-                        name = '%s@0x%x' % (irq_tgt.pseg.name, irq_tgt.pseg.base)
+                        name = '%s' % (irq_ctrl_name)
                         s += '    irq_rx@%d{\n' % channel
                         s += '      device_type = "soclib:periph:irq";\n'
@@ -1617,5 +1632,5 @@
 
                         hwi_id = 0xFFFFFFFF
-                        for irq in irq_tgt.irqs:
+                        for irq in irq_ctrl.irqs:
                             if ( (irq.isrtype == 'ISR_NIC_TX') and (irq.channel == channel) ):
                                 hwi_id = irq.srcid
@@ -1625,5 +1640,5 @@
                             sys.exit(1)
 
-                        name = '%s@0x%x' % (irq_tgt.pseg.name, irq_tgt.pseg.base)
+                        name = '%s' % (irq_ctrl_name)
                         s += '    irq_tx@%d{\n' % channel
                         s += '      device_type = "soclib:periph:irq";\n'
@@ -1646,5 +1661,5 @@
                     for channel in xrange( periph.channels ):
                         hwi_id = 0xFFFFFFFF
-                        for irq in irq_tgt.irqs:
+                        for irq in irq_ctrl.irqs:
                             if ( (irq.isrtype == 'ISR_CMA') and (irq.channel == channel) ):
                                 hwi_id = irq.srcid
@@ -1655,5 +1670,5 @@
                             sys.exit(1)
 
-                        name = '%s@0x%x' % (irq_tgt.pseg.name, irq_tgt.pseg.base)
+                        name = '%s' % (irq_ctrl_name)
                         s += '    irq@%d{\n' % channel
                         s += '      device_type = "soclib:periph:irq";\n'
@@ -1665,17 +1680,9 @@
                     s += '  };\n'
 
-                # research TIM component
-                elif ( periph.ptype == 'TIM' ):
+                else:
 
                     print '[genmap error] in netbsd_dts()'
-                    print '    TIM peripheral not supported by NetBSD'
-                    sys.exit(1)
-
-                # research MWR component
-                elif ( periph.ptype == 'MWR' ):
-
-                    print '[genmap error] in netbsd_dts()'
-                    print '    MWR peripheral not supported by NetBSD'
-                    sys.exit(1)
+                    print '    %s peripheral not supported by NetBSD' % periph.ptype
+
 
         # topology
@@ -2342,4 +2349,5 @@
         self.pseg     = pseg
         self.irqs     = []
+        self.irq_ctrl = None         # interrupt controller peripheral
         return
 
