1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | from math import log, ceil |
---|
4 | from 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 kernel |
---|
14 | # objects (global vsegs). |
---|
15 | # |
---|
16 | # The "constructor" parameters are: |
---|
17 | # - x_size : number of clusters in a row |
---|
18 | # - y_size : number of clusters in a column |
---|
19 | # - nb_procs : number of processors per cluster |
---|
20 | # - fbf_width : frame_buffer width = frame_buffer heigth |
---|
21 | # |
---|
22 | # The "hidden" parameters (defined below) are: |
---|
23 | # - nb_ttys : number of TTY channels |
---|
24 | # - nb_nics : number of NIC channels |
---|
25 | # - x_io : cluster_io x coordinate |
---|
26 | # - y_io : cluster_io y coordinate |
---|
27 | # - x_width : number of bits for x coordinate |
---|
28 | # - y_width : number of bits for y coordinate |
---|
29 | # - paddr_width : number of bits for physical address |
---|
30 | # - irq_per_proc : number of input IRQs per processor |
---|
31 | # - use_ramdisk : use a ramdisk when True |
---|
32 | # - peri_increment : address increment for replicated peripherals |
---|
33 | # |
---|
34 | # Regarding physical memory allocation, there is one allocator per cluster: |
---|
35 | # - We use only one big physical page (2 Mbytes) for the five boot vsegs, |
---|
36 | # allocated in cluster[0,0], identity mapping. |
---|
37 | # - We use one big page per cluster for the kernel vsegs. |
---|
38 | # The kernel_code, kernel_init and kernel_ptab can be replicated in all clusters. |
---|
39 | # The kernel_data and kernel_uncdata shared vsegs are only mapped in cluster[0,0]. |
---|
40 | # - We use 8 small physical pages (4 Kbytes) per cluster for the schedulers. |
---|
41 | # - We use one big page for each external peripheral in IO cluster, |
---|
42 | # - We use one small page per cluster for each internal peripheral. |
---|
43 | ################################################################################### |
---|
44 | |
---|
45 | ######################## |
---|
46 | def arch( x_size = 2, |
---|
47 | y_size = 2, |
---|
48 | nb_procs = 2, |
---|
49 | fbf_width = 128 ): |
---|
50 | |
---|
51 | ### define architecture constants |
---|
52 | |
---|
53 | nb_ttys = 1 |
---|
54 | nb_nics = 2 |
---|
55 | x_io = 0 |
---|
56 | y_io = 0 |
---|
57 | x_width = 4 |
---|
58 | y_width = 4 |
---|
59 | p_width = 2 |
---|
60 | paddr_width = 40 |
---|
61 | irq_per_proc = 4 |
---|
62 | use_ramdisk = True |
---|
63 | peri_increment = 0x10000 # distributed peripherals vbase address increment |
---|
64 | sched_increment = 0x10000 # distributed schedulers vbase address increment |
---|
65 | ptab_increment = 0x200000 # distributed page tables vbase address increment |
---|
66 | reset_address = 0x00000000 |
---|
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 ) |
---|
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_leti_%d_%d_%d' % ( x_size, y_size, nb_procs ) |
---|
84 | |
---|
85 | ### define 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 = 0x00F0000000 |
---|
92 | xcu_size = 0x1000 # 4 Kbytes |
---|
93 | |
---|
94 | mmc_base = 0x00E0000000 |
---|
95 | mmc_size = 0x1000 # 4 Kbytes |
---|
96 | |
---|
97 | ### define physical segments for external peripherals |
---|
98 | ## These segments are only defined in cluster_io |
---|
99 | |
---|
100 | offset_io = ((x_io << y_width) + y_io) << (paddr_width - x_width - y_width) |
---|
101 | |
---|
102 | bdv_base = 0x00F2000000 + offset_io |
---|
103 | bdv_size = 0x1000 # 4kbytes |
---|
104 | |
---|
105 | tty_base = 0x00F4000000 + offset_io |
---|
106 | tty_size = 0x4000 # 16 Kbytes |
---|
107 | |
---|
108 | nic_base = 0x00F7000000 + offset_io |
---|
109 | nic_size = 0x80000 # 512 kbytes |
---|
110 | |
---|
111 | cma_base = 0x00F8000000 + offset_io |
---|
112 | cma_size = 0x1000 * 2 * nb_nics # 4 kbytes * 2 * nb_nics |
---|
113 | |
---|
114 | fbf_base = 0x00F3000000 + offset_io |
---|
115 | fbf_size = fbf_width * fbf_width # fbf_width * fbf_width bytes |
---|
116 | |
---|
117 | pic_base = 0x00F9000000 + offset_io |
---|
118 | pic_size = 0x1000 # 4 Kbytes |
---|
119 | |
---|
120 | rdk_base = 0x02000000 |
---|
121 | rdk_size = 0x02000000 # 32 Mbytes |
---|
122 | |
---|
123 | ### define preloader & bootloader vsegs base addresses and sizes |
---|
124 | ### We want to pack these 5 vsegs in the same big page |
---|
125 | ### => boot cost is one BPP in cluster[0][0] |
---|
126 | |
---|
127 | preloader_vbase = 0x00000000 # ident |
---|
128 | preloader_size = 0x00010000 # 64 Kbytes |
---|
129 | |
---|
130 | boot_mapping_vbase = 0x00010000 # ident |
---|
131 | boot_mapping_size = 0x00080000 # 512 Kbytes |
---|
132 | |
---|
133 | boot_code_vbase = 0x00090000 # ident |
---|
134 | boot_code_size = 0x00040000 # 256 Kbytes |
---|
135 | |
---|
136 | boot_data_vbase = 0x000D0000 # ident |
---|
137 | boot_data_size = 0x00080000 # 512 Kbytes |
---|
138 | |
---|
139 | boot_stack_vbase = 0x00150000 # ident |
---|
140 | boot_stack_size = 0x00050000 # 320 Kbytes |
---|
141 | |
---|
142 | ### define kernel vsegs base addresses and sizes |
---|
143 | ### code, init, ptab & sched vsegs are replicated in all clusters. |
---|
144 | ### data & uncdata vsegs are only mapped in cluster[0][0]. |
---|
145 | ### - We pack code, init, data vsegs in the same BIG page. |
---|
146 | ### - We use another BIG page for the ptab vseg. |
---|
147 | ### - We use 2*nb_procs SMALL pages for the sched vseg. |
---|
148 | ### - we use one SMALL page for uncdata |
---|
149 | ### => kernel cost is 2 BPPs and (2*n + 1) SPPs per cluster. |
---|
150 | |
---|
151 | kernel_code_vbase = 0x80000000 |
---|
152 | kernel_code_size = 0x00080000 # 512 Kbytes per cluster |
---|
153 | |
---|
154 | kernel_init_vbase = 0x80080000 |
---|
155 | kernel_init_size = 0x00080000 # 512 Kbytes per cluster |
---|
156 | |
---|
157 | kernel_data_vbase = 0x80100000 |
---|
158 | kernel_data_size = 0x00100000 # 1 Mbytes in cluster[0][0] |
---|
159 | |
---|
160 | kernel_uncdata_vbase = 0x80200000 |
---|
161 | kernel_uncdata_size = 0x00001000 # 4 Kbytes |
---|
162 | |
---|
163 | kernel_sched_vbase = 0x80400000 # distributed in all clusters |
---|
164 | kernel_sched_size = 0x00002000 * nb_procs # 8 kbytes per processor |
---|
165 | |
---|
166 | kernel_ptab_vbase = 0xC0000000 |
---|
167 | kernel_ptab_size = 0x00200000 # 2 Mbytes per cluster |
---|
168 | |
---|
169 | ### create mapping |
---|
170 | |
---|
171 | mapping = Mapping( name = platform_name, |
---|
172 | x_size = x_size, |
---|
173 | y_size = y_size, |
---|
174 | nprocs = nb_procs, |
---|
175 | x_width = x_width, |
---|
176 | y_width = y_width, |
---|
177 | p_width = p_width, |
---|
178 | paddr_width = paddr_width, |
---|
179 | coherence = True, |
---|
180 | irq_per_proc = irq_per_proc, |
---|
181 | use_ramdisk = use_ramdisk, |
---|
182 | x_io = x_io, |
---|
183 | y_io = y_io, |
---|
184 | peri_increment = peri_increment, |
---|
185 | reset_address = reset_address, |
---|
186 | ram_base = ram_base, |
---|
187 | ram_size = ram_size ) |
---|
188 | |
---|
189 | ### external peripherals (accessible in cluster[0,0] only for this mapping) |
---|
190 | |
---|
191 | bdv = mapping.addPeriph( 'BDV', base = bdv_base, size = bdv_size, ptype = 'IOC', subtype = 'BDV' ) |
---|
192 | |
---|
193 | tty = mapping.addPeriph( 'TTY', base = tty_base, size = tty_size, ptype = 'TTY', channels = nb_ttys ) |
---|
194 | |
---|
195 | if x_io != 0 or y_io != 0: |
---|
196 | nic = mapping.addPeriph( 'NIC', base = nic_base, size = nic_size, ptype = 'NIC', channels = nb_nics ) |
---|
197 | cma = mapping.addPeriph( 'CMA', base = cma_base, size = cma_size, ptype = 'CMA', channels = 2*nb_nics ) |
---|
198 | fbf = mapping.addPeriph( 'FBF', base = fbf_base, size = fbf_size, ptype = 'FBF', arg = fbf_width ) |
---|
199 | pic = mapping.addPeriph( 'PIC', base = pic_base, size = pic_size, ptype = 'PIC', channels = 32 ) |
---|
200 | |
---|
201 | mapping.addIrq( pic, index = 0 , isrtype = 'ISR_NIC_RX', channel = 0 ) |
---|
202 | mapping.addIrq( pic, index = 1 , isrtype = 'ISR_NIC_RX', channel = 1 ) |
---|
203 | mapping.addIrq( pic, index = 2 , isrtype = 'ISR_NIC_TX', channel = 0 ) |
---|
204 | mapping.addIrq( pic, index = 3 , isrtype = 'ISR_NIC_TX', channel = 1 ) |
---|
205 | mapping.addIrq( pic, index = 4 , isrtype = 'ISR_CMA' , channel = 0 ) |
---|
206 | mapping.addIrq( pic, index = 5 , isrtype = 'ISR_CMA' , channel = 1 ) |
---|
207 | mapping.addIrq( pic, index = 6 , isrtype = 'ISR_CMA' , channel = 2 ) |
---|
208 | mapping.addIrq( pic, index = 7 , isrtype = 'ISR_CMA' , channel = 3 ) |
---|
209 | mapping.addIrq( pic, index = 8 , isrtype = 'ISR_BDV' , channel = 0 ) |
---|
210 | mapping.addIrq( pic, index = 16, isrtype = 'ISR_TTY_RX', channel = 0 ) |
---|
211 | |
---|
212 | mapping.addGlobal( 'seg_nic', nic_base, nic_size, '__W_', |
---|
213 | vtype = 'PERI', x = 0, y = 0, pseg = 'NIC', |
---|
214 | local = False, big = True ) |
---|
215 | |
---|
216 | mapping.addGlobal( 'seg_cma', cma_base, cma_size, '__W_', |
---|
217 | vtype = 'PERI', x = 0, y = 0, pseg = 'CMA', |
---|
218 | local = False, big = True ) |
---|
219 | |
---|
220 | mapping.addGlobal( 'seg_fbf', fbf_base, fbf_size, '__W_', |
---|
221 | vtype = 'PERI', x = 0, y = 0, pseg = 'FBF', |
---|
222 | local = False, big = True ) |
---|
223 | |
---|
224 | mapping.addGlobal( 'seg_pic', pic_base, pic_size, '__W_', |
---|
225 | vtype = 'PERI', x = 0, y = 0, pseg = 'PIC', |
---|
226 | local = False, big = True ) |
---|
227 | |
---|
228 | ### hardware components replicated in all clusters |
---|
229 | |
---|
230 | for x in xrange( x_size ): |
---|
231 | for y in xrange( y_size ): |
---|
232 | cluster_xy = (x << y_width) + y; |
---|
233 | offset = cluster_xy << (paddr_width - x_width - y_width) |
---|
234 | |
---|
235 | ram = mapping.addRam( 'RAM', base = ram_base + offset, size = ram_size ) |
---|
236 | |
---|
237 | mmc = mapping.addPeriph( 'MMC', base = mmc_base + offset, size = mmc_size, |
---|
238 | ptype = 'MMC' ) |
---|
239 | |
---|
240 | xcu = mapping.addPeriph( 'XCU', base = xcu_base + offset, size = xcu_size, |
---|
241 | ptype = 'XCU', channels = nb_procs * irq_per_proc, arg = 16 ) |
---|
242 | |
---|
243 | # IRQs replicated in all clusters |
---|
244 | mapping.addIrq( xcu, index = 8, isrtype = 'ISR_MMC' ) |
---|
245 | |
---|
246 | # IRQ in IO cluster (0,0) |
---|
247 | if x == 0 and y == 0: |
---|
248 | mapping.addIrq( xcu, index = 9 , isrtype = 'ISR_BDV' ) |
---|
249 | mapping.addIrq( xcu, index = 10, isrtype = 'ISR_TTY_RX' ) |
---|
250 | |
---|
251 | # processors |
---|
252 | for p in xrange ( nb_procs ): |
---|
253 | mapping.addProc( x, y, p ) |
---|
254 | |
---|
255 | ### global vsegs for preloader & boot_loader |
---|
256 | ### we want to pack those 5 vsegs in the same big page |
---|
257 | ### => same flags CXW_ / identity mapping / non local / big page |
---|
258 | |
---|
259 | mapping.addGlobal( 'seg_preloader', preloader_vbase, preloader_size, |
---|
260 | 'CXW_', vtype = 'BUFFER', x = 0, y = 0, pseg = 'RAM', |
---|
261 | identity = True, local = False, big = True ) |
---|
262 | |
---|
263 | mapping.addGlobal( 'seg_boot_mapping', boot_mapping_vbase, boot_mapping_size, |
---|
264 | 'CXW_', vtype = 'BLOB' , x = 0, y = 0, pseg = 'RAM', |
---|
265 | identity = True, local = False, big = True ) |
---|
266 | |
---|
267 | mapping.addGlobal( 'seg_boot_code', boot_code_vbase, boot_code_size, |
---|
268 | 'CXW_', vtype = 'BUFFER', x = 0, y = 0, pseg = 'RAM', |
---|
269 | identity = True, local = False, big = True ) |
---|
270 | |
---|
271 | mapping.addGlobal( 'seg_boot_data', boot_data_vbase, boot_data_size, |
---|
272 | 'CXW_', vtype = 'BUFFER', x = 0, y = 0, pseg = 'RAM', |
---|
273 | identity = True, local = False, big = True ) |
---|
274 | |
---|
275 | mapping.addGlobal( 'seg_boot_stack', boot_stack_vbase, boot_stack_size, |
---|
276 | 'CXW_', vtype = 'BUFFER', x = 0, y = 0, pseg = 'RAM', |
---|
277 | identity = True, local = False, big = True ) |
---|
278 | |
---|
279 | ### global vsegs kernel_code, kernel_init : local / big page |
---|
280 | ### replicated in all clusters with the same name (same vbase) |
---|
281 | for x in xrange( x_size ): |
---|
282 | for y in xrange( y_size ): |
---|
283 | mapping.addGlobal( 'seg_kernel_code', kernel_code_vbase, kernel_code_size, |
---|
284 | 'CXW_', vtype = 'ELF', x = x, y = y, pseg = 'RAM', |
---|
285 | binpath = 'build/kernel/kernel.elf', |
---|
286 | local = True, big = True ) |
---|
287 | |
---|
288 | mapping.addGlobal( 'seg_kernel_init', kernel_init_vbase, kernel_init_size, |
---|
289 | 'CXW_', vtype = 'ELF', x = x, y = y, pseg = 'RAM', |
---|
290 | binpath = 'build/kernel/kernel.elf', |
---|
291 | local = True, big = True ) |
---|
292 | |
---|
293 | ### global vseg kernel_data: non local / big page |
---|
294 | ### Only mapped in cluster[0][0] |
---|
295 | mapping.addGlobal( 'seg_kernel_data', kernel_data_vbase, kernel_data_size, |
---|
296 | 'CXW_', vtype = 'ELF', x = 0, y = 0, pseg = 'RAM', |
---|
297 | binpath = 'build/kernel/kernel.elf', |
---|
298 | local = False, big = True ) |
---|
299 | |
---|
300 | ### global vseg kernel_uncdata: non local / small page |
---|
301 | ### Only mapped in cluster[0][0] |
---|
302 | mapping.addGlobal( 'seg_kernel_uncdata', kernel_uncdata_vbase, kernel_uncdata_size, |
---|
303 | '__W_', vtype = 'ELF', x = 0, y = 0, pseg = 'RAM', |
---|
304 | binpath = 'build/kernel/kernel.elf', |
---|
305 | local = False, big = False ) |
---|
306 | |
---|
307 | for x in xrange( x_size ): |
---|
308 | for y in xrange( y_size ): |
---|
309 | cluster_xy = (x << y_width) + y; |
---|
310 | |
---|
311 | ### Global vsegs kernel_ptab_x_y: non local / big pages |
---|
312 | ### replicated in all clusters with name indexed by (x,y) |
---|
313 | ### as vbase address is incremented by (cluster_xy * vseg_increment) |
---|
314 | offset = cluster_xy * ptab_increment |
---|
315 | mapping.addGlobal( 'seg_kernel_ptab_%d_%d' %(x,y), kernel_ptab_vbase + offset, kernel_ptab_size, |
---|
316 | 'CXW_', vtype = 'PTAB', x = x, y = y, pseg = 'RAM', |
---|
317 | local = False, big = True ) |
---|
318 | |
---|
319 | ### global vsegs kernel_sched : non local / small pages |
---|
320 | ### allocated in all clusters with name indexed by (x,y) |
---|
321 | ### as vbase address is incremented by (cluster_xy * vseg_increment) |
---|
322 | offset = cluster_xy * sched_increment |
---|
323 | mapping.addGlobal( 'seg_kernel_sched_%d_%d' %(x,y), kernel_sched_vbase + offset, kernel_sched_size, |
---|
324 | 'C_W_', vtype = 'SCHED', x = x, y = y, pseg = 'RAM', |
---|
325 | local = False, big = False ) |
---|
326 | |
---|
327 | ### global vseg for ram disk |
---|
328 | if use_ramdisk: |
---|
329 | mapping.addGlobal( 'seg_rdk', rdk_base, rdk_size, '__W_', |
---|
330 | vtype = 'BUFFER', x = 0, y = 0, pseg = 'RAM', |
---|
331 | identity = True, local = False, big = True ) |
---|
332 | |
---|
333 | ### global vsegs for external peripherals: non local / big page |
---|
334 | mapping.addGlobal( 'seg_bdv', bdv_base, bdv_size, '__W_', |
---|
335 | vtype = 'PERI', x = 0, y = 0, pseg = 'BDV', |
---|
336 | local = False, big = True ) |
---|
337 | |
---|
338 | mapping.addGlobal( 'seg_tty', tty_base, tty_size, '__W_', |
---|
339 | vtype = 'PERI', x = 0, y = 0, pseg = 'TTY', |
---|
340 | local = False, big = True ) |
---|
341 | |
---|
342 | ### global vsegs for internal peripherals : non local / small pages |
---|
343 | ### allocated in all clusters with name indexed by (x,y) |
---|
344 | ### as vbase address is incremented by (cluster_xy * vseg_increment) |
---|
345 | for x in xrange( x_size ): |
---|
346 | for y in xrange( y_size ): |
---|
347 | offset = ((x << y_width) + y) * peri_increment |
---|
348 | |
---|
349 | mapping.addGlobal( 'seg_xcu_%d_%d' %(x,y), xcu_base + offset, xcu_size, |
---|
350 | '__W_', vtype = 'PERI' , x = x , y = y , pseg = 'XCU', |
---|
351 | local = False, big = False ) |
---|
352 | |
---|
353 | mapping.addGlobal( 'seg_mmc_%d_%d' %(x,y), mmc_base + offset, mmc_size, |
---|
354 | '__W_', vtype = 'PERI' , x = x , y = y , pseg = 'MMC', |
---|
355 | local = False, big = False ) |
---|
356 | |
---|
357 | ### return mapping ### |
---|
358 | |
---|
359 | return mapping |
---|
360 | |
---|
361 | ################################# platform test ####################################################### |
---|
362 | |
---|
363 | if __name__ == '__main__': |
---|
364 | |
---|
365 | mapping = arch( x_size = 2, |
---|
366 | y_size = 2, |
---|
367 | nb_procs = 2 ) |
---|
368 | |
---|
369 | # print mapping.netbsd_dts() |
---|
370 | |
---|
371 | print mapping.xml() |
---|
372 | |
---|
373 | # print mapping.giet_vsegs() |
---|
374 | |
---|
375 | |
---|
376 | # Local Variables: |
---|
377 | # tab-width: 4; |
---|
378 | # c-basic-offset: 4; |
---|
379 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); |
---|
380 | # indent-tabs-mode: nil; |
---|
381 | # End: |
---|
382 | # |
---|
383 | # vim: filetype=python:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
384 | |
---|