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 = 4 |
---|
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_ptab_vbase = 0xB0000000 |
---|
161 | kernel_ptab_size = 0x00200000 # 2 Mbytes per cluster |
---|
162 | |
---|
163 | kernel_uncdata_vbase = 0x90000000 |
---|
164 | kernel_uncdata_size = 0x00001000 # 4 Kbytes |
---|
165 | |
---|
166 | kernel_sched_vbase = 0xA0000000 # distributed in all clusters |
---|
167 | kernel_sched_size = 0x00002000 * nb_procs # 8 kbytes per processor |
---|
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 | nic = mapping.addPeriph( 'NIC', base = nic_base, size = nic_size, ptype = 'NIC', channels = nb_nics ) |
---|
196 | |
---|
197 | cma = mapping.addPeriph( 'CMA', base = cma_base, size = cma_size, ptype = 'CMA', channels = 2*nb_nics ) |
---|
198 | |
---|
199 | fbf = mapping.addPeriph( 'FBF', base = fbf_base, size = fbf_size, ptype = 'FBF', arg = fbf_width ) |
---|
200 | |
---|
201 | pic = mapping.addPeriph( 'PIC', base = pic_base, size = pic_size, ptype = 'PIC', channels = 32 ) |
---|
202 | |
---|
203 | mapping.addIrq( pic, index = 0 , isrtype = 'ISR_NIC_RX', channel = 0 ) |
---|
204 | mapping.addIrq( pic, index = 1 , isrtype = 'ISR_NIC_RX', channel = 1 ) |
---|
205 | mapping.addIrq( pic, index = 2 , isrtype = 'ISR_NIC_TX', channel = 0 ) |
---|
206 | mapping.addIrq( pic, index = 3 , isrtype = 'ISR_NIC_TX', channel = 1 ) |
---|
207 | mapping.addIrq( pic, index = 4 , isrtype = 'ISR_CMA' , channel = 0 ) |
---|
208 | mapping.addIrq( pic, index = 5 , isrtype = 'ISR_CMA' , channel = 1 ) |
---|
209 | mapping.addIrq( pic, index = 6 , isrtype = 'ISR_CMA' , channel = 2 ) |
---|
210 | mapping.addIrq( pic, index = 7 , isrtype = 'ISR_CMA' , channel = 3 ) |
---|
211 | mapping.addIrq( pic, index = 8 , isrtype = 'ISR_BDV' , channel = 0 ) |
---|
212 | mapping.addIrq( pic, index = 16, isrtype = 'ISR_TTY_RX', channel = 0 ) |
---|
213 | |
---|
214 | ### hardware components replicated in all clusters |
---|
215 | |
---|
216 | for x in xrange( x_size ): |
---|
217 | for y in xrange( y_size ): |
---|
218 | cluster_xy = (x << y_width) + y; |
---|
219 | offset = cluster_xy << (paddr_width - x_width - y_width) |
---|
220 | |
---|
221 | ram = mapping.addRam( 'RAM', base = ram_base + offset, size = ram_size ) |
---|
222 | |
---|
223 | mmc = mapping.addPeriph( 'MMC', base = mmc_base + offset, size = mmc_size, |
---|
224 | ptype = 'MMC' ) |
---|
225 | |
---|
226 | xcu = mapping.addPeriph( 'XCU', base = xcu_base + offset, size = xcu_size, |
---|
227 | ptype = 'XCU', channels = nb_procs * irq_per_proc, arg = 16 ) |
---|
228 | |
---|
229 | # IRQs replicated in all clusters |
---|
230 | mapping.addIrq( xcu, index = 8, isrtype = 'ISR_MMC' ) |
---|
231 | |
---|
232 | # IRQ in IO cluster (0,0) |
---|
233 | if x == 0 and y == 0: |
---|
234 | mapping.addIrq( xcu, index = 9 , isrtype = 'ISR_BDV' ) |
---|
235 | mapping.addIrq( xcu, index = 10, isrtype = 'ISR_TTY_RX' ) |
---|
236 | |
---|
237 | # processors |
---|
238 | for p in xrange ( nb_procs ): |
---|
239 | mapping.addProc( x, y, p ) |
---|
240 | |
---|
241 | ### global vsegs for preloader & boot_loader |
---|
242 | ### we want to pack those 5 vsegs in the same big page |
---|
243 | ### => same flags CXW_ / identity mapping / non local / big page |
---|
244 | |
---|
245 | mapping.addGlobal( 'seg_preloader', preloader_vbase, preloader_size, |
---|
246 | 'CXW_', vtype = 'BUFFER', x = 0, y = 0, pseg = 'RAM', |
---|
247 | identity = True, local = False, big = True ) |
---|
248 | |
---|
249 | mapping.addGlobal( 'seg_boot_mapping', boot_mapping_vbase, boot_mapping_size, |
---|
250 | 'CXW_', vtype = 'BLOB' , x = 0, y = 0, pseg = 'RAM', |
---|
251 | identity = True, local = False, big = True ) |
---|
252 | |
---|
253 | mapping.addGlobal( 'seg_boot_code', boot_code_vbase, boot_code_size, |
---|
254 | 'CXW_', vtype = 'BUFFER', x = 0, y = 0, pseg = 'RAM', |
---|
255 | identity = True, local = False, big = True ) |
---|
256 | |
---|
257 | mapping.addGlobal( 'seg_boot_data', boot_data_vbase, boot_data_size, |
---|
258 | 'CXW_', vtype = 'BUFFER', x = 0, y = 0, pseg = 'RAM', |
---|
259 | identity = True, local = False, big = True ) |
---|
260 | |
---|
261 | mapping.addGlobal( 'seg_boot_stack', boot_stack_vbase, boot_stack_size, |
---|
262 | 'CXW_', vtype = 'BUFFER', x = 0, y = 0, pseg = 'RAM', |
---|
263 | identity = True, local = False, big = True ) |
---|
264 | |
---|
265 | ### global vsegs kernel_code, kernel_init : local / big page |
---|
266 | ### replicated in all clusters with the same name (same vbase) |
---|
267 | for x in xrange( x_size ): |
---|
268 | for y in xrange( y_size ): |
---|
269 | cluster_xy = (x << y_width) + y; |
---|
270 | |
---|
271 | mapping.addGlobal( 'seg_kernel_code', kernel_code_vbase, kernel_code_size, |
---|
272 | 'CXW_', vtype = 'ELF', x = x, y = y, pseg = 'RAM', |
---|
273 | binpath = 'build/kernel/kernel.elf', |
---|
274 | local = True, big = True ) |
---|
275 | |
---|
276 | mapping.addGlobal( 'seg_kernel_init', kernel_init_vbase, kernel_init_size, |
---|
277 | 'CXW_', vtype = 'ELF', x = x, y = y, pseg = 'RAM', |
---|
278 | binpath = 'build/kernel/kernel.elf', |
---|
279 | local = True, big = True ) |
---|
280 | |
---|
281 | ### global vseg kernel_data: non local / big page |
---|
282 | ### Only mapped in cluster[0][0] |
---|
283 | mapping.addGlobal( 'seg_kernel_data', kernel_data_vbase, kernel_data_size, |
---|
284 | 'C_W_', vtype = 'ELF', x = 0, y = 0, pseg = 'RAM', |
---|
285 | binpath = 'build/kernel/kernel.elf', local = False ) |
---|
286 | |
---|
287 | ### global vseg kernel_uncdata: non local / small page |
---|
288 | ### Only mapped in cluster[0][0] |
---|
289 | mapping.addGlobal( 'seg_kernel_uncdata', kernel_uncdata_vbase, kernel_uncdata_size, |
---|
290 | '__W_', vtype = 'ELF', x = 0, y = 0, pseg = 'RAM', |
---|
291 | binpath = 'build/kernel/kernel.elf', local = False ) |
---|
292 | |
---|
293 | for x in xrange( x_size ): |
---|
294 | for y in xrange( y_size ): |
---|
295 | cluster_xy = (x << y_width) + y; |
---|
296 | |
---|
297 | ### Global vsegs kernel_ptab_x_y: non local / big pages |
---|
298 | ### replicated in all clusters with name indexed by (x,y) |
---|
299 | ### as vbase address is incremented by (cluster_xy * vseg_increment) |
---|
300 | offset = cluster_xy * ptab_increment |
---|
301 | mapping.addGlobal( 'seg_kernel_ptab_%d_%d' %(x,y), kernel_ptab_vbase + offset, kernel_ptab_size, |
---|
302 | 'CXW_', vtype = 'PTAB', x = x, y = y, pseg = 'RAM', |
---|
303 | local = False, big = True ) |
---|
304 | |
---|
305 | ### global vsegs kernel_sched : non local / small pages |
---|
306 | ### allocated in all clusters with name indexed by (x,y) |
---|
307 | ### as vbase address is incremented by (cluster_xy * vseg_increment) |
---|
308 | offset = cluster_xy * sched_increment |
---|
309 | mapping.addGlobal( 'seg_kernel_sched_%d_%d' %(x,y), kernel_sched_vbase + offset , kernel_sched_size, |
---|
310 | 'C_W_', vtype = 'SCHED', x = x, y = y, pseg = 'RAM', |
---|
311 | local = False, big = False ) |
---|
312 | |
---|
313 | ### global vseg for ram disk |
---|
314 | if use_ramdisk: |
---|
315 | mapping.addGlobal( 'seg_rdk', rdk_base, rdk_size, '__W_', |
---|
316 | vtype = 'BUFFER', x = 0, y = 0, pseg = 'RAM', |
---|
317 | identity = True, local = False, big = True ) |
---|
318 | |
---|
319 | ### global vsegs for external peripherals: non local / big page |
---|
320 | mapping.addGlobal( 'seg_bdv', bdv_base, bdv_size, '__W_', |
---|
321 | vtype = 'PERI', x = 0, y = 0, pseg = 'BDV', |
---|
322 | local = False, big = True ) |
---|
323 | |
---|
324 | mapping.addGlobal( 'seg_tty', tty_base, tty_size, '__W_', |
---|
325 | vtype = 'PERI', x = 0, y = 0, pseg = 'TTY', |
---|
326 | local = False, big = True ) |
---|
327 | |
---|
328 | mapping.addGlobal( 'seg_nic', nic_base, nic_size, '__W_', |
---|
329 | vtype = 'PERI', x = 0, y = 0, pseg = 'NIC', |
---|
330 | local = False, big = True ) |
---|
331 | |
---|
332 | mapping.addGlobal( 'seg_cma', cma_base, cma_size, '__W_', |
---|
333 | vtype = 'PERI', x = 0, y = 0, pseg = 'CMA', |
---|
334 | local = False, big = True ) |
---|
335 | |
---|
336 | mapping.addGlobal( 'seg_fbf', fbf_base, fbf_size, '__W_', |
---|
337 | vtype = 'PERI', x = 0, y = 0, pseg = 'FBF', |
---|
338 | local = False, big = True ) |
---|
339 | |
---|
340 | mapping.addGlobal( 'seg_pic', pic_base, pic_size, '__W_', |
---|
341 | vtype = 'PERI', x = 0, y = 0, pseg = 'PIC', |
---|
342 | local = False, big = True ) |
---|
343 | |
---|
344 | ### global vsegs for internal peripherals : non local / small pages |
---|
345 | ### allocated in all clusters with name indexed by (x,y) |
---|
346 | ### as vbase address is incremented by (cluster_xy * vseg_increment) |
---|
347 | for x in xrange( x_size ): |
---|
348 | for y in xrange( y_size ): |
---|
349 | offset = ((x << y_width) + y) * peri_increment |
---|
350 | |
---|
351 | mapping.addGlobal( 'seg_xcu_%d_%d' %(x,y), xcu_base + offset, xcu_size, |
---|
352 | '__W_', vtype = 'PERI' , x = x , y = y , pseg = 'XCU', |
---|
353 | local = False, big = False ) |
---|
354 | |
---|
355 | mapping.addGlobal( 'seg_mmc_%d_%d' %(x,y), mmc_base + offset, mmc_size, |
---|
356 | '__W_', vtype = 'PERI' , x = x , y = y , pseg = 'MMC', |
---|
357 | local = False, big = False ) |
---|
358 | |
---|
359 | ### return mapping ### |
---|
360 | |
---|
361 | return mapping |
---|
362 | |
---|
363 | ################################# platform test ####################################################### |
---|
364 | |
---|
365 | if __name__ == '__main__': |
---|
366 | |
---|
367 | mapping = arch( x_size = 2, |
---|
368 | y_size = 2, |
---|
369 | nb_procs = 2 ) |
---|
370 | |
---|
371 | # print mapping.netbsd_dts() |
---|
372 | |
---|
373 | print mapping.xml() |
---|
374 | |
---|
375 | # print mapping.giet_vsegs() |
---|
376 | |
---|
377 | |
---|
378 | # Local Variables: |
---|
379 | # tab-width: 4; |
---|
380 | # c-basic-offset: 4; |
---|
381 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); |
---|
382 | # indent-tabs-mode: nil; |
---|
383 | # End: |
---|
384 | # |
---|
385 | # vim: filetype=python:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
386 | |
---|