source: trunk/platforms/tsar_generic_leti/arch.py @ 939

Last change on this file since 939 was 939, checked in by alain, 9 years ago

Introduce the distributed kernel heap vsegs.

  • Property svn:executable set to *
File size: 18.3 KB
Line 
1#!/usr/bin/env python
2
3from math import log, ceil
4from mapping import *
5
6###############################################################################
7#   file   : arch.py  (for the tsar_generic_leti architecture)
8#   date   : may 2014
9#   author : Alain Greiner
10###############################################################################
11#  This file contains a mapping generator for the "tsar_generic_leti" platform.
12#  This includes both the hardware architecture (clusters, processors,
13#  peripherals, physical space segmentation) and the mapping of all boot
14#  and kernel objects (global vsegs).
15#
16#  The x_size & y_size parameters define the total number of clusters.
17#  The upper row (y = y_size-1) does not contain processors or memory.
18#
19#  It does not use the IOB component:
20#  The external peripherals are located in cluster[x_size-1][y_size-1].
21#
22#  It does not use an external ROM, as the preloader code is (pre)loaded
23#  at address 0x0, in the physical memory of cluster[0][0].
24#
25#  It can use an - optional - RAMDISK located in cluster[0][0].
26#
27#  The others hardware parameters are:
28#  - fbf_width      : frame_buffer width = frame_buffer heigth
29#  - nb_ttys        : number of TTY channels
30#  - nb_nics        : number of NIC channels
31#  - nb_cmas        : number of CMA channels
32#  - irq_per_proc   : number of input IRQs per processor
33#  - use_ramdisk    : use a RAMDISK when True
34#  - peri_increment : address increment for replicated peripherals
35#
36#  Regarding the boot and kernel vsegs mapping :
37#  - We use one big physical page (2 Mbytes) for the preloader and the four
38#    boot vsegs, all allocated in cluster[0,0].
39#  - We use the 16 next big pages in cluster[0][0] to implement the RAMDISK.
40#  - We use one big page per cluster for the replicated kernel code vsegs.
41#  - We use one big page in cluster[0][0] for the kernel data vseg.
42#  - We use one big page per cluster for the distributed kernel heap vsegs.
43#  - We use one big page per cluster for the distributed ptab vsegs.
44#  - We use small physical pages (4 Kbytes) per cluster for the schedulers.
45#  - We use one big page for each external peripheral in IO cluster,
46#  - We use one small page per cluster for each internal peripheral.
47###############################################################################
48
49########################
50def arch( x_size    = 2,
51          y_size    = 2,
52          nb_procs  = 4,
53          nb_ttys   = 1,
54          fbf_width = 128 ):
55
56    ### define architecture constants
57
58    nb_nics         = 1
59    nb_cmas         = 2
60    x_io            = x_size - 1
61    y_io            = y_size - 1
62    x_width         = 4
63    y_width         = 4
64    p_width         = 2
65    paddr_width     = 40
66    irq_per_proc    = 4
67    use_ramdisk     = False
68    peri_increment  = 0x10000     # distributed peripherals vbase increment
69    reset_address   = 0x00000000  # wired preloader pbase address
70
71    ### parameters checking
72
73    assert( nb_procs <= (1 << p_width) )
74
75    assert( x_size <= (1 << x_width) )
76
77    assert( y_size <= (1 << y_width) )
78
79    ### define type and name
80
81    platform_type  = 'tsar_leti'
82    platform_name  = '%s_%d_%d_%d' % (platform_type, x_size, y_size, nb_procs )
83
84    ### define physical segments replicated in all clusters
85    ### the base address is extended by the cluster_xy (8 bits)
86
87    ram_base = 0x00000000
88    ram_size = 0x4000000                   # 64 Mbytes
89
90    xcu_base = 0xF0000000
91    xcu_size = 0x1000                      # 4 Kbytes
92
93    mmc_base = 0xF1000000
94    mmc_size = 0x1000                      # 4 Kbytes
95
96    ### define physical segments for external peripherals
97    ## These segments are only defined in cluster_io
98
99    cluster_xy = ((x_io << y_width) + y_io) << (paddr_width - x_width - y_width)
100
101    bdv_base  = 0xF2000000 + cluster_xy
102    bdv_size  = 0x1000                     # 4kbytes
103
104    tty_base  = 0xF4000000 + cluster_xy
105    tty_size  = 0x4000                     # 16 Kbytes
106
107    nic_base  = 0xF7000000 + cluster_xy
108    nic_size  = 0x80000                    # 512 kbytes
109
110    cma_base  = 0xF8000000 + cluster_xy
111    cma_size  = 0x1000 * 2 * nb_nics       # 4 kbytes * 2 * nb_nics
112
113    pic_base  = 0xF9000000 + cluster_xy
114    pic_size  = 0x1000                     # 4 Kbytes
115
116    fbf_base  = 0xF3000000 + cluster_xy
117    fbf_size  = fbf_width * fbf_width      # fbf_width * fbf_width bytes
118
119
120    ### define preloader & bootloader vsegs base addresses and sizes
121    ### We want to pack these 5 vsegs in the same big page
122    ### => boot cost is one BPP in cluster[0][0]
123
124    preloader_vbase      = 0x00000000      # ident
125    preloader_size       = 0x00010000      # 64 Kbytes
126
127    boot_mapping_vbase   = 0x00010000      # ident
128    boot_mapping_size    = 0x00080000      # 512 Kbytes
129
130    boot_code_vbase      = 0x00090000      # ident
131    boot_code_size       = 0x00040000      # 256 Kbytes
132
133    boot_data_vbase      = 0x000D0000      # ident
134    boot_data_size       = 0x000B0000      # 704 Kbytes
135
136    boot_stack_vbase     = 0x00180000      # ident
137    boot_stack_size      = 0x00080000      # 512 Kbytes
138
139    ### define ramdisk vseg / must be identity mapping in cluster[0][0]
140    ### occupies 15 BPP after the boot 
141    ramdisk_vbase        = 0x00200000
142    ramdisk_size         = 0x02000000      # 32 Mbytes
143
144    ### define kernel vsegs base addresses and sizes
145    ### code, init, ptab, heap & sched vsegs are replicated in all clusters.
146    ### data & uncdata vsegs are only mapped in cluster[0][0].
147
148    kernel_code_vbase    = 0x80000000
149    kernel_code_size     = 0x00100000      # 1 Mbytes per cluster
150
151    kernel_init_vbase    = 0x80100000
152    kernel_init_size     = 0x00100000      # 1 Mbytes per cluster
153
154    kernel_data_vbase    = 0x90000000
155    kernel_data_size     = 0x00200000      # 2 Mbytes in cluster[0][0]
156
157    kernel_uncdata_vbase = 0x90200000
158    kernel_uncdata_size  = 0x00001000      # 4 Kbytes in cluster[0][0]
159
160    kernel_ptab_vbase    = 0xE0000000
161    kernel_ptab_size     = 0x00200000      # 2 Mbytes per cluster
162
163    kernel_heap_vbase    = 0xD0000000
164    kernel_heap_size     = 0x00200000      # 2 Mbytes per cluster
165
166    kernel_sched_vbase   = 0xA0000000
167    kernel_sched_size    = 0x00002000 * nb_procs # 8 kbytes per proc per cluster
168
169    #####################
170    ### create mapping
171    #####################
172
173    mapping = Mapping( name           = platform_name,
174                       x_size         = x_size,
175                       y_size         = y_size,
176                       nprocs         = nb_procs,
177                       x_width        = x_width,
178                       y_width        = y_width,
179                       p_width        = p_width,
180                       paddr_width    = paddr_width,
181                       coherence      = True,
182                       irq_per_proc   = irq_per_proc,
183                       use_ramdisk    = use_ramdisk,
184                       x_io           = x_io,
185                       y_io           = y_io,
186                       peri_increment = peri_increment,
187                       reset_address  = reset_address,
188                       ram_base       = ram_base,
189                       ram_size       = ram_size )
190
191    ###########################
192    ### Hardware Description
193    ###########################
194
195    for x in xrange( x_size ):
196        for y in xrange( y_size ):
197            cluster_xy = (x << y_width) + y;
198            offset     = cluster_xy << (paddr_width - x_width - y_width)
199 
200            ### components replicated in all clusters but the upper row
201            if ( y < (y_size - 1) ):
202
203                ram = mapping.addRam( 'RAM', base = ram_base + offset, 
204                                      size = ram_size )
205
206                mmc = mapping.addPeriph( 'MMC', base = mmc_base + offset, 
207                                         size = mmc_size, ptype = 'MMC' )
208
209                xcu = mapping.addPeriph( 'XCU', base = xcu_base + offset, 
210                                         size = xcu_size, ptype = 'XCU', 
211                                         channels = nb_procs * irq_per_proc, arg = 16 )
212
213                mapping.addIrq( xcu, index = 8, isrtype = 'ISR_MMC' )
214
215                for p in xrange ( nb_procs ):
216                    mapping.addProc( x, y, p )
217
218            ###  external peripherals in cluster_io
219            if ( (x==x_io) and (y==y_io) ):
220
221                bdv = mapping.addPeriph( 'BDV', base = bdv_base, size = bdv_size, 
222                                         ptype = 'IOC', subtype = 'BDV' )
223
224                tty = mapping.addPeriph( 'TTY', base = tty_base, size = tty_size, 
225                                         ptype = 'TTY', channels = nb_ttys )
226
227                nic = mapping.addPeriph( 'NIC', base = nic_base, size = nic_size, 
228                                         ptype = 'NIC', channels = nb_nics )
229
230                cma = mapping.addPeriph( 'CMA', base = cma_base, size = cma_size, 
231                                         ptype = 'CMA', channels = nb_cmas )
232
233                fbf = mapping.addPeriph( 'FBF', base = fbf_base, size = fbf_size, 
234                                         ptype = 'FBF', arg = fbf_width )
235
236                pic = mapping.addPeriph( 'PIC', base = pic_base, size = pic_size, 
237                                         ptype = 'PIC', channels = 32 )
238
239                mapping.addIrq( pic, index = 0 , isrtype = 'ISR_NIC_RX', channel = 0 )
240                mapping.addIrq( pic, index = 1 , isrtype = 'ISR_NIC_RX', channel = 1 )
241
242                mapping.addIrq( pic, index = 2 , isrtype = 'ISR_NIC_TX', channel = 0 )
243                mapping.addIrq( pic, index = 3 , isrtype = 'ISR_NIC_TX', channel = 1 )
244
245                mapping.addIrq( pic, index = 4 , isrtype = 'ISR_CMA'   , channel = 0 )
246                mapping.addIrq( pic, index = 5 , isrtype = 'ISR_CMA'   , channel = 1 )
247                mapping.addIrq( pic, index = 6 , isrtype = 'ISR_CMA'   , channel = 2 )
248                mapping.addIrq( pic, index = 7 , isrtype = 'ISR_CMA'   , channel = 3 )
249
250                mapping.addIrq( pic, index = 8 , isrtype = 'ISR_BDV'   , channel = 0 )
251
252                mapping.addIrq( pic, index = 16, isrtype = 'ISR_TTY_RX', channel = 0 )
253                mapping.addIrq( pic, index = 17, isrtype = 'ISR_TTY_RX', channel = 1 )
254                mapping.addIrq( pic, index = 18, isrtype = 'ISR_TTY_RX', channel = 2 )
255                mapping.addIrq( pic, index = 19, isrtype = 'ISR_TTY_RX', channel = 3 )
256                mapping.addIrq( pic, index = 20, isrtype = 'ISR_TTY_RX', channel = 4 )
257                mapping.addIrq( pic, index = 21, isrtype = 'ISR_TTY_RX', channel = 5 )
258                mapping.addIrq( pic, index = 22, isrtype = 'ISR_TTY_RX', channel = 6 )
259                mapping.addIrq( pic, index = 23, isrtype = 'ISR_TTY_RX', channel = 7 )
260
261    ###################################
262    ### boot & kernel vsegs mapping
263    ###################################
264
265    ### global vsegs for preloader & boot_loader are mapped in cluster[0][0]
266    ### => same flags CXW_ / identity mapping / non local / big page
267
268    mapping.addGlobal( 'seg_preloader', preloader_vbase, preloader_size,
269                       'CXW_', vtype = 'BUFFER', x = 0, y = 0, pseg = 'RAM',
270                       identity = True, local = False, big = True )
271
272    mapping.addGlobal( 'seg_boot_mapping', boot_mapping_vbase, boot_mapping_size,
273                       'CXW_', vtype = 'BLOB'  , x = 0, y = 0, pseg = 'RAM',
274                       identity = True, local = False, big = True )
275
276    mapping.addGlobal( 'seg_boot_code', boot_code_vbase, boot_code_size,
277                       'CXW_', vtype = 'BUFFER', x = 0, y = 0, pseg = 'RAM',
278                       identity = True, local = False, big = True )
279
280    mapping.addGlobal( 'seg_boot_data', boot_data_vbase, boot_data_size,
281                       'CXW_', vtype = 'BUFFER', x = 0, y = 0, pseg = 'RAM',
282                       identity = True, local = False, big = True )
283
284    mapping.addGlobal( 'seg_boot_stack', boot_stack_vbase, boot_stack_size,
285                       'CXW_', vtype = 'BUFFER', x = 0, y = 0, pseg = 'RAM',
286                       identity = True, local = False, big = True )
287
288    ### global vseg for RAM-DISK in cluster[0][0]
289    ### identity mapping / non local / big pages
290    if use_ramdisk:
291
292        mapping.addGlobal( 'seg_ramdisk', ramdisk_vbase, ramdisk_size,
293                           'C_W_', vtype = 'BUFFER', x = 0, y = 0, pseg = 'RAM',
294                           identity = True, local = True, big = True )
295
296    ### global vsegs kernel_code, kernel_init : local / big page
297    ### replicated in all clusters containing processors
298    ### same content => same name / same vbase
299    for x in xrange( x_size ):
300        for y in xrange( y_size - 1 ):
301
302            mapping.addGlobal( 'seg_kernel_code', 
303                               kernel_code_vbase, kernel_code_size,
304                               'CXW_', vtype = 'ELF', x = x, y = y, pseg = 'RAM',
305                               binpath = 'build/kernel/kernel.elf',
306                               local = True, big = True )
307
308            mapping.addGlobal( 'seg_kernel_init', 
309                               kernel_init_vbase, kernel_init_size,
310                               'CXW_', vtype = 'ELF', x = x, y = y, pseg = 'RAM',
311                               binpath = 'build/kernel/kernel.elf',
312                               local = True, big = True )
313
314    ### global vseg kernel_data: non local / big page
315    ### Only mapped in cluster[0][0]
316    mapping.addGlobal( 'seg_kernel_data', 
317                       kernel_data_vbase, kernel_data_size,
318                       'C_W_', vtype = 'ELF', x = 0, y = 0, pseg = 'RAM',
319                       binpath = 'build/kernel/kernel.elf', 
320                       local = False, big = True )
321
322    ### global vseg kernel_uncdata: non local / small page
323    ### Only mapped in cluster[0][0]
324    mapping.addGlobal( 'seg_kernel_uncdata', 
325                        kernel_uncdata_vbase, kernel_uncdata_size,
326                       '__W_', vtype = 'ELF', x = 0, y = 0, pseg = 'RAM',
327                       binpath = 'build/kernel/kernel.elf', 
328                       local = False, big = False )
329
330    ### Global vsegs kernel_ptab_x_y: non local / big page
331    ### replicated in all clusters containing processors
332    ### different content => name & vbase indexed by (x,y)
333    for x in xrange( x_size ):
334        for y in xrange( y_size - 1 ):
335            offset = ((x << y_width) + y) * kernel_ptab_size
336
337            mapping.addGlobal( 'seg_kernel_ptab_%d_%d' %(x,y), 
338                               kernel_ptab_vbase + offset, kernel_ptab_size,
339                               'CXW_', vtype = 'PTAB', x = x, y = y, pseg = 'RAM',
340                               local = False, big = True )
341
342    ### global vsegs kernel_heap_x_y : non local / big pages
343    ### distributed in all clusters containing processors
344    ### different content => name & vbase indexed by (x,y)
345    for x in xrange( x_size ):
346        for y in xrange( y_size - 1 ):
347            offset = ((x << y_width) + y) * kernel_heap_size
348
349            mapping.addGlobal( 'seg_kernel_heap_%d_%d' %(x,y), 
350                               kernel_heap_vbase + offset , kernel_heap_size,
351                               'C_W_', vtype = 'HEAP', x = x , y = y , pseg = 'RAM',
352                               local = False, big = True )
353
354    ### global vsegs for external peripherals: non local / big page
355    ### only mapped in cluster_io
356    mapping.addGlobal( 'seg_bdv', 
357                       bdv_base, bdv_size,
358                       '__W_', vtype = 'PERI', x = x_io, y = y_io, pseg = 'BDV',
359                       local = False, big = True )
360
361    mapping.addGlobal( 'seg_tty', 
362                       tty_base, tty_size, 
363                       '__W_', vtype = 'PERI', x = x_io, y = y_io, pseg = 'TTY',
364                       local = False, big = True )
365
366    mapping.addGlobal( 'seg_nic', 
367                       nic_base, nic_size,
368                       '__W_', vtype = 'PERI', x = x_io, y = y_io, pseg = 'NIC',
369                       local = False, big = True )
370
371    mapping.addGlobal( 'seg_cma', 
372                       cma_base, cma_size,
373                       '__W_', vtype = 'PERI', x = x_io, y = y_io, pseg = 'CMA',
374                       local = False, big = True )
375
376    mapping.addGlobal( 'seg_fbf', 
377                       fbf_base, fbf_size,
378                       '__W_', vtype = 'PERI', x = x_io, y = y_io, pseg = 'FBF',
379                       local = False, big = True )
380
381    mapping.addGlobal( 'seg_pic', 
382                       pic_base, pic_size,
383                       '__W_', vtype = 'PERI', x = x_io, y = y_io, pseg = 'PIC',
384                       local = False, big = True )
385
386    ### global vsegs for internal peripherals : non local / small pages
387    ### allocated in all clusters containing processors
388    ### name and vbase indexed by (x,y)
389    for x in xrange( x_size ):
390        for y in xrange( y_size - 1 ):
391            offset = ((x << y_width) + y) * peri_increment
392
393            mapping.addGlobal( 'seg_xcu_%d_%d' %(x,y), 
394                               xcu_base + offset, xcu_size,
395                               '__W_', vtype = 'PERI' , x = x , y = y , pseg = 'XCU',
396                               local = False, big = False )
397
398            mapping.addGlobal( 'seg_mmc_%d_%d' %(x,y), 
399                               mmc_base + offset, mmc_size,
400                               '__W_', vtype = 'PERI' , x = x , y = y , pseg = 'MMC',
401                               local = False, big = False )
402
403    ### global vsegs kernel_sched : non local / small pages
404    ### allocated in all clusters containing processors
405    ### different content => name & vbase indexed by (x,y)
406    for x in xrange( x_size ):
407        for y in xrange( y_size - 1 ):
408            offset = ((x << y_width) + y) * kernel_ptab_size
409
410            mapping.addGlobal( 'seg_kernel_sched_%d_%d' %(x,y), 
411                               kernel_sched_vbase + offset , kernel_sched_size,
412                               'C_W_', vtype = 'SCHED', x = x, y = y, pseg = 'RAM',
413                               local = False, big = False )
414
415    return mapping
416
417########################## platform test #############################################
418
419if __name__ == '__main__':
420
421    mapping = arch( x_size    = 2,
422                    y_size    = 2,
423                    nb_procs  = 2 )
424
425#   print mapping.netbsd_dts()
426
427    print mapping.xml()
428
429#   print mapping.giet_vsegs()
430
431
432# Local Variables:
433# tab-width: 4;
434# c-basic-offset: 4;
435# c-file-offsets:((innamespace . 0)(inline-open . 0));
436# indent-tabs-mode: nil;
437# End:
438#
439# vim: filetype=python:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
440
Note: See TracBrowser for help on using the repository browser.