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

Last change on this file since 491 was 491, checked in by cfuguet, 9 years ago

genmap: add distributed ROM support

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