source: soft/giet_vm/giet_python/mapping.py @ 742

Last change on this file since 742 was 742, checked in by alain, 8 years ago

Remove the seg_kernel_init vseg: All the kernel code is now packed
in one single seg_kernel_code vseg. The entry point for the _kernel_init()
function (from the boot code is now at vaddr = 0x80000000.
The goal is to use only one BPP per cluster for the replicated kernel code.

  • Property svn:executable set to *
File size: 101.3 KB
Line 
1#!/usr/bin/env python
2
3import sys
4
5###################################################################################
6#   file   : giet_mapping.py
7#   date   : april 2014
8#   author : Alain Greiner
9###################################################################################
10#  This file contains the classes required to define a mapping for the GIET_VM.
11# - A 'Mapping' contains a set of 'Cluster'   (hardware architecture)
12#                        a set of 'Vseg'      (kernel global virtual segments)
13#                        a set of 'Vspace'    (one or several user applications)
14# - A 'Cluster' contains a set of 'Pseg'      (physical segments in cluster)
15#                        a set of 'Proc'      (processors in cluster)
16#                        a set of 'Periph'    (peripherals in cluster)
17# - A 'Vspace' contains  a set of 'Vseg'      (user virtual segments)
18#                        a set of 'Thread'    (POSIX thread)
19# - A 'Periph' contains  a set of 'Irq'       (only for XCU and PIC types )
20###################################################################################
21# Implementation Note
22# The objects used to describe a mapping are distributed in the PYTHON structure:
23# For example the psegs set is split in several subsets (one subset per cluster),
24# or the threads set is split in several subsets (one subset per vspace), etc...
25# In the C binary data structure used by the giet_vm, all objects of same type
26# are stored in a linear array (one single array for all psegs for example).
27# For all objects, we compute and store in the PYTHON object  a "global index"
28# corresponding to the index in this global array, and this index can be used as
29# a pseudo-pointer to identify a specific object of a given type.
30###################################################################################
31
32###################################################################################
33# Various constants
34###################################################################################
35
36PADDR_WIDTH       = 40            # number of bits for physical address
37X_WIDTH           = 4             # number of bits encoding x coordinate
38Y_WIDTH           = 4             # number of bits encoding y coordinate
39P_WIDTH           = 4             # number of bits encoding local proc_id
40VPN_ANTI_MASK     = 0x00000FFF    # mask vaddr to get offset in small page
41BPN_MASK          = 0xFFE00000    # mask vaddr to get the BPN in big page
42PERI_INCREMENT    = 0x10000       # virtual address increment for replicated vsegs
43RESET_ADDRESS     = 0xBFC00000    # Processor wired boot_address
44MAPPING_SIGNATURE = 0xDACE2014    # Magic number indicating a valid C BLOB
45
46###################################################################################
47# These lists must be consistent with values defined in
48# mapping_info.h / xml_driver.c /xml_parser.c
49###################################################################################
50PERIPHTYPES =    [
51                  'CMA',
52                  'DMA',
53                  'FBF',
54                  'IOB',
55                  'IOC',
56                  'MMC',
57                  'MWR',
58                  'NIC',
59                  'ROM',
60                  'SIM',
61                  'TIM',
62                  'TTY',
63                  'XCU',
64                  'PIC',
65                  'DROM',
66                 ]
67
68IOCSUBTYPES =    [
69                  'BDV',
70                  'HBA',
71                  'SDC',
72                  'SPI',
73                 ]
74
75MWRSUBTYPES =    [
76                  'CPY',
77                  'GCD',
78                  'DCT',
79                 ]
80   
81###################################################################################
82# These lists must be consistent with values defined in
83# irq_handler.c / irq_handler.h / xml_driver.c / xml_parser.c
84###################################################################################
85IRQTYPES =       [
86                  'HWI',
87                  'WTI',
88                  'PTI',
89                 ]
90
91ISRTYPES =       [
92                  'ISR_DEFAULT',
93                  'ISR_TICK',
94                  'ISR_TTY_RX',
95                  'ISR_TTY_TX',
96                  'ISR_BDV',
97                  'ISR_TIMER',
98                  'ISR_WAKUP',
99                  'ISR_NIC_RX',
100                  'ISR_NIC_TX',
101                  'ISR_CMA',
102                  'ISR_MMC',
103                  'ISR_DMA',
104                  'ISR_SDC',
105                  'ISR_MWR',
106                  'ISR_HBA',
107                  'ISR_SPI',
108                 ]
109
110VSEGTYPES =      [
111                  'ELF',
112                  'BLOB',
113                  'PTAB',
114                  'PERI',
115                  'BUFFER',
116                  'SCHED',     
117                  'HEAP',
118                 ]
119
120VSEGMODES =      [
121                  '____',
122                  '___U',
123                  '__W_',
124                  '__WU',
125                  '_X__',
126                  '_X_U',
127                  '_XW_',
128                  '_XWU',
129                  'C___',
130                  'C__U',
131                  'C_W_',
132                  'C_WU',
133                  'CX__',
134                  'CX_U',
135                  'CXW_',
136                  'CXWU',
137                 ]
138
139PSEGTYPES =      [
140                  'RAM',
141                  'PERI',
142                 ]
143
144###################################################################################
145class Mapping( object ):
146###################################################################################
147    def __init__( self,
148                  name,                            # mapping name
149                  x_size,                          # number of clusters in a row
150                  y_size,                          # number of clusters in a column
151                  nprocs,                          # max number of processors per cluster
152                  x_width        = X_WIDTH,        # number of bits encoding x coordinate
153                  y_width        = Y_WIDTH,        # number of bits encoding y coordinate
154                  p_width        = P_WIDTH,        # number of bits encoding lpid
155                  paddr_width    = PADDR_WIDTH,    # number of bits for physical address
156                  coherence      = 1,              # hardware cache coherence if non-zero
157                  irq_per_proc   = 1,              # number or IRQs from XCU to processor
158                  use_ramdisk    = False,          # use ramdisk when true
159                  x_io           = 0,              # cluster_io x coordinate
160                  y_io           = 0,              # cluster_io y coordinate
161                  peri_increment = PERI_INCREMENT, # address increment for globals
162                  reset_address  = RESET_ADDRESS,  # Processor wired boot_address
163                  ram_base       = 0,              # RAM physical base in cluster[0,0]
164                  ram_size       = 0 ):            # RAM size per cluster (bytes)
165
166        assert ( x_size <= (1<<X_WIDTH) )
167        assert ( y_size <= (1<<Y_WIDTH) )
168        assert ( nprocs <= (1<<P_WIDTH) )
169
170        self.signature      = MAPPING_SIGNATURE
171        self.name           = name
172        self.name           = name
173        self.paddr_width    = paddr_width
174        self.coherence      = coherence
175        self.x_size         = x_size
176        self.y_size         = y_size
177        self.nprocs         = nprocs
178        self.x_width        = x_width
179        self.y_width        = y_width
180        self.p_width        = p_width
181        self.irq_per_proc   = irq_per_proc
182        self.use_ramdisk    = use_ramdisk
183        self.x_io           = x_io
184        self.y_io           = y_io
185        self.peri_increment = peri_increment
186        self.reset_address  = reset_address
187        self.ram_base       = ram_base
188        self.ram_size       = ram_size
189
190        self.total_vspaces  = 0
191        self.total_globals  = 0
192        self.total_psegs    = 0
193        self.total_vsegs    = 0
194        self.total_threads  = 0
195        self.total_procs    = 0
196        self.total_irqs     = 0
197        self.total_periphs  = 0
198
199        self.clusters       = []
200        self.globs          = []
201        self.vspaces        = []
202
203        for x in xrange( self.x_size ):
204            for y in xrange( self.y_size ):
205                cluster = Cluster( x , y )
206                cluster.index = (x * self.y_size) + y
207                self.clusters.append( cluster )
208
209        return
210
211    ##########################    add a ram pseg in a cluster
212    def addRam( self,
213                name,                  # pseg name
214                base,                  # pseg base address
215                size ):                # pseg length (bytes)
216
217        # computes cluster index and coordinates from the base address
218        paddr_lsb_width = self.paddr_width - self.x_width - self.y_width
219        cluster_xy = base >> paddr_lsb_width
220        x          = cluster_xy >> (self.y_width);
221        y          = cluster_xy & ((1 << self.y_width) - 1)
222        cluster_id = (x * self.y_size) + y
223
224        assert (base & VPN_ANTI_MASK) == 0
225
226        assert (x < self.x_size) and (y < self.y_size)
227
228        assert ( (base & ((1<<paddr_lsb_width)-1)) == self.ram_base )
229
230        assert ( size == self.ram_size )
231
232        # add one pseg in the mapping
233        pseg = Pseg( name, base, size, x, y, 'RAM' )
234        self.clusters[cluster_id].psegs.append( pseg )
235        pseg.index = self.total_psegs
236        self.total_psegs += 1
237
238        return pseg
239
240    ##########################   add a peripheral and the associated pseg in a cluster
241    def addPeriph( self,
242                   name,               # associated pseg name
243                   base,               # associated pseg base address
244                   size,               # associated pseg length (bytes)
245                   ptype,              # peripheral type
246                   subtype  = 'NONE',  # peripheral subtype
247                   channels = 1,       # number of channels
248                   arg0     = 0,       # optional argument (semantic depends on ptype)
249                   arg1     = 0,       # optional argument (semantic depends on ptype)
250                   arg2     = 0,       # optional argument (semantic depends on ptype)
251                   arg3     = 0 ):     # optional argument (semantic depends on ptype)
252
253        # computes cluster index and coordinates from the base address
254        cluster_xy = base >> (self.paddr_width - self.x_width - self.y_width)
255        x          = cluster_xy >> (self.y_width);
256        y          = cluster_xy & ((1 << self.y_width) - 1)
257        cluster_id = (x * self.y_size) + y
258
259        assert (x < self.x_size) and (y < self.y_size)
260
261        assert (base & VPN_ANTI_MASK) == 0
262
263        assert ptype in PERIPHTYPES
264
265        if (ptype == 'IOC'): assert subtype in IOCSUBTYPES
266        if (ptype == 'MWR'): assert subtype in MWRSUBTYPES
267
268        # add one pseg into mapping
269        pseg = Pseg( name, base, size, x, y, 'PERI' )
270        self.clusters[cluster_id].psegs.append( pseg )
271        pseg.index = self.total_psegs
272        self.total_psegs += 1
273
274        # add one periph into mapping
275        periph = Periph( pseg, ptype, subtype, channels, arg0, arg1, arg2, arg3 )
276        self.clusters[cluster_id].periphs.append( periph )
277        periph.index = self.total_periphs
278        self.total_periphs += 1
279
280        return periph
281
282    ################################   add an IRQ in a peripheral
283    def addIrq( self,
284                periph,                # peripheral containing IRQ (PIC or XCU)
285                index,                 # peripheral input port index
286                src,                   # interrupt source peripheral
287                isrtype,               # ISR type
288                channel = 0 ):         # channel for multi-channels ISR
289
290        assert isrtype in ISRTYPES
291
292        assert index < 32
293
294        # add one irq into mapping
295        irq = Irq( 'HWI', index , isrtype, channel )
296        periph.irqs.append( irq )
297        irq.index = self.total_irqs
298        self.total_irqs += 1
299
300        # pointer from the source to the interrupt controller peripheral
301        if src.irq_ctrl == None: src.irq_ctrl = periph
302        if src.irq_ctrl != periph:
303            print '[genmap error] in addIrq():'
304            print '    two different interrupt controller for the same peripheral'
305            sys.exit(1)
306
307        return irq
308
309    ##########################    add a processor in a cluster
310    def addProc( self,
311                 x,                    # cluster x coordinate
312                 y,                    # cluster y coordinate
313                 lpid ):               # processor local index
314
315        assert (x < self.x_size) and (y < self.y_size)
316
317        cluster_id = (x * self.y_size) + y
318
319        # add one proc into mapping
320        proc = Processor( x, y, lpid )
321        self.clusters[cluster_id].procs.append( proc )
322        proc.index = self.total_procs
323        self.total_procs += 1
324
325        return proc
326
327    ############################    add one global vseg into mapping
328    def addGlobal( self, 
329                   name,               # vseg name
330                   vbase,              # virtual base address
331                   length,             # vseg length (bytes)
332                   mode,               # CXWU flags
333                   vtype,              # vseg type
334                   x,                  # destination x coordinate
335                   y,                  # destination y coordinate
336                   pseg,               # destination pseg name
337                   identity = False,   # identity mapping required if true
338                   local    = False,   # only mapped in local PTAB if true
339                   big      = False,   # to be mapped in a big physical page
340                   binpath  = '' ):    # pathname for binary code if required
341
342        # two global vsegs must not overlap if they have different names
343        for prev in self.globs:
344            if ( ((prev.vbase + prev.length) > vbase ) and 
345                 ((vbase + length) > prev.vbase) and
346                 (prev.name[0:15] != name[0:15]) ):
347                print '[genmap error] in addGlobal()'
348                print '    global vseg %s overlap %s' % (name, prev.name)
349                print '    %s : base = %x / size = %x' %(name, vbase, length)
350                print '    %s : base = %x / size = %x' %(prev.name, prev.vbase, prev.length)
351                sys.exit(1)
352
353        # add one vseg into mapping
354        vseg = Vseg( name, vbase, length, mode, vtype, x, y, pseg, 
355                     identity = identity, local = local, big = big, binpath = binpath )
356
357        self.globs.append( vseg )
358        self.total_globals += 1
359        vseg.index = self.total_vsegs
360        self.total_vsegs += 1
361
362        return
363
364    ################################    add a vspace into mapping
365    def addVspace( self,
366                   name,                # vspace name
367                   startname,           # name of vseg containing start_vector
368                   active = False ):    # default value is not active at boot
369
370        # add one vspace into mapping
371        vspace = Vspace( name, startname, active )
372        self.vspaces.append( vspace )
373        vspace.index = self.total_vspaces
374        self.total_vspaces += 1
375
376        return vspace
377
378    #################################   add a private vseg in a vspace
379    def addVseg( self,
380                 vspace,                # vspace containing the vseg
381                 name,                  # vseg name
382                 vbase,                 # virtual base address
383                 length,                # vseg length (bytes)
384                 mode,                  # CXWU flags
385                 vtype,                 # vseg type
386                 x,                     # destination x coordinate
387                 y,                     # destination y coordinate
388                 pseg,                  # destination pseg name
389                 local    = False,      # only mapped in local PTAB if true
390                 big      = False,      # to be mapped in a big physical page
391                 binpath  = '' ):       # pathname for binary code
392
393        assert mode in VSEGMODES
394
395        assert vtype in VSEGTYPES
396
397        assert (x < self.x_size) and (y < self.y_size)
398
399        # add one vseg into mapping
400        vseg = Vseg( name, vbase, length, mode, vtype, x, y, pseg, 
401                     identity = False, local = local, big = big, binpath = binpath )
402        vspace.vsegs.append( vseg )
403        vseg.index = self.total_vsegs
404        self.total_vsegs += 1
405
406        return vseg
407
408    ################################    add a thread in a vspace
409    def addThread( self,
410                   vspace,                # vspace containing thread
411                   name,                  # thread name
412                   is_main,               # Boolean (one thread per vspace)
413                   x,                     # destination x coordinate
414                   y,                     # destination y coordinate
415                   p,                     # destination processor local index
416                   stackname,             # name of vseg containing stack
417                   heapname,              # name of vseg containing heap
418                   startid ):             # index in start_vector
419
420        assert x < self.x_size
421        assert y < self.y_size
422        assert p < self.nprocs
423
424        # add one thread into mapping
425        thread = Thread( name, is_main, x, y, p, stackname, heapname, startid )
426        vspace.threads.append( thread )
427        thread.index = self.total_threads
428        self.total_threads += 1
429
430        return thread
431
432    #################################
433    def str2bytes( self, nbytes, s ):    # string => nbytes_packed byte array
434
435        byte_stream = bytearray()
436        length = len( s )
437        if length < (nbytes - 1):
438            for b in s:
439                byte_stream.append( b )
440            for x in xrange(nbytes-length):
441                byte_stream.append( '\0' )
442        else:
443            print '[genmap error] in str2bytes()'
444            print '    string %s too long' % s
445            sys.exit(1)
446
447        return byte_stream
448
449    ###################################
450    def int2bytes( self, nbytes, val ):    # integer => nbytes litle endian byte array
451
452        byte_stream = bytearray()
453        for n in xrange( nbytes ):
454            byte_stream.append( (val >> (n<<3)) & 0xFF )
455
456        return byte_stream
457
458    ################
459    def xml( self ):    # compute string for map.xml file generation
460
461        s = '<?xml version="1.0"?>\n\n'
462        s += '<mapping_info signature    = "0x%x"\n' % (self.signature)
463        s += '              name         = "%s"\n'   % (self.name)
464        s += '              x_size       = "%d"\n'   % (self.x_size)
465        s += '              y_size       = "%d"\n'   % (self.y_size)
466        s += '              x_width      = "%d"\n'   % (self.x_width)
467        s += '              y_width      = "%d"\n'   % (self.y_width)
468        s += '              irq_per_proc = "%d"\n'   % (self.irq_per_proc)
469        s += '              use_ramdisk  = "%d"\n'   % (self.use_ramdisk)
470        s += '              x_io         = "%d"\n'   % (self.x_io)
471        s += '              y_io         = "%d" >\n' % (self.y_io)
472        s += '\n'
473
474        s += '    <clusterset>\n'
475        for x in xrange ( self.x_size ):
476            for y in xrange ( self.y_size ):
477                cluster_id = (x * self.y_size) + y
478                s += self.clusters[cluster_id].xml()
479        s += '    </clusterset>\n'
480        s += '\n'
481
482        s += '    <globalset>\n'
483        for vseg in self.globs: s += vseg.xml()
484        s += '    </globalset>\n'
485        s += '\n'
486
487        s += '    <vspaceset>\n'
488        for vspace in self.vspaces: s += vspace.xml()
489        s += '    </vspaceset>\n'
490
491        s += '</mapping_info>\n'
492        return s
493
494    ##########################
495    def cbin( self, verbose ):     # C binary structure for map.bin file generation
496
497        byte_stream = bytearray()
498
499        # header
500        byte_stream += self.int2bytes(4,   self.signature)
501        byte_stream += self.int2bytes(4,   self.x_size)
502        byte_stream += self.int2bytes(4,   self.y_size)
503        byte_stream += self.int2bytes(4,   self.x_width)
504        byte_stream += self.int2bytes(4,   self.y_width)
505        byte_stream += self.int2bytes(4,   self.x_io)
506        byte_stream += self.int2bytes(4,   self.y_io)
507        byte_stream += self.int2bytes(4,   self.irq_per_proc)
508        byte_stream += self.int2bytes(4,   self.use_ramdisk)
509        byte_stream += self.int2bytes(4,   self.total_globals)
510        byte_stream += self.int2bytes(4,   self.total_vspaces)
511        byte_stream += self.int2bytes(4,   self.total_psegs)
512        byte_stream += self.int2bytes(4,   self.total_vsegs)
513        byte_stream += self.int2bytes(4,   self.total_threads)
514        byte_stream += self.int2bytes(4,   self.total_procs)
515        byte_stream += self.int2bytes(4,   self.total_irqs)
516        byte_stream += self.int2bytes(4,   self.total_periphs)
517        byte_stream += self.str2bytes(256, self.name)
518
519        if ( verbose ):
520            print '\n'
521            print 'name          = %s' % self.name
522            print 'signature     = %x' % self.signature
523            print 'x_size        = %d' % self.x_size
524            print 'y_size        = %d' % self.y_size
525            print 'x_width       = %d' % self.x_width
526            print 'y_width       = %d' % self.y_width
527            print 'x_io          = %d' % self.x_io
528            print 'y_io          = %d' % self.y_io
529            print 'irq_per_proc  = %d' % self.irq_per_proc
530            print 'use_ramdisk   = %d' % self.use_ramdisk
531            print 'total_globals = %d' % self.total_globals
532            print 'total_psegs   = %d' % self.total_psegs
533            print 'total_vsegs   = %d' % self.total_vsegs
534            print 'total_threads   = %d' % self.total_threads
535            print 'total_procs   = %d' % self.total_procs
536            print 'total_irqs    = %d' % self.total_irqs
537            print 'total_periphs = %d' % self.total_periphs
538            print '\n'
539
540        # clusters array
541        index = 0
542        for cluster in self.clusters:
543            byte_stream += cluster.cbin( self, verbose, index )
544            index += 1
545
546        if ( verbose ): print '\n'
547
548        # psegs array
549        index = 0
550        for cluster in self.clusters:
551            for pseg in cluster.psegs:
552                byte_stream += pseg.cbin( self, verbose, index, cluster )
553                index += 1
554
555        if ( verbose ): print '\n'
556
557        # vspaces array
558        index = 0
559        for vspace in self.vspaces:
560            byte_stream += vspace.cbin( self, verbose, index )
561            index += 1
562
563        if ( verbose ): print '\n'
564
565        # vsegs array
566        index = 0
567        for vseg in self.globs:
568            byte_stream += vseg.cbin( self, verbose, index )
569            index += 1
570        for vspace in self.vspaces:
571            for vseg in vspace.vsegs:
572                byte_stream += vseg.cbin( self, verbose, index )
573                index += 1
574
575        if ( verbose ): print '\n'
576
577        # threads array
578        index = 0
579        for vspace in self.vspaces:
580            for thread in vspace.threads:
581                byte_stream += thread.cbin( self, verbose, index, vspace )
582                index += 1
583
584        if ( verbose ): print '\n'
585
586        # procs array
587        index = 0
588        for cluster in self.clusters:
589            for proc in cluster.procs:
590                byte_stream += proc.cbin( self, verbose, index )
591                index += 1
592
593        if ( verbose ): print '\n'
594
595        # irqs array
596        index = 0
597        for cluster in self.clusters:
598            for periph in cluster.periphs:
599                for irq in periph.irqs:
600                    byte_stream += irq.cbin( self, verbose, index )
601                    index += 1
602
603        if ( verbose ): print '\n'
604
605        # periphs array
606        index = 0
607        for cluster in self.clusters:
608            for periph in cluster.periphs:
609                byte_stream += periph.cbin( self, verbose, index )
610                index += 1
611
612        return byte_stream
613    # end of cbin()
614
615    #######################################################################
616    def giet_vsegs( self ):      # compute string for giet_vsegs.ld file
617                                 # required by giet_vm compilation
618
619        # search the vsegs required for the giet_vsegs.ld
620        boot_code_found      = False
621        boot_data_found      = False
622        kernel_uncdata_found = False
623        kernel_data_found    = False
624        kernel_code_found    = False
625        for vseg in self.globs:
626
627            if ( vseg.name[0:13] == 'seg_boot_code' ):
628                boot_code_vbase      = vseg.vbase
629                boot_code_size       = vseg.length
630                boot_code_found      = True
631
632            if ( vseg.name[0:13] == 'seg_boot_data' ):
633                boot_data_vbase      = vseg.vbase
634                boot_data_size       = vseg.length
635                boot_data_found      = True
636
637            if ( vseg.name[0:15] == 'seg_kernel_data' ):
638                kernel_data_vbase    = vseg.vbase
639                kernel_data_size     = vseg.length
640                kernel_data_found    = True
641
642            if ( vseg.name[0:15] == 'seg_kernel_code' ):
643                kernel_code_vbase    = vseg.vbase
644                kernel_code_size     = vseg.length
645                kernel_code_found    = True
646
647        # check if all required vsegs have been found
648        if ( boot_code_found      == False ):
649             print '[genmap error] in giet_vsegs()'
650             print '    seg_boot_code vseg missing'
651             sys.exit()
652
653        if ( boot_data_found      == False ):
654             print '[genmap error] in giet_vsegs()'
655             print '    seg_boot_data vseg missing'
656             sys.exit()
657
658        if ( kernel_data_found    == False ):
659             print '[genmap error] in giet_vsegs()'
660             print '    seg_kernel_data vseg missing'
661             sys.exit()
662
663        if ( kernel_code_found    == False ):
664             print '[genmap error] in giet_vsegs()'
665             print '    seg_kernel_code vseg missing'
666             sys.exit()
667
668        # build string
669        s =  '/* Generated by genmap for %s */\n'  % self.name
670        s += '\n'
671
672        s += 'boot_code_vbase      = 0x%x;\n'   % boot_code_vbase
673        s += 'boot_code_size       = 0x%x;\n'   % boot_code_size
674        s += '\n'
675        s += 'boot_data_vbase      = 0x%x;\n'   % boot_data_vbase
676        s += 'boot_data_size       = 0x%x;\n'   % boot_data_size
677        s += '\n'
678        s += 'kernel_code_vbase    = 0x%x;\n'   % kernel_code_vbase
679        s += 'kernel_code_size     = 0x%x;\n'   % kernel_code_size
680        s += '\n'
681        s += 'kernel_data_vbase    = 0x%x;\n'   % kernel_data_vbase
682        s += 'kernel_data_size     = 0x%x;\n'   % kernel_data_size
683        s += '\n'
684
685        return s
686
687    ######################################################################
688    def hard_config( self ):     # compute string for hard_config.h file
689                                 # required by
690                                 # - top.cpp compilation
691                                 # - giet_vm compilation
692                                 # - tsar_preloader compilation
693
694        nb_total_procs = 0
695
696        # for each peripheral type, define default values
697        # for pbase address, size, number of components, and channels
698        nb_cma       = 0
699        cma_channels = 0
700        seg_cma_base = 0xFFFFFFFF
701        seg_cma_size = 0
702
703        nb_dma       = 0
704        dma_channels = 0
705        seg_dma_base = 0xFFFFFFFF
706        seg_dma_size = 0
707
708        nb_fbf       = 0
709        fbf_channels = 0
710        seg_fbf_base = 0xFFFFFFFF
711        seg_fbf_size = 0
712        fbf_arg0     = 0
713        fbf_arg1     = 0
714
715        nb_iob       = 0
716        iob_channels = 0
717        seg_iob_base = 0xFFFFFFFF
718        seg_iob_size = 0
719
720        nb_ioc       = 0
721        ioc_channels = 0
722        seg_ioc_base = 0xFFFFFFFF
723        seg_ioc_size = 0
724        use_ioc_bdv  = False
725        use_ioc_sdc  = False
726        use_ioc_hba  = False
727        use_ioc_spi  = False
728
729        nb_mmc       = 0
730        mmc_channels = 0
731        seg_mmc_base = 0xFFFFFFFF
732        seg_mmc_size = 0
733
734        nb_mwr       = 0
735        mwr_channels = 0
736        seg_mwr_base = 0xFFFFFFFF
737        seg_mwr_size = 0
738        mwr_arg0     = 0
739        mwr_arg1     = 0
740        mwr_arg2     = 0
741        mwr_arg3     = 0
742        use_mwr_gcd  = False
743        use_mwr_dct  = False
744        use_mwr_cpy  = False
745
746        nb_nic       = 0
747        nic_channels = 0
748        seg_nic_base = 0xFFFFFFFF
749        seg_nic_size = 0
750
751        nb_pic       = 0
752        pic_channels = 0
753        seg_pic_base = 0xFFFFFFFF
754        seg_pic_size = 0
755
756        nb_rom       = 0
757        rom_channels = 0
758        seg_rom_base = 0xFFFFFFFF
759        seg_rom_size = 0
760
761        nb_sim       = 0
762        sim_channels = 0
763        seg_sim_base = 0xFFFFFFFF
764        seg_sim_size = 0
765
766        nb_tim       = 0
767        tim_channels = 0
768        seg_tim_base = 0xFFFFFFFF
769        seg_tim_size = 0
770
771        nb_tty       = 0
772        tty_channels = 0
773        seg_tty_base = 0xFFFFFFFF
774        seg_tty_size = 0
775
776        nb_xcu       = 0
777        xcu_channels = 0
778        seg_xcu_base = 0xFFFFFFFF
779        seg_xcu_size = 0
780        xcu_arg0     = 0
781
782        nb_drom       = 0
783        drom_channels = 0
784        seg_drom_base = 0xFFFFFFFF
785        seg_drom_size = 0
786
787        # get peripherals attributes
788        for cluster in self.clusters:
789            for periph in cluster.periphs:
790                if   ( periph.ptype == 'CMA' ):
791                    seg_cma_base = periph.pseg.base & 0xFFFFFFFF
792                    seg_cma_size = periph.pseg.size
793                    cma_channels = periph.channels
794                    nb_cma +=1
795
796                elif ( periph.ptype == 'DMA' ):
797                    seg_dma_base = periph.pseg.base & 0xFFFFFFFF
798                    seg_dma_size = periph.pseg.size
799                    dma_channels = periph.channels
800                    nb_dma +=1
801
802                elif ( periph.ptype == 'FBF' ):
803                    seg_fbf_base = periph.pseg.base & 0xFFFFFFFF
804                    seg_fbf_size = periph.pseg.size
805                    fbf_channels = periph.channels
806                    fbf_arg0     = periph.arg0
807                    fbf_arg1     = periph.arg1
808                    nb_fbf +=1
809
810                elif ( periph.ptype == 'IOB' ):
811                    seg_iob_base = periph.pseg.base & 0xFFFFFFFF
812                    seg_iob_size = periph.pseg.size
813                    iob_channels = periph.channels
814                    nb_iob +=1
815
816                elif ( periph.ptype == 'IOC' ):
817                    seg_ioc_base = periph.pseg.base & 0xFFFFFFFF
818                    seg_ioc_size = periph.pseg.size
819                    ioc_channels = periph.channels
820                    nb_ioc += 1
821                    if ( periph.subtype == 'BDV' ): use_ioc_bdv = True
822                    if ( periph.subtype == 'HBA' ): use_ioc_hba = True
823                    if ( periph.subtype == 'SDC' ): use_ioc_sdc = True
824                    if ( periph.subtype == 'SPI' ): use_ioc_spi = True
825
826                elif ( periph.ptype == 'MMC' ):
827                    seg_mmc_base = periph.pseg.base & 0xFFFFFFFF
828                    seg_mmc_size = periph.pseg.size
829                    mmc_channels = periph.channels
830                    nb_mmc +=1
831
832                elif ( periph.ptype == 'MWR' ):
833                    seg_mwr_base = periph.pseg.base & 0xFFFFFFFF
834                    seg_mwr_size = periph.pseg.size
835                    mwr_channels = periph.channels
836                    mwr_arg0     = periph.arg0
837                    mwr_arg1     = periph.arg1
838                    mwr_arg2     = periph.arg2
839                    mwr_arg3     = periph.arg3
840                    nb_mwr +=1
841                    if ( periph.subtype == 'GCD' ): use_mwr_gcd = True
842                    if ( periph.subtype == 'DCT' ): use_mwr_dct = True
843                    if ( periph.subtype == 'CPY' ): use_mwr_cpy = True
844
845                elif ( periph.ptype == 'ROM' ):
846                    seg_rom_base = periph.pseg.base & 0xFFFFFFFF
847                    seg_rom_size = periph.pseg.size
848                    rom_channels = periph.channels
849                    nb_rom +=1
850
851                elif ( periph.ptype == 'DROM' ):
852                    seg_drom_base = periph.pseg.base & 0xFFFFFFFF
853                    seg_drom_size = periph.pseg.size
854                    drom_channels = periph.channels
855                    nb_drom +=1
856
857                elif ( periph.ptype == 'SIM' ):
858                    seg_sim_base = periph.pseg.base & 0xFFFFFFFF
859                    seg_sim_size = periph.pseg.size
860                    sim_channels = periph.channels
861                    nb_sim +=1
862
863                elif ( periph.ptype == 'NIC' ):
864                    seg_nic_base = periph.pseg.base & 0xFFFFFFFF
865                    seg_nic_size = periph.pseg.size
866                    nic_channels = periph.channels
867                    nb_nic +=1
868
869                elif ( periph.ptype == 'PIC' ):
870                    seg_pic_base = periph.pseg.base & 0xFFFFFFFF
871                    seg_pic_size = periph.pseg.size
872                    pic_channels = periph.channels
873                    nb_pic +=1
874
875                elif ( periph.ptype == 'TIM' ):
876                    seg_tim_base = periph.pseg.base & 0xFFFFFFFF
877                    seg_tim_size = periph.pseg.size
878                    tim_channels = periph.channels
879                    nb_tim +=1
880
881                elif ( periph.ptype == 'TTY' ):
882                    seg_tty_base = periph.pseg.base & 0xFFFFFFFF
883                    seg_tty_size = periph.pseg.size
884                    tty_channels = periph.channels
885                    nb_tty +=1
886
887                elif ( periph.ptype == 'XCU' ):
888                    seg_xcu_base = periph.pseg.base & 0xFFFFFFFF
889                    seg_xcu_size = periph.pseg.size
890                    xcu_channels = periph.channels
891                    xcu_arg0     = periph.arg0
892                    xcu_arg1     = periph.arg1
893                    xcu_arg2     = periph.arg2
894                    nb_xcu +=1
895
896        # no more than two access to external peripherals
897        assert ( nb_fbf <= 2 )
898        assert ( nb_cma <= 2 )
899        assert ( nb_ioc <= 2 )
900        assert ( nb_nic <= 2 )
901        assert ( nb_tim <= 2 )
902        assert ( nb_tty <= 2 )
903        assert ( nb_pic <= 2 )
904
905        # one and only one type of IOC controller
906        nb_ioc_types = 0
907        if use_ioc_hba:       nb_ioc_types += 1
908        if use_ioc_bdv:       nb_ioc_types += 1
909        if use_ioc_sdc:       nb_ioc_types += 1
910        if use_ioc_spi:       nb_ioc_types += 1
911        if self.use_ramdisk:  nb_ioc_types += 1
912        assert ( nb_ioc_types == 1 )
913
914        # one and only one type of MWR controller
915        nb_mwr_types = 0
916        if use_mwr_gcd:       nb_mwr_types += 1
917        if use_mwr_dct:       nb_mwr_types += 1
918        if use_mwr_cpy:       nb_mwr_types += 1
919        if ( nb_mwr > 0 ) : assert ( nb_mwr_types == 1 )
920
921        # Compute total number of processors
922        for cluster in self.clusters:
923            nb_total_procs += len( cluster.procs )
924
925        # Compute physical addresses for BOOT vsegs
926        boot_mapping_found   = False
927        boot_code_found      = False
928        boot_data_found      = False
929        boot_stack_found     = False
930
931        for vseg in self.globs:
932            if ( vseg.name == 'seg_boot_mapping' ):
933                boot_mapping_base       = vseg.vbase
934                boot_mapping_size       = vseg.length
935                boot_mapping_identity   = vseg.identity
936                boot_mapping_found      = True
937
938            if ( vseg.name == 'seg_boot_code' ):
939                boot_code_base          = vseg.vbase
940                boot_code_size          = vseg.length
941                boot_code_identity      = vseg.identity
942                boot_code_found         = True
943
944            if ( vseg.name == 'seg_boot_data' ):
945                boot_data_base          = vseg.vbase
946                boot_data_size          = vseg.length
947                boot_data_identity      = vseg.identity
948                boot_data_found         = True
949
950            if ( vseg.name == 'seg_boot_stack' ):
951                boot_stack_base         = vseg.vbase
952                boot_stack_size         = vseg.length
953                boot_stack_identity     = vseg.identity
954                boot_stack_found        = True
955
956        # check that BOOT vsegs are found and identity mapping
957        if ( (boot_mapping_found == False) or (boot_mapping_identity == False) ):
958             print '[genmap error] in hard_config()'
959             print '    seg_boot_mapping missing or not identity mapping'
960             sys.exit()
961
962        if ( (boot_code_found == False) or (boot_code_identity == False) ):
963             print '[genmap error] in hard_config()'
964             print '    seg_boot_code missing or not identity mapping'
965             sys.exit()
966
967        if ( (boot_data_found == False) or (boot_data_identity == False) ):
968             print '[genmap error] in hard_config()'
969             print '    seg_boot_data missing or not identity mapping'
970             sys.exit()
971
972        if ( (boot_stack_found == False) or (boot_stack_identity == False) ):
973             print '[genmap error] in giet_vsegs()'
974             print '    seg_boot_stack missing or not identity mapping'
975             sys.exit()
976
977        # Search RAMDISK global vseg if required
978        seg_rdk_base =  0xFFFFFFFF
979        seg_rdk_size =  0
980        seg_rdk_found = False
981
982        if self.use_ramdisk:
983            for vseg in self.globs:
984                if ( vseg.name == 'seg_ramdisk' ):
985                    seg_rdk_base  = vseg.vbase
986                    seg_rdk_size  = vseg.length
987                    seg_rdk_found = True
988
989            if ( seg_rdk_found == False ):
990                print 'Error in hard_config() "seg_ramdisk" not found'
991                sys.exit(1)
992
993        # build string
994        s =  '/* Generated by genmap for %s */\n'  % self.name
995        s += '\n'
996        s += '#ifndef HARD_CONFIG_H\n'
997        s += '#define HARD_CONFIG_H\n'
998        s += '\n'
999
1000        s += '/* General platform parameters */\n'
1001        s += '\n'
1002        s += '#define X_SIZE                 %d\n'    % self.x_size
1003        s += '#define Y_SIZE                 %d\n'    % self.y_size
1004        s += '#define X_WIDTH                %d\n'    % self.x_width
1005        s += '#define Y_WIDTH                %d\n'    % self.y_width
1006        s += '#define P_WIDTH                %d\n'    % self.p_width
1007        s += '#define X_IO                   %d\n'    % self.x_io
1008        s += '#define Y_IO                   %d\n'    % self.y_io
1009        s += '#define NB_PROCS_MAX           %d\n'    % self.nprocs
1010        s += '#define IRQ_PER_PROCESSOR      %d\n'    % self.irq_per_proc
1011        s += '#define RESET_ADDRESS          0x%x\n'  % self.reset_address
1012        s += '#define NB_TOTAL_PROCS         %d\n'    % nb_total_procs
1013        s += '\n'
1014
1015        s += '/* Peripherals */\n'
1016        s += '\n'
1017        s += '#define NB_TTY_CHANNELS        %d\n'    % tty_channels
1018        s += '#define NB_IOC_CHANNELS        %d\n'    % ioc_channels
1019        s += '#define NB_NIC_CHANNELS        %d\n'    % nic_channels
1020        s += '#define NB_CMA_CHANNELS        %d\n'    % cma_channels
1021        s += '#define NB_TIM_CHANNELS        %d\n'    % tim_channels
1022        s += '#define NB_DMA_CHANNELS        %d\n'    % dma_channels
1023        s += '\n'
1024        s += '#define USE_XCU                %d\n'    % ( nb_xcu != 0 )
1025        s += '#define USE_DMA                %d\n'    % ( nb_dma != 0 )
1026        s += '\n'
1027        s += '#define USE_IOB                %d\n'    % ( nb_iob != 0 )
1028        s += '#define USE_PIC                %d\n'    % ( nb_pic != 0 )
1029        s += '#define USE_FBF                %d\n'    % ( nb_fbf != 0 )
1030        s += '#define USE_NIC                %d\n'    % ( nb_nic != 0 )
1031        s += '\n'
1032        s += '#define USE_IOC_BDV            %d\n'    % use_ioc_bdv
1033        s += '#define USE_IOC_SDC            %d\n'    % use_ioc_sdc
1034        s += '#define USE_IOC_HBA            %d\n'    % use_ioc_hba
1035        s += '#define USE_IOC_SPI            %d\n'    % use_ioc_spi
1036        s += '#define USE_IOC_RDK            %d\n'    % self.use_ramdisk
1037        s += '\n'
1038        s += '#define USE_MWR_GCD            %d\n'    % use_mwr_gcd
1039        s += '#define USE_MWR_DCT            %d\n'    % use_mwr_dct
1040        s += '#define USE_MWR_CPY            %d\n'    % use_mwr_cpy
1041        s += '\n'
1042        s += '#define FBUF_X_SIZE            %d\n'    % fbf_arg0
1043        s += '#define FBUF_Y_SIZE            %d\n'    % fbf_arg1
1044        s += '\n'
1045        s += '#define XCU_NB_HWI             %d\n'    % xcu_arg0
1046        s += '#define XCU_NB_PTI             %d\n'    % xcu_arg1
1047        s += '#define XCU_NB_WTI             %d\n'    % xcu_arg2
1048        s += '#define XCU_NB_OUT             %d\n'    % xcu_channels
1049        s += '\n'
1050        s += '#define MWR_TO_COPROC          %d\n'    % mwr_arg0
1051        s += '#define MWR_FROM_COPROC        %d\n'    % mwr_arg1
1052        s += '#define MWR_CONFIG             %d\n'    % mwr_arg2
1053        s += '#define MWR_STATUS             %d\n'    % mwr_arg3
1054        s += '\n'
1055
1056        s += '/* base addresses and sizes for physical segments */\n'
1057        s += '\n'
1058        s += '#define SEG_RAM_BASE           0x%x\n'  % self.ram_base
1059        s += '#define SEG_RAM_SIZE           0x%x\n'  % self.ram_size
1060        s += '\n'
1061        s += '#define SEG_CMA_BASE           0x%x\n'  % seg_cma_base
1062        s += '#define SEG_CMA_SIZE           0x%x\n'  % seg_cma_size
1063        s += '\n'
1064        s += '#define SEG_DMA_BASE           0x%x\n'  % seg_dma_base
1065        s += '#define SEG_DMA_SIZE           0x%x\n'  % seg_dma_size
1066        s += '\n'
1067        s += '#define SEG_FBF_BASE           0x%x\n'  % seg_fbf_base
1068        s += '#define SEG_FBF_SIZE           0x%x\n'  % seg_fbf_size
1069        s += '\n'
1070        s += '#define SEG_IOB_BASE           0x%x\n'  % seg_iob_base
1071        s += '#define SEG_IOB_SIZE           0x%x\n'  % seg_iob_size
1072        s += '\n'
1073        s += '#define SEG_IOC_BASE           0x%x\n'  % seg_ioc_base
1074        s += '#define SEG_IOC_SIZE           0x%x\n'  % seg_ioc_size
1075        s += '\n'
1076        s += '#define SEG_MMC_BASE           0x%x\n'  % seg_mmc_base
1077        s += '#define SEG_MMC_SIZE           0x%x\n'  % seg_mmc_size
1078        s += '\n'
1079        s += '#define SEG_MWR_BASE           0x%x\n'  % seg_mwr_base
1080        s += '#define SEG_MWR_SIZE           0x%x\n'  % seg_mwr_size
1081        s += '\n'
1082        s += '#define SEG_ROM_BASE           0x%x\n'  % seg_rom_base
1083        s += '#define SEG_ROM_SIZE           0x%x\n'  % seg_rom_size
1084        s += '\n'
1085        s += '#define SEG_SIM_BASE           0x%x\n'  % seg_sim_base
1086        s += '#define SEG_SIM_SIZE           0x%x\n'  % seg_sim_size
1087        s += '\n'
1088        s += '#define SEG_NIC_BASE           0x%x\n'  % seg_nic_base
1089        s += '#define SEG_NIC_SIZE           0x%x\n'  % seg_nic_size
1090        s += '\n'
1091        s += '#define SEG_PIC_BASE           0x%x\n'  % seg_pic_base
1092        s += '#define SEG_PIC_SIZE           0x%x\n'  % seg_pic_size
1093        s += '\n'
1094        s += '#define SEG_TIM_BASE           0x%x\n'  % seg_tim_base
1095        s += '#define SEG_TIM_SIZE           0x%x\n'  % seg_tim_size
1096        s += '\n'
1097        s += '#define SEG_TTY_BASE           0x%x\n'  % seg_tty_base
1098        s += '#define SEG_TTY_SIZE           0x%x\n'  % seg_tty_size
1099        s += '\n'
1100        s += '#define SEG_XCU_BASE           0x%x\n'  % seg_xcu_base
1101        s += '#define SEG_XCU_SIZE           0x%x\n'  % seg_xcu_size
1102        s += '\n'
1103        s += '#define SEG_RDK_BASE           0x%x\n'  % seg_rdk_base
1104        s += '#define SEG_RDK_SIZE           0x%x\n'  % seg_rdk_size
1105        s += '\n'
1106        s += '#define SEG_DROM_BASE          0x%x\n'  % seg_drom_base
1107        s += '#define SEG_DROM_SIZE          0x%x\n'  % seg_drom_size
1108        s += '\n'
1109        s += '#define PERI_CLUSTER_INCREMENT 0x%x\n'  % self.peri_increment
1110        s += '\n'
1111
1112        s += '/* physical base addresses for identity mapped vsegs */\n'
1113        s += '/* used by the GietVM OS                             */\n'
1114        s += '\n'
1115        s += '#define SEG_BOOT_MAPPING_BASE  0x%x\n'  % boot_mapping_base
1116        s += '#define SEG_BOOT_MAPPING_SIZE  0x%x\n'  % boot_mapping_size
1117        s += '\n'
1118        s += '#define SEG_BOOT_CODE_BASE     0x%x\n'  % boot_code_base
1119        s += '#define SEG_BOOT_CODE_SIZE     0x%x\n'  % boot_code_size
1120        s += '\n'
1121        s += '#define SEG_BOOT_DATA_BASE     0x%x\n'  % boot_data_base
1122        s += '#define SEG_BOOT_DATA_SIZE     0x%x\n'  % boot_data_size
1123        s += '\n'
1124        s += '#define SEG_BOOT_STACK_BASE    0x%x\n'  % boot_stack_base
1125        s += '#define SEG_BOOT_STACK_SIZE    0x%x\n'  % boot_stack_size
1126        s += '#endif\n'
1127
1128        return s
1129
1130    # end of hard_config()
1131
1132    #################################################################
1133    def linux_dts( self ):     # compute string for linux.dts file
1134                               # used for linux configuration
1135        # header
1136        s =  '/dts-v1/;\n'
1137        s += '\n'
1138        s += '/{\n'
1139        s += '  compatible = "tsar,%s";\n' % self.name
1140        s += '  #address-cells = <2>;\n'               # physical address on 64 bits
1141        s += '  #size-cells    = <1>;\n'               # segment size on 32 bits
1142        s += '  model = "%s";\n' % self.name
1143        s += '\n'
1144
1145        # linux globals arguments
1146        s += '  chosen {\n'
1147        s += '    linux,stdout-path = &tty;\n'
1148        s += '    bootargs = "console=tty0 console=ttyVTTY0 earlyprintk";\n'
1149        s += '  };\n\n'
1150
1151        # cpus (for each cluster)
1152        s += '  cpus {\n'
1153        s += '    #address-cells = <1>;\n'
1154        s += '    #size-cells    = <0>;\n'
1155
1156        for cluster in self.clusters:
1157            for proc in cluster.procs:
1158                x       = cluster.x
1159                y       = cluster.y
1160                l       = proc.lpid
1161                proc_id = (((x << self.y_width) + y) << self.p_width) + l
1162                s += '    cpu@%d_%d_%d {\n' %(x,y,l)
1163                s += '      device_type = "cpu";\n'
1164                s += '      compatible = "soclib,mips32el";\n'
1165                s += '      reg = <0x%x>;\n' % proc_id
1166                s += '    };\n'
1167                s += '\n'
1168
1169        s += '  };\n\n'
1170
1171        # devices (ram or peripheral) are grouped per cluster
1172        # the "compatible" attribute links a peripheral device
1173        # to one or several drivers identified by ("major","minor")
1174
1175        chosen_tty = False
1176        for cluster in self.clusters:
1177            x               = cluster.x
1178            y               = cluster.y
1179            found_xcu       = False
1180            found_pic       = False
1181
1182            s += '  /*** cluster[%d,%d] ***/\n\n' % (x,y)
1183
1184            # scan all psegs to find RAM in current cluster
1185            for pseg in cluster.psegs:
1186                if ( pseg.segtype == 'RAM' ):
1187                    msb  = pseg.base >> 32
1188                    lsb  = pseg.base & 0xFFFFFFFF
1189                    size = pseg.size
1190
1191                    s += %s@0x%x {\n' % (pseg.name, pseg.base)
1192                    s += '    device_type = "memory";\n'
1193                    s += '    reg = <0x%x  0x%x  0x%x>;\n' % (msb, lsb, size)
1194                    s += '  };\n\n'
1195
1196            # scan all periphs to find XCU or PIC in current cluster
1197            for periph in cluster.periphs:
1198                msb     = periph.pseg.base >> 32
1199                lsb     = periph.pseg.base & 0xFFFFFFFF
1200                size    = periph.pseg.size
1201
1202                # search XCU (can be replicated)
1203                if ( (periph.ptype == 'XCU') ):
1204                    found_xcu     = True
1205
1206                    s += %s@0x%x {\n' % (periph.pseg.name, periph.pseg.base)
1207                    s += '    compatible = "soclib,vci_xicu","soclib,vci_xicu_timer";\n'
1208                    s += '    interrupt-controller;\n'
1209                    s += '    #interrupt-cells = <1>;\n'
1210                    s += '    clocks = <&freq>;\n'         # XCU contains a timer
1211                    s += '    reg = <0x%x  0x%x  0x%x>;\n' % (msb, lsb, size)
1212                    s += '  };\n\n'
1213
1214                # search PIC (non replicated)
1215                if ( periph.ptype == 'PIC' ):
1216                    found_pic     = True
1217
1218                    s += %s@0x%x {\n' % (periph.pseg.name, periph.pseg.base)
1219                    s += '    compatible = "soclib,vci_iopic";\n'
1220                    s += '    interrupt-controller;\n'
1221                    s += '    #interrupt-cells = <1>;\n'
1222                    s += '    reg = <0x%x  0x%x  0x%x>;\n' % (msb, lsb, size)
1223                    s += '  };\n\n'
1224
1225            # we need one interrupt controler in any cluster containing peripherals
1226            if ( (found_xcu == False) and
1227                 (found_pic == False) and
1228                 (len(cluster.periphs) > 0) ):
1229                print '[genmap error] in linux_dts()'
1230                print '    No XCU/PIC in cluster(%d,%d)' % (x,y)
1231                sys.exit(1)
1232
1233            # scan all periphs to find TTY and IOC in current cluster
1234            for periph in cluster.periphs:
1235                msb     = periph.pseg.base >> 32
1236                lsb     = periph.pseg.base & 0xFFFFFFFF
1237                size    = periph.pseg.size
1238
1239                irq_ctrl = periph.irq_ctrl
1240                if irq_ctrl != None:
1241                    irq_ctrl_name = '%s@0x%x' % (irq_ctrl.pseg.name, irq_ctrl.pseg.base)
1242
1243                # search TTY (non replicated)
1244                if periph.ptype == 'TTY':
1245                    assert irq_ctrl != None
1246
1247                    # get HWI index to XCU or PIC (only TTY0 is used by Linux)
1248                    hwi_id = 0xFFFFFFFF
1249                    for irq in irq_ctrl.irqs:
1250                        if ( (irq.isrtype == 'ISR_TTY_RX') and (irq.channel == 0) ):
1251                            hwi_id = irq.srcid
1252
1253                    if ( hwi_id == 0xFFFFFFFF ):
1254                        print '[genmap error] in linux.dts()'
1255                        print '    IRQ_TTY_RX not found'
1256                        sys.exit(1)
1257
1258                    if chosen_tty == False:
1259                        chosen_tty = True
1260                        s += '  tty:\n'
1261
1262                    s += %s@0x%x {\n' % (periph.pseg.name, periph.pseg.base)
1263                    s += '    compatible = "soclib,vci_multi_tty";\n'
1264                    s += '    interrupt-parent = <&{/%s}>;\n' % (irq_ctrl_name)
1265                    s += '    interrupts = <%d>;\n' % hwi_id
1266                    s += '    reg = <0x%x  0x%x  0x%x>;\n' % (msb, lsb, size)
1267                    s += '  };\n\n'
1268
1269
1270                # search IOC (non replicated)
1271                elif ( periph.ptype == 'IOC' ):
1272                    assert irq_ctrl != None
1273
1274                    if ( periph.subtype == 'BDV' ):
1275
1276                        # get irq line index associated to bdv
1277                        hwi_id = 0xFFFFFFFF
1278                        for irq in irq_ctrl.irqs:
1279                            if ( irq.isrtype == 'ISR_BDV' ): hwi_id = irq.srcid
1280
1281                        if ( hwi_id == 0xFFFFFFFF ):
1282                            print '[genmap error] in linux.dts()'
1283                            print '    ISR_BDV not found'
1284                            sys.exit(1)
1285
1286                        s += %s@0x%x {\n' % (periph.pseg.name, periph.pseg.base)
1287                        s += '    compatible = "tsar,vci_block_device";\n'
1288                        s += '    interrupt-parent = <&{/%s}>;\n' % (irq_ctrl_name)
1289                        s += '    interrupts = <%d>;\n' % hwi_id
1290                        s += '    reg = <0x%x  0x%x  0x%x>;\n' % (msb, lsb, size)
1291                        s += '  };\n\n'
1292
1293                    else:
1294                        print '[genmap warning] in linux_dts() : '
1295                        print ' %s' % (periph.subtype),
1296                        print 'peripheral not supported by LINUX'
1297
1298                # XCU or PIC have been already parsed
1299                elif ( periph.ptype == 'XCU' ) or ( periph.ptype == 'PIC' ):
1300                    pass
1301
1302                # other peripherals
1303                else:
1304                    print '[genmap warning] in linux_dts() : '
1305                    print ' %s peripheral not supported by LINUX' % (periph.ptype)
1306
1307        # clocks
1308        s += '  clocks {\n'
1309        s += '    freq: freq@50MHZ {\n'
1310        s += '      #clock-cells = <0>;\n'
1311        s += '      compatible = "fixed-clock";\n'
1312        s += '      clock-frequency = <50000000>;\n'
1313        s += '    };\n'
1314        s += '  };\n\n'
1315        s += '  cpuclk {\n'
1316        s += '    compatible = "soclib,mips32_clksrc";\n'
1317        s += '    clocks = <&freq>;\n'
1318        s += '  };\n'
1319        s += '};\n'
1320
1321        return s
1322        # end linux_dts()
1323
1324
1325    #################################################################
1326    def netbsd_dts( self ):    # compute string for netbsd.dts file
1327                               # used for netbsd configuration
1328        # header
1329        s =  '/dts-v1/;\n'
1330        s += '\n'
1331        s += '/{\n'
1332        s += '  #address-cells = <2>;\n'
1333        s += '  #size-cells    = <1>;\n'
1334
1335        # cpus (for each cluster)
1336        s += '  cpus {\n'
1337        s += '    #address-cells = <1>;\n'
1338        s += '    #size-cells    = <0>;\n'
1339
1340        for cluster in self.clusters:
1341            for proc in cluster.procs:
1342                proc_id = (((cluster.x << self.y_width) + cluster.y)
1343                              << self.p_width) + proc.lpid
1344
1345                s += '    Mips,32@0x%x {\n'                % proc_id
1346                s += '      device_type = "cpu";\n'
1347                s += '      icudev_type = "cpu:mips";\n'
1348                s += '      name        = "Mips,32";\n'
1349                s += '      reg         = <0x%x>;\n'     % proc_id
1350                s += '    };\n'
1351                s += '\n'
1352
1353        s += '  };\n'
1354
1355        # physical memory banks (for each cluster)
1356        for cluster in self.clusters:
1357            for pseg in cluster.psegs:
1358
1359                if ( pseg.segtype == 'RAM' ):
1360                    msb  = pseg.base >> 32
1361                    lsb  = pseg.base & 0xFFFFFFFF
1362                    size = pseg.size
1363
1364                    s += %s@0x%x {\n' % (pseg.name, pseg.base)
1365                    s += '    cached      = <1>;\n'
1366                    s += '    device_type = "memory";\n'
1367                    s += '    reg         = <0x%x  0x%x  0x%x>;\n' % (msb,lsb,size)
1368                    s += '  };\n'
1369
1370        # peripherals (for each cluster)
1371        for cluster in self.clusters:
1372            x = cluster.x
1373            y = cluster.y
1374
1375            # research XCU or PIC component
1376            found_xcu = False
1377            found_pic = False
1378            for periph in cluster.periphs:
1379                if ( (periph.ptype == 'XCU') ):
1380                    found_xcu = True
1381                    xcu = periph
1382                    msb  = periph.pseg.base >> 32
1383                    lsb  = periph.pseg.base & 0xFFFFFFFF
1384                    size = periph.pseg.size
1385
1386                    s += %s@0x%x {\n'  % (periph.pseg.name, periph.pseg.base)
1387                    s += '    device_type = "soclib:xicu:root";\n'
1388                    s += '    reg         = <0x%x  0x%x  0x%x>;\n' % (msb,lsb,size)
1389                    s += '    input_lines = <%d>;\n'    % periph.arg0
1390                    s += '    ipis        = <%d>;\n'    % periph.arg1
1391                    s += '    timers      = <%d>;\n'    % periph.arg2
1392
1393                    output_id = 0            # output index from XCU
1394                    for lpid in xrange ( len(cluster.procs) ):        # destination processor index
1395                        for itid in xrange ( self.irq_per_proc ):     # input irq index on processor
1396                            cluster_xy = (cluster.x << self.y_width) + cluster.y
1397                            proc_id    = (cluster_xy << self.p_width) + lpid
1398                            s += '    out@%d {\n' % output_id
1399                            s += '      device_type = "soclib:xicu:filter";\n'
1400                            s += '      irq = <&{/cpus/Mips,32@0x%x} %d>;\n' % (proc_id, itid)
1401                            s += '      output_line = <%d>;\n' % output_id
1402                            s += '      parent = <&{/%s@0x%x}>;\n' % (periph.pseg.name, periph.pseg.base)
1403                            s += '    };\n'
1404
1405                            output_id += 1
1406
1407                    s += '  };\n'
1408
1409                if ( periph.ptype == 'PIC' ):
1410                    found_pic = True
1411                    pic  = periph
1412                    msb  = periph.pseg.base >> 32
1413                    lsb  = periph.pseg.base & 0xFFFFFFFF
1414                    size = periph.pseg.size
1415
1416                    s += %s@0x%x {\n'  % (periph.pseg.name, periph.pseg.base)
1417                    s += '    device_type = "soclib:pic:root";\n'
1418                    s += '    reg         = <0x%x  0x%x  0x%x>;\n' % (msb, lsb, size)
1419                    s += '    input_lines = <%d>;\n' % periph.channels
1420                    s += '  };\n'
1421
1422            # at least one interrupt controller
1423            if ( (found_xcu == False) and (found_pic == False) and (len(cluster.periphs) > 0) ):
1424                print '[genmap error] in netbsd_dts()'
1425                print '    No XCU/PIC in cluster(%d,%d)' % (x,y)
1426                sys.exit(1)
1427
1428            # get all others peripherals in cluster
1429            for periph in cluster.periphs:
1430                msb  = periph.pseg.base >> 32
1431                lsb  = periph.pseg.base & 0xFFFFFFFF
1432                size = periph.pseg.size
1433
1434                irq_ctrl = periph.irq_ctrl
1435                if irq_ctrl != None:
1436                    irq_ctrl_name = '%s@0x%x' % (irq_ctrl.pseg.name, irq_ctrl.pseg.base)
1437
1438                # XCU or PIC have been already parsed
1439                if ( periph.ptype == 'XCU' ) or ( periph.ptype == 'PIC' ):
1440                    pass
1441
1442                # research DMA component
1443                elif ( periph.ptype == 'DMA' ):
1444
1445                    s += %s@0x%x {\n'  % (periph.pseg.name, periph.pseg.base)
1446                    s += '    device_type = "soclib:dma";\n'
1447                    s += '    reg = <0x%x  0x%x  0x%x>;\n' % (msb, lsb, size)
1448                    s += '    channel_count = <%d>;\n' % periph.channels
1449
1450                    # multi-channels : get HWI index (to XCU) for each channel
1451                    for channel in xrange( periph.channels ):
1452                        hwi_id = 0xFFFFFFFF
1453                        for irq in xcu.irqs:
1454                            if ( (irq.isrtype == 'ISR_DMA') and
1455                                 (irq.channel == channel) ):
1456                                hwi_id = irq.srcid
1457
1458                        if ( hwi_id == 0xFFFFFFFF ):
1459                            print '[genmap error] in netbsd.dts()'
1460                            print '    ISR_DMA channel %d not found' % channel
1461                            sys.exit(1)
1462
1463                        name = '%s@0x%x' % (xcu.pseg.name, xcu.pseg.base)
1464                        s += '    irq@%d{\n' % channel
1465                        s += '      device_type = "soclib:periph:irq";\n'
1466                        s += '      output_line = <%d>;\n' % channel
1467                        s += '      irq = <&{/%s%d>;\n' % (name, hwi_id)
1468                        s += '      parent = <&{/%s@0x%x}>;\n' % (periph.pseg.name, periph.pseg.base)
1469                        s += '    };\n'
1470
1471                    s += '  };\n'
1472
1473                # research MMC component
1474                elif ( periph.ptype == 'MMC' ):
1475
1476                    # get irq line index associated to MMC in XCU
1477                    irq_in = 0xFFFFFFFF
1478                    for irq in xcu.irqs:
1479                        if ( irq.isrtype == 'ISR_MMC' ): irq_in = irq.srcid
1480
1481                    if ( irq_in == 0xFFFFFFFF ):
1482                        print '[genmap error] in netbsd.dts()'
1483                        print '    ISR_MMC not found'
1484                        sys.exit(1)
1485
1486                    s += %s@0x%x {\n'  % (periph.pseg.name, periph.pseg.base)
1487                    s += '    device_type = "soclib:mmc";\n'
1488                    s += '    irq = <&{/%s} %d>;\n' % (irq_ctrl_name, irq_in)
1489                    s += '    reg = <0x%x  0x%x  0x%x>;\n' % (msb, lsb, size)
1490                    s += '  };\n'
1491
1492                # research FBF component
1493                elif ( periph.ptype == 'FBF' ):
1494
1495                    s += %s@0x%x {\n' % (periph.pseg.name, periph.pseg.base)
1496                    s += '    device_type = "soclib:framebuffer";\n'
1497                    s += '    mode        = <32>;\n'            # bits par pixel
1498                    s += '    width       = <%d>;\n'    % periph.arg0
1499                    s += '    height      = <%d>;\n'    % periph.arg1
1500                    s += '    reg         = <0x%x  0x%x  0x%x>;\n' % (msb, lsb, size)
1501                    s += '  };\n'
1502
1503                # research IOC component
1504                elif ( periph.ptype == 'IOC' ):
1505
1506                    if   ( periph.subtype == 'BDV' ):
1507
1508                        # get irq line index associated to bdv
1509                        irq_in = 0xFFFFFFFF
1510                        for irq in irq_ctrl.irqs:
1511                            if ( irq.isrtype == 'ISR_BDV' ): irq_in = irq.srcid
1512                        if ( irq_in == 0xFFFFFFFF ):
1513                            print '[genmap error] in netbsd.dts()'
1514                            print '    ISR_BDV not found'
1515                            sys.exit(1)
1516
1517                        s += %s@0x%x {\n' % (periph.pseg.name, periph.pseg.base)
1518                        s += '    device_type = "soclib:blockdevice";\n'
1519                        s += '    irq = <&{/%s} %d>;\n' % (irq_ctrl_name, irq_in)
1520                        s += '    reg = <0x%x  0x%x  0x%x>;\n' % (msb, lsb, size)
1521                        s += '  };\n'
1522
1523                    elif ( periph.subtype == 'HBA' ):
1524
1525                        print '[genmap error] in netbsd_dts()'
1526                        print '    HBA peripheral not supported by NetBSD'
1527
1528                    elif ( periph.subtype == 'SDC' ):
1529
1530                        # get irq line index associated to sdc
1531                        irq_in = 0xFFFFFFFF
1532                        for irq in irq_ctrl.irqs:
1533                            if ( irq.isrtype == 'ISR_SDC' ): irq_in = irq.srcid
1534                        if ( irq_in == 0xFFFFFFFF ):
1535                            print '[genmap error] in netbsd.dts()'
1536                            print '    ISR_SDC not found'
1537                            sys.exit(1)
1538
1539                        s += %s@0x%x {\n'  % (periph.pseg.name, periph.pseg.base)
1540                        s += '    device_type = "soclib:sdc";\n'
1541                        s += '    irq = <&{/%s} %d>;\n' % (irq_ctrl_name, irq_in)
1542                        s += '    reg = <0x%x  0x%x  0x%x>;\n' % (msb, lsb, size)
1543                        s += '  };\n'
1544
1545                # research ROM component
1546                elif ( periph.ptype == 'ROM' ) or ( periph.ptype == 'DROM' ):
1547
1548                    s += %s@0x%x {\n' % (periph.pseg.name, periph.pseg.base)
1549                    s += '    device_type = "rom";\n'
1550                    s += '    cached = <1>;\n'
1551                    s += '    reg = <0x%x  0x%x  0x%x>;\n' % (msb, lsb, size)
1552                    s += '  };\n'
1553
1554                # research SIM component
1555                elif ( periph.ptype == 'SIM' ):
1556
1557                    s += %s@0x%x {\n'  % (periph.pseg.name, periph.pseg.base)
1558                    s += '    device_type = "soclib:simhelper";\n'
1559                    s += '    reg         = <0x%x  0x%x  0x%x>;\n' % (msb, lsb, size)
1560                    s += '  };\n'
1561
1562                # research TTY component
1563                elif ( periph.ptype == 'TTY' ):
1564
1565                    s += %s@0x%x {\n' % (periph.pseg.name, periph.pseg.base)
1566                    s += '    device_type = "soclib:tty";\n'
1567                    s += '    channel_count = < %d >;\n' % periph.channels
1568                    s += '    reg = <0x%x  0x%x  0x%x>;\n' % (msb, lsb, size)
1569
1570                    # multi-channels : get HWI index (to XCU or PIC) for each channel
1571                    for channel in xrange( periph.channels ):
1572                        hwi_id = 0xFFFFFFFF
1573                        for irq in irq_ctrl.irqs:
1574                            if ( (irq.isrtype == 'ISR_TTY_RX') and (irq.channel == channel) ):
1575                                hwi_id = irq.srcid
1576                        if ( hwi_id == 0xFFFFFFFF ):
1577                            print '[genmap error] in netbsd.dts()'
1578                            print '    ISR_TTY_RX channel %d not found' % channel
1579                            sys.exit(1)
1580
1581                        name = '%s' % (irq_ctrl_name)
1582                        s += '    irq@%d{\n' % channel
1583                        s += '      device_type = "soclib:periph:irq";\n'
1584                        s += '      output_line = <%d>;\n' % channel
1585                        s += '      irq = <&{/%s%d>;\n' % (name, hwi_id)
1586                        s += '      parent = <&{/%s@0x%x}>;\n' % (periph.pseg.name, periph.pseg.base)
1587                        s += '    };\n'
1588
1589                    s += '  };\n'
1590
1591                # research IOB component
1592                elif ( periph.ptype == 'IOB' ):
1593
1594                    s += %s@0x%x {\n'  % (periph.pseg.name, periph.pseg.base)
1595                    s += '    device_type = "soclib:iob";\n'
1596                    s += '    reg         = <0x%x  0x%x  0x%x>;\n' % (msb, lsb, size)
1597                    s += '  };\n'
1598
1599                # research NIC component
1600                elif ( periph.ptype == 'NIC' ):
1601
1602                    s += %s@0x%x {\n'  % (periph.pseg.name, periph.pseg.base)
1603                    s += '    device_type   = "soclib:nic";\n'
1604                    s += '    reg           = <0x%x  0x%x  0x%x>;\n' % (msb, lsb, size)
1605                    s += '    channel_count = < %d >;\n' % periph.channels
1606
1607                    # multi-channels : get HWI index (to XCU or PIC) for RX & TX IRQs
1608                    # RX IRQ : (2*channel) / TX IRQs : (2*channel + 1)
1609                    for channel in xrange( periph.channels ):
1610                        hwi_id = 0xFFFFFFFF
1611                        for irq in irq_ctrl.irqs:
1612                            if ( (irq.isrtype == 'ISR_NIC_RX') and (irq.channel == channel) ):
1613                                hwi_id = irq.srcid
1614                        if ( hwi_id == 0xFFFFFFFF ):
1615                            print '[genmap error] in netbsd.dts()'
1616                            print '    ISR_NIC_RX channel %d not found' % channel
1617                            sys.exit(1)
1618
1619                        name = '%s' % (irq_ctrl_name)
1620                        s += '    irq_rx@%d{\n' % channel
1621                        s += '      device_type = "soclib:periph:irq";\n'
1622                        s += '      output_line = <%d>;\n' % (2*channel)
1623                        s += '      irq         = <&{/%s%d>;\n' % (name, hwi_id)
1624                        s += '      parent      = <&{/%s@0x%x}>;\n' % (periph.pseg.name, periph.pseg.base)
1625                        s += '    };\n'
1626
1627                        hwi_id = 0xFFFFFFFF
1628                        for irq in irq_ctrl.irqs:
1629                            if ( (irq.isrtype == 'ISR_NIC_TX') and (irq.channel == channel) ):
1630                                hwi_id = irq.srcid
1631                        if ( hwi_id == 0xFFFFFFFF ):
1632                            print '[genmap error] in netbsd.dts()'
1633                            print '    ISR_NIC_TX channel %d not found' % channel
1634                            sys.exit(1)
1635
1636                        name = '%s' % (irq_ctrl_name)
1637                        s += '    irq_tx@%d{\n' % channel
1638                        s += '      device_type = "soclib:periph:irq";\n'
1639                        s += '      output_line = <%d>;\n' % (2*channel + 1)
1640                        s += '      irq         = <&{/%s%d>;\n' % (name, hwi_id)
1641                        s += '      parent      = <&{/%s@0x%x}>;\n' % (periph.pseg.name, periph.pseg.base)
1642                        s += '    };\n'
1643
1644                    s += '  };\n'
1645
1646                # research CMA component
1647                elif ( periph.ptype == 'CMA' ):
1648
1649                    s += %s@0x%x {\n'  % (periph.pseg.name, periph.pseg.base)
1650                    s += '    device_type   = "soclib:cma";\n'
1651                    s += '    reg           = <0x%x  0x%x  0x%x>;\n' % (msb, lsb, size)
1652                    s += '    channel_count = < %d >;\n' % periph.channels
1653
1654                    # multi-channels : get HWI index (to XCU or PIC) for each channel
1655                    for channel in xrange( periph.channels ):
1656                        hwi_id = 0xFFFFFFFF
1657                        for irq in irq_ctrl.irqs:
1658                            if ( (irq.isrtype == 'ISR_CMA') and (irq.channel == channel) ):
1659                                hwi_id = irq.srcid
1660
1661                        if ( hwi_id == 0xFFFFFFFF ):
1662                            print '[genmap error] in netbsd.dts()'
1663                            print '    ISR_CMA channel %d not found' % channel
1664                            sys.exit(1)
1665
1666                        name = '%s' % (irq_ctrl_name)
1667                        s += '    irq@%d{\n' % channel
1668                        s += '      device_type = "soclib:periph:irq";\n'
1669                        s += '      output_line = <%d>;\n' % channel
1670                        s += '      irq = <&{/%s%d>;\n' % (name, hwi_id)
1671                        s += '      parent = <&{/%s@0x%x}>;\n' % (periph.pseg.name, periph.pseg.base)
1672                        s += '    };\n'
1673
1674                    s += '  };\n'
1675
1676                else:
1677
1678                    print '[genmap error] in netbsd_dts()'
1679                    print '    %s peripheral not supported by NetBSD' % periph.ptype
1680
1681
1682        # topology
1683        s += '\n'
1684        s += '  topology {\n'
1685        s += '    #address-cells = <2>;\n'
1686        s += '    #size-cells = <0>;\n'
1687        for cluster in self.clusters:
1688            s += '    cluster@%d,%d {\n' % (cluster.x, cluster.y)
1689            s += '      reg     = <%d %d>;\n' % (cluster.x, cluster.y)
1690            s += '      devices = <\n'
1691
1692            offset = ((cluster.x << self.y_width) + cluster.y) << self.p_width
1693            for proc in cluster.procs:
1694                s += '                &{/cpus/Mips,32@0x%x}\n' % (offset + proc.lpid)
1695            for periph in cluster.periphs:
1696                s += '                &{/%s@0x%x}\n' % (periph.pseg.name, periph.pseg.base)
1697            for pseg in cluster.psegs:
1698                if ( pseg.segtype == 'RAM' ):
1699                    s += '                &{/%s@0x%x}\n' % (pseg.name, pseg.base)
1700
1701            s += '                >;\n'
1702            s += '    };\n'
1703        s += '  };\n'
1704        s += '};\n'
1705
1706        return s
1707        # end netbsd_dts()
1708
1709    ######################################################################
1710    def almos_archinfo( self ):    # compute string for arch.info file
1711                                   # used for almos configuration
1712        # header
1713        s =  '# arch.info file generated by genmap for %s\n' % self.name
1714        s += '\n'
1715        s += '[HEADER]\n'
1716        s += '        REVISION=1\n'
1717        s += '        ARCH=%s\n'            % self.name
1718        s += '        XMAX=%d\n'            % self.x_size
1719        s += '        YMAX=%d\n'            % self.y_size
1720        s += '        CPU_NR=%d\n'          % self.nprocs
1721        s += '\n'
1722
1723        # clusters
1724        cluster_id = 0
1725        for cluster in self.clusters:
1726
1727            ram = None
1728            nb_cpus = len( cluster.procs )
1729            nb_devs = len( cluster.periphs )
1730
1731            # search a RAM
1732            for pseg in cluster.psegs:
1733                if ( pseg.segtype == 'RAM' ):
1734                    ram     = pseg
1735                    nb_devs += 1
1736
1737            # search XCU to get IRQs indexes if cluster contains peripherals
1738            if ( len( cluster.periphs ) != 0 ):
1739                tty_irq_id = None
1740                bdv_irq_id = None
1741                dma_irq_id = None
1742
1743                for periph in cluster.periphs:
1744                    if ( periph.ptype == 'XCU' ):
1745                        # scan irqs
1746                        for irq in periph.irqs:
1747                            if (irq.isrtype=='ISR_TTY_RX'): tty_irq_id = irq.srcid
1748                            if (irq.isrtype=='ISR_BDV'   ): bdv_irq_id = irq.srcid
1749                            if (irq.isrtype=='ISR_DMA'   ): dma_irq_id = irq.srcid
1750
1751            # Build the cluster description
1752            s += '[CLUSTER]\n'
1753            s += '         CID=%d\n'        % cluster_id
1754            s += '         ARCH_CID=0x%x\n' % ((cluster.x<<self.y_width)+cluster.y)
1755            s += '         CPU_NR=%d\n'     % nb_cpus
1756            s += '         DEV_NR=%d\n'     % nb_devs
1757
1758
1759            # Handling RAM when cluster contain a RAM
1760            if (ram != None ):
1761                base  = ram.base
1762                size  = ram.size
1763                irqid = -1
1764                s += '         DEVID=RAM'
1765                s += '  BASE=0x%x  SIZE=0x%x  IRQ=-1\n' % (base,size)
1766
1767            # Handling peripherals
1768            for periph in cluster.periphs:
1769                base  = periph.pseg.base
1770                size  = periph.pseg.size
1771
1772                if   ( periph.ptype == 'XCU' ):
1773
1774                    s += '         DEVID=XICU'
1775                    s += '  BASE=0x%x  SIZE=0x%x  IRQ=-1\n' %(base,size)
1776
1777                elif ( (periph.ptype == 'TTY')
1778                       and (tty_irq_id != None) ):
1779
1780                    s += '         DEVID=TTY'
1781                    s += '  BASE=0x%x  SIZE=0x%x  IRQ=%d\n' %(base,size,tty_irq_id)
1782
1783                elif ( (periph.ptype == 'DMA')
1784                       and (dma_irq_id != None) ):
1785
1786                    s += '         DEVID=DMA'
1787                    s += '  BASE=0x%x  SIZE=0x%x  IRQ=%d\n' %(base,size,dma_irq_id)
1788
1789                elif ( periph.ptype == 'FBF' ):
1790
1791                    s += '         DEVID=FB'
1792                    s += '  BASE=0x%x  SIZE=0x%x  IRQ=-1\n' %(base,size )
1793
1794                elif ( (periph.ptype == 'IOC') and (periph.subtype == 'BDV')
1795                       and (bdv_irq_id != None) ):
1796
1797                    s += '         DEVID=BLKDEV'
1798                    s += '  BASE=0x%x  SIZE=0x%x  IRQ=%d\n' %(base,size,bdv_irq_id)
1799
1800                elif ( periph.ptype == 'PIC' ):
1801
1802                    s += '         DEVID=IOPIC'
1803                    s += '  BASE=0x%x  SIZE=0x%x  IRQ=-1\n' %(base,size)
1804
1805                else:
1806                    print '# Warning from almos_archinfo() in cluster[%d,%d]' \
1807                          % (cluster.x, cluster.y)
1808                    print '# peripheral type %s/%s not supported yet\n' \
1809                          % ( periph.ptype, periph.subtype )
1810
1811            cluster_id += 1
1812
1813        return s
1814
1815    # end of almos_archinfo()
1816
1817
1818
1819
1820
1821
1822
1823
1824###################################################################################
1825class Cluster ( object ):
1826###################################################################################
1827    def __init__( self,
1828                  x,
1829                  y ):
1830
1831        self.index       = 0           # global index (set by Mapping constructor)
1832        self.x           = x           # x coordinate
1833        self.y           = y           # y coordinate
1834        self.psegs       = []          # filled by addRam() or addPeriph()
1835        self.procs       = []          # filled by addProc()
1836        self.periphs     = []          # filled by addPeriph()
1837
1838        return
1839
1840    ################
1841    def xml( self ):  # xml for a cluster
1842
1843        s = '        <cluster x="%d" y="%d" >\n' % (self.x, self.y)
1844        for pseg in self.psegs:   s += pseg.xml()
1845        for proc in self.procs:   s += proc.xml()
1846        for peri in self.periphs: s += peri.xml()
1847        s += '        </cluster>\n'
1848
1849        return s
1850
1851    #############################################
1852    def cbin( self, mapping, verbose, expected ):  # C binary structure for Cluster
1853
1854        if ( verbose ):
1855            print '*** cbin for cluster [%d,%d]' % (self.x, self.y)
1856
1857        # check index
1858        if (self.index != expected):
1859            print '[genmap error] in Cluster.cbin()'
1860            print '    cluster global index = %d / expected = %d' \
1861                       % (self.index,expected)
1862            sys.exit(1)
1863
1864        # compute global index for first pseg
1865        if ( len(self.psegs) > 0 ):
1866            pseg_id = self.psegs[0].index
1867        else:
1868            pseg_id = 0
1869
1870        # compute global index for first proc
1871        if ( len(self.procs) > 0 ):
1872            proc_id = self.procs[0].index
1873        else:
1874            proc_id = 0
1875
1876        # compute global index for first periph
1877        if ( len(self.periphs) > 0 ):
1878            periph_id = self.periphs[0].index
1879        else:
1880            periph_id = 0
1881
1882        byte_stream = bytearray()
1883        byte_stream += mapping.int2bytes(4,self.x)            # x coordinate
1884        byte_stream += mapping.int2bytes(4,self.y)            # x coordinate
1885        byte_stream += mapping.int2bytes(4,len(self.psegs))   # psegs in cluster
1886        byte_stream += mapping.int2bytes(4,pseg_id )          # global index
1887        byte_stream += mapping.int2bytes(4,len(self.procs))   # procs in cluster
1888        byte_stream += mapping.int2bytes(4,proc_id )          # global index
1889        byte_stream += mapping.int2bytes(4,len(self.periphs)) # periphs in cluster
1890        byte_stream += mapping.int2bytes(4, periph_id )       # global index
1891
1892        if ( verbose ):
1893            print 'nb_psegs   = %d' %  len( self.psegs )
1894            print 'pseg_id    = %d' %  pseg_id
1895            print 'nb_procs   = %d' %  len( self.procs )
1896            print 'proc_id    = %d' %  proc_id
1897            print 'nb_periphs = %d' %  len( self.periphs )
1898            print 'periph_id  = %d' %  periph_id
1899
1900        return byte_stream
1901
1902##################################################################################
1903class Vspace( object ):
1904##################################################################################
1905    def __init__( self,
1906                  name,
1907                  startname,
1908                  active ):
1909
1910        self.index     = 0              # global index ( set by addVspace() )
1911        self.name      = name           # vspace name
1912        self.startname = startname      # name of vseg containing the start_vector
1913        self.active    = active         # active at boot if true
1914        self.vsegs     = []
1915        self.threads   = []
1916
1917        return
1918
1919    ################
1920    def xml( self ):   # xml for one vspace
1921
1922        s =  '        <vspace name="%s" startname="%s" active="%d" >\n' \
1923                            %(self.name , self.startname , self.active)
1924        for vseg in self.vsegs: s += vseg.xml()
1925        for thread in self.threads: s += thread.xml()
1926        s += '        </vspace>\n'
1927
1928        return s
1929
1930    #############################################
1931    def cbin( self, mapping, verbose, expected ):   # C binary for Vspace
1932
1933        if ( verbose ):
1934            print '*** cbin for vspace %s' % (self.name)
1935
1936        # check index
1937        if (self.index != expected):
1938            print '[genmap error] in Vspace.cbin()'
1939            print '    vspace global index = %d / expected = %d' \
1940                        %(self.index,expected)
1941            sys.exit(1)
1942
1943        # compute global index for vseg containing start_vector
1944        vseg_start_id = 0xFFFFFFFF
1945        for vseg in self.vsegs:
1946            if ( vseg.name == self.startname ): vseg_start_id = vseg.index
1947
1948        if ( vseg_start_id == 0xFFFFFFFF ):
1949            print '[genmap error] in Vspace.cbin()'
1950            print '    startname %s not found for vspace %s' \
1951                        %(self.startname,self.name)
1952            sys.exit(1)
1953
1954        # compute first vseg and first thread global index
1955        first_vseg_id = self.vsegs[0].index
1956        first_thread_id = self.threads[0].index
1957
1958        # compute number of threads and number of vsegs
1959        nb_vsegs = len( self.vsegs )
1960        nb_threads = len( self.threads )
1961
1962        byte_stream = bytearray()
1963        byte_stream += mapping.str2bytes(32,self.name)         # vspace name
1964        byte_stream += mapping.int2bytes(4, vseg_start_id)     # vseg start_vector
1965        byte_stream += mapping.int2bytes(4, nb_vsegs)          # number of vsegs
1966        byte_stream += mapping.int2bytes(4, nb_threads)        # number of threads
1967        byte_stream += mapping.int2bytes(4, first_vseg_id)     # global index
1968        byte_stream += mapping.int2bytes(4, first_thread_id)     # global index
1969        byte_stream += mapping.int2bytes(4, self.active)       # always active if non zero
1970
1971        if ( verbose ):
1972            print 'start_id   = %d' %  vseg_start_id
1973            print 'nb_vsegs   = %d' %  nb_vsegs
1974            print 'nb_threads = %d' %  nb_threads
1975            print 'vseg_id    = %d' %  first_vseg_id
1976            print 'thread_id  = %d' %  first_thread_id
1977            print 'active     = %d' %  self.active
1978
1979        return byte_stream
1980
1981##################################################################################
1982class Thread( object ):
1983##################################################################################
1984    def __init__( self,
1985                  name,
1986                  is_main,
1987                  x,
1988                  y,
1989                  p,
1990                  stackname,
1991                  heapname,
1992                  startid ):
1993
1994        self.index     = 0             # global index value set by addThread()
1995        self.name      = name          # thread name
1996        self.is_main   = is_main       # Boolean (one main per vspace)
1997        self.x         = x             # cluster x coordinate
1998        self.y         = y             # cluster y coordinate
1999        self.p         = p             # processor local index
2000        self.stackname = stackname     # name of vseg containing the stack
2001        self.heapname  = heapname      # name of vseg containing the heap
2002        self.startid   = startid       # index in start_vector
2003        return
2004
2005    ########################################
2006    def xml( self ):    # xml for one thread
2007
2008        s =  '            <thread name="%s"' % self.name
2009        s += ' is_main="%d"'               % self.is_main
2010        s += ' x="%d"'                     % self.x
2011        s += ' y="%d"'                     % self.y
2012        s += ' p="%d"'                     % self.p
2013        s += '\n                 '
2014        s += ' stackname="%s"'             % self.stackname
2015        s += ' heapname="%s"'              % self.heapname
2016        s += ' startid="%d"'               % self.startid
2017        s += ' />\n'
2018
2019        return s
2020
2021    ############################################################################
2022    def cbin( self, mapping, verbose, expected, vspace ):  # C binary for Thread
2023
2024        if ( verbose ):
2025            print '*** cbin for thread %s in vspace %s' \
2026                     % (self.name, vspace.name)
2027
2028        # check index
2029        if (self.index != expected):
2030            print '[genmap error] in Thread.cbin()'
2031            print '    thread global index = %d / expected = %d' \
2032                        %(self.index,expected)
2033            sys.exit(1)
2034
2035        # compute cluster global index
2036        cluster_id = (self.x * mapping.y_size) + self.y
2037
2038        # compute vseg index for stack
2039        vseg_stack_id = 0xFFFFFFFF
2040        for vseg in vspace.vsegs:
2041            if ( vseg.name == self.stackname ): vseg_stack_id = vseg.index
2042
2043        if ( vseg_stack_id == 0xFFFFFFFF ):
2044            print '[genmap error] in Thread.cbin()'
2045            print '    stackname %s not found for thread %s in vspace %s' \
2046                  % ( self.stackname, self.name, vspace.name )
2047            sys.exit(1)
2048
2049        # compute vseg index for heap
2050        if ( self.heapname == '' ):
2051            vseg_heap_id = 0
2052        else:
2053            vseg_heap_id = 0xFFFFFFFF
2054            for vseg in vspace.vsegs:
2055                if ( vseg.name == self.heapname ): vseg_heap_id = vseg.index
2056
2057            if ( vseg_heap_id == 0xFFFFFFFF ):
2058                print '[genmap error] in Thread.cbin()'
2059                print '    heapname %s not found for thread %s in vspace %s' \
2060                      % ( self.heapname, self.name, vspace.name )
2061                sys.exit(1)
2062
2063        byte_stream = bytearray()
2064        byte_stream += mapping.str2bytes(32,self.name)     # thread name in vspace
2065        byte_stream += mapping.int2bytes(4, cluster_id)    # cluster global index
2066        byte_stream += mapping.int2bytes(4, self.p)        # processor local index
2067        byte_stream += mapping.int2bytes(4, self.is_main)  # main if non zero
2068        byte_stream += mapping.int2bytes(4, vseg_stack_id) # stack vseg local index
2069        byte_stream += mapping.int2bytes(4, vseg_heap_id)  # heap vseg local index
2070        byte_stream += mapping.int2bytes(4, self.startid)  # index in start vector
2071        byte_stream += mapping.int2bytes(4 ,0)             # ltid (dynamically computed)
2072
2073        if ( verbose ):
2074            print 'clusterid  = %d' %  cluster_id
2075            print 'lpid       = %d' %  self.p
2076            print 'is_main    = %d' %  self.is_main
2077            print 'stackid    = %d' %  vseg_stack_id
2078            print 'heapid     = %d' %  vseg_heap_id
2079            print 'startid    = %d' %  self.startid
2080
2081        return byte_stream
2082
2083##################################################################################
2084class Vseg( object ):
2085##################################################################################
2086    def __init__( self,
2087                  name,
2088                  vbase,
2089                  length,
2090                  mode,
2091                  vtype,
2092                  x,
2093                  y,
2094                  pseg,
2095                  identity = False,
2096                  local    = False,
2097                  big      = False,
2098                  binpath  = '' ):
2099
2100        assert (vbase & 0xFFFFFFFF) == vbase
2101
2102        assert (length & 0xFFFFFFFF) == length
2103
2104        assert mode in VSEGMODES
2105
2106        assert vtype in VSEGTYPES
2107
2108        assert (vtype != 'ELF') or (binpath != '')
2109
2110        self.index    = 0                   # global index ( set by addVseg() )
2111        self.name     = name                # vseg name (unique in vspace)
2112        self.vbase    = vbase               # virtual base address in vspace
2113        self.length   = length              # vseg length (bytes)
2114        self.vtype    = vtype               # vseg type (defined in VSEGTYPES)
2115        self.mode     = mode                # CXWU access rights
2116        self.x        = x                   # x coordinate of destination cluster
2117        self.y        = y                   # y coordinate of destination cluster
2118        self.psegname = pseg                # name of pseg in destination cluster
2119        self.identity = identity            # identity mapping required
2120        self.local    = local               # only mapped in local PTAB when true
2121        self.big      = big                 # to be mapped in a big physical page
2122        self.binpath  = binpath             # pathname for binary file (ELF or BLOB)
2123
2124        return
2125
2126    ##################################
2127    def xml( self ):  # xml for a vseg
2128
2129        s =  '            <vseg name="%s"' %(self.name)
2130        s += ' vbase="0x%x"'               %(self.vbase)
2131        s += ' length="0x%x"'              %(self.length)
2132        s += ' type="%s"'                  %(self.vtype)
2133        s += ' mode="%s"'                  %(self.mode)
2134        s += '\n                 '
2135        s += ' x="%d"'                     %(self.x)
2136        s += ' y="%d"'                     %(self.y)
2137        s += ' psegname="%s"'              %(self.psegname)
2138        if ( self.identity ):       s += ' ident="1"'
2139        if ( self.local ):          s += ' local="1"'
2140        if ( self.big ):            s += ' big="1"'
2141        if ( self.binpath != '' ):  s += ' binpath="%s"' %(self.binpath)
2142        s += ' />\n'
2143
2144        return s
2145
2146    #####################################################################
2147    def cbin( self, mapping, verbose, expected ):    # C binary for Vseg
2148
2149        if ( verbose ):
2150            print '*** cbin for vseg[%d] %s' % (self.index, self.name)
2151
2152        # check index
2153        if (self.index != expected):
2154            print '[genmap error] in Vseg.cbin()'
2155            print '    vseg global index = %d / expected = %d' \
2156                  % (self.index, expected )
2157            sys.exit(1)
2158
2159        # compute pseg_id
2160        pseg_id = 0xFFFFFFFF
2161        cluster_id = (self.x * mapping.y_size) + self.y
2162        cluster = mapping.clusters[cluster_id]
2163        for pseg in cluster.psegs:
2164            if (self.psegname == pseg.name):
2165                pseg_id = pseg.index
2166        if (pseg_id == 0xFFFFFFFF):
2167            print '[genmap error] in Vseg.cbin() : '
2168            print '    psegname %s not found for vseg %s in cluster %d' \
2169                  % ( self.psegname, self.name, cluster_id )
2170            sys.exit(1)
2171
2172        # compute numerical value for mode
2173        mode_id = 0xFFFFFFFF
2174        for x in xrange( len(VSEGMODES) ):
2175            if ( self.mode == VSEGMODES[x] ):
2176                mode_id = x
2177        if ( mode_id == 0xFFFFFFFF ):
2178            print '[genmap error] in Vseg.cbin() : '
2179            print '    undefined vseg mode %s' % self.mode
2180            sys.exit(1)
2181
2182        # compute numerical value for vtype
2183        vtype_id = 0xFFFFFFFF
2184        for x in xrange( len(VSEGTYPES) ):
2185            if ( self.vtype == VSEGTYPES[x] ):
2186                vtype_id = x
2187        if ( vtype_id == 0xFFFFFFFF ):
2188            print '[genmap error] in Vseg.cbin()'
2189            print '    undefined vseg type %s' % self.vtype
2190            sys.exit(1)
2191
2192        byte_stream = bytearray()
2193        byte_stream += mapping.str2bytes(32,self.name )     # vseg name
2194        byte_stream += mapping.str2bytes(64,self.binpath )  # binpath
2195        byte_stream += mapping.int2bytes(4, self.vbase )    # virtual base address
2196        byte_stream += mapping.int2bytes(8, 0 )             # physical base address
2197        byte_stream += mapping.int2bytes(4, self.length )   # vseg size (bytes)
2198        byte_stream += mapping.int2bytes(4, pseg_id )       # pseg global index
2199        byte_stream += mapping.int2bytes(4, mode_id )       # CXWU flags
2200        byte_stream += mapping.int2bytes(4, vtype_id )      # vseg type
2201        byte_stream += mapping.int2bytes(1, 0 )             # mapped when non zero
2202        byte_stream += mapping.int2bytes(1, self.identity ) # identity mapping
2203        byte_stream += mapping.int2bytes(1, self.local )    # only in local PTAB
2204        byte_stream += mapping.int2bytes(1,  self.big )     # to be mapped in BPP
2205
2206        if ( verbose ):
2207            print 'binpath    = %s' %  self.binpath
2208            print 'vbase      = %x' %  self.vbase
2209            print 'pbase      = 0'
2210            print 'length     = %x' %  self.length
2211            print 'pseg_id    = %d' %  pseg_id
2212            print 'mode       = %d' %  mode_id
2213            print 'type       = %d' %  vtype_id
2214            print 'mapped     = 0'
2215            print 'ident      = %d' %  self.identity
2216            print 'local      = %d' %  self.local
2217            print 'big        = %d' %  self.big
2218
2219        return byte_stream
2220
2221##################################################################################
2222class Processor ( object ):
2223##################################################################################
2224    def __init__( self,
2225                  x,
2226                  y,
2227                  lpid ):
2228
2229        self.index    = 0      # global index ( set by addProc() )
2230        self.x        = x      # x cluster coordinate
2231        self.y        = y      # y cluster coordinate
2232        self.lpid     = lpid   # processor local index
2233
2234        return
2235
2236    ########################################
2237    def xml( self ):   # xml for a processor
2238        return '            <proc index="%d" />\n' % (self.lpid)
2239
2240    ####################################################################
2241    def cbin( self, mapping, verbose, expected ):    # C binary for Proc
2242
2243        if ( verbose ):
2244            print '*** cbin for proc %d in cluster (%d,%d)' \
2245                  % (self.lpid, self.x, self.y)
2246
2247        # check index
2248        if (self.index != expected):
2249            print '[genmap error] in Proc.cbin()'
2250            print '    proc global index = %d / expected = %d' \
2251                       % (self.index,expected)
2252            sys.exit(1)
2253
2254        byte_stream = bytearray()
2255        byte_stream += mapping.int2bytes( 4 , self.lpid )       # local index
2256
2257        return byte_stream
2258
2259##################################################################################
2260class Pseg ( object ):
2261##################################################################################
2262    def __init__( self,
2263                  name,
2264                  base,
2265                  size,
2266                  x,
2267                  y,
2268                  segtype ):
2269
2270        assert( segtype in PSEGTYPES )
2271
2272        self.index    = 0       # global index ( set by addPseg() )
2273        self.name     = name    # pseg name (unique in cluster)
2274        self.base     = base    # physical base address
2275        self.size     = size    # segment size (bytes)
2276        self.x        = x       # cluster x coordinate
2277        self.y        = y       # cluster y coordinate
2278        self.segtype  = segtype # RAM / PERI (defined in mapping_info.h)
2279
2280        return
2281
2282    ###################################
2283    def xml( self ):   # xml for a pseg
2284
2285        s = '            <pseg name="%s" type="%s" base="0x%x" length="0x%x" />\n' \
2286                         % (self.name, self.segtype, self.base, self.size)
2287        return s
2288
2289    ###########################################################################
2290    def cbin( self, mapping, verbose, expected, cluster ):  # C binary for Pseg
2291
2292        if ( verbose ):
2293            print '*** cbin for pseg[%d] %s in cluster[%d,%d]' \
2294                  % (self.index, self.name, cluster.x, cluster.y)
2295
2296        # check index
2297        if (self.index != expected):
2298            print '[genmap error] in Pseg.cbin()'
2299            print '    pseg global index = %d / expected = %d' \
2300                       % (self.index,expected)
2301            sys.exit(1)
2302
2303        # compute numerical value for segtype
2304        segtype_int = 0xFFFFFFFF
2305        for x in xrange( len(PSEGTYPES) ):
2306            if ( self.segtype == PSEGTYPES[x] ): segtype_int = x
2307
2308        if ( segtype_int == 0xFFFFFFFF ):
2309            print '[genmap error] in Pseg.cbin()'
2310            print '    undefined segment type %s' % self.segtype
2311            sys.exit(1)
2312
2313        byte_stream = bytearray()
2314        byte_stream += mapping.str2bytes(32,self.name)     # pseg name
2315        byte_stream += mapping.int2bytes(8 ,self.base)     # physical base address
2316        byte_stream += mapping.int2bytes(8 ,self.size)     # segment length
2317        byte_stream += mapping.int2bytes(4 ,segtype_int)   # segment type
2318        byte_stream += mapping.int2bytes(4 ,cluster.index) # cluster global index
2319        byte_stream += mapping.int2bytes(4 ,0)             # linked list of vsegs
2320
2321        if ( verbose ):
2322            print 'pbase      = %x' %  self.base
2323            print 'size       = %x' %  self.size
2324            print 'type       = %s' %  self.segtype
2325
2326        return byte_stream
2327
2328##################################################################################
2329class Periph ( object ):
2330##################################################################################
2331    def __init__( self,
2332                  pseg,               # associated pseg
2333                  ptype,              # peripheral type
2334                  subtype  = 'NONE',  # peripheral subtype
2335                  channels = 1,       # for multi-channels peripherals
2336                  arg0     = 0,       # optional (semantic depends on ptype)
2337                  arg1     = 0,       # optional (semantic depends on ptype)
2338                  arg2     = 0,       # optional (semantic depends on ptype)
2339                  arg3     = 0 ):     # optional (semantic depends on ptype)
2340
2341        self.index    = 0            # global index ( set by addPeriph() )
2342        self.channels = channels
2343        self.ptype    = ptype
2344        self.subtype  = subtype
2345        self.arg0     = arg0
2346        self.arg1     = arg1
2347        self.arg2     = arg2
2348        self.arg3     = arg3
2349        self.pseg     = pseg
2350        self.irqs     = []
2351        self.irq_ctrl = None         # interrupt controller peripheral
2352        return
2353
2354    ######################################
2355    def xml( self ):    # xml for a periph
2356
2357        s =  '            <periph type="%s"' % self.ptype
2358        s += ' subtype="%s"'                 % self.subtype
2359        s += ' psegname="%s"'                % self.pseg.name
2360        s += ' channels="%d"'                % self.channels
2361        s += ' arg0="%d"'                    % self.arg0
2362        s += ' arg1="%d"'                    % self.arg1
2363        s += ' arg2="%d"'                    % self.arg2
2364        s += ' arg3="%d"'                    % self.arg3
2365        if ( (self.ptype == 'PIC') or (self.ptype == 'XCU') ):
2366            s += ' >\n'
2367            for irq in self.irqs: s += irq.xml()
2368            s += '            </periph>\n'
2369        else:
2370            s += ' />\n'
2371        return s
2372
2373    ######################################################################
2374    def cbin( self, mapping, verbose, expected ):    # C binary for Periph
2375
2376        if ( verbose ):
2377            print '*** cbin for periph %s in cluster [%d,%d]' \
2378                  % (self.ptype, self.pseg.x, self.pseg.y)
2379
2380        # check index
2381        if (self.index != expected):
2382            print '[genmap error] in Periph.cbin()'
2383            print '    periph global index = %d / expected = %d' \
2384                       % (self.index,expected)
2385            sys.exit(1)
2386
2387        # compute pseg global index
2388        pseg_id = self.pseg.index
2389
2390        # compute first irq global index
2391        if ( len(self.irqs) > 0 ):
2392            irq_id = self.irqs[0].index
2393        else:
2394            irq_id = 0
2395
2396        # compute numerical value for ptype
2397        ptype_id = 0xFFFFFFFF
2398        for x in xrange( len(PERIPHTYPES) ):
2399            if ( self.ptype == PERIPHTYPES[x] ):  ptype_id = x
2400
2401        if ( ptype_id == 0xFFFFFFFF ):
2402            print '[genmap error] in Periph.cbin()'
2403            print '    undefined peripheral type %s' % self.ptype
2404            sys.exit(1)
2405
2406        # compute numerical value for subtype
2407        subtype_id = 0xFFFFFFFF
2408        if (self.ptype == 'IOC'):
2409            for x in xrange( len(IOCSUBTYPES) ):
2410                if ( self.subtype == IOCSUBTYPES[x] ):  subtype_id = x
2411        if (self.ptype == 'MWR'):
2412            for x in xrange( len(MWRSUBTYPES) ):
2413                if ( self.subtype == MWRSUBTYPES[x] ):  subtype_id = x
2414       
2415        byte_stream = bytearray()
2416        byte_stream += mapping.int2bytes(4,ptype_id)       # peripheral type
2417        byte_stream += mapping.int2bytes(4,subtype_id)     # peripheral subtype
2418        byte_stream += mapping.int2bytes(4,pseg_id)        # pseg global index
2419        byte_stream += mapping.int2bytes(4,self.channels)  # number of channels
2420        byte_stream += mapping.int2bytes(4,self.arg0)      # optionnal arg0
2421        byte_stream += mapping.int2bytes(4,self.arg1)      # optionnal arg1
2422        byte_stream += mapping.int2bytes(4,self.arg2)      # optionnal arg2
2423        byte_stream += mapping.int2bytes(4,self.arg3)      # optionnal arg3
2424        byte_stream += mapping.int2bytes(4,len(self.irqs)) # number of input irqs
2425        byte_stream += mapping.int2bytes( 4 , irq_id )     # global index
2426
2427        if ( verbose ):
2428            print 'ptype      = %d' %  ptype_id
2429            print 'subtype    = %d' %  subtype_id
2430            print 'pseg_id    = %d' %  pseg_id
2431            print 'nb_irqs    = %d' %  len( self.irqs )
2432            print 'irq_id     = %d' %  irq_id
2433        return byte_stream
2434
2435##################################################################################
2436class Irq ( object ):
2437##################################################################################
2438    def __init__( self,
2439                  irqtype,         # input IRQ type : HWI / WTI / PTI (for XCU only)
2440                  srcid,           # input IRQ index (for XCU or PIC)
2441                  isrtype,         # Type of ISR to be executed
2442                  channel = 0 ):   # channel index for multi-channel ISR
2443
2444        assert irqtype in IRQTYPES
2445        assert isrtype in ISRTYPES
2446        assert srcid < 32
2447
2448        self.index   = 0        # global index ( set by addIrq() )
2449        self.irqtype = irqtype  # IRQ type
2450        self.srcid   = srcid    # source IRQ index
2451        self.isrtype = isrtype  # ISR type
2452        self.channel = channel  # channel index (for multi-channels ISR)
2453        return
2454
2455    ################################
2456    def xml( self ):   # xml for Irq
2457
2458        s = '                <irq srctype="%s" srcid="%d" isr="%s" channel="%d" />\n' \
2459                % ( self.irqtype, self.srcid, self.isrtype, self.channel )
2460        return s
2461
2462    ####################################################################
2463    def cbin( self, mapping, verbose, expected ):     # C binary for Irq
2464
2465        if ( verbose ):
2466            print '*** cbin for irq[%d]' % (self.index)
2467
2468        # check index
2469        if (self.index != expected):
2470            print '[genmap error] in Irq.cbin()'
2471            print '    irq global index = %d / expected = %d' \
2472                       % (self.index,expected)
2473            sys.exit(1)
2474
2475        # compute numerical value for irqtype
2476        irqtype_id = 0xFFFFFFFF
2477        for x in xrange( len(IRQTYPES) ):
2478            if ( self.irqtype == IRQTYPES[x] ): irqtype_id = x
2479
2480        if ( irqtype_id == 0xFFFFFFFF ):
2481            print '[genmap error] in Irq.cbin()'
2482            print '    undefined irqtype %s' % self.irqtype
2483            sys.exit(1)
2484
2485        # compute numerical value for isrtype
2486        isrtype_id = 0xFFFFFFFF
2487        for x in xrange( len(ISRTYPES) ):
2488            if ( self.isrtype == ISRTYPES[x] ): isrtype_id = x
2489
2490        if ( isrtype_id == 0xFFFFFFFF ):
2491            print '[genmap error] in Irq.cbin()' 
2492            print '    undefined isrtype %s' % self.isrtype
2493            sys.exit(1)
2494
2495        byte_stream = bytearray()
2496        byte_stream += mapping.int2bytes( 4,  irqtype_id )
2497        byte_stream += mapping.int2bytes( 4,  self.srcid )
2498        byte_stream += mapping.int2bytes( 4,  isrtype_id )
2499        byte_stream += mapping.int2bytes( 4,  self.channel )
2500        byte_stream += mapping.int2bytes( 4,  0 )
2501        byte_stream += mapping.int2bytes( 4,  0 )
2502
2503        if ( verbose ):
2504            print 'irqtype    = %s' %  self.irqtype
2505            print 'srcid      = %d' %  self.srcid
2506            print 'isrtype    = %s' %  self.isrtype
2507            print 'channel    = %d' %  self.channel
2508
2509        return byte_stream
2510
2511# Local Variables:
2512# tab-width: 4;
2513# c-basic-offset: 4;
2514# c-file-offsets:((innamespace . 0)(inline-open . 0));
2515# indent-tabs-mode: nil;
2516# End:
2517#
2518# vim: filetype=python:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
2519
Note: See TracBrowser for help on using the repository browser.