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

Last change on this file since 465 was 465, checked in by cfuguet, 10 years ago

mapping.py: avoid erroneous warnings concerning XCUs on linux_dts
generation

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