1 | #!/usr/bin/env python2.7 |
---|
2 | """This file contains a mapping generator for the tsar_generic_iob platform""" |
---|
3 | |
---|
4 | from math import log |
---|
5 | from mapping import Mapping |
---|
6 | |
---|
7 | ################################################################################ |
---|
8 | # file : arch.py (for the tsar_generic_iob architecture) |
---|
9 | # date : may 2014 |
---|
10 | # author : Alain Greiner |
---|
11 | # |
---|
12 | # modified by: |
---|
13 | # Cesar Fuguet |
---|
14 | # - Adding distributed ROMs used by the distributed reconfiguration |
---|
15 | # procedure |
---|
16 | # |
---|
17 | ################################################################################ |
---|
18 | # This platform includes 6 external peripherals, accessible through two |
---|
19 | # IO_Bridge components located in cluster [0,0] and cluster [x_size-1, |
---|
20 | # y_size-1]. Available peripherals are: TTY, BDV, FBF, ROM, NIC, CMA. |
---|
21 | # |
---|
22 | # The "constructor" parameters are: |
---|
23 | # - x_size : number of clusters in a row |
---|
24 | # - y_size : number of clusters in a column |
---|
25 | # - nb_procs : number of processors per cluster |
---|
26 | # - nb_ttys : number of TTY channels |
---|
27 | # - fbf_width : frame_buffer width = frame_buffer heigth |
---|
28 | # |
---|
29 | # The "hidden" parameters (defined below) are: |
---|
30 | # - NB_NICS : number of NIC channels |
---|
31 | # - X_IO : cluster_io x coordinate |
---|
32 | # - Y_IO : cluster_io y coordinate |
---|
33 | # - X_WIDTH : number of bits for x coordinate |
---|
34 | # - Y_WIDTH : number of bits for y coordinate |
---|
35 | # - P_WIDTH : number of bits for processor local id field |
---|
36 | # - PADDR_WIDTH : number of bits for physical address |
---|
37 | # - IRQ_PER_PROC : number of input IRQs per processor |
---|
38 | # - USE_RAMDISK : use a ramdisk when True |
---|
39 | # - PERI_INCREMENT : virtual address increment for replicated peripherals |
---|
40 | # - PTAB_INCREMENT : virtual address increment for replicated page tables |
---|
41 | # - SCHED_INCREMENT: virtual address increment for replicated schedulers |
---|
42 | ################################################################################ |
---|
43 | |
---|
44 | # define architecture constants |
---|
45 | PADDR_WIDTH = 40 |
---|
46 | NB_NICS = 2 |
---|
47 | FBF_WIDTH = 128 |
---|
48 | X_WIDTH = 4 |
---|
49 | Y_WIDTH = 4 |
---|
50 | P_WIDTH = 2 |
---|
51 | X_IO = 0 |
---|
52 | Y_IO = 0 |
---|
53 | IRQ_PER_PROC = 4 |
---|
54 | USE_RAMDISK = False |
---|
55 | USE_NIC = False |
---|
56 | |
---|
57 | # virtual address increment for distributed memory segments in the GietVM OS |
---|
58 | PERI_INCREMENT = 0x10000 |
---|
59 | PTAB_INCREMENT = 0x200000 |
---|
60 | SCHED_INCREMENT = 0x10000 |
---|
61 | |
---|
62 | def pmsb(x, y): |
---|
63 | """This function returns the physical most signicant bits for the |
---|
64 | cluster(x,y)""" |
---|
65 | |
---|
66 | return (x << Y_WIDTH) | y |
---|
67 | |
---|
68 | def arch(x_size=2, |
---|
69 | y_size=2, |
---|
70 | nb_procs=4, |
---|
71 | nb_ttys=1, |
---|
72 | fbf_width=FBF_WIDTH, |
---|
73 | ioc_type='BDV'): |
---|
74 | """This function describes the tsar_generic_iob platform and defines its |
---|
75 | parameters""" |
---|
76 | |
---|
77 | # parameters checking |
---|
78 | assert (nb_procs <= (1 << P_WIDTH)) |
---|
79 | |
---|
80 | assert ((x_size >= 1) and (x_size <= (1 << X_WIDTH))) |
---|
81 | |
---|
82 | assert ((y_size >= 1) and (y_size <= (1 << Y_WIDTH))) |
---|
83 | |
---|
84 | assert ((nb_ttys >= 1) and (nb_ttys <= 16)) |
---|
85 | |
---|
86 | assert (((X_IO == 0) and (Y_IO == 0)) or |
---|
87 | ((X_IO == (x_size - 1)) and (Y_IO == (y_size - 1)))) |
---|
88 | |
---|
89 | platform_name = 'reconf-tsar_iob_%d_%d_%d' % (x_size, y_size, nb_procs) |
---|
90 | |
---|
91 | # define physical segments |
---|
92 | ram_base = 0x0000000000 |
---|
93 | ram_size = 0x4000000 / (x_size * y_size) |
---|
94 | |
---|
95 | xcu_base = 0x00B0000000 |
---|
96 | xcu_size = 0x1000 # 4 Kbytes |
---|
97 | |
---|
98 | dma_base = 0x00B1000000 |
---|
99 | dma_size = 0x1000 * nb_procs # 4 Kbytes * nb_procs |
---|
100 | |
---|
101 | mmc_base = 0x00B2000000 |
---|
102 | mmc_size = 0x1000 # 4 Kbytes |
---|
103 | |
---|
104 | drom_base = 0x00BFC00000 |
---|
105 | drom_size = 0x8000 # 32 Kbytes |
---|
106 | |
---|
107 | offset_io = pmsb(X_IO, Y_IO) << (PADDR_WIDTH - X_WIDTH - Y_WIDTH) |
---|
108 | |
---|
109 | bdv_base = 0x00B3000000 + offset_io |
---|
110 | bdv_size = 0x1000 # 4 kbytes |
---|
111 | |
---|
112 | tty_base = 0x00B4000000 + offset_io |
---|
113 | tty_size = 0x1000 # 4 Kbytes |
---|
114 | |
---|
115 | nic_base = 0x00B5000000 + offset_io |
---|
116 | nic_size = 0x80000 # 512 kbytes |
---|
117 | |
---|
118 | cma_base = 0x00B6000000 + offset_io |
---|
119 | cma_size = 0x1000 * 2 * NB_NICS # 4 kbytes * 2 * NB_NICS |
---|
120 | |
---|
121 | fbf_base = 0x00B7000000 + offset_io |
---|
122 | fbf_size = fbf_width * fbf_width # fbf_width * fbf_width bytes |
---|
123 | |
---|
124 | pic_base = 0x00B8000000 + offset_io |
---|
125 | pic_size = 0x1000 # 4 Kbytes |
---|
126 | |
---|
127 | sim_base = 0x00B9000000 + offset_io |
---|
128 | sim_size = 0x1000 # 4 kbytes |
---|
129 | |
---|
130 | iob_base = 0x00BE000000 + offset_io |
---|
131 | iob_size = 0x1000 # 4 kbytes |
---|
132 | |
---|
133 | rom_base = 0x00BA000000 |
---|
134 | rom_size = 0x8000 # 32 Kbytes |
---|
135 | |
---|
136 | # create mapping |
---|
137 | mapping = Mapping(name=platform_name, |
---|
138 | x_size=x_size, |
---|
139 | y_size=y_size, |
---|
140 | nprocs=nb_procs, |
---|
141 | x_width=X_WIDTH, |
---|
142 | y_width=Y_WIDTH, |
---|
143 | p_width=P_WIDTH, |
---|
144 | paddr_width=PADDR_WIDTH, |
---|
145 | coherence=True, |
---|
146 | irq_per_proc=IRQ_PER_PROC, |
---|
147 | use_ramdisk=USE_RAMDISK, |
---|
148 | x_io=X_IO, |
---|
149 | y_io=Y_IO, |
---|
150 | peri_increment=PERI_INCREMENT, |
---|
151 | ram_base=ram_base, |
---|
152 | ram_size=ram_size) |
---|
153 | |
---|
154 | # external peripherals (accessible in cluster[0,0] only for this mapping) |
---|
155 | pic = mapping.addPeriph('PIC', base=pic_base, size=pic_size, |
---|
156 | ptype='PIC', channels=32) |
---|
157 | |
---|
158 | mapping.addPeriph('IOB', base=iob_base, size=iob_size, |
---|
159 | ptype='IOB') |
---|
160 | |
---|
161 | bdv = mapping.addPeriph('BDV', base=bdv_base, size=bdv_size, |
---|
162 | ptype='IOC', subtype='BDV') |
---|
163 | |
---|
164 | mapping.addIrq(pic, index=8, src=bdv, isrtype='ISR_BDV', channel=0) |
---|
165 | |
---|
166 | tty = mapping.addPeriph('TTY', base=tty_base, size=tty_size, |
---|
167 | ptype='TTY', channels=nb_ttys) |
---|
168 | |
---|
169 | for i in xrange(nb_ttys): |
---|
170 | mapping.addIrq(pic, index=16+i, src=tty, isrtype='ISR_TTY_RX', channel=i) |
---|
171 | |
---|
172 | if USE_NIC: |
---|
173 | nic = mapping.addPeriph('NIC', base=nic_base, size=nic_size, |
---|
174 | ptype='NIC', channels=NB_NICS) |
---|
175 | |
---|
176 | mapping.addIrq(pic, index=0, src=nic, isrtype='ISR_NIC_RX', channel=0) |
---|
177 | mapping.addIrq(pic, index=1, src=nic, isrtype='ISR_NIC_RX', channel=1) |
---|
178 | mapping.addIrq(pic, index=2, src=nic, isrtype='ISR_NIC_TX', channel=0) |
---|
179 | mapping.addIrq(pic, index=3, src=nic, isrtype='ISR_NIC_TX', channel=1) |
---|
180 | |
---|
181 | cma = mapping.addPeriph('CMA', base=cma_base, size=cma_size, |
---|
182 | ptype='CMA', channels=2*NB_NICS) |
---|
183 | |
---|
184 | mapping.addIrq(pic, index=4, src=cma, isrtype='ISR_CMA', channel=0) |
---|
185 | mapping.addIrq(pic, index=5, src=cma, isrtype='ISR_CMA', channel=1) |
---|
186 | mapping.addIrq(pic, index=6, src=cma, isrtype='ISR_CMA', channel=2) |
---|
187 | mapping.addIrq(pic, index=7, src=cma, isrtype='ISR_CMA', channel=3) |
---|
188 | |
---|
189 | mapping.addPeriph('FBF', base=fbf_base, size=fbf_size, |
---|
190 | ptype='FBF', arg0=fbf_width, arg1=fbf_width) |
---|
191 | |
---|
192 | mapping.addPeriph('SIM', base=sim_base, size=sim_size, |
---|
193 | ptype='SIM') |
---|
194 | |
---|
195 | mapping.addPeriph('ROM', base=rom_base, size=rom_size, |
---|
196 | ptype='ROM') |
---|
197 | |
---|
198 | # hardware components replicated in all clusters |
---|
199 | for x in xrange(x_size): |
---|
200 | for y in xrange(y_size): |
---|
201 | offset = pmsb(x, y) << (PADDR_WIDTH - X_WIDTH - Y_WIDTH) |
---|
202 | |
---|
203 | mapping.addRam('RAM', base=ram_base + offset, size=ram_size) |
---|
204 | |
---|
205 | mapping.addPeriph('DROM', base=drom_base + offset, size=drom_size, |
---|
206 | ptype='DROM') |
---|
207 | |
---|
208 | mmc = mapping.addPeriph('MMC', base=mmc_base + offset, size=mmc_size, |
---|
209 | ptype='MMC') |
---|
210 | |
---|
211 | dma = mapping.addPeriph('DMA', base=dma_base + offset, |
---|
212 | size=dma_size, ptype='DMA', |
---|
213 | channels=nb_procs) |
---|
214 | |
---|
215 | xcu = mapping.addPeriph('XCU', base=xcu_base + offset, |
---|
216 | size=xcu_size, ptype='XCU', |
---|
217 | channels=nb_procs * IRQ_PER_PROC, |
---|
218 | arg0=16, arg1=16, arg2=16) |
---|
219 | |
---|
220 | # MMC IRQ replicated in all clusters |
---|
221 | mapping.addIrq(xcu, index=0, src=mmc, isrtype='ISR_MMC') |
---|
222 | |
---|
223 | # DMA IRQ replicated in all clusters |
---|
224 | for i in xrange(dma.channels): |
---|
225 | mapping.addIrq(xcu, index=1+i, src=dma, isrtype='ISR_DMA', channel=i) |
---|
226 | |
---|
227 | # processors |
---|
228 | for p in xrange(nb_procs): |
---|
229 | mapping.addProc(x, y, p) |
---|
230 | |
---|
231 | ############################################################################ |
---|
232 | # GIET_VM specifics |
---|
233 | |
---|
234 | # define bootloader vsegs base addresses |
---|
235 | bmapping_vbase = 0x00001000 # ident |
---|
236 | bmapping_size = 0x0007F000 # 508 Kbytes |
---|
237 | |
---|
238 | bcode_vbase = 0x00080000 # ident |
---|
239 | bcode_size = 0x00040000 # 256 Kbytes |
---|
240 | |
---|
241 | bdata_vbase = 0x000C0000 # ident |
---|
242 | bdata_size = 0x00080000 # 512 Kbytes |
---|
243 | |
---|
244 | bstack_vbase = 0x00140000 # ident |
---|
245 | bstack_size = 0x00050000 # 320 Kbytes |
---|
246 | |
---|
247 | # define kernel vsegs base addresses and sizes |
---|
248 | kcode_vbase = 0x80000000 |
---|
249 | kcode_size = 0x00080000 # 512 Kbytes |
---|
250 | |
---|
251 | kdata_vbase = 0x80100000 |
---|
252 | kdata_size = 0x00080000 # 512 Kbytes |
---|
253 | |
---|
254 | kinit_vbase = 0x80800000 |
---|
255 | kinit_size = 0x00080000 # 512 Kbytes |
---|
256 | |
---|
257 | kuncdata_vbase = 0x80180000 |
---|
258 | kuncdata_size = 0x00001000 # 4 Kbytes |
---|
259 | |
---|
260 | kptab_vbase = 0xC0000000 |
---|
261 | kptab_size = 0x00200000 # 512 Kbytes |
---|
262 | |
---|
263 | ksched_vbase = 0xF0000000 # distributed in all clusters |
---|
264 | ksched_size = 0x2000 * nb_procs # 8 kbytes per processor |
---|
265 | |
---|
266 | # global vsegs for boot_loader / identity mapping |
---|
267 | mapping.addGlobal('seg_boot_mapping', bmapping_vbase, bmapping_size, |
---|
268 | 'CXW_', vtype='BLOB', x=0, y=0, pseg='RAM', |
---|
269 | identity=True, local=False, big=True) |
---|
270 | |
---|
271 | mapping.addGlobal('seg_boot_code', bcode_vbase, bcode_size, |
---|
272 | 'CXW_', vtype='BUFFER', x=0, y=0, pseg='RAM', |
---|
273 | identity=True, local=False, big=True) |
---|
274 | |
---|
275 | mapping.addGlobal('seg_boot_data', bdata_vbase, bdata_size, |
---|
276 | 'CXW_', vtype='BUFFER', x=0, y=0, pseg='RAM', |
---|
277 | identity=True, local=False, big=True) |
---|
278 | |
---|
279 | mapping.addGlobal('seg_boot_stack', bstack_vbase, bstack_size, |
---|
280 | 'CXW_', vtype='BUFFER', x=0, y=0, pseg='RAM', |
---|
281 | identity=True, local=False, big=True) |
---|
282 | |
---|
283 | # the code global vsegs for kernel can be replicated in all clusters |
---|
284 | # if the page tables are distributed in all clusters. |
---|
285 | for x in xrange(x_size): |
---|
286 | for y in xrange(y_size): |
---|
287 | mapping.addGlobal('seg_kernel_code', kcode_vbase, kcode_size, |
---|
288 | 'CXW_', vtype='ELF', x=x, y=y, pseg='RAM', |
---|
289 | binpath='build/kernel/kernel.elf', |
---|
290 | local=True, big=True) |
---|
291 | |
---|
292 | mapping.addGlobal('seg_kernel_init', kinit_vbase, kinit_size, |
---|
293 | 'CXW_', vtype='ELF', x=x, y=y, pseg='RAM', |
---|
294 | binpath='build/kernel/kernel.elf', |
---|
295 | local=True, big=True) |
---|
296 | |
---|
297 | offset = pmsb(x, y) * PTAB_INCREMENT |
---|
298 | mapping.addGlobal('seg_kernel_ptab_%d_%d' % (x, y), |
---|
299 | kptab_vbase + offset, kptab_size, 'C_W_', |
---|
300 | vtype='PTAB', x=x, y=y, pseg='RAM', |
---|
301 | local=False, big=True) |
---|
302 | |
---|
303 | |
---|
304 | offset = pmsb(x, y) * SCHED_INCREMENT |
---|
305 | mapping.addGlobal('seg_kernel_sched_%d_%d' % (x, y), |
---|
306 | ksched_vbase + offset, ksched_size, 'C_W_', |
---|
307 | vtype='SCHED', x=x, y=y, pseg='RAM', |
---|
308 | local=False, big=False) |
---|
309 | |
---|
310 | # shared global vsegs for kernel |
---|
311 | mapping.addGlobal('seg_kernel_data', kdata_vbase, kdata_size, |
---|
312 | 'CXW_', vtype='ELF', x=0, y=0, pseg='RAM', |
---|
313 | binpath='build/kernel/kernel.elf', local=False, |
---|
314 | big=True) |
---|
315 | |
---|
316 | mapping.addGlobal('seg_kernel_uncdata', kuncdata_vbase, kuncdata_size, |
---|
317 | 'CXW_', vtype='ELF', x=0, y=0, pseg='RAM', |
---|
318 | binpath='build/kernel/kernel.elf', local=False, |
---|
319 | big=True) |
---|
320 | |
---|
321 | # global vsegs for external peripherals / identity mapping |
---|
322 | mapping.addGlobal('seg_iob', iob_base, iob_size, '__W_', vtype='PERI', |
---|
323 | x=X_IO, y=Y_IO, pseg='IOB', local=False, big=False) |
---|
324 | |
---|
325 | mapping.addGlobal('seg_bdv', bdv_base, bdv_size, '__W_', vtype='PERI', |
---|
326 | x=X_IO, y=Y_IO, pseg='BDV', local=False, big=False) |
---|
327 | |
---|
328 | mapping.addGlobal('seg_tty', tty_base, tty_size, '__W_', vtype='PERI', |
---|
329 | x=X_IO, y=Y_IO, pseg='TTY', local=False, big=False) |
---|
330 | |
---|
331 | mapping.addGlobal('seg_nic', nic_base, nic_size, '__W_', vtype='PERI', |
---|
332 | x=X_IO, y=Y_IO, pseg='NIC', local=False, big=False) |
---|
333 | |
---|
334 | mapping.addGlobal('seg_cma', cma_base, cma_size, '__W_', vtype='PERI', |
---|
335 | x=X_IO, y=Y_IO, pseg='CMA', local=False, big=False) |
---|
336 | |
---|
337 | mapping.addGlobal('seg_fbf', fbf_base, fbf_size, '__W_', vtype='PERI', |
---|
338 | x=X_IO, y=Y_IO, pseg='FBF', local=False, big=True) |
---|
339 | |
---|
340 | mapping.addGlobal('seg_pic', pic_base, pic_size, '__W_', vtype='PERI', |
---|
341 | x=X_IO, y=Y_IO, pseg='PIC', local=False, big=False) |
---|
342 | |
---|
343 | mapping.addGlobal('seg_sim', sim_base, sim_size, '__W_', vtype='PERI', |
---|
344 | x=X_IO, y=Y_IO, pseg='SIM', local=False, big=False) |
---|
345 | |
---|
346 | # for the Giet-VM is not necessary to map the replicated ROMs |
---|
347 | mapping.addGlobal('seg_rom', drom_base, drom_size, 'CX__', vtype='PERI', |
---|
348 | x=X_IO, y=Y_IO, pseg='ROM', local=False, big=True) |
---|
349 | |
---|
350 | # global vsegs for internal peripherals |
---|
351 | for x in xrange(x_size): |
---|
352 | for y in xrange(y_size): |
---|
353 | offset = pmsb(x, y) * PERI_INCREMENT |
---|
354 | |
---|
355 | mapping.addGlobal('seg_xcu_%d_%d' % (x, y), xcu_base + offset, |
---|
356 | xcu_size, '__W_', vtype='PERI', x=x, y=y, |
---|
357 | pseg='XCU', local=False, big=False) |
---|
358 | |
---|
359 | mapping.addGlobal('seg_dma_%d_%d' % (x, y), dma_base + offset, |
---|
360 | dma_size, '__W_', vtype='PERI', x=x, y=y, |
---|
361 | pseg='DMA', local=False, big=False) |
---|
362 | |
---|
363 | mapping.addGlobal('seg_mmc_%d_%d' % (x, y), mmc_base + offset, |
---|
364 | mmc_size, '__W_', vtype='PERI', x=x, y=y, |
---|
365 | pseg='MMC', local=False, big=False) |
---|
366 | |
---|
367 | return mapping |
---|
368 | |
---|
369 | def main(x, y, p, hard_path, xml_path, dts_path): |
---|
370 | """main function: it generates the map.xml and the hard_config.h file based |
---|
371 | on the Mapping object returned by arch()""" |
---|
372 | mapping = arch(x_size=x, |
---|
373 | y_size=y, |
---|
374 | nb_procs=p) |
---|
375 | |
---|
376 | with open(xml_path, "w") as map_xml: |
---|
377 | map_xml.write(mapping.xml()) |
---|
378 | with open(hard_path, "w") as hard_config: |
---|
379 | hard_config.write(mapping.hard_config()) |
---|
380 | |
---|
381 | if dts_path != None: |
---|
382 | with open(dts_path, "w") as linux_dts: |
---|
383 | linux_dts.write(mapping.linux_dts()) |
---|
384 | |
---|
385 | ################################# platform test ################################ |
---|
386 | import sys |
---|
387 | if __name__ == '__main__': |
---|
388 | main(x=int(sys.argv[1]), |
---|
389 | y=int(sys.argv[2]), |
---|
390 | p=int(sys.argv[3]), |
---|
391 | hard_path="hard_config.test.h", |
---|
392 | xml_path="map.test.xml", |
---|
393 | dts_path="linux.dts") |
---|
394 | |
---|
395 | # Local Variables: |
---|
396 | # tab-width: 4; |
---|
397 | # c-basic-offset: 4; |
---|
398 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); |
---|
399 | # indent-tabs-mode: nil; |
---|
400 | # End: |
---|
401 | # |
---|
402 | # vim: filetype=python:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
403 | |
---|