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_xbar architecture) |
---|
8 | # date : march 2015 |
---|
9 | # author : Manuel Bouyer |
---|
10 | ################################################################################## |
---|
11 | # This file contains a mapping generator for the "tsar_generic_xbar" platform. |
---|
12 | # This includes both the hardware architecture (clusters, processors, peripherals, |
---|
13 | # physical space segmentation) and the mapping of all boot and kernel objects |
---|
14 | # (global vsegs). |
---|
15 | # |
---|
16 | # This platform includes 7 external peripherals, located in the [x_io, x_io] |
---|
17 | # cluster. |
---|
18 | # Available peripherals are: TTY, IOC, FBF, ROM, NIC, CMA, PIC. |
---|
19 | # |
---|
20 | # All clusters contain (nb_procs) processors, one L2 cache, one XCU, and |
---|
21 | # one optional hardware coprocessor connected to a MWMR_DMA controller. |
---|
22 | # |
---|
23 | # The "constructor" parameters (defined in Makefile) are: |
---|
24 | # - x_size : number of clusters in a row |
---|
25 | # - y_size : number of clusters in a column |
---|
26 | # - nb_procs : number of processors per cluster |
---|
27 | # - nb_ttys : number of TTY channels |
---|
28 | # - fbf_width : frame_buffer width = frame_buffer heigth |
---|
29 | # - ioc_type : can be 'BDV','HBA','SDC', 'SPI' but not 'RDK' |
---|
30 | # - mwr_type : coprocessor type / only 'NONE' is supported |
---|
31 | # |
---|
32 | # The other hardware parameters (defined in this script) are: |
---|
33 | # - nb_nics : number of NIC channels |
---|
34 | # - nb_cmas : number of CMA channels |
---|
35 | # - x_io : cluster_io x coordinate |
---|
36 | # - y_io : cluster_io y coordinate |
---|
37 | # - x_width : number of bits for x coordinate |
---|
38 | # - y_width : number of bits for y coordinate |
---|
39 | # - p_width : number of bits for processor local index |
---|
40 | # - paddr_width : number of bits for physical address |
---|
41 | # - irq_per_proc : number of input IRQs per processor |
---|
42 | # - peri_increment : address increment for replicated peripherals |
---|
43 | # |
---|
44 | # Regarding the boot and kernel vsegs mapping : |
---|
45 | # - We use one big physical page (2 Mbytes) for the preloader, |
---|
46 | # the 4 boot vsegs are packed in one BPP allocated in cluster[0,0]. |
---|
47 | # - We use one BPP per cluster for the replicated kernel code vsegs. |
---|
48 | # - We use one BPP in cluster[0][0] for the kernel data vseg. |
---|
49 | # - We use two BPP per cluster for the distributed kernel heap vsegs. |
---|
50 | # - We use one BPP per cluster for the distributed ptab vsegs. |
---|
51 | # - We use two SPP per cluster for each schedulers. |
---|
52 | # - We use one PBB for each external peripheral in IO cluster, |
---|
53 | # - We use one SPP per cluster for each internal peripheral. |
---|
54 | ################################################################################## |
---|
55 | |
---|
56 | ######################## |
---|
57 | def arch( x_size = 1, |
---|
58 | y_size = 1, |
---|
59 | nb_procs = 4, |
---|
60 | nb_ttys = 1, |
---|
61 | fbf_width = 128, |
---|
62 | ioc_type = 'BDV', |
---|
63 | mwr_type = 'NONE' ): |
---|
64 | |
---|
65 | ### define architecture constants |
---|
66 | |
---|
67 | nb_nics = 0 |
---|
68 | nb_cmas = 4 |
---|
69 | x_io = 0 |
---|
70 | y_io = 0 |
---|
71 | x_width = 2 |
---|
72 | y_width = 6 |
---|
73 | p_width = 4 |
---|
74 | paddr_width = 40 |
---|
75 | irq_per_proc = 4 |
---|
76 | peri_increment = 0x10000 |
---|
77 | |
---|
78 | ### constructor parameters checking |
---|
79 | |
---|
80 | assert( nb_procs <= (1 << p_width) ) |
---|
81 | |
---|
82 | assert( (x_size == 1) or (x_size == 2) or (x_size == 4) |
---|
83 | or (x_size == 8) or (x_size == 16) ) |
---|
84 | |
---|
85 | assert( (y_size == 1) or (y_size == 2) or (y_size == 4) |
---|
86 | or (y_size == 8) or (y_size == 16) ) |
---|
87 | |
---|
88 | assert( (nb_ttys >= 1) and (nb_ttys <= 16) ) |
---|
89 | |
---|
90 | assert( ((x_io >= 0) and (y_io >= 0)) and |
---|
91 | ((x_io < x_size) and (y_io < y_size)) ) |
---|
92 | |
---|
93 | assert( ioc_type in [ 'BDV' , 'HBA' , 'SDC' , 'SPI' ] ) |
---|
94 | |
---|
95 | assert( mwr_type in [ 'NONE' ] ) |
---|
96 | |
---|
97 | ### define platform name |
---|
98 | |
---|
99 | platform_name = 'tsar_xbar_%d_%d_%d' % ( x_size, y_size , nb_procs ) |
---|
100 | platform_name += '_%d_%d_%s' % ( fbf_width , nb_ttys , ioc_type ) |
---|
101 | |
---|
102 | ### define physical segments replicated in all clusters |
---|
103 | |
---|
104 | ram_base = 0x0000000000 |
---|
105 | ram_size = 0x4000000 # 64 Mbytes |
---|
106 | |
---|
107 | xcu_base = 0x00B0000000 |
---|
108 | xcu_size = 0x1000 # 4 Kbytes |
---|
109 | |
---|
110 | mmc_base = 0x00B2000000 |
---|
111 | mmc_size = 0x1000 # 4 Kbytes |
---|
112 | |
---|
113 | ### define physical segments for peripherals |
---|
114 | ## These segments are only defined in cluster_io |
---|
115 | |
---|
116 | ioc_base = 0x00B3000000 |
---|
117 | ioc_size = 0x1000 # 4 Kbytes |
---|
118 | |
---|
119 | tty_base = 0x00B4000000 |
---|
120 | tty_size = 0x4000 # 16 Kbytes |
---|
121 | |
---|
122 | nic_base = 0x00B5000000 |
---|
123 | nic_size = 0x80000 # 512 kbytes |
---|
124 | |
---|
125 | cma_base = 0x00B6000000 |
---|
126 | cma_size = 0x1000 * nb_cmas # 4 kbytes * nb_cmas |
---|
127 | |
---|
128 | fbf_base = 0x00B7000000 |
---|
129 | fbf_size = fbf_width * fbf_width # fbf_width * fbf_width bytes |
---|
130 | |
---|
131 | sim_base = 0x00B8000000 |
---|
132 | sim_size = 0x1000 # 4 Kbytes |
---|
133 | |
---|
134 | rom_base = 0x00BFC00000 |
---|
135 | rom_size = 0x4000 # 16 Kbytes |
---|
136 | |
---|
137 | ### define bootloader vsegs base addresses and sizes |
---|
138 | ### We want to pack these 4 vsegs in 2 big pages |
---|
139 | ### => boot cost two BIG pages in cluster[0][0] |
---|
140 | |
---|
141 | boot_mapping_vbase = 0x00000000 # ident |
---|
142 | boot_mapping_size = 0x00100000 # 1 Mbytes |
---|
143 | |
---|
144 | boot_code_vbase = 0x00100000 # ident |
---|
145 | boot_code_size = 0x00080000 # 512 Kbytes |
---|
146 | |
---|
147 | boot_stack_vbase = 0x00180000 # ident |
---|
148 | boot_stack_size = 0x00080000 # 512 Kbytes |
---|
149 | |
---|
150 | boot_data_vbase = 0x00200000 # ident |
---|
151 | boot_data_size = 0x00200000 # 2 Mbytes |
---|
152 | |
---|
153 | ### define kernel vsegs base addresses and sizes |
---|
154 | ### code, init, ptab, heap & sched vsegs are replicated in all clusters. |
---|
155 | ### data & uncdata vsegs are only mapped in cluster[0][0]. |
---|
156 | |
---|
157 | kernel_code_vbase = 0x80000000 |
---|
158 | kernel_code_size = 0x00200000 # 2 Mbytes per cluster |
---|
159 | |
---|
160 | kernel_data_vbase = 0x90000000 |
---|
161 | kernel_data_size = 0x00200000 # 2 Mbytes in cluster[0,0] |
---|
162 | |
---|
163 | kernel_ptab_vbase = 0xE0000000 |
---|
164 | kernel_ptab_size = 0x00200000 # 2 Mbytes per cluster |
---|
165 | |
---|
166 | kernel_heap_vbase = 0xC0000000 |
---|
167 | kernel_heap_size = 0x00400000 # 4 Mbytes per cluster |
---|
168 | |
---|
169 | kernel_sched_vbase = 0xA0000000 |
---|
170 | kernel_sched_size = 0x00002000*nb_procs # 8 Kbytes per proc per cluster |
---|
171 | |
---|
172 | ######################### |
---|
173 | ### create mapping |
---|
174 | ######################### |
---|
175 | |
---|
176 | mapping = Mapping( name = platform_name, |
---|
177 | x_size = x_size, |
---|
178 | y_size = y_size, |
---|
179 | nprocs = nb_procs, |
---|
180 | x_width = x_width, |
---|
181 | y_width = y_width, |
---|
182 | p_width = p_width, |
---|
183 | paddr_width = paddr_width, |
---|
184 | coherence = True, |
---|
185 | irq_per_proc = irq_per_proc, |
---|
186 | use_ramdisk = (ioc_type == 'RDK'), |
---|
187 | x_io = x_io, |
---|
188 | y_io = y_io, |
---|
189 | peri_increment = peri_increment, |
---|
190 | ram_base = ram_base, |
---|
191 | ram_size = ram_size ) |
---|
192 | |
---|
193 | |
---|
194 | ############################# |
---|
195 | ### Hardware Components |
---|
196 | ############################# |
---|
197 | |
---|
198 | for x in xrange( x_size ): |
---|
199 | for y in xrange( y_size ): |
---|
200 | cluster_xy = (x << y_width) + y; |
---|
201 | offset = cluster_xy << (paddr_width - x_width - y_width) |
---|
202 | |
---|
203 | ### components replicated in all clusters |
---|
204 | mapping.addRam( 'RAM', base = ram_base + offset, |
---|
205 | size = ram_size ) |
---|
206 | |
---|
207 | xcu = mapping.addPeriph( 'XCU', base = xcu_base + offset, |
---|
208 | size = xcu_size, ptype = 'XCU', |
---|
209 | channels = nb_procs * irq_per_proc, |
---|
210 | arg0 = 32, arg1 = 32, arg2 = 32 ) |
---|
211 | mmc = mapping.addPeriph( 'MMC', base = mmc_base + offset, |
---|
212 | size = mmc_size, ptype = 'MMC' ) |
---|
213 | |
---|
214 | for p in xrange ( nb_procs ): |
---|
215 | mapping.addProc( x , y , p ) |
---|
216 | |
---|
217 | ### peripherals in cluster_io |
---|
218 | if ( (x==x_io) and (y==y_io) ): |
---|
219 | |
---|
220 | ioc = mapping.addPeriph( 'IOC', base = ioc_base + offset, size = ioc_size, |
---|
221 | ptype = 'IOC', subtype = ioc_type ) |
---|
222 | |
---|
223 | if ( ioc_type == 'BDV' ): isr_type = 'ISR_BDV' |
---|
224 | elif ( ioc_type == 'HBA' ): isr_type = 'ISR_HBA' |
---|
225 | elif ( ioc_type == 'SPI' ): isr_type = 'ISR_SPI' |
---|
226 | elif ( ioc_type == 'SDC' ): isr_type = 'ISR_SDC' |
---|
227 | mapping.addIrq( xcu, index = 31, src = ioc, isrtype = isr_type, channel = 0 ) |
---|
228 | |
---|
229 | tty = mapping.addPeriph( 'TTY', base = tty_base + offset, size = tty_size, |
---|
230 | ptype = 'TTY', channels = nb_ttys ) |
---|
231 | for t in xrange( nb_ttys ): |
---|
232 | mapping.addIrq( xcu, index = 16 + t, src = tty, isrtype = 'ISR_TTY_RX', channel = t ) |
---|
233 | |
---|
234 | nic = mapping.addPeriph( 'NIC', base = nic_base + offset, size = nic_size, |
---|
235 | ptype = 'NIC', channels = nb_nics ) |
---|
236 | |
---|
237 | #mapping.addIrq( xcu, index = xcu_index, src = nic, |
---|
238 | # isrtype = 'ISR_NIC_RX', channel = 0 ) |
---|
239 | #mapping.addIrq( xcu, index = xcu_index, src = nic, |
---|
240 | # isrtype = 'ISR_NIC_RX', channel = 1 ) |
---|
241 | #mapping.addIrq( xcu, index = xcu_index, src = nic, |
---|
242 | # isrtype = 'ISR_NIC_TX', channel = 0 ) |
---|
243 | #mapping.addIrq( xcu, index = xcu_index, src = nic, |
---|
244 | # isrtype = 'ISR_NIC_TX', channel = 1 ) |
---|
245 | |
---|
246 | cma = mapping.addPeriph( 'CMA', base = cma_base + offset, size = cma_size, |
---|
247 | ptype = 'CMA', channels = nb_cmas ) |
---|
248 | #mapping.addIrq( xcu, index = xcu_index, src = cma, |
---|
249 | # isrtype = 'ISR_CMA', channel = 0 ) |
---|
250 | #mapping.addIrq( xcu, index = xcu_index, src = cma, |
---|
251 | # isrtype = 'ISR_CMA', channel = 1 ) |
---|
252 | #mapping.addIrq( xcu, index = xcu_index, src = cma, |
---|
253 | # isrtype = 'ISR_CMA', channel = 2 ) |
---|
254 | #mapping.addIrq( xcu, index = xcu_index, src = cma, |
---|
255 | # isrtype = 'ISR_CMA', channel = 3 ) |
---|
256 | |
---|
257 | fbf = mapping.addPeriph( 'FBF', base = fbf_base + offset, size = fbf_size, |
---|
258 | ptype = 'FBF', arg0 = fbf_width, arg1 = fbf_width ) |
---|
259 | |
---|
260 | rom = mapping.addPeriph( 'ROM', base = rom_base + offset, size = rom_size, |
---|
261 | ptype = 'ROM' ) |
---|
262 | |
---|
263 | sim = mapping.addPeriph( 'SIM', base = sim_base + offset, size = sim_size, |
---|
264 | ptype = 'SIM') |
---|
265 | |
---|
266 | #################################### |
---|
267 | ### Boot & Kernel vsegs mapping |
---|
268 | #################################### |
---|
269 | |
---|
270 | ### global vsegs for boot_loader |
---|
271 | ### we want to pack those 4 vsegs in the same big page |
---|
272 | ### => same flags CXW_ / identity mapping / non local / big page |
---|
273 | |
---|
274 | mapping.addGlobal( 'seg_boot_mapping', boot_mapping_vbase, boot_mapping_size, |
---|
275 | 'CXW_', vtype = 'BLOB' , x = 0, y = 0, pseg = 'RAM', |
---|
276 | identity = True , local = False, big = True ) |
---|
277 | |
---|
278 | mapping.addGlobal( 'seg_boot_code', boot_code_vbase, boot_code_size, |
---|
279 | 'CXW_', vtype = 'BUFFER', x = 0, y = 0, pseg = 'RAM', |
---|
280 | identity = True , local = False, big = True ) |
---|
281 | |
---|
282 | mapping.addGlobal( 'seg_boot_data', boot_data_vbase, boot_data_size, |
---|
283 | 'CXW_', vtype = 'BUFFER', x = 0, y = 0, pseg = 'RAM', |
---|
284 | identity = True , local = False, big = True ) |
---|
285 | |
---|
286 | mapping.addGlobal( 'seg_boot_stack', boot_stack_vbase, boot_stack_size, |
---|
287 | 'CXW_', vtype = 'BUFFER', x = 0, y = 0, pseg = 'RAM', |
---|
288 | identity = True , local = False, big = True ) |
---|
289 | |
---|
290 | ### global vseg kernel_data : big / non local |
---|
291 | ### Only mapped in cluster[0][0] |
---|
292 | mapping.addGlobal( 'seg_kernel_data', kernel_data_vbase, kernel_data_size, |
---|
293 | 'CXW_', vtype = 'ELF', x = 0, y = 0, pseg = 'RAM', |
---|
294 | binpath = 'bin/kernel/kernel.elf', |
---|
295 | local = False, big = True ) |
---|
296 | |
---|
297 | ### global vsegs kernel_code : big / local |
---|
298 | ### replicated in all clusters with indexed name & same vbase |
---|
299 | for x in xrange( x_size ): |
---|
300 | for y in xrange( y_size ): |
---|
301 | mapping.addGlobal( 'seg_kernel_code_%d_%d' %(x,y), |
---|
302 | kernel_code_vbase, kernel_code_size, |
---|
303 | 'CXW_', vtype = 'ELF', x = x , y = y , pseg = 'RAM', |
---|
304 | binpath = 'bin/kernel/kernel.elf', |
---|
305 | local = True, big = True ) |
---|
306 | |
---|
307 | ### Global vsegs kernel_ptab_x_y : big / non local |
---|
308 | ### one vseg per cluster: name indexed by (x,y) |
---|
309 | for x in xrange( x_size ): |
---|
310 | for y in xrange( y_size ): |
---|
311 | offset = ((x << y_width) + y) * kernel_ptab_size |
---|
312 | base = kernel_ptab_vbase + offset |
---|
313 | mapping.addGlobal( 'seg_kernel_ptab_%d_%d' %(x,y), base, kernel_ptab_size, |
---|
314 | 'CXW_', vtype = 'PTAB', x = x, y = y, pseg = 'RAM', |
---|
315 | local = False , big = True ) |
---|
316 | |
---|
317 | ### global vsegs kernel_sched_x_y : small / non local |
---|
318 | ### one vseg per cluster with name indexed by (x,y) |
---|
319 | for x in xrange( x_size ): |
---|
320 | for y in xrange( y_size ): |
---|
321 | offset = ((x << y_width) + y) * kernel_sched_size |
---|
322 | mapping.addGlobal( 'seg_kernel_sched_%d_%d' %(x,y), |
---|
323 | 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 vsegs kernel_heap_x_y : big / non local |
---|
328 | ### one vseg per cluster with name indexed by (x,y) |
---|
329 | for x in xrange( x_size ): |
---|
330 | for y in xrange( y_size ): |
---|
331 | offset = ((x << y_width) + y) * kernel_heap_size |
---|
332 | mapping.addGlobal( 'seg_kernel_heap_%d_%d' %(x,y), |
---|
333 | kernel_heap_vbase + offset , kernel_heap_size, |
---|
334 | 'C_W_', vtype = 'HEAP', x = x , y = y , pseg = 'RAM', |
---|
335 | local = False, big = True ) |
---|
336 | |
---|
337 | ### global vsegs for external peripherals : non local / big page |
---|
338 | mapping.addGlobal( 'seg_ioc', ioc_base, ioc_size, '__W_', |
---|
339 | vtype = 'PERI', x = 0, y = 0, pseg = 'IOC', |
---|
340 | local = False, big = True ) |
---|
341 | |
---|
342 | mapping.addGlobal( 'seg_tty', tty_base, tty_size, '__W_', |
---|
343 | vtype = 'PERI', x = 0, y = 0, pseg = 'TTY', |
---|
344 | local = False, big = True ) |
---|
345 | |
---|
346 | mapping.addGlobal( 'seg_nic', nic_base, nic_size, '__W_', |
---|
347 | vtype = 'PERI', x = 0, y = 0, pseg = 'NIC', |
---|
348 | local = False, big = True ) |
---|
349 | |
---|
350 | mapping.addGlobal( 'seg_cma', cma_base, cma_size, '__W_', |
---|
351 | vtype = 'PERI', x = 0, y = 0, pseg = 'CMA', |
---|
352 | local = False, big = True ) |
---|
353 | |
---|
354 | mapping.addGlobal( 'seg_fbf', fbf_base, fbf_size, '__W_', |
---|
355 | vtype = 'PERI', x = 0, y = 0, pseg = 'FBF', |
---|
356 | local = False, big = True ) |
---|
357 | |
---|
358 | mapping.addGlobal( 'seg_sim', sim_base, sim_size, '__W_', |
---|
359 | vtype = 'PERI', x = 0, y = 0, pseg = 'SIM', |
---|
360 | local = False, big = True ) |
---|
361 | |
---|
362 | mapping.addGlobal( 'seg_rom', rom_base, rom_size, 'CXW_', |
---|
363 | vtype = 'PERI', x = 0, y = 0, pseg = 'ROM', |
---|
364 | local = False, big = True ) |
---|
365 | |
---|
366 | ### global vsegs for internal peripherals : non local / small pages |
---|
367 | ### allocated in all clusters with name indexed by (x,y) |
---|
368 | ### as vbase address is incremented by (cluster_xy * vseg_increment) |
---|
369 | for x in xrange( x_size ): |
---|
370 | for y in xrange( y_size ): |
---|
371 | offset = ((x << y_width) + y) * peri_increment |
---|
372 | |
---|
373 | mapping.addGlobal( 'seg_xcu_%d_%d' %(x,y), xcu_base + offset, xcu_size, |
---|
374 | '__W_', vtype = 'PERI' , x = x , y = y , pseg = 'XCU', |
---|
375 | local = False, big = False ) |
---|
376 | |
---|
377 | mapping.addGlobal( 'seg_mmc_%d_%d' %(x,y), mmc_base + offset, mmc_size, |
---|
378 | '__W_', vtype = 'PERI' , x = x , y = y , pseg = 'MMC', |
---|
379 | local = False, big = False ) |
---|
380 | |
---|
381 | return mapping |
---|
382 | |
---|
383 | ################################# platform test #################################### |
---|
384 | |
---|
385 | if __name__ == '__main__': |
---|
386 | |
---|
387 | mapping = arch( x_size = 2, |
---|
388 | y_size = 2, |
---|
389 | nb_procs = 2 ) |
---|
390 | |
---|
391 | # print mapping.netbsd_dts() |
---|
392 | |
---|
393 | print mapping.xml() |
---|
394 | |
---|
395 | # print mapping.giet_vsegs() |
---|
396 | |
---|
397 | |
---|
398 | # Local Variables: |
---|
399 | # tab-width: 4; |
---|
400 | # c-basic-offset: 4; |
---|
401 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); |
---|
402 | # indent-tabs-mode: nil; |
---|
403 | # End: |
---|
404 | # |
---|
405 | # vim: filetype=python:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
406 | |
---|