source: trunk/tools/arch_info/arch_classes.py @ 577

Last change on this file since 577 was 571, checked in by alain, 5 years ago

Introduce the soclib_mty driver for the TSAR-LETI architecture.

File size: 37.0 KB
Line 
1#!/usr/bin/env python
2
3import sys
4
5##########################################################################################
6#  File   : arch_classes.py
7#  Date   : 2016
8#  Author : Alain Greiner
9#  Copyright (c)  UPMC Sorbonne Universites
10#########################################################################################
11#  This file contains the python classes required to define a generic hardware
12#  architecture for the ALMOS-MK operating system.
13#  It handle 4 types of objects: clusters, cores, devices and irqs.
14#  - The number of cluster is variable (can be one).
15#  - The cluster topology can be a 2D mesh or a simple 1D array.
16#  - The number of cores per cluster is variable (can be zero).
17#  - The number of addressable devices per cluster is variable.
18#  - The size of the physical memory bank per cluster is variable.
19#  An adressable device can be a physical memory bank or a peripheral.
20#  Each cluster cover a fixed size segment in physical address space,
21# that is defined by (PADDR_WIDTH - X_WIDTH - Y_WIDTH)
22#########################################################################################
23# Implementation Note:
24# The objects used to describe an architecture are distributed in the python structure:
25# For example the set of cores and the set of devices are split in several subsets
26# (one subset of cores and one subset of devices per cluster).
27# In the generated C binary data structure, all objects of same type
28# are stored in a linear array (one single array for all cores for example).
29# For all objects, we compute and store in the python object  a "global index"
30# corresponding to the index in this global array, and this index can be used as
31# a pseudo-pointer to identify a specific object of a given type.
32#########################################################################################
33
34#########################################################################################
35#  Define global parameters
36#########################################################################################
37
38ARCHINFO_SIGNATURE = 0xBABE2016    # magic number indicating a valid C BLOB
39PAGE_SIZE          = 0x1000        # to check peripherals alignment
40
41#########################################################################################
42# These arrays define the supported types of peripherals.
43# They must be kept consistent with values defined in file arch_info.h
44#########################################################################################
45
46DEVICE_TYPES_STR = [
47    'RAM_SCL',         # 0.0
48    'ROM_SCL',         # 1.0
49    'FBF_SCL',         # 2.0
50    'IOB_TSR',         # 3.0
51    'IOC_BDV',         # 4.0
52    'IOC_HBA',         # 4.1
53    'IOC_SDC',         # 4.2
54    'IOC_SPI',         # 4.3
55    'IOC_RDK',         # 4.4
56    'MMC_TSR',         # 5.0
57    'DMA_SCL',         # 6.0
58    'NIC_CBF',         # 7.0
59    'TIM_SCL',         # 8.0
60    'TXT_TTY',         # 9.0
61    'TXT_MTY',         # 9.1
62    'ICU_XCU',         # A.0
63    'PIC_TSR',         # B.0
64    ]
65   
66DEVICE_TYPES_INT = [
67    0x00000000,        # 0.0
68    0x00010000,        # 1.0
69    0x00020000,        # 1.0
70    0x00030000,        # 3.0
71    0x00040000,        # 4.0
72    0x00040001,        # 4.1
73    0x00040002,        # 4.2
74    0x00040003,        # 4.3
75    0x00040004,        # 4.4
76    0x00050000,        # 5.0
77    0x00060000,        # 6.0
78    0x00070000,        # 7.0
79    0x00080000,        # 8.0
80    0x00090000,        # 9.0
81    0x00090001,        # 9.1
82    0x000A0000,        # A.0
83    0x000B0000,        # B.0
84    ]
85
86 #########################################################################################
87class Archinfo( object ):         
88#########################################################################################
89    def __init__( self,
90                  name,              # architecture instance name
91                  x_size,            # number of clusters in a row
92                  y_size,            # number of clusters in a column
93                  cores_max,         # max number of cores per cluster
94                  devices_max,       # max number of devices per cluster
95                  paddr_width,       # number of bits in physical address
96                  x_width,           # number of bits for x coordinate
97                  y_width,           # number of bits for y coordinate
98                  irqs_per_core,     # number or IRQs from ICU to one core
99                  io_cxy,            # IO cluster identifier
100                  boot_cxy,          # boot cluster identifier
101                  cache_line,        # number of bytes in cache line
102                  reset_address,     # Preloader physical base address
103                  p_width ):         # TSAR specific : number of bits to code core lid
104
105        assert ( x_size <= (1<<x_width) )
106        assert ( y_size <= (1<<y_width) )
107
108        self.signature      = ARCHINFO_SIGNATURE
109        self.name           = name
110        self.x_size         = x_size
111        self.y_size         = y_size
112        self.cores_max      = cores_max
113        self.devices_max    = devices_max
114        self.paddr_width    = paddr_width
115        self.x_width        = x_width
116        self.y_width        = y_width
117        self.irqs_per_core  = irqs_per_core
118        self.io_cxy         = io_cxy
119        self.boot_cxy       = boot_cxy
120        self.cache_line     = cache_line
121        self.reset_address  = reset_address
122        self.p_width        = p_width
123
124        self.total_cores    = 0
125        self.total_devices  = 0
126        self.total_irqs     = 0
127
128        self.clusters       = []
129
130        for x in xrange( self.x_size ):
131            for y in xrange( self.y_size ):
132
133                # call cluster constructor
134                cxy = (x<<y_width) + y
135                cluster = Cluster( cxy )
136
137                # update cluster global index
138                cluster.index = (x * self.y_size) + y
139
140                # register cluster in Archinfo
141                self.clusters.append( cluster )
142
143        return
144
145    ##########################   add a device in a cluster
146    def addDevice( self,
147                   ptype,              # device type
148                   base,               # associated pseg base address
149                   size,               # associated pseg length (bytes)
150                   channels = 1,       # number of channels
151                   arg0     = 0,       # optional argument (semantic depends on ptype)
152                   arg1     = 0,       # optional argument (semantic depends on ptype)
153                   arg2     = 0,       # optional argument (semantic depends on ptype)
154                   arg3     = 0 ):     # optional argument (semantic depends on ptype)
155
156        # computes cluster identifier and global index from the base address
157        cxy = base >> (self.paddr_width - self.x_width - self.y_width)
158        x          = cxy >> (self.y_width);
159        y          = cxy & ((1 << self.y_width) - 1)
160        cluster_id = (x * self.y_size) + y
161
162        assert (x < self.x_size) and (y < self.y_size)
163        assert (base & (PAGE_SIZE-1) == 0)
164        assert (ptype in DEVICE_TYPES_STR)
165
166        # call device constructor
167        device = Device( base, size, ptype, channels, arg0, arg1, arg2, arg3 )
168
169        # register device in cluster
170        self.clusters[cluster_id].devices.append( device )
171
172        # update device global index
173        device.index = self.total_devices
174        self.total_devices += 1
175
176        return device
177
178    ################################   add an input IRQ in a device
179    def addIrq( self,
180                dstdev,                # destination device (PIC or ICU)
181                port,                  # input IRQ port index
182                srcdev,                # source device
183                channel = 0,           # source device channel
184                is_rx = False ):       # I/O operation direction
185
186        assert (dstdev.ptype == 'ICU_XCU') or (dstdev.ptype == 'PIC_TSR')
187        assert (port < dstdev.arg0)
188
189        # call Irq constructor
190        irq = Irq( port , srcdev, channel , is_rx )
191
192        # register IRQ in destination device
193        dstdev.irqs.append( irq )
194
195        # update IRQ global index
196        irq.index = self.total_irqs
197        self.total_irqs += 1
198
199        # pointer from the source to the interrupt controller device
200        if (srcdev.irq_ctrl == None): srcdev.irq_ctrl = dstdev
201
202        if (srcdev.irq_ctrl != dstdev):
203            print '[genarch error] in addIrq():'
204            print '    two different interrupt controller for the same device'
205            sys.exit(1)
206
207        return irq
208
209    ##########################    add a core in a cluster
210    def addCore( self,
211                 gid,                  # global hardware identifier
212                 cxy,                  # cluster identifier
213                 lid ):                # local index in cluster
214
215        assert ((cxy >> self.y_width) < self.x_size)
216        assert ((cxy & ((1<<self.y_width)-1)) < self.y_size)
217        assert (lid < self.cores_max)
218 
219        # call Core contructor
220        core = Core( gid, cxy, lid )
221
222        # compute cluster global index from cluster identifier
223        x          = cxy>>self.y_width
224        y          = cxy & ((1<<self.y_width)-1)
225        cluster_id = (x * self.y_size) + y
226
227        # register core in cluster
228        self.clusters[cluster_id].cores.append( core )
229
230        # update core global index
231        core.index = self.total_cores
232        self.total_cores += 1
233
234        return core
235
236    #################################
237    def str2bytes( self, nbytes, s ):    # string => nbytes_packed byte array
238
239        byte_stream = bytearray()
240        length = len( s )
241        if length < (nbytes - 1):
242            for b in s:
243                byte_stream.append( b )
244            for x in xrange(nbytes-length):
245                byte_stream.append( '\0' )
246        else:
247            print '[genarch error] in str2bytes()'
248            print '    string %s too long' % s
249            sys.exit(1)
250
251        return byte_stream
252
253    ###################################
254    def int2bytes( self, nbytes, val ):    # integer => nbytes litle endian byte array
255
256        byte_stream = bytearray()
257        for n in xrange( nbytes ):
258            byte_stream.append( (val >> (n<<3)) & 0xFF )
259
260        return byte_stream
261
262    ################
263    def xml( self ):    # compute string for xml file generation
264
265        s = '<?xml version="1.0"?>\n\n'
266        s += '<arch_info signature    = "0x%x"\n' % (self.signature)
267        s += '           name         = "%s"\n'   % (self.name)
268        s += '           x_size       = "%d"\n'   % (self.x_size)
269        s += '           y_size       = "%d"\n'   % (self.y_size)
270        s += '           cores        = "%d"\n'   % (self.cores_max)
271        s += '           io_cxy       = "%d" >\n' % (self.io_cxy)
272        s += '\n'
273
274        s += '    <clusterset>\n'
275        for x in xrange ( self.x_size ):
276            for y in xrange ( self.y_size ):
277                cluster_id = (x * self.y_size) + y
278                s += self.clusters[cluster_id].xml()
279        s += '    </clusterset>\n'
280        s += '\n'
281
282        s += '</arch_info>\n'
283        return s
284
285    ##########################
286    def cbin( self, verbose ):     # C binary structure for "archinfo.bin" file generation
287
288        byte_stream = bytearray()
289
290        # header
291        byte_stream += self.int2bytes(4,  self.signature)
292        byte_stream += self.int2bytes(4,  self.x_size)
293        byte_stream += self.int2bytes(4,  self.y_size)
294        byte_stream += self.int2bytes(4,  self.paddr_width)
295        byte_stream += self.int2bytes(4,  self.x_width)
296        byte_stream += self.int2bytes(4,  self.y_width)
297        byte_stream += self.int2bytes(4,  self.cores_max)
298        byte_stream += self.int2bytes(4,  self.devices_max)
299
300        byte_stream += self.int2bytes(4,  self.total_cores)
301        byte_stream += self.int2bytes(4,  self.total_devices)
302        byte_stream += self.int2bytes(4,  self.total_irqs)
303        byte_stream += self.int2bytes(4,  self.io_cxy)
304        byte_stream += self.int2bytes(4,  self.boot_cxy)
305        byte_stream += self.int2bytes(4,  self.irqs_per_core)
306        byte_stream += self.int2bytes(4,  self.cache_line)
307        byte_stream += self.int2bytes(4,  0)
308
309        byte_stream += self.str2bytes(64, self.name)
310
311        if ( verbose ):
312            print '\n'
313            print 'name          = %s' % self.name
314            print 'signature     = %x' % self.signature
315            print 'x_size        = %d' % self.x_size
316            print 'y_size        = %d' % self.y_size
317            print 'total_cores   = %d' % self.total_cores
318            print 'total_devices = %d' % self.total_devices
319            print 'total_irqs    = %d' % self.total_irqs
320            print '\n'
321
322        # cores array
323        index = 0
324        for cluster in self.clusters:
325            for core in cluster.cores:
326                byte_stream += core.cbin( self, verbose, index )
327                index += 1
328
329        if ( verbose ): print '\n'
330
331        # clusters array
332        index = 0
333        for cluster in self.clusters:
334            byte_stream += cluster.cbin( self, verbose, index )
335            index += 1
336
337        if ( verbose ): print '\n'
338
339        # devices array
340        index = 0
341        for cluster in self.clusters:
342            for device in cluster.devices:
343                byte_stream += device.cbin( self, verbose, index )
344                index += 1
345
346        if ( verbose ): print '\n'
347
348        # irqs array
349        index = 0
350        for cluster in self.clusters:
351            for device in cluster.devices:
352                for irq in device.irqs:
353                    byte_stream += irq.cbin( self, verbose, index )
354                    index += 1
355
356        if ( verbose ): print '\n'
357
358        return byte_stream
359    # end of cbin()
360
361
362    ######################################################################
363    def hard_config( self ):     # compute string for hard_config.h file
364                                 # required by
365                                 # - top.cpp compilation
366                                 # - almos-mk bootloader compilation
367                                 # - tsar_preloader compilation
368
369        # for each device type, define default values
370        # for pbase address, size, number of components, and channels
371        nb_ram       = 0
372        ram_channels = 0
373        ram_base     = 0xFFFFFFFFFFFFFFFF
374        ram_size     = 0
375
376        nb_rom       = 0
377        rom_channels = 0
378        rom_base     = 0xFFFFFFFFFFFFFFFF
379        rom_size     = 0
380
381        nb_fbf       = 0
382        fbf_channels = 0
383        fbf_base     = 0xFFFFFFFFFFFFFFFF
384        fbf_size     = 0
385        fbf_arg0     = 0
386        fbf_arg1     = 0
387
388        nb_iob       = 0
389        iob_channels = 0
390        iob_base     = 0xFFFFFFFFFFFFFFFF
391        iob_size     = 0
392
393        nb_ioc       = 0
394        ioc_channels = 0
395        ioc_base     = 0xFFFFFFFFFFFFFFFF
396        ioc_size     = 0
397        use_ioc_bdv  = False
398        use_ioc_sdc  = False
399        use_ioc_hba  = False
400        use_ioc_spi  = False
401        use_ioc_rdk  = False
402
403        nb_mmc       = 0
404        mmc_channels = 0
405        mmc_base     = 0xFFFFFFFFFFFFFFFF
406        mmc_size     = 0
407
408        nb_dma       = 0
409        dma_channels = 0
410        dma_base     = 0xFFFFFFFFFFFFFFFF
411        dma_size     = 0
412
413        nb_nic       = 0
414        nic_channels = 0
415        nic_base     = 0xFFFFFFFFFFFFFFFF
416        nic_size     = 0
417
418        nb_sim       = 0
419        sim_channels = 0
420        sim_base     = 0xFFFFFFFFFFFFFFFF
421        sim_size     = 0
422
423        nb_tim       = 0
424        tim_channels = 0
425        tim_base     = 0xFFFFFFFFFFFFFFFF
426        tim_size     = 0
427
428        nb_txt       = 0
429        txt_channels = 0
430        txt_base     = 0xFFFFFFFFFFFFFFFF
431        txt_size     = 0
432
433        nb_icu       = 0
434        icu_channels = 0
435        icu_base     = 0xFFFFFFFFFFFFFFFF
436        icu_size     = 0
437        icu_arg0     = 0
438
439        nb_pic       = 0
440        pic_channels = 0
441        pic_base     = 0xFFFFFFFFFFFFFFFF
442        pic_size     = 0
443
444        nb_rom        = 0
445        rom_channels  = 0
446        rom_base      = 0xFFFFFFFFFFFFFFFF
447        rom_size      = 0
448
449        # get devices attributes
450        for cluster in self.clusters:
451            for device in cluster.devices:
452
453                if ( device.ptype == 'RAM_SCL' ):
454                    ram_base     = device.base
455                    ram_size     = device.size
456                    ram_channels = device.channels
457                    nb_ram +=1
458               
459                elif ( device.ptype == 'ROM_SCL' ):
460                    rom_base     = device.base
461                    rom_size     = device.size
462                    rom_channels = device.channels
463                    nb_rom +=1
464
465                elif ( device.ptype == 'FBF_SCL' ):
466                    fbf_base     = device.base
467                    fbf_size     = device.size
468                    fbf_channels = device.channels
469                    fbf_arg0     = device.arg0
470                    fbf_arg1     = device.arg1
471                    nb_fbf +=1
472
473                elif ( device.ptype == 'IOB_TSR' ):
474                    iob_base     = device.base
475                    iob_size     = device.size
476                    iob_channels = device.channels
477                    nb_iob +=1
478
479                elif ( device.ptype == 'IOC_BDV' ):
480                    ioc_base     = device.base
481                    ioc_size     = device.size
482                    ioc_channels = device.channels
483                    use_ioc_bdv  = True
484                    nb_ioc += 1
485                elif ( device.ptype == 'IOC_HBA' ):
486                    ioc_base     = device.base
487                    ioc_size     = device.size
488                    ioc_channels = device.channels
489                    use_ioc_hba  = True
490                    nb_ioc += 1
491                elif ( device.ptype == 'IOC_SDC' ):
492                    ioc_base     = device.base
493                    ioc_size     = device.size
494                    ioc_channels = device.channels
495                    use_ioc_sdc  = True
496                    nb_ioc += 1
497                elif ( device.ptype == 'IOC_SPI' ):
498                    ioc_base     = device.base
499                    ioc_size     = device.size
500                    ioc_channels = device.channels
501                    use_ioc_spi  = True
502                    nb_ioc += 1
503                elif ( device.ptype == 'IOC_RDK' ):
504                    ioc_base     = device.base
505                    ioc_size     = device.size
506                    ioc_channels = device.channels
507                    use_ioc_rdk  = True
508                    nb_ioc += 1
509
510                elif ( device.ptype == 'MMC_TSR' ):
511                    mmc_base     = device.base
512                    mmc_size     = device.size
513                    mmc_channels = device.channels
514                    nb_mmc +=1
515
516                elif ( device.ptype == 'DMA_SCL' ):
517                    dma_base     = device.base
518                    dma_size     = device.size
519                    dma_channels = device.channels
520                    nb_dma +=1
521
522                elif ( device.ptype == 'NIC_CBF' ):
523                    nic_base     = device.base
524                    nic_size     = device.size
525                    nic_channels = device.channels
526                    nb_nic +=1
527
528                elif ( device.ptype == 'TIM_SCL' ):
529                    tim_base     = device.pseg.base
530                    tim_size     = device.pseg.size
531                    tim_channels = device.channels
532                    nb_tim +=1
533
534                elif ( device.ptype == 'TXT_TTY' ):
535                    txt_base     = device.base
536                    txt_size     = device.size
537                    txt_channels = device.channels
538                    nb_txt +=1
539
540                elif ( device.ptype == 'ICU_XCU' ):
541                    icu_base     = device.base
542                    icu_size     = device.size
543                    icu_channels = device.channels
544                    icu_arg0     = device.arg0
545                    icu_arg1     = device.arg1
546                    icu_arg2     = device.arg2
547                    icu_arg3     = device.arg3
548                    nb_icu +=1
549
550                elif ( device.ptype == 'PIC_TSR' ):
551                    pic_base     = device.base
552                    pic_size     = device.size
553                    pic_channels = device.channels
554                    nb_pic +=1
555
556        # one and only one IOC controller
557        assert ( nb_ioc == 1 )
558
559        # compute rdk_base and rdk_size
560        if( use_ioc_rdk ):
561            rdk_base = ioc_base
562            rdk_size = ioc_size
563        else:
564            rdk_base = 0
565            rdk_size = 0
566
567        # Compute total number of cores, devices and irqs
568        nb_total_cores   = self.total_cores
569        nb_total_devices = self.total_devices
570        nb_total_irqs    = self.total_irqs
571
572        # boot core has (cxy == boot_cxy) and (lid == 0)
573        for cluster in self.clusters:
574            if( cluster.cxy == self.boot_cxy ): boot_core_gid = cluster.cores[0].gid
575
576        # compute mask to get local physical address (cluster independant)
577        local_paddr_width   = self.paddr_width - self.x_width - self.y_width
578        local_physical_mask = (1<<local_paddr_width)-1
579
580        # build string
581        s =  '/* Generated by genarch for %s */\n'  % self.name
582        s += '\n'
583        s += '#ifndef HARD_CONFIG_H\n'
584        s += '#define HARD_CONFIG_H\n'
585        s += '\n'
586
587        s += '/* General platform parameters */\n'
588        s += '\n'
589        s += '#define X_SIZE                 %d\n'    % self.x_size
590        s += '#define Y_SIZE                 %d\n'    % self.y_size
591        s += '#define PADDR_WIDTH            %d\n'    % self.paddr_width
592        s += '#define X_WIDTH                %d\n'    % self.x_width
593        s += '#define Y_WIDTH                %d\n'    % self.y_width
594        s += '#define P_WIDTH                %d\n'    % self.p_width 
595        s += '#define X_IO                   %d\n'    % (self.io_cxy >> self.y_width)
596        s += '#define Y_IO                   %d\n'    % (self.io_cxy & ((1<<self.y_width)-1))
597        s += '#define NB_PROCS_MAX           %d\n'    % self.cores_max
598        s += '#define NB_DEVICES_MAX         %d\n'    % self.devices_max
599        s += '#define IRQ_PER_PROCESSOR      %d\n'    % self.irqs_per_core
600        s += '#define RESET_ADDRESS          0x%x\n'  % self.reset_address
601        s += '#define NB_TOTAL_PROCS         %d\n'    % nb_total_cores
602        s += '#define BOOT_CORE_GID          %d\n'    % boot_core_gid
603        s += '#define BOOT_CORE_CXY          %d\n'    % self.boot_cxy
604        s += '#define CACHE_LINE_SIZE        %d\n'    % self.cache_line
605        s += '\n'
606
607        s += '/* Peripherals */\n'
608        s += '\n'
609        s += '#define NB_TXT_CHANNELS        %d\n'    % txt_channels
610        s += '#define NB_IOC_CHANNELS        %d\n'    % ioc_channels
611        s += '#define NB_NIC_CHANNELS        %d\n'    % nic_channels
612        s += '#define NB_TIM_CHANNELS        %d\n'    % tim_channels
613        s += '\n'
614        s += '#define USE_ICU                %d\n'    % ( nb_icu != 0 )
615        s += '#define USE_IOB                %d\n'    % ( nb_iob != 0 )
616        s += '#define USE_PIC                %d\n'    % ( nb_pic != 0 )
617        s += '#define USE_FBF                %d\n'    % ( nb_fbf != 0 )
618        s += '#define USE_NIC                %d\n'    % ( nb_nic != 0 )
619        s += '#define USE_DMA                %d\n'    % ( nb_dma != 0 )
620        s += '\n'
621        s += '#define USE_IOC_BDV            %d\n'    % use_ioc_bdv
622        s += '#define USE_IOC_SDC            %d\n'    % use_ioc_sdc
623        s += '#define USE_IOC_HBA            %d\n'    % use_ioc_hba
624        s += '#define USE_IOC_SPI            %d\n'    % use_ioc_spi
625        s += '#define USE_IOC_RDK            %d\n'    % use_ioc_rdk
626        s += '\n'
627        s += '#define FBUF_X_SIZE            %d\n'    % fbf_arg0
628        s += '#define FBUF_Y_SIZE            %d\n'    % fbf_arg1
629        s += '\n'
630        s += '#define ICU_NB_HWI             %d\n'    % icu_arg0
631        s += '#define ICU_NB_PTI             %d\n'    % icu_arg1
632        s += '#define ICU_NB_WTI             %d\n'    % icu_arg2
633        s += '#define ICU_NB_OUT             %d\n'    % icu_arg3
634        s += '\n'
635
636        s += '/* local physical base address and size for devices */\n'
637        s += '\n'
638        s += '#define SEG_RAM_BASE           0x%x\n'  % (ram_base & local_physical_mask)
639        s += '#define SEG_RAM_SIZE           0x%x\n'  % ram_size
640        s += '\n'
641        s += '#define SEG_FBF_BASE           0x%x\n'  % (fbf_base & local_physical_mask)
642        s += '#define SEG_FBF_SIZE           0x%x\n'  % fbf_size
643        s += '\n'
644        s += '#define SEG_IOB_BASE           0x%x\n'  % (iob_base & local_physical_mask)
645        s += '#define SEG_IOB_SIZE           0x%x\n'  % iob_size
646        s += '\n'
647        s += '#define SEG_IOC_BASE           0x%x\n'  % (ioc_base & local_physical_mask)
648        s += '#define SEG_IOC_SIZE           0x%x\n'  % ioc_size
649        s += '\n'
650        s += '#define SEG_MMC_BASE           0x%x\n'  % (mmc_base & local_physical_mask)
651        s += '#define SEG_MMC_SIZE           0x%x\n'  % mmc_size
652        s += '\n'
653        s += '#define SEG_DMA_BASE           0x%x\n'  % (dma_base & local_physical_mask)
654        s += '#define SEG_DMA_SIZE           0x%x\n'  % dma_size
655        s += '\n'
656        s += '#define SEG_ROM_BASE           0x%x\n'  % (rom_base & local_physical_mask)
657        s += '#define SEG_ROM_SIZE           0x%x\n'  % rom_size
658        s += '\n'
659        s += '#define SEG_SIM_BASE           0x%x\n'  % (sim_base & local_physical_mask)
660        s += '#define SEG_SIM_SIZE           0x%x\n'  % sim_size
661        s += '\n'
662        s += '#define SEG_NIC_BASE           0x%x\n'  % (nic_base & local_physical_mask)
663        s += '#define SEG_NIC_SIZE           0x%x\n'  % nic_size
664        s += '\n'
665        s += '#define SEG_PIC_BASE           0x%x\n'  % (pic_base & local_physical_mask)
666        s += '#define SEG_PIC_SIZE           0x%x\n'  % pic_size
667        s += '\n'
668        s += '#define SEG_TIM_BASE           0x%x\n'  % (tim_base & local_physical_mask)
669        s += '#define SEG_TIM_SIZE           0x%x\n'  % tim_size
670        s += '\n'
671        s += '#define SEG_TXT_BASE           0x%x\n'  % (txt_base & local_physical_mask)
672        s += '#define SEG_TXT_SIZE           0x%x\n'  % txt_size
673        s += '\n'
674        s += '#define SEG_ICU_BASE           0x%x\n'  % (icu_base & local_physical_mask)
675        s += '#define SEG_ICU_SIZE           0x%x\n'  % icu_size
676        s += '\n'
677        s += '#define SEG_RDK_BASE           0x%x\n'  % (rdk_base & local_physical_mask)
678        s += '#define SEG_RDK_SIZE           0x%x\n'  % rdk_size
679        s += '\n'
680        s += '#endif\n'
681
682        return s
683
684    # end of hard_config()
685
686
687
688
689
690###################################################################################
691class Cluster ( object ):
692###################################################################################
693    def __init__( self,
694                  cxy ):
695
696        self.index       = 0           # global index (set by Archinfo constructor)
697        self.cxy         = cxy         # cluster identifier
698        self.cores       = []          # local cores (filled by addCore)
699        self.devices     = []          # local devices(filled by addDevice)
700
701        return
702
703    ################
704    def xml( self ):  # xml for a cluster
705
706        s = '        <cluster cxy = "%x" >\n' % (self.cxy)
707        for core   in self.cores:   s += core.xml()
708        for device in self.devices: s += device.xml()
709        s += '        </cluster>\n'
710
711        return s
712
713    #############################################
714    def cbin( self, mapping, verbose, expected ):  # C binary structure for Cluster
715
716        if ( verbose ):
717            print '*** cbin for cluster[%d] / identifier = %x' \
718                   % (self.index , self.cxy)
719
720        # check index
721        if (self.index != expected):
722            print '[genarch error] in Cluster.cbin()'
723            print '    cluster global index = %d / expected = %d' \
724                       % (self.index,expected)
725            sys.exit(1)
726
727        # compute global index for first core in cluster
728        if ( len(self.cores) > 0 ):
729            core_id = self.cores[0].index
730        else:
731            core_id = 0
732
733        # compute global index for first device in cluster
734        if ( len(self.devices) > 0 ):
735            device_id = self.devices[0].index
736        else:
737            device_id = 0
738
739        byte_stream = bytearray()
740        byte_stream += mapping.int2bytes(4,self.cxy)          # cxy
741        byte_stream += mapping.int2bytes(4,len(self.cores))   # cores in cluster
742        byte_stream += mapping.int2bytes(4,core_id )          # first core global index
743        byte_stream += mapping.int2bytes(4,len(self.devices)) # devices in cluster
744        byte_stream += mapping.int2bytes(4, device_id )       # first device global index
745
746        if ( verbose ):
747            print 'nb_cores   = %d' %  len( self.cores )
748            print 'core_id    = %d' %  core_id
749            print 'nb_devices = %d' %  len( self.devices )
750            print 'device_id  = %d' %  device_id
751
752        return byte_stream
753
754
755
756
757##################################################################################
758class Core ( object ):         
759##################################################################################
760    def __init__( self,
761                  gid,
762                  cxy,
763                  lid ):
764
765        self.index    = 0          # global index / set by addProc()
766        self.gid      = gid        # hardware identifier
767        self.cxy      = cxy        # cluster identifier
768        self.lid      = lid        # local index in cluster
769
770        return
771
772    ###################################
773    def xml( self ):   # xml for a core
774        return '            <core gid="%x" lid="%d" />\n' % (self.gid, self.lid)
775
776    ####################################################################
777    def cbin( self, mapping, verbose, expected ):    # C binary for Proc
778
779        if ( verbose ):
780            print '*** cbin for core [%d] in cluster %x' \
781                  % (self.lid, self.cxy)
782
783        # check index
784        if (self.index != expected):
785            print '[genarch error] in Core.cbin()'
786            print '    core global index = %d / expected = %d' \
787                       % (self.index,expected)
788            sys.exit(1)
789
790        byte_stream = bytearray()
791        byte_stream += mapping.int2bytes( 4 , self.gid )      # hardware identifier
792        byte_stream += mapping.int2bytes( 2 , self.cxy )      # cluster identifier
793        byte_stream += mapping.int2bytes( 2 , self.lid )      # local index
794
795        return byte_stream
796
797
798
799
800##################################################################################
801class Device ( object ):
802##################################################################################
803    def __init__( self,
804                  base,
805                  size,
806                  ptype,
807                  channels = 1,
808                  arg0     = 0,
809                  arg1     = 0,
810                  arg2     = 0,
811                  arg3     = 0 ):
812
813        self.index    = 0             # global device index ( set by addDevice() )
814        self.base     = base          # associated segment base
815        self.size     = size          # associated segment size (bytes)
816        self.ptype    = ptype         # device type
817        self.channels = channels      # number of channels
818        self.arg0     = arg0          # optional (semantic depends on ptype)
819        self.arg1     = arg1          # optional (semantic depends on ptype)
820        self.arg2     = arg2          # optional (semantic depends on ptype)
821        self.arg3     = arg3          # optional (semantic depends on ptype)
822        self.irqs     = []            # set of input IRQs (for PIC and ICU only)
823        self.irq_ctrl = None          # interrupt controller for this device
824        return
825
826    ######################################
827    def xml( self ):    # xml for a device
828
829        s =  '            <device type="%s"' % self.ptype
830        s += ' base="%x"'                    % self.base
831        s += ' size="%x"'                    % self.size
832        s += ' channels="%d"'                % self.channels
833        s += ' arg0="%d"'                    % self.arg0
834        s += ' arg1="%d"'                    % self.arg1
835        s += ' arg2="%d"'                    % self.arg2
836        s += ' arg3="%d"'                    % self.arg3
837        if ( (self.ptype == 'PIC_TSR') or (self.ptype == 'ICU_XCU') ):
838            s += ' >\n'
839            for irq in self.irqs: s += irq.xml()
840            s += '            </device>\n'
841        else:
842            s += ' />\n'
843        return s
844
845    ######################################################################
846    def cbin( self, mapping, verbose, expected ):    # C binary for Periph
847
848        if ( verbose ):
849            print '*** cbin for device[%d] / type = %s / base = %x' \
850                  % (self.index , self.ptype , self.base)
851
852        # check index
853        if (self.index != expected):
854            print '[genarch error] in Periph.cbin()'
855            print '    device global index = %d / expected = %d' \
856                       % (self.index,expected)
857            sys.exit(1)
858
859        # compute first irq global index
860        if ( len(self.irqs) > 0 ):
861            irq_id = self.irqs[0].index
862        else:
863            irq_id = 0
864
865        # compute device type numerical value
866        ptype_id = 0xFFFFFFFF
867        for x in xrange( len(DEVICE_TYPES_STR) ):
868            if ( self.ptype == DEVICE_TYPES_STR[x] ):  ptype_id = DEVICE_TYPES_INT[x]
869
870        if ( ptype_id == 0xFFFFFFFF ):
871            print '[genarch error] in Device.cbin()'
872            print '    undefined device type %s' % self.ptype
873            sys.exit(1)
874
875        byte_stream = bytearray()
876        byte_stream += mapping.int2bytes(8,self.base)      # segment base address
877        byte_stream += mapping.int2bytes(8,self.size)      # segment size
878        byte_stream += mapping.int2bytes(4,ptype_id)       # device type
879        byte_stream += mapping.int2bytes(4,self.channels)  # number of channels
880        byte_stream += mapping.int2bytes(4,self.arg0)      # optionnal arg0
881        byte_stream += mapping.int2bytes(4,self.arg1)      # optionnal arg1
882        byte_stream += mapping.int2bytes(4,self.arg2)      # optionnal arg2
883        byte_stream += mapping.int2bytes(4,self.arg3)      # optionnal arg3
884        byte_stream += mapping.int2bytes(4,len(self.irqs)) # number of input irqs
885        byte_stream += mapping.int2bytes(4 ,irq_id)        # first irq global index
886
887        if ( verbose ):
888            print 'base       = %x' %  self.base
889            print 'size       = %x' %  self.size
890            print 'nb_irqs    = %d' %  len( self.irqs )
891            print 'irq_id     = %d' %  irq_id
892
893        return byte_stream
894
895##################################################################################
896class Irq ( object ): 
897##################################################################################
898    def __init__( self,
899                  port,
900                  dev,
901                  channel,
902                  is_rx ): 
903
904        assert port < 32
905
906        self.index   = 0              # global index ( set by addIrq() )
907        self.port    = port           # input IRQ port index
908        self.dev     = dev            # source device
909        self.channel = channel        # source device channel
910        self.is_rx   = is_rx          # source device direction
911
912        return
913
914    ################################
915    def xml( self ):   # xml for Irq
916        s = '                <irq port="%d" devtype="%s" channel="%d" is_rx="%d" />\n' \
917                             % ( self.port, self.dev.ptype, self.channel, self.is_rx )
918        return s
919
920    ####################################################################
921    def cbin( self, mapping, verbose, expected ):     # C binary for Irq
922
923        if ( verbose ):
924            print '*** cbin for irq[%d] / src_dev = %s' \
925                   % (self.port , self.dev.ptype)
926
927        # check index
928        if (self.index != expected):
929            print '[genarch error] in Irq.cbin()'
930            print '    irq global index = %d / expected = %d' \
931                       % (self.index , expected)
932            sys.exit(1)
933
934        # compute source device type numerical value
935        dev_id = 0xFFFFFFFF
936        for x in xrange( len(DEVICE_TYPES_STR) ):
937            if ( self.dev.ptype == DEVICE_TYPES_STR[x] ): dev_id = DEVICE_TYPES_INT[x]
938
939        if ( dev_id == 0xFFFFFFFF ):
940            print '[genarch error] in Irq.cbin()'
941            print '    undefined device type %s' % self.dev.ptype
942            sys.exit(1)
943
944        byte_stream = bytearray()
945        byte_stream += mapping.int2bytes( 4,  dev_id )
946        byte_stream += mapping.int2bytes( 1,  self.channel )
947        byte_stream += mapping.int2bytes( 1,  self.is_rx )
948        byte_stream += mapping.int2bytes( 1,  self.port )
949        byte_stream += mapping.int2bytes( 1,  0 )
950
951        if ( verbose ):
952            print 'dev_id     = %d' %  dev_id
953            print 'channel    = %d' %  self.channel
954            print 'is_rx      = %d' %  self.is_rx   
955            print 'port       = %s' %  self.port
956
957        return byte_stream
958
959# Local Variables:
960# tab-width: 4;
961# c-basic-offset: 4;
962# c-file-offsets:((innamespace . 0)(inline-open . 0));
963# indent-tabs-mode: nil;
964# End:
965#
966# vim: filetype=python:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
967
Note: See TracBrowser for help on using the repository browser.