source: trunk/platforms/tsar_generic_iob/arch.py @ 914

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

Update arch.py for tsar_generic_iob.

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