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

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

Introducing support for multiple TTY terminals (up to 16 channels) in the tsar_generic_iob platform.

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