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_monocluster_fpga architecture) |
---|
8 | # date : March 2015 |
---|
9 | # author : Cesar Fuguet |
---|
10 | ############################################################################### |
---|
11 | # This file contains a mapping generator for the "tsar_mono_fpga" |
---|
12 | # platform. |
---|
13 | # This includes both the hardware architecture (clusters, processors, |
---|
14 | # peripherals, physical space segmentation) and the mapping of all boot |
---|
15 | # and kernel objects (global vsegs). |
---|
16 | # |
---|
17 | # It is inspired on the tsar_mono_fpga platform but includes a ROM in the |
---|
18 | # cluster. |
---|
19 | # |
---|
20 | # The others hardware parameters are: |
---|
21 | # - fbf_width : frame_buffer width = frame_buffer heigth |
---|
22 | # - nb_ttys : number of TTY channels |
---|
23 | # - nb_nics : number of NIC channels |
---|
24 | # - nb_cmas : number of CMA channels |
---|
25 | # - irq_per_proc : number of input IRQs per processor |
---|
26 | # - use_ramdisk : use a RAMDISK when True |
---|
27 | # - peri_increment : address increment for replicated peripherals |
---|
28 | ############################################################################### |
---|
29 | |
---|
30 | ######################## |
---|
31 | def arch( x_size = 1, |
---|
32 | y_size = 1, |
---|
33 | nb_procs = 2, |
---|
34 | nb_ttys = 1, |
---|
35 | fbf_width = 480 ): |
---|
36 | |
---|
37 | ### define architecture constants |
---|
38 | |
---|
39 | x_io = 0 |
---|
40 | y_io = 0 |
---|
41 | x_width = 4 |
---|
42 | y_width = 4 |
---|
43 | p_width = 2 |
---|
44 | paddr_width = 40 |
---|
45 | irq_per_proc = 4 |
---|
46 | use_ramdisk = False |
---|
47 | peri_increment = 0x10000 # distributed peripherals vbase increment |
---|
48 | reset_address = 0xFF000000 # wired preloader pbase address |
---|
49 | use_backup_peri = True |
---|
50 | |
---|
51 | ### parameters checking |
---|
52 | |
---|
53 | assert( nb_procs <= (1 << p_width) ) |
---|
54 | assert( (x_size == 1) and (y_size == 1) ); |
---|
55 | |
---|
56 | ### define type and name |
---|
57 | |
---|
58 | platform_type = 'tsar_fpga' |
---|
59 | platform_name = '%s_%d' % (platform_type, nb_procs ) |
---|
60 | |
---|
61 | ### define physical segments replicated in all clusters |
---|
62 | ### the base address is extended by the cluster_xy (8 bits) |
---|
63 | |
---|
64 | ram_base = 0x00000000 |
---|
65 | ram_size = 0x8000000 # 128 Mbytes |
---|
66 | |
---|
67 | xcu_base = 0xF0000000 |
---|
68 | xcu_size = 0x1000 # 4 Kbytes |
---|
69 | |
---|
70 | mmc_base = 0xF1000000 |
---|
71 | mmc_size = 0x1000 # 4 Kbytes |
---|
72 | |
---|
73 | rom_base = 0xFF000000 |
---|
74 | rom_size = 0x10000 # 64 Kbytes |
---|
75 | |
---|
76 | bdv_base = 0xF2000000 |
---|
77 | bdv_size = 0x1000 # 4kbytes |
---|
78 | |
---|
79 | tty_base = 0xF4000000 |
---|
80 | tty_size = 0x4000 # 16 Kbytes |
---|
81 | |
---|
82 | fbf_base = 0xF3000000 |
---|
83 | fbf_size = fbf_width * fbf_width # fbf_width * fbf_width bytes |
---|
84 | |
---|
85 | ### define preloader & bootloader vsegs base addresses and sizes |
---|
86 | ### We want to pack these 5 vsegs in the same big page |
---|
87 | ### => boot cost is one BPP in cluster[0][0] |
---|
88 | |
---|
89 | preloader_vbase = reset_address # ident |
---|
90 | preloader_size = 0x00010000 # 64 Kbytes |
---|
91 | |
---|
92 | boot_mapping_vbase = 0x00010000 # ident |
---|
93 | boot_mapping_size = 0x00080000 # 512 Kbytes |
---|
94 | |
---|
95 | boot_code_vbase = 0x00090000 # ident |
---|
96 | boot_code_size = 0x00040000 # 256 Kbytes |
---|
97 | |
---|
98 | boot_data_vbase = 0x000D0000 # ident |
---|
99 | boot_data_size = 0x000B0000 # 704 Kbytes |
---|
100 | |
---|
101 | boot_stack_vbase = 0x00180000 # ident |
---|
102 | boot_stack_size = 0x00080000 # 512 Kbytes |
---|
103 | |
---|
104 | ### define ramdisk vseg / must be identity mapping in cluster[0][0] |
---|
105 | ### occupies 15 BPP after the boot |
---|
106 | ramdisk_vbase = 0x00200000 |
---|
107 | ramdisk_size = 0x02000000 # 32 Mbytes |
---|
108 | |
---|
109 | ### define kernel vsegs base addresses and sizes |
---|
110 | ### code, init, ptab, heap & sched vsegs are replicated in all clusters. |
---|
111 | ### data & uncdata vsegs are only mapped in cluster[0][0]. |
---|
112 | |
---|
113 | kernel_code_vbase = 0x80000000 |
---|
114 | kernel_code_size = 0x00100000 # 1 Mbytes per cluster |
---|
115 | |
---|
116 | kernel_init_vbase = 0x80100000 |
---|
117 | kernel_init_size = 0x00100000 # 1 Mbytes per cluster |
---|
118 | |
---|
119 | kernel_data_vbase = 0x90000000 |
---|
120 | kernel_data_size = 0x00200000 # 2 Mbytes in cluster[0][0] |
---|
121 | |
---|
122 | kernel_ptab_vbase = 0xE0000000 |
---|
123 | kernel_ptab_size = 0x00200000 # 2 Mbytes per cluster |
---|
124 | |
---|
125 | kernel_heap_vbase = 0xD0000000 |
---|
126 | kernel_heap_size = 0x00200000 # 2 Mbytes per cluster |
---|
127 | |
---|
128 | kernel_sched_vbase = 0xA0000000 |
---|
129 | kernel_sched_size = 0x00002000 * nb_procs # 8 kbytes per proc per cluster |
---|
130 | |
---|
131 | ##################### |
---|
132 | ### create mapping |
---|
133 | ##################### |
---|
134 | |
---|
135 | mapping = Mapping( name = platform_name, |
---|
136 | x_size = x_size, |
---|
137 | y_size = y_size, |
---|
138 | nprocs = nb_procs, |
---|
139 | x_width = x_width, |
---|
140 | y_width = y_width, |
---|
141 | p_width = p_width, |
---|
142 | paddr_width = paddr_width, |
---|
143 | coherence = True, |
---|
144 | irq_per_proc = irq_per_proc, |
---|
145 | use_ramdisk = use_ramdisk, |
---|
146 | x_io = x_io, |
---|
147 | y_io = y_io, |
---|
148 | peri_increment = peri_increment, |
---|
149 | reset_address = reset_address, |
---|
150 | ram_base = ram_base, |
---|
151 | ram_size = ram_size ) |
---|
152 | |
---|
153 | ########################### |
---|
154 | ### Hardware Description |
---|
155 | ########################### |
---|
156 | |
---|
157 | ### components replicated in all clusters but the upper row |
---|
158 | ram = mapping.addRam( 'RAM', base = ram_base, size = ram_size ) |
---|
159 | |
---|
160 | xcu = mapping.addPeriph( 'XCU', base = xcu_base, size = xcu_size, |
---|
161 | ptype = 'XCU', channels = nb_procs * irq_per_proc, |
---|
162 | arg0 = 16, arg1 = 16, arg2 = 16 ) |
---|
163 | |
---|
164 | mmc = mapping.addPeriph( 'MMC', base = mmc_base, size = mmc_size, |
---|
165 | ptype = 'MMC' ) |
---|
166 | |
---|
167 | mapping.addIrq( xcu, index = 8 , isrtype = 'ISR_MMC' ) |
---|
168 | |
---|
169 | for p in xrange ( nb_procs ): mapping.addProc( 0, 0, p ) |
---|
170 | |
---|
171 | bdv = mapping.addPeriph( 'BDV0', base = bdv_base, size = bdv_size, |
---|
172 | ptype = 'IOC', subtype = 'BDV' ) |
---|
173 | |
---|
174 | mapping.addIrq( xcu, index = 9 , isrtype = 'ISR_BDV' ) |
---|
175 | |
---|
176 | tty = mapping.addPeriph( 'TTY0', base = tty_base, size = tty_size, |
---|
177 | ptype = 'TTY', channels = nb_ttys ) |
---|
178 | |
---|
179 | mapping.addIrq( xcu, index = 10, isrtype = 'ISR_TTY_RX' ) |
---|
180 | |
---|
181 | rom = mapping.addPeriph( 'ROM', base = rom_base, size = rom_size, |
---|
182 | ptype = 'ROM' ) |
---|
183 | |
---|
184 | fbf = mapping.addPeriph( 'FBF', base = fbf_base, size = fbf_size, |
---|
185 | ptype = 'FBF', arg0 = fbf_width , arg1 = fbf_width) |
---|
186 | |
---|
187 | ################################### |
---|
188 | ### boot & kernel vsegs mapping |
---|
189 | ################################### |
---|
190 | |
---|
191 | ### global vsegs for preloader & boot_loader are mapped in cluster[0][0] |
---|
192 | ### => same flags CXW_ / identity mapping / non local / big page |
---|
193 | |
---|
194 | mapping.addGlobal( 'seg_preloader', preloader_vbase, preloader_size, |
---|
195 | 'CXW_', vtype = 'BUFFER', x = 0, y = 0, pseg = 'RAM', |
---|
196 | identity = True, local = False, big = True ) |
---|
197 | |
---|
198 | mapping.addGlobal( 'seg_boot_mapping', boot_mapping_vbase, boot_mapping_size, |
---|
199 | 'CXW_', vtype = 'BLOB' , x = 0, y = 0, pseg = 'RAM', |
---|
200 | identity = True, local = False, big = True ) |
---|
201 | |
---|
202 | mapping.addGlobal( 'seg_boot_code', boot_code_vbase, boot_code_size, |
---|
203 | 'CXW_', vtype = 'BUFFER', x = 0, y = 0, pseg = 'RAM', |
---|
204 | identity = True, local = False, big = True ) |
---|
205 | |
---|
206 | mapping.addGlobal( 'seg_boot_data', boot_data_vbase, boot_data_size, |
---|
207 | 'CXW_', vtype = 'BUFFER', x = 0, y = 0, pseg = 'RAM', |
---|
208 | identity = True, local = False, big = True ) |
---|
209 | |
---|
210 | mapping.addGlobal( 'seg_boot_stack', boot_stack_vbase, boot_stack_size, |
---|
211 | 'CXW_', vtype = 'BUFFER', x = 0, y = 0, pseg = 'RAM', |
---|
212 | identity = True, local = False, big = True ) |
---|
213 | |
---|
214 | ### global vseg for RAM-DISK in cluster[0][0] |
---|
215 | ### identity mapping / non local / big pages |
---|
216 | if use_ramdisk: |
---|
217 | |
---|
218 | mapping.addGlobal( 'seg_ramdisk', ramdisk_vbase, ramdisk_size, |
---|
219 | 'C_W_', vtype = 'BUFFER', x = 0, y = 0, pseg = 'RAM', |
---|
220 | identity = True, local = True, big = True ) |
---|
221 | |
---|
222 | ### global vsegs kernel_code, kernel_init : local / big page |
---|
223 | ### replicated in all clusters containing processors |
---|
224 | ### same content => same name / same vbase |
---|
225 | mapping.addGlobal( 'seg_kernel_code', |
---|
226 | kernel_code_vbase, kernel_code_size, |
---|
227 | 'CXW_', vtype = 'ELF', x = 0, y = 0, pseg = 'RAM', |
---|
228 | binpath = 'build/kernel/kernel.elf', |
---|
229 | local = True, big = True ) |
---|
230 | |
---|
231 | mapping.addGlobal( 'seg_kernel_init', |
---|
232 | kernel_init_vbase, kernel_init_size, |
---|
233 | 'CXW_', vtype = 'ELF', x = 0, y = 0, pseg = 'RAM', |
---|
234 | binpath = 'build/kernel/kernel.elf', |
---|
235 | local = True, big = True ) |
---|
236 | |
---|
237 | ### global vseg kernel_data: non local / big page |
---|
238 | ### Only mapped in cluster[0][0] |
---|
239 | mapping.addGlobal( 'seg_kernel_data', |
---|
240 | kernel_data_vbase, kernel_data_size, |
---|
241 | 'C_W_', vtype = 'ELF', x = 0, y = 0, pseg = 'RAM', |
---|
242 | binpath = 'build/kernel/kernel.elf', |
---|
243 | local = False, big = True ) |
---|
244 | |
---|
245 | ### Global vsegs kernel_ptab_x_y: non local / big page |
---|
246 | ### replicated in all clusters containing processors |
---|
247 | ### different content => name & vbase indexed by (x,y) |
---|
248 | mapping.addGlobal( 'seg_kernel_ptab', |
---|
249 | kernel_ptab_vbase, kernel_ptab_size, |
---|
250 | 'CXW_', vtype = 'PTAB', x = 0, y = 0, pseg = 'RAM', |
---|
251 | local = False, big = True ) |
---|
252 | |
---|
253 | ### global vsegs kernel_heap_x_y : non local / big pages |
---|
254 | ### distributed in all clusters containing processors |
---|
255 | ### different content => name & vbase indexed by (x,y) |
---|
256 | mapping.addGlobal( 'seg_kernel_heap', |
---|
257 | kernel_heap_vbase, kernel_heap_size, |
---|
258 | 'C_W_', vtype = 'HEAP', x = 0 , y = 0 , pseg = 'RAM', |
---|
259 | local = False, big = True ) |
---|
260 | |
---|
261 | ### global vsegs for external peripherals: non local / big page |
---|
262 | ### only mapped in cluster_io |
---|
263 | mapping.addGlobal( 'seg_bdv', bdv_base, bdv_size, |
---|
264 | '__W_', vtype = 'PERI', x = 0, y = 0, pseg = 'BDV', |
---|
265 | local = False, big = True ) |
---|
266 | |
---|
267 | mapping.addGlobal( 'seg_tty', tty_base, tty_size, |
---|
268 | '__W_', vtype = 'PERI', x = 0, y = 0, pseg = 'TTY', |
---|
269 | local = False, big = True ) |
---|
270 | |
---|
271 | mapping.addGlobal( 'seg_fbf', fbf_base, fbf_size, |
---|
272 | '__W_', vtype = 'PERI', x = 0, y = 0, pseg = 'FBF', |
---|
273 | local = False, big = True ) |
---|
274 | |
---|
275 | ### global vsegs for internal peripherals : non local / small pages |
---|
276 | ### allocated in all clusters containing processors |
---|
277 | ### name and vbase indexed by (x,y) |
---|
278 | mapping.addGlobal( 'seg_xcu', |
---|
279 | xcu_base, xcu_size, |
---|
280 | '__W_', vtype = 'PERI' , x = 0 , y = 0 , pseg = 'XCU', |
---|
281 | local = False, big = False ) |
---|
282 | |
---|
283 | mapping.addGlobal( 'seg_mmc', |
---|
284 | mmc_base, mmc_size, |
---|
285 | '__W_', vtype = 'PERI' , x = 0 , y = 0 , pseg = 'MMC', |
---|
286 | local = False, big = False ) |
---|
287 | |
---|
288 | ### global vsegs kernel_sched : non local / small pages |
---|
289 | ### allocated in all clusters containing processors |
---|
290 | ### different content => name & vbase indexed by (x,y) |
---|
291 | mapping.addGlobal( 'seg_kernel_sched', |
---|
292 | kernel_sched_vbase, kernel_sched_size, |
---|
293 | 'C_W_', vtype = 'SCHED', x = 0, y = 0, pseg = 'RAM', |
---|
294 | local = False, big = False ) |
---|
295 | |
---|
296 | return mapping |
---|
297 | |
---|
298 | ########################## platform test ############################################# |
---|
299 | |
---|
300 | if __name__ == '__main__': |
---|
301 | mapping = arch( x_size = 1, |
---|
302 | y_size = 1, |
---|
303 | nb_procs = 2 ) |
---|
304 | |
---|
305 | # print mapping.netbsd_dts() |
---|
306 | |
---|
307 | print mapping.xml() |
---|
308 | |
---|
309 | # print mapping.giet_vsegs() |
---|
310 | |
---|
311 | |
---|
312 | # Local Variables: |
---|
313 | # tab-width: 4; |
---|
314 | # c-basic-offset: 4; |
---|
315 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); |
---|
316 | # indent-tabs-mode: nil; |
---|
317 | # End: |
---|
318 | # |
---|
319 | # vim: filetype=python:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
320 | |
---|