1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | import sys |
---|
4 | |
---|
5 | ########################################################################################## |
---|
6 | # file : giet_mapping.py |
---|
7 | # date : april 2014 |
---|
8 | # author : Alain Greiner |
---|
9 | ########################################################################################## |
---|
10 | # This file contains the classes required to define a mapping for the GIET_VM. |
---|
11 | # - A 'Mapping' contains a set of 'Cluster' (hardware architecture) |
---|
12 | # a set of 'Vseg' (kernel virtual segments mapping) |
---|
13 | # a set of 'Vspace' (several user applications). |
---|
14 | # - A 'Cluster' contains a set of 'Pseg' (all physical segments in cluster) |
---|
15 | # a set of 'Proc' (processors in cluster) |
---|
16 | # a set of 'Periph' (peripherals in cluster) |
---|
17 | # a set of 'Coproc' (coprocessors in cluster) |
---|
18 | # - A 'Vspace' contains a set of 'Vseg' (user virtual segments mapping) |
---|
19 | # a set of 'Task' (user tasks mapping) |
---|
20 | # - A 'Vseg' contains a set of 'Vobj' |
---|
21 | # - A 'Periph' contains a set of 'Irq' (only for XCU and PIC types ) |
---|
22 | # - A 'Coproc' contains a set of 'Cpports' (one port per MWMR channel) |
---|
23 | ########################################################################################## |
---|
24 | # Implementation Note |
---|
25 | # The various objects used to describe a mapping are distributed in the PYTHON structure: |
---|
26 | # For example the psegs set is split in several subsets (one subset per cluster), |
---|
27 | # or the tasks set is split in several subsets (one subset per vspace), etc... |
---|
28 | # In the C binary data structure used by the giet_vm, all objects of same type |
---|
29 | # are stored in a linear array (one single array for all psegs for example). |
---|
30 | # For all objects, we compute and store in the PYTHON object itsel a "global index" |
---|
31 | # corresponding to the index in this global array, and this index can be used as |
---|
32 | # a pseudo-pointer to identify a specific object of a given type. |
---|
33 | ########################################################################################## |
---|
34 | |
---|
35 | ########################################################################################## |
---|
36 | # Various constants |
---|
37 | ########################################################################################## |
---|
38 | |
---|
39 | PADDR_WIDTH = 40 # number of bits for physical address |
---|
40 | X_WIDTH = 4 # number of bits encoding x coordinate |
---|
41 | Y_WIDTH = 4 # number of bits encoding y coordinate |
---|
42 | P_WIDTH = 4 # number of bits encoding local proc_id |
---|
43 | VPN_ANTI_MASK = 0x00000FFF # mask virtual address to get offset in a small page |
---|
44 | BPN_MASK = 0xFFE00000 # mask virtual address to get the BPN (big page) |
---|
45 | PERI_INCREMENT = 0x10000 # virtual address increment for replicated global vsegs |
---|
46 | RESET_ADDRESS = 0xBFC00000 # Processor wired boot_address |
---|
47 | MAPPING_SIGNATURE = 0xDACE2014 # Magic number indicating a valid C binary struture |
---|
48 | |
---|
49 | ########################################################################################## |
---|
50 | # These global lists must be consistent with enums in mapping_info.h or irq_handler. |
---|
51 | ########################################################################################## |
---|
52 | PERIPHTYPES = [ |
---|
53 | 'CMA', |
---|
54 | 'DMA', |
---|
55 | 'FBF', |
---|
56 | 'IOB', |
---|
57 | 'IOC', |
---|
58 | 'MMC', |
---|
59 | 'MWR', |
---|
60 | 'NIC', |
---|
61 | 'ROM', |
---|
62 | 'SIM', |
---|
63 | 'TIM', |
---|
64 | 'TTY', |
---|
65 | 'XCU', |
---|
66 | 'PIC', |
---|
67 | 'DROM', |
---|
68 | ] |
---|
69 | |
---|
70 | PERIPHSUBTYPES = [ |
---|
71 | 'BDV', |
---|
72 | 'HBA', |
---|
73 | 'SPI', |
---|
74 | 'NONE', |
---|
75 | ] |
---|
76 | |
---|
77 | IRQTYPES = [ |
---|
78 | 'HWI', |
---|
79 | 'WTI', |
---|
80 | 'PTI', |
---|
81 | ] |
---|
82 | |
---|
83 | ISRTYPES = [ |
---|
84 | 'ISR_DEFAULT', |
---|
85 | 'ISR_TICK', |
---|
86 | 'ISR_TTY_RX', |
---|
87 | 'ISR_TTY_TX', |
---|
88 | 'ISR_BDV', |
---|
89 | 'ISR_TIMER', |
---|
90 | 'ISR_WAKUP', |
---|
91 | 'ISR_NIC_RX', |
---|
92 | 'ISR_NIC_TX', |
---|
93 | 'ISR_CMA', |
---|
94 | 'ISR_MMC', |
---|
95 | 'ISR_DMA', |
---|
96 | 'ISR_SPI', |
---|
97 | ] |
---|
98 | |
---|
99 | VOBJTYPES = [ |
---|
100 | 'ELF', |
---|
101 | 'BLOB', |
---|
102 | 'PTAB', |
---|
103 | 'PERI', |
---|
104 | 'MWMR', |
---|
105 | 'LOCK', |
---|
106 | 'BUFFER', |
---|
107 | 'BARRIER', |
---|
108 | 'CONST', |
---|
109 | 'MEMSPACE', |
---|
110 | 'SCHED', |
---|
111 | 'HEAP', |
---|
112 | ] |
---|
113 | |
---|
114 | VSEGMODES = [ |
---|
115 | '____', |
---|
116 | '___U', |
---|
117 | '__W_', |
---|
118 | '__WU', |
---|
119 | '_X__', |
---|
120 | '_X_U', |
---|
121 | '_XW_', |
---|
122 | '_XWU', |
---|
123 | 'C___', |
---|
124 | 'C__U', |
---|
125 | 'C_W_', |
---|
126 | 'C_WU', |
---|
127 | 'CX__', |
---|
128 | 'CX_U', |
---|
129 | 'CXW_', |
---|
130 | 'CXWU', |
---|
131 | ] |
---|
132 | |
---|
133 | PSEGTYPES = [ |
---|
134 | 'RAM', |
---|
135 | 'ROM', # deprecated => use PERI |
---|
136 | 'PERI', |
---|
137 | ] |
---|
138 | |
---|
139 | CP_PORT_DIRS = [ |
---|
140 | 'TO_COPROC', |
---|
141 | 'FROM_COPROC', |
---|
142 | ] |
---|
143 | |
---|
144 | ########################################################################################## |
---|
145 | class Mapping( object ): |
---|
146 | ########################################################################################## |
---|
147 | def __init__( self, |
---|
148 | name, # mapping name |
---|
149 | x_size, # number of clusters in a row |
---|
150 | y_size, # number of clusters in a column |
---|
151 | nprocs, # max number of processors per cluster |
---|
152 | x_width = X_WIDTH, # number of bits encoding x coordinate |
---|
153 | y_width = Y_WIDTH, # number of bits encoding y coordinate |
---|
154 | p_width = P_WIDTH, # number of bits encoding local proc_id |
---|
155 | paddr_width = PADDR_WIDTH, # number of bits for physical address |
---|
156 | coherence = 1, # hardware cache coherence when non-zero |
---|
157 | irq_per_proc = 1, # number or IRQs from XCU to processor |
---|
158 | use_ramdisk = False, # use ramdisk when true |
---|
159 | x_io = 0, # cluster_io x coordinate |
---|
160 | y_io = 0, # cluster_io y coordinate |
---|
161 | peri_increment = PERI_INCREMENT, # address increment for globals |
---|
162 | reset_address = RESET_ADDRESS, # Processor wired boot_address |
---|
163 | ram_base = 0, # RAM physical base in cluster[0,0] |
---|
164 | ram_size = 0 ): # RAM size in each cluster (bytes) |
---|
165 | |
---|
166 | assert ( x_size <= (1<<X_WIDTH) ) |
---|
167 | assert ( y_size <= (1<<Y_WIDTH) ) |
---|
168 | assert ( nprocs <= (1<<P_WIDTH) ) |
---|
169 | |
---|
170 | self.signature = MAPPING_SIGNATURE |
---|
171 | self.name = name |
---|
172 | self.paddr_width = paddr_width |
---|
173 | self.coherence = coherence |
---|
174 | self.x_size = x_size |
---|
175 | self.y_size = y_size |
---|
176 | self.nprocs = nprocs |
---|
177 | self.x_width = x_width |
---|
178 | self.y_width = y_width |
---|
179 | self.p_width = p_width |
---|
180 | self.irq_per_proc = irq_per_proc |
---|
181 | self.use_ramdisk = use_ramdisk |
---|
182 | self.x_io = x_io |
---|
183 | self.y_io = y_io |
---|
184 | self.peri_increment = peri_increment |
---|
185 | self.reset_address = reset_address |
---|
186 | self.ram_base = ram_base |
---|
187 | self.ram_size = ram_size |
---|
188 | |
---|
189 | self.total_vspaces = 0 |
---|
190 | self.total_globals = 0 |
---|
191 | self.total_psegs = 0 |
---|
192 | self.total_vsegs = 0 |
---|
193 | self.total_vobjs = 0 |
---|
194 | self.total_tasks = 0 |
---|
195 | self.total_procs = 0 |
---|
196 | self.total_irqs = 0 |
---|
197 | self.total_coprocs = 0 |
---|
198 | self.total_cpports = 0 |
---|
199 | self.total_periphs = 0 |
---|
200 | |
---|
201 | self.clusters = [] |
---|
202 | self.globs = [] |
---|
203 | self.vspaces = [] |
---|
204 | |
---|
205 | for x in xrange( self.x_size ): |
---|
206 | for y in xrange( self.y_size ): |
---|
207 | cluster = Cluster( x , y ) |
---|
208 | cluster.index = (x * self.y_size) + y |
---|
209 | self.clusters.append( cluster ) |
---|
210 | |
---|
211 | return |
---|
212 | |
---|
213 | ########################## add a ram pseg in a cluster |
---|
214 | def addRam( self, |
---|
215 | name, # pseg name |
---|
216 | base, # pseg base address |
---|
217 | size ): # pseg length (bytes) |
---|
218 | |
---|
219 | # computes coordinates from the base address extension |
---|
220 | paddr_lsb_width = self.paddr_width - self.x_width - self.y_width |
---|
221 | cluster_xy = base >> paddr_lsb_width |
---|
222 | x = cluster_xy >> (self.y_width); |
---|
223 | y = cluster_xy & ((1 << self.y_width) - 1) |
---|
224 | |
---|
225 | assert (base & VPN_ANTI_MASK) == 0 |
---|
226 | |
---|
227 | assert (x < self.x_size) and (y < self.y_size) |
---|
228 | |
---|
229 | assert ( (base & ((1<<paddr_lsb_width)-1)) == self.ram_base ) |
---|
230 | |
---|
231 | assert ( size == self.ram_size ) |
---|
232 | |
---|
233 | cluster_id = (x * self.y_size) + y |
---|
234 | |
---|
235 | # add one pseg in the mapping |
---|
236 | pseg = Pseg( name, base, size, x, y, 'RAM' ) |
---|
237 | self.clusters[cluster_id].psegs.append( pseg ) |
---|
238 | pseg.index = self.total_psegs |
---|
239 | self.total_psegs += 1 |
---|
240 | |
---|
241 | return pseg |
---|
242 | |
---|
243 | ############################## add a peripheral and the associated pseg in a cluster |
---|
244 | def addPeriph( self, |
---|
245 | name, # associated pseg name |
---|
246 | base, # associated pseg base address |
---|
247 | size, # associated pseg length (bytes) |
---|
248 | ptype, # peripheral type |
---|
249 | subtype = 'NONE', # peripheral subtype |
---|
250 | channels = 1, # number of channels |
---|
251 | arg = 0 ): # optional argument (semantic depends on ptype) |
---|
252 | |
---|
253 | # check cluster coordinates (obtained from the base address) |
---|
254 | cluster_xy = base >> (self.paddr_width - self.x_width - self.y_width) |
---|
255 | x = cluster_xy >> (self.y_width); |
---|
256 | y = cluster_xy & ((1 << self.y_width) - 1) |
---|
257 | |
---|
258 | assert (x < self.x_size) and (y < self.y_size) |
---|
259 | |
---|
260 | assert (base & VPN_ANTI_MASK) == 0 |
---|
261 | |
---|
262 | assert ptype in PERIPHTYPES |
---|
263 | |
---|
264 | assert subtype in PERIPHSUBTYPES |
---|
265 | |
---|
266 | cluster_id = (x * self.y_size) + y |
---|
267 | |
---|
268 | # add one pseg into mapping |
---|
269 | pseg = Pseg( name, base, size, x, y, 'PERI' ) |
---|
270 | self.clusters[cluster_id].psegs.append( pseg ) |
---|
271 | pseg.index = self.total_psegs |
---|
272 | self.total_psegs += 1 |
---|
273 | |
---|
274 | # add one periph into mapping |
---|
275 | periph = Periph( pseg, ptype, subtype, channels, arg ) |
---|
276 | self.clusters[cluster_id].periphs.append( periph ) |
---|
277 | periph.index = self.total_periphs |
---|
278 | self.total_periphs += 1 |
---|
279 | |
---|
280 | return periph |
---|
281 | |
---|
282 | ################################ add an IRQ in a peripheral |
---|
283 | def addIrq( self, |
---|
284 | periph, # peripheral containing IRQ (PIC or XCU) |
---|
285 | index, # peripheral input port index |
---|
286 | isrtype, # ISR type |
---|
287 | channel = 0 ): # channel for multi-channels ISR |
---|
288 | |
---|
289 | assert isrtype in ISRTYPES |
---|
290 | |
---|
291 | assert index < 32 |
---|
292 | |
---|
293 | # add one irq into mapping |
---|
294 | irq = Irq( 'HWI', index , isrtype, channel ) |
---|
295 | periph.irqs.append( irq ) |
---|
296 | irq.index = self.total_irqs |
---|
297 | self.total_irqs += 1 |
---|
298 | |
---|
299 | return irq |
---|
300 | |
---|
301 | ########################## add a processor in a cluster |
---|
302 | def addProc( self, |
---|
303 | x, # cluster x coordinate |
---|
304 | y, # cluster y coordinate |
---|
305 | p ): # processor local index |
---|
306 | |
---|
307 | assert (x < self.x_size) and (y < self.y_size) |
---|
308 | |
---|
309 | cluster_id = (x * self.y_size) + y |
---|
310 | |
---|
311 | # add one proc into mapping |
---|
312 | proc = Processor( x, y, p ) |
---|
313 | self.clusters[cluster_id].procs.append( proc ) |
---|
314 | proc.index = self.total_procs |
---|
315 | self.total_procs += 1 |
---|
316 | |
---|
317 | return proc |
---|
318 | |
---|
319 | ############################## add a coprocessor in a cluster |
---|
320 | def addCoproc( self, |
---|
321 | name, # associated pseg name |
---|
322 | base, # associated pseg base address |
---|
323 | size ): # associated pseg length |
---|
324 | |
---|
325 | # check cluster coordinates (obtained from the base address) |
---|
326 | cluster_xy = base >> (self.paddr_width - self.x_width - self.y_width) |
---|
327 | x = cluster_xy >> (self.y_width); |
---|
328 | y = cluster_xy & ((1 << self.y_width) - 1) |
---|
329 | |
---|
330 | assert (x < self.x_size) and (y < self.y_size) |
---|
331 | |
---|
332 | cluster_id = (x * self.y_size) + y |
---|
333 | |
---|
334 | # add one pseg into mapping |
---|
335 | pseg = Pseg( name, base, size, x, y, 'PERI' ) |
---|
336 | self.clusters[cluster_id].psegs.append( pseg ) |
---|
337 | pseg.index = self.total_psegs |
---|
338 | self.total_psegs += 1 |
---|
339 | |
---|
340 | # add one coproc into mapping |
---|
341 | periph = Coproc( pseg ) |
---|
342 | self.clusters[cluster_id].coprocs.append( coproc ) |
---|
343 | periph.index = self.total_coprocs |
---|
344 | self.total_coprocs += 1 |
---|
345 | |
---|
346 | return coproc |
---|
347 | |
---|
348 | ################################## add a port in a coprocessor |
---|
349 | def addPort( self, |
---|
350 | coproc, # coprocessor containing the port |
---|
351 | direction, # direction (TO_COPROC / FROM_COPROC) |
---|
352 | vspacename, # name of vspace using the coproc |
---|
353 | mwmrname ): # name of the vobj defining the MWMR channel |
---|
354 | |
---|
355 | assert direction in CP_PORT_DIRS |
---|
356 | |
---|
357 | # add one cpport into mapping |
---|
358 | port = Cpport( direction, vspacename, mwmrname ) |
---|
359 | coproc.ports.append( port ) |
---|
360 | port.index = self.total_cpports |
---|
361 | self.total_cpports += 1 |
---|
362 | |
---|
363 | return port |
---|
364 | |
---|
365 | ############################ add one global vseg into mapping |
---|
366 | def addGlobal( self, |
---|
367 | name, # vseg name |
---|
368 | vbase, # virtual base address |
---|
369 | size, # vobj length (bytes) |
---|
370 | mode, # CXWU flags |
---|
371 | vtype, # vobj type |
---|
372 | x, # destination x coordinate |
---|
373 | y, # destination y coordinate |
---|
374 | pseg, # destination pseg name |
---|
375 | identity = False, # identity mapping required if true |
---|
376 | binpath = '', # pathname for binary code if required |
---|
377 | align = 0, # alignment required |
---|
378 | local = False, # only mapped in local PTAB if true |
---|
379 | big = False ): # to be mapped in a big physical page |
---|
380 | |
---|
381 | assert mode in VSEGMODES |
---|
382 | |
---|
383 | assert vtype in VOBJTYPES |
---|
384 | |
---|
385 | assert (x < self.x_size) and (y < self.y_size) |
---|
386 | |
---|
387 | # two global vsegs must not overlap if they have different names |
---|
388 | for prev in self.globs: |
---|
389 | prev_vbase = prev.vbase |
---|
390 | prev_size = prev.vobjs[0].length |
---|
391 | |
---|
392 | if ( ((prev_vbase + prev_size) > vbase ) and |
---|
393 | ((vbase + size) > prev_vbase) and |
---|
394 | (prev.name != name) ): |
---|
395 | print '[genmap error] in addGlobal() : %s overlap %s' % (name, prev.name) |
---|
396 | print ' %s : base = %x / size = %x' %( name, vbase, size ) |
---|
397 | print ' %s : base = %x / size = %x' %( prev.name, prev_vbase, prev_size ) |
---|
398 | sys.exit(1) |
---|
399 | |
---|
400 | # add one vseg into mapping |
---|
401 | vseg = Vseg( name, vbase, mode, x, y, pseg, |
---|
402 | identity = identity, local = local, big = big ) |
---|
403 | |
---|
404 | self.globs.append( vseg ) |
---|
405 | self.total_globals += 1 |
---|
406 | vseg.index = self.total_vsegs |
---|
407 | self.total_vsegs += 1 |
---|
408 | |
---|
409 | # add one vobj into mapping |
---|
410 | vobj = Vobj( name, size, vtype, binpath, 0, 0 ) |
---|
411 | vseg.vobjs.append( vobj ) |
---|
412 | vobj.index = self.total_vobjs |
---|
413 | self.total_vobjs += 1 |
---|
414 | |
---|
415 | return |
---|
416 | |
---|
417 | ################################ add a vspace into mapping |
---|
418 | def addVspace( self, |
---|
419 | name, # vspace name |
---|
420 | startname ): # name of vobj containing start_vector |
---|
421 | |
---|
422 | # add one vspace into mapping |
---|
423 | vspace = Vspace( name, startname ) |
---|
424 | self.vspaces.append( vspace ) |
---|
425 | vspace.index = self.total_vspaces |
---|
426 | self.total_vspaces += 1 |
---|
427 | |
---|
428 | return vspace |
---|
429 | |
---|
430 | ################################# add a private vseg and a vobj in a vspace |
---|
431 | def addVseg( self, |
---|
432 | vspace, # vspace containing the vseg |
---|
433 | name, # vseg name |
---|
434 | vbase, # virtual base address |
---|
435 | size, # vobj length (bytes) |
---|
436 | mode, # CXWU flags |
---|
437 | vtype, # vobj type |
---|
438 | x, # destination x coordinate |
---|
439 | y, # destination y coordinate |
---|
440 | pseg, # destination pseg name |
---|
441 | binpath = '', # pathname for binary code |
---|
442 | align = 0, # alignment required |
---|
443 | init = 0, # initial value |
---|
444 | local = False, # only mapped in local PTAB if true |
---|
445 | big = False ): # to be mapped in a big physical page |
---|
446 | |
---|
447 | assert mode in VSEGMODES |
---|
448 | |
---|
449 | assert vtype in VOBJTYPES |
---|
450 | |
---|
451 | assert (x < self.x_size) and (y < self.y_size) |
---|
452 | |
---|
453 | # add one vseg into mapping |
---|
454 | vseg = Vseg( name, vbase, mode, x, y, pseg, local = local, big = big ) |
---|
455 | vspace.vsegs.append( vseg ) |
---|
456 | vseg.index = self.total_vsegs |
---|
457 | self.total_vsegs += 1 |
---|
458 | |
---|
459 | # add one vobj into mapping |
---|
460 | vobj = Vobj( name, size, vtype, binpath, align, init ) |
---|
461 | vseg.vobjs.append( vobj ) |
---|
462 | vobj.index = self.total_vobjs |
---|
463 | self.total_vobjs += 1 |
---|
464 | |
---|
465 | return vseg |
---|
466 | |
---|
467 | ################################ add a vobj in a private vseg |
---|
468 | def addVobj( self, |
---|
469 | vseg, # vseg containing vobj |
---|
470 | name, # vobj name |
---|
471 | size, # vobj length (bytes) |
---|
472 | vtype, # vobj type |
---|
473 | binpath = '', # pathname to binary |
---|
474 | align = 0, # alignment constraint |
---|
475 | init = 0 ): # initial value |
---|
476 | |
---|
477 | assert vtype in VOBJTYPES |
---|
478 | |
---|
479 | # add one vobj into mapping |
---|
480 | vobj = Vobj( name, size, vtype, binpath, align, init ) |
---|
481 | vseg.vobjs.append( vobj ) |
---|
482 | vobj.index = self.total_vobjs |
---|
483 | self.total_vobjs += 1 |
---|
484 | |
---|
485 | return vobj |
---|
486 | |
---|
487 | ################################ add a task in a vspace |
---|
488 | def addTask( self, |
---|
489 | vspace, # vspace containing task |
---|
490 | name, # task name |
---|
491 | trdid, # task index in vspace |
---|
492 | x, # destination x coordinate |
---|
493 | y, # destination y coordinate |
---|
494 | lpid, # destination processor local index |
---|
495 | stackname, # name of vobj containing stack |
---|
496 | heapname, # name of vobj containing heap |
---|
497 | startid ): # index in start_vector |
---|
498 | |
---|
499 | assert (x < self.x_size) and (y < self.y_size) |
---|
500 | assert lpid < self.nprocs |
---|
501 | |
---|
502 | # add one task into mapping |
---|
503 | task = Task( name, trdid, x, y, lpid, stackname, heapname, startid ) |
---|
504 | vspace.tasks.append( task ) |
---|
505 | task.index = self.total_tasks |
---|
506 | self.total_tasks += 1 |
---|
507 | |
---|
508 | return task |
---|
509 | |
---|
510 | ################################# |
---|
511 | def str2bytes( self, nbytes, s ): # string => nbytes_packed byte array |
---|
512 | |
---|
513 | byte_stream = bytearray() |
---|
514 | length = len( s ) |
---|
515 | if length < (nbytes - 1): |
---|
516 | for b in s: |
---|
517 | byte_stream.append( b ) |
---|
518 | for x in xrange(nbytes-length): |
---|
519 | byte_stream.append( '\0' ) |
---|
520 | else: |
---|
521 | print '[genmap error] in str2bytes() : string %s too long' % s |
---|
522 | sys.exit(1) |
---|
523 | |
---|
524 | return byte_stream |
---|
525 | |
---|
526 | ################################### |
---|
527 | def int2bytes( self, nbytes, val ): # integer => nbytes litle endian byte array |
---|
528 | |
---|
529 | byte_stream = bytearray() |
---|
530 | for n in xrange( nbytes ): |
---|
531 | byte_stream.append( (val >> (n<<3)) & 0xFF ) |
---|
532 | |
---|
533 | return byte_stream |
---|
534 | |
---|
535 | #################################################################################### |
---|
536 | def xml( self ): # compute string for map.xml file generation |
---|
537 | |
---|
538 | s = '<?xml version="1.0"?>\n\n' |
---|
539 | s += '<mapping_info signature = "0x%x"\n' % (self.signature) |
---|
540 | s += ' name = "%s"\n' % (self.name) |
---|
541 | s += ' x_size = "%d"\n' % (self.x_size) |
---|
542 | s += ' y_size = "%d"\n' % (self.y_size) |
---|
543 | s += ' x_width = "%d"\n' % (self.x_width) |
---|
544 | s += ' y_width = "%d"\n' % (self.y_width) |
---|
545 | s += ' irq_per_proc = "%d"\n' % (self.irq_per_proc) |
---|
546 | s += ' use_ramdisk = "%d"\n' % (self.use_ramdisk) |
---|
547 | s += ' x_io = "%d"\n' % (self.x_io) |
---|
548 | s += ' y_io = "%d" >\n' % (self.y_io) |
---|
549 | s += '\n' |
---|
550 | |
---|
551 | s += ' <clusterset>\n' |
---|
552 | for x in xrange ( self.x_size ): |
---|
553 | for y in xrange ( self.y_size ): |
---|
554 | cluster_id = (x * self.y_size) + y |
---|
555 | s += self.clusters[cluster_id].xml() |
---|
556 | s += ' </clusterset>\n' |
---|
557 | s += '\n' |
---|
558 | |
---|
559 | s += ' <globalset>\n' |
---|
560 | for vseg in self.globs: s += vseg.xml() |
---|
561 | s += ' </globalset>\n' |
---|
562 | s += '\n' |
---|
563 | |
---|
564 | s += ' <vspaceset>\n' |
---|
565 | for vspace in self.vspaces: s += vspace.xml() |
---|
566 | s += ' </vspaceset>\n' |
---|
567 | |
---|
568 | s += '</mapping_info>\n' |
---|
569 | return s |
---|
570 | |
---|
571 | ##################################################################################### |
---|
572 | def cbin( self, verbose ): # C binary structure for map.bin file generation |
---|
573 | |
---|
574 | byte_stream = bytearray() |
---|
575 | |
---|
576 | # header |
---|
577 | byte_stream += self.int2bytes(4, self.signature) |
---|
578 | byte_stream += self.int2bytes(4, self.x_size) |
---|
579 | byte_stream += self.int2bytes(4, self.y_size) |
---|
580 | byte_stream += self.int2bytes(4, self.x_width) |
---|
581 | byte_stream += self.int2bytes(4, self.y_width) |
---|
582 | byte_stream += self.int2bytes(4, self.x_io) |
---|
583 | byte_stream += self.int2bytes(4, self.y_io) |
---|
584 | byte_stream += self.int2bytes(4, self.irq_per_proc) |
---|
585 | byte_stream += self.int2bytes(4, self.use_ramdisk) |
---|
586 | byte_stream += self.int2bytes(4, self.total_globals) |
---|
587 | byte_stream += self.int2bytes(4, self.total_vspaces) |
---|
588 | byte_stream += self.int2bytes(4, self.total_psegs) |
---|
589 | byte_stream += self.int2bytes(4, self.total_vsegs) |
---|
590 | byte_stream += self.int2bytes(4, self.total_vobjs) |
---|
591 | byte_stream += self.int2bytes(4, self.total_tasks) |
---|
592 | byte_stream += self.int2bytes(4, self.total_procs) |
---|
593 | byte_stream += self.int2bytes(4, self.total_irqs) |
---|
594 | byte_stream += self.int2bytes(4, self.total_coprocs) |
---|
595 | byte_stream += self.int2bytes(4, self.total_cpports) |
---|
596 | byte_stream += self.int2bytes(4, self.total_periphs) |
---|
597 | byte_stream += self.str2bytes(32, self.name) |
---|
598 | |
---|
599 | if ( verbose ): |
---|
600 | print '\n' |
---|
601 | print 'name = %s' % self.name |
---|
602 | print 'signature = %x' % self.signature |
---|
603 | print 'x_size = %d' % self.x_size |
---|
604 | print 'y_size = %d' % self.y_size |
---|
605 | print 'x_width = %d' % self.x_width |
---|
606 | print 'y_width = %d' % self.y_width |
---|
607 | print 'x_io = %d' % self.x_io |
---|
608 | print 'y_io = %d' % self.y_io |
---|
609 | print 'irq_per_proc = %d' % self.irq_per_proc |
---|
610 | print 'use_ramdisk = %d' % self.use_ramdisk |
---|
611 | print 'total_globals = %d' % self.total_globals |
---|
612 | print 'total_psegs = %d' % self.total_psegs |
---|
613 | print 'total_vsegs = %d' % self.total_vsegs |
---|
614 | print 'total_vobjs = %d' % self.total_vobjs |
---|
615 | print 'total_tasks = %d' % self.total_tasks |
---|
616 | print 'total_procs = %d' % self.total_procs |
---|
617 | print 'total_irqs = %d' % self.total_irqs |
---|
618 | print 'total_coprocs = %d' % self.total_coprocs |
---|
619 | print 'total_cpports = %d' % self.total_cpports |
---|
620 | print 'total_periphs = %d' % self.total_periphs |
---|
621 | print '\n' |
---|
622 | |
---|
623 | # clusters array |
---|
624 | index = 0 |
---|
625 | for cluster in self.clusters: |
---|
626 | byte_stream += cluster.cbin( self, verbose, index ) |
---|
627 | index += 1 |
---|
628 | |
---|
629 | if ( verbose ): print '\n' |
---|
630 | |
---|
631 | # psegs array |
---|
632 | index = 0 |
---|
633 | for cluster in self.clusters: |
---|
634 | for pseg in cluster.psegs: |
---|
635 | byte_stream += pseg.cbin( self, verbose, index, cluster ) |
---|
636 | index += 1 |
---|
637 | |
---|
638 | if ( verbose ): print '\n' |
---|
639 | |
---|
640 | # vspaces array |
---|
641 | index = 0 |
---|
642 | for vspace in self.vspaces: |
---|
643 | byte_stream += vspace.cbin( self, verbose, index ) |
---|
644 | index += 1 |
---|
645 | |
---|
646 | if ( verbose ): print '\n' |
---|
647 | |
---|
648 | # vsegs array |
---|
649 | index = 0 |
---|
650 | for vseg in self.globs: |
---|
651 | byte_stream += vseg.cbin( self, verbose, index ) |
---|
652 | index += 1 |
---|
653 | for vspace in self.vspaces: |
---|
654 | for vseg in vspace.vsegs: |
---|
655 | byte_stream += vseg.cbin( self, verbose, index ) |
---|
656 | index += 1 |
---|
657 | |
---|
658 | if ( verbose ): print '\n' |
---|
659 | |
---|
660 | # vobjs array |
---|
661 | index = 0 |
---|
662 | for vseg in self.globs: |
---|
663 | for vobj in vseg.vobjs: |
---|
664 | byte_stream += vobj.cbin( self, verbose, index ) |
---|
665 | index += 1 |
---|
666 | for vspace in self.vspaces: |
---|
667 | for vseg in vspace.vsegs: |
---|
668 | for vobj in vseg.vobjs: |
---|
669 | byte_stream += vobj.cbin( self, verbose, index ) |
---|
670 | index += 1 |
---|
671 | |
---|
672 | if ( verbose ): print '\n' |
---|
673 | |
---|
674 | # tasks array |
---|
675 | index = 0 |
---|
676 | for vspace in self.vspaces: |
---|
677 | for task in vspace.tasks: |
---|
678 | byte_stream += task.cbin( self, verbose, index, vspace ) |
---|
679 | index += 1 |
---|
680 | |
---|
681 | if ( verbose ): print '\n' |
---|
682 | |
---|
683 | # procs array |
---|
684 | index = 0 |
---|
685 | for cluster in self.clusters: |
---|
686 | for proc in cluster.procs: |
---|
687 | byte_stream += proc.cbin( self, verbose, index ) |
---|
688 | index += 1 |
---|
689 | |
---|
690 | if ( verbose ): print '\n' |
---|
691 | |
---|
692 | # irqs array |
---|
693 | index = 0 |
---|
694 | for cluster in self.clusters: |
---|
695 | for periph in cluster.periphs: |
---|
696 | for irq in periph.irqs: |
---|
697 | byte_stream += irq.cbin( self, verbose, index ) |
---|
698 | index += 1 |
---|
699 | |
---|
700 | if ( verbose ): print '\n' |
---|
701 | |
---|
702 | # coprocs array |
---|
703 | index = 0 |
---|
704 | for cluster in self.clusters: |
---|
705 | for coproc in cluster.coprocs: |
---|
706 | byte_stream += coproc.cbin( self, verbose, index ) |
---|
707 | index += 1 |
---|
708 | |
---|
709 | if ( verbose ): print '\n' |
---|
710 | |
---|
711 | # cpports array |
---|
712 | index = 0 |
---|
713 | for cluster in self.clusters: |
---|
714 | for coproc in cluster.coprocs: |
---|
715 | for port in coproc.ports: |
---|
716 | byte_stream += port.cbin( self, verbose, index ) |
---|
717 | index += 1 |
---|
718 | |
---|
719 | if ( verbose ): print '\n' |
---|
720 | |
---|
721 | # periphs array |
---|
722 | index = 0 |
---|
723 | for cluster in self.clusters: |
---|
724 | for periph in cluster.periphs: |
---|
725 | byte_stream += periph.cbin( self, verbose, index ) |
---|
726 | index += 1 |
---|
727 | |
---|
728 | return byte_stream |
---|
729 | # end of cbin() |
---|
730 | |
---|
731 | ################################################################################## |
---|
732 | def giet_vsegs( self ): # compute string for giet_vsegs.ld file generation |
---|
733 | # required by giet_vm compilation |
---|
734 | |
---|
735 | # search the vsegs required for the giet_vsegs.ld |
---|
736 | boot_code_found = False |
---|
737 | boot_data_found = False |
---|
738 | kernel_uncdata_found = False |
---|
739 | kernel_data_found = False |
---|
740 | kernel_code_found = False |
---|
741 | kernel_init_found = False |
---|
742 | for vseg in self.globs: |
---|
743 | |
---|
744 | if ( vseg.name == 'seg_boot_code' ): |
---|
745 | boot_code_vbase = vseg.vbase |
---|
746 | boot_code_size = vseg.vobjs[0].length |
---|
747 | boot_code_found = True |
---|
748 | |
---|
749 | if ( vseg.name == 'seg_boot_data' ): |
---|
750 | boot_data_vbase = vseg.vbase |
---|
751 | boot_data_size = vseg.vobjs[0].length |
---|
752 | boot_data_found = True |
---|
753 | |
---|
754 | if ( vseg.name == 'seg_kernel_uncdata' ): |
---|
755 | kernel_uncdata_vbase = vseg.vbase |
---|
756 | kernel_uncdata_size = vseg.vobjs[0].length |
---|
757 | kernel_uncdata_found = True |
---|
758 | |
---|
759 | if ( vseg.name == 'seg_kernel_data' ): |
---|
760 | kernel_data_vbase = vseg.vbase |
---|
761 | kernel_data_size = vseg.vobjs[0].length |
---|
762 | kernel_data_found = True |
---|
763 | |
---|
764 | if ( vseg.name == 'seg_kernel_code' ): |
---|
765 | kernel_code_vbase = vseg.vbase |
---|
766 | kernel_code_size = vseg.vobjs[0].length |
---|
767 | kernel_code_found = True |
---|
768 | |
---|
769 | if ( vseg.name == 'seg_kernel_init' ): |
---|
770 | kernel_init_vbase = vseg.vbase |
---|
771 | kernel_init_size = vseg.vobjs[0].length |
---|
772 | kernel_init_found = True |
---|
773 | |
---|
774 | # check if all required vsegs have been found |
---|
775 | if ( boot_code_found == False ): |
---|
776 | print '[genmap error] in giet_vsegs() : seg_boot_code vseg missing' |
---|
777 | sys.exit() |
---|
778 | |
---|
779 | if ( boot_data_found == False ): |
---|
780 | print '[genmap error] in giet_vsegs() : seg_boot_data vseg missing' |
---|
781 | sys.exit() |
---|
782 | |
---|
783 | if ( kernel_data_found == False ): |
---|
784 | print '[genmap error] in giet_vsegs() : seg_kernel_data vseg missing' |
---|
785 | sys.exit() |
---|
786 | |
---|
787 | if ( kernel_uncdata_found == False ): |
---|
788 | print '[genmap error] in giet_vsegs() : seg_kernel_uncdata vseg missing' |
---|
789 | sys.exit() |
---|
790 | |
---|
791 | if ( kernel_code_found == False ): |
---|
792 | print '[genmap error] in giet_vsegs() : seg_kernel_code vseg missing' |
---|
793 | sys.exit() |
---|
794 | |
---|
795 | if ( kernel_init_found == False ): |
---|
796 | print '[genmap error] in giet_vsegs() : seg_kernel_init vseg missing' |
---|
797 | sys.exit() |
---|
798 | |
---|
799 | # build string |
---|
800 | s = '/* Generated by genmap for %s */\n' % self.name |
---|
801 | s += '\n' |
---|
802 | |
---|
803 | s += 'boot_code_vbase = 0x%x;\n' % boot_code_vbase |
---|
804 | s += 'boot_code_size = 0x%x;\n' % boot_code_size |
---|
805 | s += '\n' |
---|
806 | s += 'boot_data_vbase = 0x%x;\n' % boot_data_vbase |
---|
807 | s += 'boot_data_size = 0x%x;\n' % boot_data_size |
---|
808 | s += '\n' |
---|
809 | s += 'kernel_code_vbase = 0x%x;\n' % kernel_code_vbase |
---|
810 | s += 'kernel_code_size = 0x%x;\n' % kernel_code_size |
---|
811 | s += '\n' |
---|
812 | s += 'kernel_data_vbase = 0x%x;\n' % kernel_data_vbase |
---|
813 | s += 'kernel_data_size = 0x%x;\n' % kernel_data_size |
---|
814 | s += '\n' |
---|
815 | s += 'kernel_uncdata_vbase = 0x%x;\n' % kernel_uncdata_vbase |
---|
816 | s += 'kernel_uncdata_size = 0x%x;\n' % kernel_uncdata_size |
---|
817 | s += '\n' |
---|
818 | s += 'kernel_init_vbase = 0x%x;\n' % kernel_init_vbase |
---|
819 | s += 'kernel_init_size = 0x%x;\n' % kernel_init_size |
---|
820 | s += '\n' |
---|
821 | |
---|
822 | return s |
---|
823 | |
---|
824 | ################################################################################### |
---|
825 | def hard_config( self ): # compute string for hard_config.h file generation, |
---|
826 | # required by |
---|
827 | # - top.cpp compilation |
---|
828 | # - giet_vm compilation |
---|
829 | # - tsar_preloader compilation |
---|
830 | |
---|
831 | nb_total_procs = 0 |
---|
832 | |
---|
833 | # for each peripheral type, define default values |
---|
834 | # for pbase address, size, number of components, and channels |
---|
835 | nb_cma = 0 |
---|
836 | cma_channels = 0 |
---|
837 | seg_cma_base = 0xFFFFFFFF |
---|
838 | seg_cma_size = 0 |
---|
839 | |
---|
840 | nb_dma = 0 |
---|
841 | dma_channels = 0 |
---|
842 | seg_dma_base = 0xFFFFFFFF |
---|
843 | seg_dma_size = 0 |
---|
844 | |
---|
845 | nb_fbf = 0 |
---|
846 | fbf_channels = 0 |
---|
847 | fbf_arg = 0 |
---|
848 | seg_fbf_base = 0xFFFFFFFF |
---|
849 | seg_fbf_size = 0 |
---|
850 | |
---|
851 | nb_iob = 0 |
---|
852 | iob_channels = 0 |
---|
853 | seg_iob_base = 0xFFFFFFFF |
---|
854 | seg_iob_size = 0 |
---|
855 | |
---|
856 | nb_ioc = 0 |
---|
857 | ioc_channels = 0 |
---|
858 | seg_ioc_base = 0xFFFFFFFF |
---|
859 | seg_ioc_size = 0 |
---|
860 | |
---|
861 | nb_mmc = 0 |
---|
862 | mmc_channels = 0 |
---|
863 | seg_mmc_base = 0xFFFFFFFF |
---|
864 | seg_mmc_size = 0 |
---|
865 | |
---|
866 | nb_mwr = 0 |
---|
867 | mwr_channels = 0 |
---|
868 | seg_mwr_base = 0xFFFFFFFF |
---|
869 | seg_mwr_size = 0 |
---|
870 | |
---|
871 | nb_nic = 0 |
---|
872 | nic_channels = 0 |
---|
873 | seg_nic_base = 0xFFFFFFFF |
---|
874 | seg_nic_size = 0 |
---|
875 | |
---|
876 | nb_pic = 0 |
---|
877 | pic_channels = 0 |
---|
878 | seg_pic_base = 0xFFFFFFFF |
---|
879 | seg_pic_size = 0 |
---|
880 | |
---|
881 | nb_rom = 0 |
---|
882 | rom_channels = 0 |
---|
883 | seg_rom_base = 0xFFFFFFFF |
---|
884 | seg_rom_size = 0 |
---|
885 | |
---|
886 | nb_sim = 0 |
---|
887 | sim_channels = 0 |
---|
888 | seg_sim_base = 0xFFFFFFFF |
---|
889 | seg_sim_size = 0 |
---|
890 | |
---|
891 | nb_tim = 0 |
---|
892 | tim_channels = 0 |
---|
893 | seg_tim_base = 0xFFFFFFFF |
---|
894 | seg_tim_size = 0 |
---|
895 | |
---|
896 | nb_tty = 0 |
---|
897 | tty_channels = 0 |
---|
898 | seg_tty_base = 0xFFFFFFFF |
---|
899 | seg_tty_size = 0 |
---|
900 | |
---|
901 | nb_xcu = 0 |
---|
902 | xcu_channels = 0 |
---|
903 | xcu_arg = 0 |
---|
904 | seg_xcu_base = 0xFFFFFFFF |
---|
905 | seg_xcu_size = 0 |
---|
906 | |
---|
907 | nb_drom = 0 |
---|
908 | drom_channels = 0 |
---|
909 | seg_drom_base = 0xFFFFFFFF |
---|
910 | seg_drom_size = 0 |
---|
911 | |
---|
912 | use_bdv = False |
---|
913 | use_spi = False |
---|
914 | use_hba = False |
---|
915 | |
---|
916 | # get peripherals attributes |
---|
917 | for cluster in self.clusters: |
---|
918 | for periph in cluster.periphs: |
---|
919 | if ( periph.ptype == 'CMA' ): |
---|
920 | seg_cma_base = periph.pseg.base & 0xFFFFFFFF |
---|
921 | seg_cma_size = periph.pseg.size |
---|
922 | cma_channels = periph.channels |
---|
923 | nb_cma +=1 |
---|
924 | |
---|
925 | elif ( periph.ptype == 'DMA' ): |
---|
926 | seg_dma_base = periph.pseg.base & 0xFFFFFFFF |
---|
927 | seg_dma_size = periph.pseg.size |
---|
928 | dma_channels = periph.channels |
---|
929 | nb_dma +=1 |
---|
930 | |
---|
931 | elif ( periph.ptype == 'FBF' ): |
---|
932 | seg_fbf_base = periph.pseg.base & 0xFFFFFFFF |
---|
933 | seg_fbf_size = periph.pseg.size |
---|
934 | fbf_channels = periph.channels |
---|
935 | fbf_arg = periph.arg |
---|
936 | nb_fbf +=1 |
---|
937 | |
---|
938 | elif ( periph.ptype == 'IOB' ): |
---|
939 | seg_iob_base = periph.pseg.base & 0xFFFFFFFF |
---|
940 | seg_iob_size = periph.pseg.size |
---|
941 | iob_channels = periph.channels |
---|
942 | nb_iob +=1 |
---|
943 | |
---|
944 | elif ( periph.ptype == 'IOC' ): |
---|
945 | seg_ioc_base = periph.pseg.base & 0xFFFFFFFF |
---|
946 | seg_ioc_size = periph.pseg.size |
---|
947 | ioc_channels = periph.channels |
---|
948 | nb_ioc += 1 |
---|
949 | |
---|
950 | if self.use_ramdisk: continue |
---|
951 | |
---|
952 | if ( periph.subtype == 'BDV' ): use_bdv = True |
---|
953 | elif ( periph.subtype == 'HBA' ): use_hba = True |
---|
954 | elif ( periph.subtype == 'SPI' ): use_spi = True |
---|
955 | |
---|
956 | elif ( periph.ptype == 'MMC' ): |
---|
957 | seg_mmc_base = periph.pseg.base & 0xFFFFFFFF |
---|
958 | seg_mmc_size = periph.pseg.size |
---|
959 | mmc_channels = periph.channels |
---|
960 | nb_mmc +=1 |
---|
961 | |
---|
962 | elif ( periph.ptype == 'MWR' ): |
---|
963 | seg_mwr_base = periph.pseg.base & 0xFFFFFFFF |
---|
964 | seg_wmr_size = periph.pseg.size |
---|
965 | mwr_channels = periph.channels |
---|
966 | nb_mwr +=1 |
---|
967 | |
---|
968 | elif ( periph.ptype == 'ROM' ): |
---|
969 | seg_rom_base = periph.pseg.base & 0xFFFFFFFF |
---|
970 | seg_rom_size = periph.pseg.size |
---|
971 | rom_channels = periph.channels |
---|
972 | nb_rom +=1 |
---|
973 | |
---|
974 | elif ( periph.ptype == 'DROM' ): |
---|
975 | seg_drom_base = periph.pseg.base & 0xFFFFFFFF |
---|
976 | seg_drom_size = periph.pseg.size |
---|
977 | drom_channels = periph.channels |
---|
978 | nb_drom +=1 |
---|
979 | |
---|
980 | elif ( periph.ptype == 'SIM' ): |
---|
981 | seg_sim_base = periph.pseg.base & 0xFFFFFFFF |
---|
982 | seg_sim_size = periph.pseg.size |
---|
983 | sim_channels = periph.channels |
---|
984 | nb_sim +=1 |
---|
985 | |
---|
986 | elif ( periph.ptype == 'NIC' ): |
---|
987 | seg_nic_base = periph.pseg.base & 0xFFFFFFFF |
---|
988 | seg_nic_size = periph.pseg.size |
---|
989 | nic_channels = periph.channels |
---|
990 | nb_nic +=1 |
---|
991 | |
---|
992 | elif ( periph.ptype == 'PIC' ): |
---|
993 | seg_pic_base = periph.pseg.base & 0xFFFFFFFF |
---|
994 | seg_pic_size = periph.pseg.size |
---|
995 | pic_channels = periph.channels |
---|
996 | nb_pic +=1 |
---|
997 | |
---|
998 | elif ( periph.ptype == 'TIM' ): |
---|
999 | seg_tim_base = periph.pseg.base & 0xFFFFFFFF |
---|
1000 | seg_tim_size = periph.pseg.size |
---|
1001 | tim_channels = periph.channels |
---|
1002 | nb_tim +=1 |
---|
1003 | |
---|
1004 | elif ( periph.ptype == 'TTY' ): |
---|
1005 | seg_tty_base = periph.pseg.base & 0xFFFFFFFF |
---|
1006 | seg_tty_size = periph.pseg.size |
---|
1007 | tty_channels = periph.channels |
---|
1008 | nb_tty +=1 |
---|
1009 | |
---|
1010 | elif ( periph.ptype == 'XCU' ): |
---|
1011 | seg_xcu_base = periph.pseg.base & 0xFFFFFFFF |
---|
1012 | seg_xcu_size = periph.pseg.size |
---|
1013 | xcu_channels = periph.channels |
---|
1014 | xcu_arg = periph.arg |
---|
1015 | nb_xcu +=1 |
---|
1016 | |
---|
1017 | # no more than two access to external peripherals |
---|
1018 | assert ( nb_fbf <= 2 ) |
---|
1019 | assert ( nb_cma <= 2 ) |
---|
1020 | assert ( nb_ioc <= 2 ) |
---|
1021 | assert ( nb_nic <= 2 ) |
---|
1022 | assert ( nb_tim <= 2 ) |
---|
1023 | assert ( nb_tty <= 2 ) |
---|
1024 | assert ( nb_pic <= 2 ) |
---|
1025 | |
---|
1026 | # one and only one type of IOC controller |
---|
1027 | nb_iocs = 0 |
---|
1028 | if use_hba : nb_iocs += 1 |
---|
1029 | if use_bdv : nb_iocs += 1 |
---|
1030 | if use_spi : nb_iocs += 1 |
---|
1031 | if self.use_ramdisk: nb_iocs += 1 |
---|
1032 | assert ( nb_iocs == 1 ) |
---|
1033 | |
---|
1034 | # Compute total number of processors |
---|
1035 | for cluster in self.clusters: |
---|
1036 | nb_total_procs += len( cluster.procs ) |
---|
1037 | |
---|
1038 | # Compute physical addresses for BOOT vsegs |
---|
1039 | boot_mapping_found = False |
---|
1040 | boot_code_found = False |
---|
1041 | boot_data_found = False |
---|
1042 | boot_stack_found = False |
---|
1043 | |
---|
1044 | for vseg in self.globs: |
---|
1045 | if ( vseg.name == 'seg_boot_mapping' ): |
---|
1046 | boot_mapping_base = vseg.vbase |
---|
1047 | boot_mapping_size = vseg.vobjs[0].length |
---|
1048 | boot_mapping_identity = vseg.identity |
---|
1049 | boot_mapping_found = True |
---|
1050 | |
---|
1051 | if ( vseg.name == 'seg_boot_code' ): |
---|
1052 | boot_code_base = vseg.vbase |
---|
1053 | boot_code_size = vseg.vobjs[0].length |
---|
1054 | boot_code_identity = vseg.identity |
---|
1055 | boot_code_found = True |
---|
1056 | |
---|
1057 | if ( vseg.name == 'seg_boot_data' ): |
---|
1058 | boot_data_base = vseg.vbase |
---|
1059 | boot_data_size = vseg.vobjs[0].length |
---|
1060 | boot_data_identity = vseg.identity |
---|
1061 | boot_data_found = True |
---|
1062 | |
---|
1063 | if ( vseg.name == 'seg_boot_stack' ): |
---|
1064 | boot_stack_base = vseg.vbase |
---|
1065 | boot_stack_size = vseg.vobjs[0].length |
---|
1066 | boot_stack_identity = vseg.identity |
---|
1067 | boot_stack_found = True |
---|
1068 | |
---|
1069 | # check that BOOT vsegs are found and identity mapping |
---|
1070 | if ( (boot_mapping_found == False) or (boot_mapping_identity == False) ): |
---|
1071 | print '[genmap error] in hard_config() : seg_boot_mapping missing or not ident' |
---|
1072 | sys.exit() |
---|
1073 | |
---|
1074 | if ( (boot_code_found == False) or (boot_code_identity == False) ): |
---|
1075 | print '[genmap error] in hard_config() : seg_boot_code missing or not ident' |
---|
1076 | sys.exit() |
---|
1077 | |
---|
1078 | if ( (boot_data_found == False) or (boot_data_identity == False) ): |
---|
1079 | print '[genmap error] in hard_config() : seg_boot_data missing or not ident' |
---|
1080 | sys.exit() |
---|
1081 | |
---|
1082 | if ( (boot_stack_found == False) or (boot_stack_identity == False) ): |
---|
1083 | print '[genmap error] in giet_vsegs() : seg_boot_stack missing or not ident' |
---|
1084 | sys.exit() |
---|
1085 | |
---|
1086 | # Search RAMDISK global vseg if required |
---|
1087 | seg_rdk_base = 0xFFFFFFFF |
---|
1088 | seg_rdk_size = 0 |
---|
1089 | seg_rdk_found = False |
---|
1090 | |
---|
1091 | if self.use_ramdisk: |
---|
1092 | for vseg in self.globs: |
---|
1093 | if ( vseg.name == 'seg_rdk' ): |
---|
1094 | seg_rdk_base = vseg.vbase |
---|
1095 | seg_rdk_size = vseg.vobjs[0].length |
---|
1096 | seg_rdk_found = True |
---|
1097 | |
---|
1098 | if ( seg_rdk_found == False ): |
---|
1099 | print 'Error in hard_config() "seg_ramdisk" not found' |
---|
1100 | sys.exit(1) |
---|
1101 | |
---|
1102 | # build string |
---|
1103 | s = '/* Generated by genmap for %s */\n' % self.name |
---|
1104 | s += '\n' |
---|
1105 | s += '#ifndef HARD_CONFIG_H\n' |
---|
1106 | s += '#define HARD_CONFIG_H\n' |
---|
1107 | s += '\n' |
---|
1108 | |
---|
1109 | s += '/* General platform parameters */\n' |
---|
1110 | s += '\n' |
---|
1111 | s += '#define X_SIZE %d\n' % self.x_size |
---|
1112 | s += '#define Y_SIZE %d\n' % self.y_size |
---|
1113 | s += '#define X_WIDTH %d\n' % self.x_width |
---|
1114 | s += '#define Y_WIDTH %d\n' % self.y_width |
---|
1115 | s += '#define P_WIDTH %d\n' % self.p_width |
---|
1116 | s += '#define X_IO %d\n' % self.x_io |
---|
1117 | s += '#define Y_IO %d\n' % self.y_io |
---|
1118 | s += '#define NB_PROCS_MAX %d\n' % self.nprocs |
---|
1119 | s += '#define IRQ_PER_PROCESSOR %d\n' % self.irq_per_proc |
---|
1120 | s += '#define RESET_ADDRESS 0x%x\n' % self.reset_address |
---|
1121 | s += '#define NB_TOTAL_PROCS %d\n' % nb_total_procs |
---|
1122 | s += '\n' |
---|
1123 | |
---|
1124 | s += '/* Peripherals */\n' |
---|
1125 | s += '\n' |
---|
1126 | s += '#define NB_TTY_CHANNELS %d\n' % tty_channels |
---|
1127 | s += '#define NB_IOC_CHANNELS %d\n' % ioc_channels |
---|
1128 | s += '#define NB_NIC_CHANNELS %d\n' % nic_channels |
---|
1129 | s += '#define NB_CMA_CHANNELS %d\n' % cma_channels |
---|
1130 | s += '#define NB_TIM_CHANNELS %d\n' % tim_channels |
---|
1131 | s += '#define NB_DMA_CHANNELS %d\n' % dma_channels |
---|
1132 | s += '\n' |
---|
1133 | s += '#define USE_XCU %d\n' % ( nb_xcu != 0 ) |
---|
1134 | s += '#define USE_IOB %d\n' % ( nb_iob != 0 ) |
---|
1135 | s += '#define USE_PIC %d\n' % ( nb_pic != 0 ) |
---|
1136 | s += '#define USE_FBF %d\n' % ( nb_fbf != 0 ) |
---|
1137 | s += '\n' |
---|
1138 | s += '#define USE_IOC_BDV %d\n' % use_bdv |
---|
1139 | s += '#define USE_IOC_SPI %d\n' % use_spi |
---|
1140 | s += '#define USE_IOC_HBA %d\n' % use_hba |
---|
1141 | s += '#define USE_IOC_RDK %d\n' % self.use_ramdisk |
---|
1142 | s += '\n' |
---|
1143 | s += '#define FBUF_X_SIZE %d\n' % fbf_arg |
---|
1144 | s += '#define FBUF_Y_SIZE %d\n' % fbf_arg |
---|
1145 | s += '\n' |
---|
1146 | s += '#define XCU_NB_INPUTS %d\n' % xcu_arg |
---|
1147 | s += '\n' |
---|
1148 | |
---|
1149 | s += '/* base addresses and sizes for physical segments */\n' |
---|
1150 | s += '\n' |
---|
1151 | s += '#define SEG_RAM_BASE 0x%x\n' % self.ram_base |
---|
1152 | s += '#define SEG_RAM_SIZE 0x%x\n' % self.ram_size |
---|
1153 | s += '\n' |
---|
1154 | s += '#define SEG_CMA_BASE 0x%x\n' % seg_cma_base |
---|
1155 | s += '#define SEG_CMA_SIZE 0x%x\n' % seg_cma_size |
---|
1156 | s += '\n' |
---|
1157 | s += '#define SEG_DMA_BASE 0x%x\n' % seg_dma_base |
---|
1158 | s += '#define SEG_DMA_SIZE 0x%x\n' % seg_dma_size |
---|
1159 | s += '\n' |
---|
1160 | s += '#define SEG_FBF_BASE 0x%x\n' % seg_fbf_base |
---|
1161 | s += '#define SEG_FBF_SIZE 0x%x\n' % seg_fbf_size |
---|
1162 | s += '\n' |
---|
1163 | s += '#define SEG_IOB_BASE 0x%x\n' % seg_iob_base |
---|
1164 | s += '#define SEG_IOB_SIZE 0x%x\n' % seg_iob_size |
---|
1165 | s += '\n' |
---|
1166 | s += '#define SEG_IOC_BASE 0x%x\n' % seg_ioc_base |
---|
1167 | s += '#define SEG_IOC_SIZE 0x%x\n' % seg_ioc_size |
---|
1168 | s += '\n' |
---|
1169 | s += '#define SEG_MMC_BASE 0x%x\n' % seg_mmc_base |
---|
1170 | s += '#define SEG_MMC_SIZE 0x%x\n' % seg_mmc_size |
---|
1171 | s += '\n' |
---|
1172 | s += '#define SEG_MWR_BASE 0x%x\n' % seg_mwr_base |
---|
1173 | s += '#define SEG_MWR_SIZE 0x%x\n' % seg_mwr_size |
---|
1174 | s += '\n' |
---|
1175 | s += '#define SEG_ROM_BASE 0x%x\n' % seg_rom_base |
---|
1176 | s += '#define SEG_ROM_SIZE 0x%x\n' % seg_rom_size |
---|
1177 | s += '\n' |
---|
1178 | s += '#define SEG_SIM_BASE 0x%x\n' % seg_sim_base |
---|
1179 | s += '#define SEG_SIM_SIZE 0x%x\n' % seg_sim_size |
---|
1180 | s += '\n' |
---|
1181 | s += '#define SEG_NIC_BASE 0x%x\n' % seg_nic_base |
---|
1182 | s += '#define SEG_NIC_SIZE 0x%x\n' % seg_nic_size |
---|
1183 | s += '\n' |
---|
1184 | s += '#define SEG_PIC_BASE 0x%x\n' % seg_pic_base |
---|
1185 | s += '#define SEG_PIC_SIZE 0x%x\n' % seg_pic_size |
---|
1186 | s += '\n' |
---|
1187 | s += '#define SEG_TIM_BASE 0x%x\n' % seg_tim_base |
---|
1188 | s += '#define SEG_TIM_SIZE 0x%x\n' % seg_tim_size |
---|
1189 | s += '\n' |
---|
1190 | s += '#define SEG_TTY_BASE 0x%x\n' % seg_tty_base |
---|
1191 | s += '#define SEG_TTY_SIZE 0x%x\n' % seg_tty_size |
---|
1192 | s += '\n' |
---|
1193 | s += '#define SEG_XCU_BASE 0x%x\n' % seg_xcu_base |
---|
1194 | s += '#define SEG_XCU_SIZE 0x%x\n' % seg_xcu_size |
---|
1195 | s += '\n' |
---|
1196 | s += '#define SEG_RDK_BASE 0x%x\n' % seg_rdk_base |
---|
1197 | s += '#define SEG_RDK_SIZE 0x%x\n' % seg_rdk_size |
---|
1198 | s += '\n' |
---|
1199 | s += '#define SEG_DROM_BASE 0x%x\n' % seg_drom_base |
---|
1200 | s += '#define SEG_DROM_SIZE 0x%x\n' % seg_drom_size |
---|
1201 | s += '\n' |
---|
1202 | s += '#define PERI_CLUSTER_INCREMENT 0x%x\n' % self.peri_increment |
---|
1203 | s += '\n' |
---|
1204 | |
---|
1205 | s += '/* physical base addresses for identity mapped vsegs */\n' |
---|
1206 | s += '/* used by the GietVM OS */\n' |
---|
1207 | s += '\n' |
---|
1208 | s += '#define SEG_BOOT_MAPPING_BASE 0x%x\n' % boot_mapping_base |
---|
1209 | s += '#define SEG_BOOT_MAPPING_SIZE 0x%x\n' % boot_mapping_size |
---|
1210 | s += '\n' |
---|
1211 | s += '#define SEG_BOOT_CODE_BASE 0x%x\n' % boot_code_base |
---|
1212 | s += '#define SEG_BOOT_CODE_SIZE 0x%x\n' % boot_code_size |
---|
1213 | s += '\n' |
---|
1214 | s += '#define SEG_BOOT_DATA_BASE 0x%x\n' % boot_data_base |
---|
1215 | s += '#define SEG_BOOT_DATA_SIZE 0x%x\n' % boot_data_size |
---|
1216 | s += '\n' |
---|
1217 | s += '#define SEG_BOOT_STACK_BASE 0x%x\n' % boot_stack_base |
---|
1218 | s += '#define SEG_BOOT_STACK_SIZE 0x%x\n' % boot_stack_size |
---|
1219 | s += '#endif\n' |
---|
1220 | |
---|
1221 | return s |
---|
1222 | |
---|
1223 | # end of hard_config() |
---|
1224 | |
---|
1225 | ################################################################################ |
---|
1226 | def linux_dts( self ): # compute string for linux.dts file generation |
---|
1227 | # used for linux configuration |
---|
1228 | # header |
---|
1229 | s = '/dts-v1/;\n' |
---|
1230 | s += '\n' |
---|
1231 | s += '/{\n' |
---|
1232 | s += ' compatible = "tsar,%s";\n' % self.name |
---|
1233 | s += ' #address-cells = <2>;\n' # physical address on 64 bits |
---|
1234 | s += ' #size-cells = <1>;\n' # segment size on 32 bits |
---|
1235 | s += ' model = "%s";\n' % self.name |
---|
1236 | s += '\n' |
---|
1237 | |
---|
1238 | # linux globals arguments |
---|
1239 | s += ' chosen {\n' |
---|
1240 | s += ' linux,stdout-path = &tty;\n' |
---|
1241 | s += ' bootargs = "console=tty0 console=ttyVTTY0 earlyprintk";\n' |
---|
1242 | s += ' };\n\n' |
---|
1243 | |
---|
1244 | # cpus (for each cluster) |
---|
1245 | s += ' cpus {\n' |
---|
1246 | s += ' #address-cells = <1>;\n' |
---|
1247 | s += ' #size-cells = <0>;\n' |
---|
1248 | |
---|
1249 | for cluster in self.clusters: |
---|
1250 | for proc in cluster.procs: |
---|
1251 | x = cluster.x |
---|
1252 | y = cluster.y |
---|
1253 | l = proc.lpid |
---|
1254 | proc_id = (((x << self.y_width) + y) << self.p_width) + l |
---|
1255 | s += ' cpu@%d_%d_%d {\n' %(x,y,l) |
---|
1256 | s += ' device_type = "cpu";\n' |
---|
1257 | s += ' compatible = "soclib,mips32el";\n' |
---|
1258 | s += ' reg = <0x%x>;\n' % proc_id |
---|
1259 | s += ' };\n' |
---|
1260 | s += '\n' |
---|
1261 | |
---|
1262 | s += ' };\n\n' |
---|
1263 | |
---|
1264 | # devices (ram or peripheral) are grouped per cluster |
---|
1265 | # the "compatible" attribute links a peripheral device |
---|
1266 | # to one or several drivers identified by ("major","minor") |
---|
1267 | |
---|
1268 | for cluster in self.clusters: |
---|
1269 | x = cluster.x |
---|
1270 | y = cluster.y |
---|
1271 | found_xcu = False |
---|
1272 | found_pic = False |
---|
1273 | |
---|
1274 | s += ' /*** cluster[%d,%d] ***/\n\n' % (x,y) |
---|
1275 | |
---|
1276 | # scan all psegs to find RAM in current cluster |
---|
1277 | for pseg in cluster.psegs: |
---|
1278 | if ( pseg.segtype == 'RAM' ): |
---|
1279 | msb = pseg.base >> 32 |
---|
1280 | lsb = pseg.base & 0xFFFFFFFF |
---|
1281 | size = pseg.size |
---|
1282 | |
---|
1283 | s += ' ram_%d_%d: ram@0x%x {\n' % (x, y, pseg.base) |
---|
1284 | s += ' device_type = "memory";\n' |
---|
1285 | s += ' reg = <0x%x 0x%x 0x%x>;\n' % (msb, lsb, size) |
---|
1286 | s += ' };\n\n' |
---|
1287 | |
---|
1288 | # scan all periphs to find XCU or PIC in current cluster |
---|
1289 | for periph in cluster.periphs: |
---|
1290 | msb = periph.pseg.base >> 32 |
---|
1291 | lsb = periph.pseg.base & 0xFFFFFFFF |
---|
1292 | size = periph.pseg.size |
---|
1293 | |
---|
1294 | # search XCU (can be replicated) |
---|
1295 | if ( (periph.ptype == 'XCU') ): |
---|
1296 | found_xcu = True |
---|
1297 | xcu = periph |
---|
1298 | irq_ctrl_name = 'xcu_%d_%d' % (x, y) |
---|
1299 | |
---|
1300 | s += ' %s: xcu@0x%x {\n' % (irq_ctrl_name, periph.pseg.base) |
---|
1301 | s += ' compatible = "soclib,vci_xicu","soclib,vci_xicu_timer";\n' |
---|
1302 | s += ' interrupt-controller;\n' |
---|
1303 | s += ' #interrupt-cells = <1>;\n' |
---|
1304 | s += ' clocks = <&freq>;\n' # the XCU component contains a timer |
---|
1305 | s += ' reg = <0x%x 0x%x 0x%x>;\n' % (msb, lsb, size) |
---|
1306 | s += ' };\n\n' |
---|
1307 | |
---|
1308 | # search PIC (non replicated) |
---|
1309 | if ( periph.ptype == 'PIC' ): |
---|
1310 | found_pic = True |
---|
1311 | pic = periph |
---|
1312 | irq_ctrl_name = 'pic' |
---|
1313 | |
---|
1314 | s += ' %s: pic@0x%x {\n' % (irq_ctrl_name, periph.pseg.base) |
---|
1315 | s += ' compatible = "soclib,vci_iopic";\n' |
---|
1316 | s += ' interrupt-controller;\n' |
---|
1317 | s += ' #interrupt-cells = <1>;\n' |
---|
1318 | s += ' reg = <0x%x 0x%x 0x%x>;\n' % (msb, lsb, size) |
---|
1319 | s += ' };\n\n' |
---|
1320 | |
---|
1321 | # we need one interrupt controler in any cluster containing peripherals |
---|
1322 | if ( (found_xcu == False) and (found_pic == False) and (len(cluster.periphs) > 0) ): |
---|
1323 | print '[genmap error] in linux_dts() : No XCU/PIC in cluster(%d,%d)' % (x,y) |
---|
1324 | sys.exit(1) |
---|
1325 | |
---|
1326 | if ( found_pic == True ): irq_ctrl = pic |
---|
1327 | else: irq_ctrl = xcu |
---|
1328 | |
---|
1329 | # scan all periphs to find TTY and IOC in current cluster |
---|
1330 | for periph in cluster.periphs: |
---|
1331 | msb = periph.pseg.base >> 32 |
---|
1332 | lsb = periph.pseg.base & 0xFFFFFFFF |
---|
1333 | size = periph.pseg.size |
---|
1334 | |
---|
1335 | # search TTY (non replicated) |
---|
1336 | if ( periph.ptype == 'TTY' ): |
---|
1337 | |
---|
1338 | # get HWI index to XCU or PIC (only TTY channel 0 is used by Linux) |
---|
1339 | hwi_id = 0xFFFFFFFF |
---|
1340 | for irq in irq_ctrl.irqs: |
---|
1341 | if ( (irq.isrtype == 'ISR_TTY_RX') and (irq.channel == 0) ): hwi_id = irq.srcid |
---|
1342 | if ( hwi_id == 0xFFFFFFFF ): |
---|
1343 | print '[genmap error] in linux.dts() IRQ_TTY_RX not found' |
---|
1344 | sys.exit(1) |
---|
1345 | |
---|
1346 | s += ' tty: tty {\n' |
---|
1347 | s += ' compatible = "soclib,vci_multi_tty";\n' |
---|
1348 | s += ' interrupt-parent = <&%s>;\n' % (irq_ctrl_name) |
---|
1349 | s += ' interrupts = <%d>;\n' % hwi_id |
---|
1350 | s += ' reg = <0x%x 0x%x 0x%x>;\n' % (msb, lsb, size) |
---|
1351 | s += ' };\n\n' |
---|
1352 | |
---|
1353 | # search IOC (non replicated) |
---|
1354 | elif ( periph.ptype == 'IOC' ): |
---|
1355 | |
---|
1356 | if ( periph.subtype == 'BDV' ): |
---|
1357 | |
---|
1358 | # get irq line index associated to bdv |
---|
1359 | hwi_id = 0xFFFFFFFF |
---|
1360 | for irq in irq_ctrl.irqs: |
---|
1361 | if ( irq.isrtype == 'ISR_BDV' ): hwi_id = irq.srcid |
---|
1362 | if ( hwi_id == 0xFFFFFFFF ): |
---|
1363 | print '[genmap error] in linux.dts() ISR_BDV not found' |
---|
1364 | sys.exit(1) |
---|
1365 | |
---|
1366 | s += ' bdv: bdv {\n' |
---|
1367 | s += ' compatible = "soclib,vci_blockdevice";\n' |
---|
1368 | s += ' interrupt-parent = <&%s>;\n' % (irq_ctrl_name) |
---|
1369 | s += ' interrupts = <%d>;\n' % hwi_id |
---|
1370 | s += ' reg = <0x%x 0x%x 0x%x>;\n' % (msb, lsb, size) |
---|
1371 | s += ' };\n\n' |
---|
1372 | |
---|
1373 | elif ( periph.subtype == 'HBA' ): |
---|
1374 | |
---|
1375 | print '[genmap error] in linux_dts() : HBA peripheral not supported by LINUX' |
---|
1376 | sys.exit(1) |
---|
1377 | |
---|
1378 | elif ( periph.subtype == 'SPI' ): |
---|
1379 | |
---|
1380 | print '[genmap error] in linux_dts() : SPI peripheral not supported by LINUX' |
---|
1381 | sys.exit(1) |
---|
1382 | |
---|
1383 | # XCU or PIC have been already parsed |
---|
1384 | elif ( periph.ptype == 'XCU' ) or ( periph.ptype == 'PIC' ): |
---|
1385 | pass |
---|
1386 | |
---|
1387 | # other peripherals |
---|
1388 | else: |
---|
1389 | type = periph.ptype |
---|
1390 | print '[genmap warning] in linux_dts() : %s peripheral not supported by LINUX' % (type) |
---|
1391 | |
---|
1392 | # clocks |
---|
1393 | s += ' /*** clocks ***/\n\n' |
---|
1394 | s += ' clocks {\n' |
---|
1395 | s += ' freq: freq@50MHZ {\n' |
---|
1396 | s += ' #clock-cells = <0>;\n' |
---|
1397 | s += ' compatible = "fixed-clock";\n' |
---|
1398 | s += ' clock-frequency = <50000000>;\n' |
---|
1399 | s += ' };\n' |
---|
1400 | s += ' };\n\n' |
---|
1401 | s += ' cpuclk {\n' |
---|
1402 | s += ' compatible = "soclib,mips32_clksrc";\n' |
---|
1403 | s += ' clocks = <&freq>;\n' |
---|
1404 | s += ' };\n' |
---|
1405 | s += '};\n' |
---|
1406 | |
---|
1407 | return s |
---|
1408 | # end linux_dts() |
---|
1409 | |
---|
1410 | |
---|
1411 | ############################################################################# |
---|
1412 | def netbsd_dts( self ): # compute string for netbsd.dts file generation, |
---|
1413 | # used for netbsd configuration |
---|
1414 | # header |
---|
1415 | s = '/dts-v1/;\n' |
---|
1416 | s += '\n' |
---|
1417 | s += '/{\n' |
---|
1418 | s += ' #address-cells = <2>;\n' |
---|
1419 | s += ' #size-cells = <1>;\n' |
---|
1420 | |
---|
1421 | # cpus (for each cluster) |
---|
1422 | s += ' cpus {\n' |
---|
1423 | s += ' #address-cells = <1>;\n' |
---|
1424 | s += ' #size-cells = <0>;\n' |
---|
1425 | |
---|
1426 | for cluster in self.clusters: |
---|
1427 | for proc in cluster.procs: |
---|
1428 | proc_id = (((cluster.x << self.y_width) + cluster.y) << self.p_width) + proc.lpid |
---|
1429 | |
---|
1430 | s += ' Mips,32@0x%x {\n' % proc_id |
---|
1431 | s += ' device_type = "cpu";\n' |
---|
1432 | s += ' icudev_type = "cpu:mips";\n' |
---|
1433 | s += ' name = "Mips,32";\n' |
---|
1434 | s += ' reg = <0x%x>;\n' % proc_id |
---|
1435 | s += ' };\n' |
---|
1436 | s += '\n' |
---|
1437 | |
---|
1438 | s += ' };\n' |
---|
1439 | |
---|
1440 | # physical memory banks (for each cluster) |
---|
1441 | for cluster in self.clusters: |
---|
1442 | for pseg in cluster.psegs: |
---|
1443 | |
---|
1444 | if ( pseg.segtype == 'RAM' ): |
---|
1445 | msb = pseg.base >> 32 |
---|
1446 | lsb = pseg.base & 0xFFFFFFFF |
---|
1447 | size = pseg.size |
---|
1448 | |
---|
1449 | s += ' %s@0x%x {\n' % (pseg.name, pseg.base) |
---|
1450 | s += ' cached = <1>;\n' |
---|
1451 | s += ' device_type = "memory";\n' |
---|
1452 | s += ' reg = <0x%x 0x%x 0x%x>;\n' % (msb, lsb, size) |
---|
1453 | s += ' };\n' |
---|
1454 | |
---|
1455 | # peripherals (for each cluster) |
---|
1456 | for cluster in self.clusters: |
---|
1457 | x = cluster.x |
---|
1458 | y = cluster.y |
---|
1459 | |
---|
1460 | # research XCU component |
---|
1461 | found_xcu = False |
---|
1462 | for periph in cluster.periphs: |
---|
1463 | if ( (periph.ptype == 'XCU') ): |
---|
1464 | found_xcu = True |
---|
1465 | xcu = periph |
---|
1466 | msb = periph.pseg.base >> 32 |
---|
1467 | lsb = periph.pseg.base & 0xFFFFFFFF |
---|
1468 | size = periph.pseg.size |
---|
1469 | |
---|
1470 | s += ' %s@0x%x {\n' % (periph.pseg.name, periph.pseg.base) |
---|
1471 | s += ' device_type = "soclib:xicu:root";\n' |
---|
1472 | s += ' reg = <0x%x 0x%x 0x%x>;\n' % (msb, lsb, size) |
---|
1473 | s += ' input_lines = <%d>;\n' % periph.arg |
---|
1474 | s += ' ipis = <%d>;\n' % periph.arg |
---|
1475 | s += ' timers = <%d>;\n' % periph.arg |
---|
1476 | |
---|
1477 | output_id = 0 # output index from XCU |
---|
1478 | for lpid in xrange ( len(cluster.procs) ): # destination processor index |
---|
1479 | for itid in xrange ( self.irq_per_proc ): # input irq index on processor |
---|
1480 | cluster_xy = (cluster.x << self.y_width) + cluster.y |
---|
1481 | proc_id = (cluster_xy << self.p_width) + lpid |
---|
1482 | s += ' out@%d {\n' % output_id |
---|
1483 | s += ' device_type = "soclib:xicu:filter";\n' |
---|
1484 | s += ' irq = <&{/cpus/Mips,32@0x%x} %d>;\n' % (proc_id, itid) |
---|
1485 | s += ' output_line = <%d>;\n' % output_id |
---|
1486 | s += ' parent = <&{/%s@0x%x}>;\n' % (periph.pseg.name, periph.pseg.base) |
---|
1487 | s += ' };\n' |
---|
1488 | |
---|
1489 | output_id += 1 |
---|
1490 | |
---|
1491 | s += ' };\n' |
---|
1492 | |
---|
1493 | # research PIC component |
---|
1494 | found_pic = False |
---|
1495 | for periph in cluster.periphs: |
---|
1496 | if ( periph.ptype == 'PIC' ): |
---|
1497 | found_pic = True |
---|
1498 | pic = periph |
---|
1499 | msb = periph.pseg.base >> 32 |
---|
1500 | lsb = periph.pseg.base & 0xFFFFFFFF |
---|
1501 | size = periph.pseg.size |
---|
1502 | |
---|
1503 | s += ' %s@0x%x {\n' % (periph.pseg.name, periph.pseg.base) |
---|
1504 | s += ' device_type = "soclib:pic:root";\n' |
---|
1505 | s += ' reg = <0x%x 0x%x 0x%x>;\n' % (msb, lsb, size) |
---|
1506 | s += ' input_lines = <%d>;\n' % periph.channels |
---|
1507 | s += ' };\n' |
---|
1508 | |
---|
1509 | # at least one interrupt controller |
---|
1510 | if ( (found_xcu == False) and (found_pic == False) and (len(cluster.periphs) > 0) ): |
---|
1511 | print '[genmap error] in netbsd_dts() : No XCU/PIC in cluster(%d,%d)' % (x,y) |
---|
1512 | sys.exit(1) |
---|
1513 | |
---|
1514 | if ( found_pic == True ): irq_tgt = pic |
---|
1515 | else: irq_tgt = xcu |
---|
1516 | |
---|
1517 | # get all others peripherals in cluster |
---|
1518 | for periph in cluster.periphs: |
---|
1519 | msb = periph.pseg.base >> 32 |
---|
1520 | lsb = periph.pseg.base & 0xFFFFFFFF |
---|
1521 | size = periph.pseg.size |
---|
1522 | |
---|
1523 | # research DMA component |
---|
1524 | if ( periph.ptype == 'DMA' ): |
---|
1525 | |
---|
1526 | s += ' %s@0x%x {\n' % (periph.pseg.name, periph.pseg.base) |
---|
1527 | s += ' device_type = "soclib:dma";\n' |
---|
1528 | s += ' reg = <0x%x 0x%x 0x%x>;\n' % (msb, lsb, size) |
---|
1529 | s += ' channel_count = <%d>;\n' % periph.channels |
---|
1530 | |
---|
1531 | # multi-channels : get HWI index (to XCU) for each channel |
---|
1532 | for channel in xrange( periph.channels ): |
---|
1533 | hwi_id = 0xFFFFFFFF |
---|
1534 | for irq in xcu.irqs: |
---|
1535 | if ( (irq.isrtype == 'ISR_DMA') and (irq.channel == channel) ): |
---|
1536 | hwi_id = irq.srcid |
---|
1537 | if ( hwi_id == 0xFFFFFFFF ): |
---|
1538 | print '[genmap error] in netbsd.dts() ISR_DMA channel %d not found' % channel |
---|
1539 | sys.exit(1) |
---|
1540 | |
---|
1541 | name = '%s@0x%x' % (xcu.pseg.name, xcu.pseg.base) |
---|
1542 | s += ' irq@%d{\n' % channel |
---|
1543 | s += ' device_type = "soclib:periph:irq";\n' |
---|
1544 | s += ' output_line = <%d>;\n' % channel |
---|
1545 | s += ' irq = <&{/%s} %d>;\n' % (name, hwi_id) |
---|
1546 | s += ' parent = <&{/%s@0x%x}>;\n' % (periph.pseg.name, periph.pseg.base) |
---|
1547 | s += ' };\n' |
---|
1548 | |
---|
1549 | s += ' };\n' |
---|
1550 | |
---|
1551 | # research MMC component |
---|
1552 | elif ( periph.ptype == 'MMC' ): |
---|
1553 | |
---|
1554 | # get irq line index associated to MMC in XCU |
---|
1555 | irq_in = 0xFFFFFFFF |
---|
1556 | for irq in xcu.irqs: |
---|
1557 | if ( irq.isrtype == 'ISR_MMC' ): irq_in = irq.srcid |
---|
1558 | if ( irq_in == 0xFFFFFFFF ): |
---|
1559 | print '[genmap error] in netbsd.dts() ISR_MMC not found' |
---|
1560 | sys.exit(1) |
---|
1561 | |
---|
1562 | s += ' %s@0x%x {\n' % (periph.pseg.name, periph.pseg.base) |
---|
1563 | s += ' device_type = "soclib:mmc";\n' |
---|
1564 | s += ' irq = <&{/%s@0x%x} %d>;\n' % (irq_tgt.pseg.name, irq_tgt.pseg.base, irq_in) |
---|
1565 | s += ' reg = <0x%x 0x%x 0x%x>;\n' % (msb, lsb, size) |
---|
1566 | s += ' };\n' |
---|
1567 | |
---|
1568 | # research FBF component |
---|
1569 | elif ( periph.ptype == 'FBF' ): |
---|
1570 | |
---|
1571 | s += ' %s@0x%x {\n' % (periph.pseg.name, periph.pseg.base) |
---|
1572 | s += ' device_type = "soclib:framebuffer";\n' |
---|
1573 | s += ' mode = <32>;\n' # bits par pixel |
---|
1574 | s += ' width = <%d>;\n' % periph.arg |
---|
1575 | s += ' height = <%d>;\n' % periph.arg |
---|
1576 | s += ' reg = <0x%x 0x%x 0x%x>;\n' % (msb, lsb, size) |
---|
1577 | s += ' };\n' |
---|
1578 | |
---|
1579 | # research IOC component |
---|
1580 | elif ( periph.ptype == 'IOC' ): |
---|
1581 | |
---|
1582 | if ( periph.subtype == 'BDV' ): |
---|
1583 | |
---|
1584 | # get irq line index associated to bdv |
---|
1585 | irq_in = 0xFFFFFFFF |
---|
1586 | for irq in irq_tgt.irqs: |
---|
1587 | if ( irq.isrtype == 'ISR_BDV' ): irq_in = irq.srcid |
---|
1588 | if ( irq_in == 0xFFFFFFFF ): |
---|
1589 | print '[genmap error] in netbsd.dts() ISR_BDV not found' |
---|
1590 | sys.exit(1) |
---|
1591 | |
---|
1592 | s += ' %s@0x%x {\n' % (periph.pseg.name, periph.pseg.base) |
---|
1593 | s += ' device_type = "soclib:blockdevice";\n' |
---|
1594 | s += ' irq = <&{/%s@0x%x} %d>;\n' % (irq_tgt.pseg.name,irq_tgt.pseg.base,irq_in) |
---|
1595 | s += ' reg = <0x%x 0x%x 0x%x>;\n' % (msb, lsb, size) |
---|
1596 | s += ' };\n' |
---|
1597 | |
---|
1598 | elif ( periph.subtype == 'HBA' ): |
---|
1599 | print '[genmap error] in netbsd_dts() : HBA peripheral not supported by NetBSD' |
---|
1600 | sys.exit(1) |
---|
1601 | |
---|
1602 | elif ( periph.subtype == 'SPI' ): |
---|
1603 | |
---|
1604 | # get irq line index associated to spi |
---|
1605 | irq_in = 0xFFFFFFFF |
---|
1606 | for irq in irq_tgt.irqs: |
---|
1607 | if ( irq.isrtype == 'ISR_SPI' ): irq_in = irq.srcid |
---|
1608 | if ( irq_in == 0xFFFFFFFF ): |
---|
1609 | print '[genmap error] in netbsd.dts() ISR_SPI not found' |
---|
1610 | sys.exit(1) |
---|
1611 | |
---|
1612 | s += ' %s@0x%x {\n' % (periph.pseg.name, periph.pseg.base) |
---|
1613 | s += ' device_type = "soclib:spi";\n' |
---|
1614 | s += ' irq = <&{/%s@0x%x} %d>;\n' % (irq_tgt.pseg.name,irq_tgt.pseg.base,irq_in) |
---|
1615 | s += ' reg = <0x%x 0x%x 0x%x>;\n' % (msb, lsb, size) |
---|
1616 | s += ' };\n' |
---|
1617 | |
---|
1618 | # research ROM component |
---|
1619 | elif ( periph.ptype == 'ROM' ): |
---|
1620 | |
---|
1621 | s += ' %s@0x%x {\n' % (periph.pseg.name, periph.pseg.base) |
---|
1622 | s += ' device_type = "rom";\n' |
---|
1623 | s += ' cached = <1>;\n' |
---|
1624 | s += ' reg = <0x%x 0x%x 0x%x>;\n' % (msb, lsb, size) |
---|
1625 | s += ' };\n' |
---|
1626 | |
---|
1627 | # research SIM component |
---|
1628 | elif ( periph.ptype == 'SIM' ): |
---|
1629 | |
---|
1630 | s += ' %s@0x%x {\n' % (periph.pseg.name, periph.pseg.base) |
---|
1631 | s += ' device_type = "soclib:simhelper";\n' |
---|
1632 | s += ' reg = <0x%x 0x%x 0x%x>;\n' % (msb, lsb, size) |
---|
1633 | s += ' };\n' |
---|
1634 | |
---|
1635 | # research TTY component |
---|
1636 | elif ( periph.ptype == 'TTY' ): |
---|
1637 | |
---|
1638 | s += ' %s@0x%x {\n' % (periph.pseg.name, periph.pseg.base) |
---|
1639 | s += ' device_type = "soclib:tty";\n' |
---|
1640 | s += ' channel_count = < %d >;\n' % periph.channels |
---|
1641 | s += ' reg = <0x%x 0x%x 0x%x>;\n' % (msb, lsb, size) |
---|
1642 | |
---|
1643 | # multi-channels : get HWI index (to XCU or PIC) for each channel |
---|
1644 | for channel in xrange( periph.channels ): |
---|
1645 | hwi_id = 0xFFFFFFFF |
---|
1646 | for irq in irq_tgt.irqs: |
---|
1647 | if ( (irq.isrtype == 'ISR_TTY_RX') and (irq.channel == channel) ): |
---|
1648 | hwi_id = irq.srcid |
---|
1649 | if ( hwi_id == 0xFFFFFFFF ): |
---|
1650 | print '[genmap error] in netbsd.dts() ISR_TTY_RX channel %d not found' % channel |
---|
1651 | sys.exit(1) |
---|
1652 | |
---|
1653 | name = '%s@0x%x' % (irq_tgt.pseg.name, irq_tgt.pseg.base) |
---|
1654 | s += ' irq@%d{\n' % channel |
---|
1655 | s += ' device_type = "soclib:periph:irq";\n' |
---|
1656 | s += ' output_line = <%d>;\n' % channel |
---|
1657 | s += ' irq = <&{/%s} %d>;\n' % (name, hwi_id) |
---|
1658 | s += ' parent = <&{/%s@0x%x}>;\n' % (periph.pseg.name, periph.pseg.base) |
---|
1659 | s += ' };\n' |
---|
1660 | |
---|
1661 | s += ' };\n' |
---|
1662 | |
---|
1663 | # research IOB component |
---|
1664 | elif ( periph.ptype == 'IOB' ): |
---|
1665 | |
---|
1666 | s += ' %s@0x%x {\n' % (periph.pseg.name, periph.pseg.base) |
---|
1667 | s += ' device_type = "soclib:iob";\n' |
---|
1668 | s += ' reg = <0x%x 0x%x 0x%x>;\n' % (msb, lsb, size) |
---|
1669 | s += ' };\n' |
---|
1670 | |
---|
1671 | # research NIC component |
---|
1672 | elif ( periph.ptype == 'NIC' ): |
---|
1673 | |
---|
1674 | s += ' %s@0x%x {\n' % (periph.pseg.name, periph.pseg.base) |
---|
1675 | s += ' device_type = "soclib:nic";\n' |
---|
1676 | s += ' reg = <0x%x 0x%x 0x%x>;\n' % (msb, lsb, size) |
---|
1677 | s += ' channel_count = < %d >;\n' % periph.channels |
---|
1678 | |
---|
1679 | # multi-channels : get HWI index (to XCU or PIC) for RX & TX IRQs |
---|
1680 | # RX IRQ : (2*channel) / TX IRQs : (2*channel + 1) |
---|
1681 | for channel in xrange( periph.channels ): |
---|
1682 | hwi_id = 0xFFFFFFFF |
---|
1683 | for irq in irq_tgt.irqs: |
---|
1684 | if ( (irq.isrtype == 'ISR_NIC_RX') and (irq.channel == channel) ): |
---|
1685 | hwi_id = irq.srcid |
---|
1686 | if ( hwi_id == 0xFFFFFFFF ): |
---|
1687 | print '[genmap error] in netbsd.dts() ISR_NIC_RX channel %d not found' % channel |
---|
1688 | sys.exit(1) |
---|
1689 | |
---|
1690 | name = '%s@0x%x' % (irq_tgt.pseg.name, irq_tgt.pseg.base) |
---|
1691 | s += ' irq_rx@%d{\n' % channel |
---|
1692 | s += ' device_type = "soclib:periph:irq";\n' |
---|
1693 | s += ' output_line = <%d>;\n' % (2*channel) |
---|
1694 | s += ' irq = <&{/%s} %d>;\n' % (name, hwi_id) |
---|
1695 | s += ' parent = <&{/%s@0x%x}>;\n' % (periph.pseg.name, periph.pseg.base) |
---|
1696 | s += ' };\n' |
---|
1697 | |
---|
1698 | hwi_id = 0xFFFFFFFF |
---|
1699 | for irq in irq_tgt.irqs: |
---|
1700 | if ( (irq.isrtype == 'ISR_NIC_TX') and (irq.channel == channel) ): |
---|
1701 | hwi_id = irq.srcid |
---|
1702 | if ( hwi_id == 0xFFFFFFFF ): |
---|
1703 | print '[genmap error] in netbsd.dts() ISR_NIC_TX channel %d not found' % channel |
---|
1704 | sys.exit(1) |
---|
1705 | |
---|
1706 | name = '%s@0x%x' % (irq_tgt.pseg.name, irq_tgt.pseg.base) |
---|
1707 | s += ' irq_tx@%d{\n' % channel |
---|
1708 | s += ' device_type = "soclib:periph:irq";\n' |
---|
1709 | s += ' output_line = <%d>;\n' % (2*channel + 1) |
---|
1710 | s += ' irq = <&{/%s} %d>;\n' % (name, hwi_id) |
---|
1711 | s += ' parent = <&{/%s@0x%x}>;\n' % (periph.pseg.name, periph.pseg.base) |
---|
1712 | s += ' };\n' |
---|
1713 | |
---|
1714 | s += ' };\n' |
---|
1715 | |
---|
1716 | # research CMA component |
---|
1717 | elif ( periph.ptype == 'CMA' ): |
---|
1718 | |
---|
1719 | s += ' %s@0x%x {\n' % (periph.pseg.name, periph.pseg.base) |
---|
1720 | s += ' device_type = "soclib:cma";\n' |
---|
1721 | s += ' reg = <0x%x 0x%x 0x%x>;\n' % (msb, lsb, size) |
---|
1722 | s += ' channel_count = < %d >;\n' % periph.channels |
---|
1723 | |
---|
1724 | # multi-channels : get HWI index (to XCU or PIC) for each channel |
---|
1725 | for channel in xrange( periph.channels ): |
---|
1726 | hwi_id = 0xFFFFFFFF |
---|
1727 | for irq in irq_tgt.irqs: |
---|
1728 | if ( (irq.isrtype == 'ISR_CMA') and (irq.channel == channel) ): |
---|
1729 | hwi_id = irq.srcid |
---|
1730 | if ( hwi_id == 0xFFFFFFFF ): |
---|
1731 | print '[genmap error] in netbsd.dts() ISR_CMA channel %d not found' % channel |
---|
1732 | sys.exit(1) |
---|
1733 | |
---|
1734 | name = '%s@0x%x' % (irq_tgt.pseg.name, irq_tgt.pseg.base) |
---|
1735 | s += ' irq@%d{\n' % channel |
---|
1736 | s += ' device_type = "soclib:periph:irq";\n' |
---|
1737 | s += ' output_line = <%d>;\n' % channel |
---|
1738 | s += ' irq = <&{/%s} %d>;\n' % (name, hwi_id) |
---|
1739 | s += ' parent = <&{/%s@0x%x}>;\n' % (periph.pseg.name, periph.pseg.base) |
---|
1740 | s += ' };\n' |
---|
1741 | |
---|
1742 | s += ' };\n' |
---|
1743 | |
---|
1744 | # research TIM component |
---|
1745 | elif ( periph.ptype == 'TIM' ): |
---|
1746 | |
---|
1747 | print '[genmap error] in netbsd_dts() : TIM peripheral not supported by NetBSD' |
---|
1748 | sys.exit(1) |
---|
1749 | |
---|
1750 | # research MWR component |
---|
1751 | elif ( periph.ptype == 'MWR' ): |
---|
1752 | |
---|
1753 | print '[genmap error] in netbsd_dts() : MWR peripheral not supported by NetBSD' |
---|
1754 | sys.exit(1) |
---|
1755 | |
---|
1756 | # topology |
---|
1757 | s += '\n' |
---|
1758 | s += ' topology {\n' |
---|
1759 | s += ' #address-cells = <2>;\n' |
---|
1760 | s += ' #size-cells = <0>;\n' |
---|
1761 | for cluster in self.clusters: |
---|
1762 | s += ' cluster@%d,%d {\n' % (cluster.x, cluster.y) |
---|
1763 | s += ' reg = <%d %d>;\n' % (cluster.x, cluster.y) |
---|
1764 | s += ' devices = <\n' |
---|
1765 | |
---|
1766 | offset = ((cluster.x << self.y_width) + cluster.y) << self.p_width |
---|
1767 | for proc in cluster.procs: |
---|
1768 | s += ' &{/cpus/Mips,32@0x%x}\n' % (offset + proc.lpid) |
---|
1769 | for periph in cluster.periphs: |
---|
1770 | s += ' &{/%s@0x%x}\n' % (periph.pseg.name, periph.pseg.base) |
---|
1771 | for pseg in cluster.psegs: |
---|
1772 | if ( pseg.segtype == 'RAM' ): |
---|
1773 | s += ' &{/%s@0x%x}\n' % (pseg.name, pseg.base) |
---|
1774 | |
---|
1775 | s += ' >;\n' |
---|
1776 | s += ' };\n' |
---|
1777 | s += ' };\n' |
---|
1778 | s += '};\n' |
---|
1779 | |
---|
1780 | return s |
---|
1781 | # end netbsd_dts() |
---|
1782 | |
---|
1783 | ########################### |
---|
1784 | def almos_archinfo( self ): # compute string for arch.info file generation, |
---|
1785 | # used for almos configuration |
---|
1786 | # header |
---|
1787 | s = '# arch.info file generated by genmap for %s\n' % self.name |
---|
1788 | s += '\n' |
---|
1789 | s += '[HEADER]\n' |
---|
1790 | s += ' REVISION=1\n' |
---|
1791 | s += ' ARCH=%s\n' % self.name |
---|
1792 | s += ' XMAX=%d\n' % self.x_size |
---|
1793 | s += ' YMAX=%d\n' % self.y_size |
---|
1794 | s += ' CPU_NR=%d\n' % self.nprocs |
---|
1795 | s += '\n' |
---|
1796 | |
---|
1797 | # clusters |
---|
1798 | cluster_id = 0 |
---|
1799 | for cluster in self.clusters: |
---|
1800 | |
---|
1801 | ram = None |
---|
1802 | nb_cpus = len( cluster.procs ) |
---|
1803 | nb_devs = len( cluster.periphs ) |
---|
1804 | if ( len( cluster.coprocs ) != 0 ): |
---|
1805 | print 'Error in almos_archinfo() coprocessors not supported yet' |
---|
1806 | sys.exit(1) |
---|
1807 | |
---|
1808 | # search a RAM |
---|
1809 | for pseg in cluster.psegs: |
---|
1810 | if ( pseg.segtype == 'RAM' ): |
---|
1811 | ram = pseg |
---|
1812 | nb_devs += 1 |
---|
1813 | |
---|
1814 | # search XCU to get IRQs indexes if cluster contains peripherals |
---|
1815 | if ( len( cluster.periphs ) != 0 ): |
---|
1816 | tty_irq_id = None |
---|
1817 | bdv_irq_id = None |
---|
1818 | dma_irq_id = None |
---|
1819 | |
---|
1820 | for periph in cluster.periphs: |
---|
1821 | if ( periph.ptype == 'XCU' ): |
---|
1822 | # scan irqs |
---|
1823 | for irq in periph.irqs: |
---|
1824 | if ( irq.isrtype == 'ISR_TTY_RX' ) : tty_irq_id = irq.srcid |
---|
1825 | if ( irq.isrtype == 'ISR_BDV' ) : bdv_irq_id = irq.srcid |
---|
1826 | if ( irq.isrtype == 'ISR_DMA' ) : dma_irq_id = irq.srcid |
---|
1827 | |
---|
1828 | # Build the cluster description |
---|
1829 | s += '[CLUSTER]\n' |
---|
1830 | s += ' CID=%d\n' % cluster_id |
---|
1831 | s += ' ARCH_CID=0x%x\n' % ((cluster.x << self.y_width) + cluster.y) |
---|
1832 | s += ' CPU_NR=%d\n' % nb_cpus |
---|
1833 | s += ' DEV_NR=%d\n' % nb_devs |
---|
1834 | |
---|
1835 | |
---|
1836 | # Handling RAM when cluster contain a RAM |
---|
1837 | if (ram != None ): |
---|
1838 | base = ram.base |
---|
1839 | size = ram.size |
---|
1840 | irqid = -1 |
---|
1841 | s += ' DEVID=RAM' |
---|
1842 | s += ' BASE=0x%x SIZE=0x%x IRQ=-1\n' % ( base, size ) |
---|
1843 | |
---|
1844 | # Handling peripherals |
---|
1845 | for periph in cluster.periphs: |
---|
1846 | base = periph.pseg.base |
---|
1847 | size = periph.pseg.size |
---|
1848 | |
---|
1849 | if ( periph.ptype == 'XCU' ): |
---|
1850 | |
---|
1851 | s += ' DEVID=XICU' |
---|
1852 | s += ' BASE=0x%x SIZE=0x%x IRQ=-1\n' % ( base, size ) |
---|
1853 | |
---|
1854 | elif ( (periph.ptype == 'TTY') |
---|
1855 | and (tty_irq_id != None) ): |
---|
1856 | |
---|
1857 | s += ' DEVID=TTY' |
---|
1858 | s += ' BASE=0x%x SIZE=0x%x IRQ=%d\n' % ( base, size, tty_irq_id ) |
---|
1859 | |
---|
1860 | elif ( (periph.ptype == 'DMA') |
---|
1861 | and (dma_irq_id != None) ): |
---|
1862 | |
---|
1863 | s += ' DEVID=DMA' |
---|
1864 | s += ' BASE=0x%x SIZE=0x%x IRQ=%d\n' % ( base, size, dma_irq_id ) |
---|
1865 | |
---|
1866 | elif ( periph.ptype == 'FBF' ): |
---|
1867 | |
---|
1868 | s += ' DEVID=FB' |
---|
1869 | s += ' BASE=0x%x SIZE=0x%x IRQ=-1\n' % ( base, size ) |
---|
1870 | |
---|
1871 | elif ( (periph.ptype == 'IOC') and (periph.subtype == 'BDV') |
---|
1872 | and (bdv_irq_id != None) ): |
---|
1873 | |
---|
1874 | s += ' DEVID=BLKDEV' |
---|
1875 | s += ' BASE=0x%x SIZE=0x%x IRQ=%d\n' % ( base, size, bdv_irq_id ) |
---|
1876 | |
---|
1877 | elif ( periph.ptype == 'PIC' ): |
---|
1878 | |
---|
1879 | s += ' DEVID=IOPIC' |
---|
1880 | s += ' BASE=0x%x SIZE=0x%x IRQ=-1\n' % ( base, size ) |
---|
1881 | |
---|
1882 | else: |
---|
1883 | print '# Warning from almos_archinfo() in cluster[%d,%d]' \ |
---|
1884 | % (cluster.x, cluster.y) |
---|
1885 | print '# peripheral type %s/%s not supported yet\n' \ |
---|
1886 | % ( periph.ptype, periph.subtype ) |
---|
1887 | |
---|
1888 | cluster_id += 1 |
---|
1889 | |
---|
1890 | return s |
---|
1891 | |
---|
1892 | # end of almos_archinfo() |
---|
1893 | |
---|
1894 | |
---|
1895 | |
---|
1896 | |
---|
1897 | |
---|
1898 | |
---|
1899 | |
---|
1900 | |
---|
1901 | ########################################################################################### |
---|
1902 | class Cluster ( object ): |
---|
1903 | ########################################################################################### |
---|
1904 | def __init__( self, |
---|
1905 | x, |
---|
1906 | y ): |
---|
1907 | |
---|
1908 | self.index = 0 # global index (set by Mapping constructor) |
---|
1909 | self.x = x # x coordinate |
---|
1910 | self.y = y # y coordinate |
---|
1911 | self.psegs = [] # filled by addRam() or addPeriph() |
---|
1912 | self.procs = [] # filled by addProc() |
---|
1913 | self.coprocs = [] # filled by addCoproc() |
---|
1914 | self.periphs = [] # filled by addPeriph() |
---|
1915 | |
---|
1916 | return |
---|
1917 | |
---|
1918 | ################ |
---|
1919 | def xml( self ): # xml for a cluster |
---|
1920 | |
---|
1921 | s = ' <cluster x="%d" y="%d" >\n' % (self.x, self.y) |
---|
1922 | for pseg in self.psegs: s += pseg.xml() |
---|
1923 | for proc in self.procs: s += proc.xml() |
---|
1924 | for copr in self.coprocs: s += copr.xml() |
---|
1925 | for peri in self.periphs: s += peri.xml() |
---|
1926 | s += ' </cluster>\n' |
---|
1927 | |
---|
1928 | return s |
---|
1929 | |
---|
1930 | ############################################# |
---|
1931 | def cbin( self, mapping, verbose, expected ): # C binary structure for Cluster |
---|
1932 | |
---|
1933 | if ( verbose ): |
---|
1934 | print '*** cbin for cluster [%d,%d]' % (self.x, self.y) |
---|
1935 | |
---|
1936 | # check index |
---|
1937 | if (self.index != expected): |
---|
1938 | print '[genmap error] in Cluster.cbin() : cluster global index = %d / expected = %d' \ |
---|
1939 | % (self.index, expected ) |
---|
1940 | sys.exit(1) |
---|
1941 | |
---|
1942 | # compute global index for first pseg |
---|
1943 | if ( len(self.psegs) > 0 ): |
---|
1944 | pseg_id = self.psegs[0].index |
---|
1945 | else: |
---|
1946 | pseg_id = 0 |
---|
1947 | |
---|
1948 | # compute global index for first proc |
---|
1949 | if ( len(self.procs) > 0 ): |
---|
1950 | proc_id = self.procs[0].index |
---|
1951 | else: |
---|
1952 | proc_id = 0 |
---|
1953 | |
---|
1954 | # compute global index for first coproc |
---|
1955 | if ( len(self.coprocs) > 0 ): |
---|
1956 | coproc_id = self.coprocs[0].index |
---|
1957 | else: |
---|
1958 | coproc_id = 0 |
---|
1959 | |
---|
1960 | # compute global index for first periph |
---|
1961 | if ( len(self.periphs) > 0 ): |
---|
1962 | periph_id = self.periphs[0].index |
---|
1963 | else: |
---|
1964 | periph_id = 0 |
---|
1965 | |
---|
1966 | byte_stream = bytearray() |
---|
1967 | byte_stream += mapping.int2bytes( 4 , self.x ) # x coordinate |
---|
1968 | byte_stream += mapping.int2bytes( 4 , self.y ) # x coordinate |
---|
1969 | byte_stream += mapping.int2bytes( 4 , len( self.psegs ) ) # number of psegs in cluster |
---|
1970 | byte_stream += mapping.int2bytes( 4 , pseg_id ) # first pseg global index |
---|
1971 | byte_stream += mapping.int2bytes( 4 , len( self.procs ) ) # number of procs in cluster |
---|
1972 | byte_stream += mapping.int2bytes( 4 , proc_id ) # first proc global index |
---|
1973 | byte_stream += mapping.int2bytes( 4 , len( self.coprocs ) ) # number of coprocs in cluster |
---|
1974 | byte_stream += mapping.int2bytes( 4 , coproc_id ) # first coproc global index |
---|
1975 | byte_stream += mapping.int2bytes( 4 , len( self.periphs ) ) # number of periphs in cluster |
---|
1976 | byte_stream += mapping.int2bytes( 4 , periph_id ) # first periph global index |
---|
1977 | |
---|
1978 | if ( verbose ): |
---|
1979 | print 'nb_psegs = %d' % len( self.psegs ) |
---|
1980 | print 'pseg_id = %d' % pseg_id |
---|
1981 | print 'nb_procs = %d' % len( self.procs ) |
---|
1982 | print 'proc_id = %d' % proc_id |
---|
1983 | print 'nb_coprocs = %d' % len( self.coprocs ) |
---|
1984 | print 'coproc_id = %d' % coproc_id |
---|
1985 | print 'nb_periphs = %d' % len( self.periphs ) |
---|
1986 | print 'periph_id = %d' % periph_id |
---|
1987 | |
---|
1988 | return byte_stream |
---|
1989 | |
---|
1990 | ########################################################################################### |
---|
1991 | class Vspace( object ): |
---|
1992 | ########################################################################################### |
---|
1993 | def __init__( self, |
---|
1994 | name, |
---|
1995 | startname ): |
---|
1996 | |
---|
1997 | self.index = 0 # global index ( set by addVspace() ) |
---|
1998 | self.name = name # vspace name |
---|
1999 | self.startname = startname # name of vobj containing the start_vector |
---|
2000 | self.vsegs = [] |
---|
2001 | self.tasks = [] |
---|
2002 | |
---|
2003 | return |
---|
2004 | |
---|
2005 | ################ |
---|
2006 | def xml( self ): # xml for one vspace |
---|
2007 | |
---|
2008 | s = ' <vspace name="%s" startname="%s" >\n' % ( self.name, self.startname ) |
---|
2009 | for vseg in self.vsegs: s += vseg.xml() |
---|
2010 | for task in self.tasks: s += task.xml() |
---|
2011 | s += ' </vspace>\n' |
---|
2012 | |
---|
2013 | return s |
---|
2014 | |
---|
2015 | ############################################# |
---|
2016 | def cbin( self, mapping, verbose, expected ): # C binary structure for Vspace |
---|
2017 | |
---|
2018 | if ( verbose ): |
---|
2019 | print '*** cbin for vspace %s' % (self.name) |
---|
2020 | |
---|
2021 | # check index |
---|
2022 | if (self.index != expected): |
---|
2023 | print '[genmap error] in Vspace.cbin() : vspace global index = %d / expected = %d' \ |
---|
2024 | % (self.index, expected ) |
---|
2025 | sys.exit(1) |
---|
2026 | |
---|
2027 | # compute global index for vobj containing start_vector |
---|
2028 | vobj_start_id = 0xFFFFFFFF |
---|
2029 | for vseg in self.vsegs: |
---|
2030 | if ( vseg.vobjs[0].name == self.startname ): |
---|
2031 | vobj_start_id = vseg.vobjs[0].index |
---|
2032 | if ( vobj_start_id == 0xFFFFFFFF ): |
---|
2033 | print '[genmap error] in Vspace.cbin() : startname %s not found for vspace %s' \ |
---|
2034 | % ( self.startname, self.name ) |
---|
2035 | sys.exit(1) |
---|
2036 | |
---|
2037 | # compute first vseg, vobj, task global index |
---|
2038 | first_vseg_id = self.vsegs[0].index |
---|
2039 | first_vobj_id = self.vsegs[0].vobjs[0].index |
---|
2040 | first_task_id = self.tasks[0].index |
---|
2041 | |
---|
2042 | # compute number of vobjs, tasks, vsegs |
---|
2043 | nb_vsegs = len( self.vsegs ) |
---|
2044 | nb_tasks = len( self.tasks ) |
---|
2045 | nb_vobjs = 0 |
---|
2046 | for vseg in self.vsegs: |
---|
2047 | nb_vobjs += len( vseg.vobjs ) |
---|
2048 | |
---|
2049 | byte_stream = bytearray() |
---|
2050 | byte_stream += mapping.str2bytes( 32, self.name ) # vspace name |
---|
2051 | byte_stream += mapping.int2bytes( 4, vobj_start_id ) # vobj start_vector |
---|
2052 | byte_stream += mapping.int2bytes( 4, nb_vsegs ) # number of vsegs |
---|
2053 | byte_stream += mapping.int2bytes( 4, nb_vobjs ) # number of vobjs |
---|
2054 | byte_stream += mapping.int2bytes( 4, nb_tasks ) # number of tasks |
---|
2055 | byte_stream += mapping.int2bytes( 4, first_vseg_id ) # first vseg global index |
---|
2056 | byte_stream += mapping.int2bytes( 4, first_vobj_id ) # first vobj global index |
---|
2057 | byte_stream += mapping.int2bytes( 4, first_task_id ) # first task global index |
---|
2058 | |
---|
2059 | if ( verbose ): |
---|
2060 | print 'start_id = %d' % vobj_start_id |
---|
2061 | print 'nb_vsegs = %d' % nb_vsegs |
---|
2062 | print 'nb_vobjs = %d' % nb_vobjs |
---|
2063 | print 'nb_tasks = %d' % nb_tasks |
---|
2064 | print 'vseg_id = %d' % first_vseg_id |
---|
2065 | print 'vobj_id = %d' % first_vobj_id |
---|
2066 | print 'task_id = %d' % first_task_id |
---|
2067 | |
---|
2068 | return byte_stream |
---|
2069 | |
---|
2070 | ########################################################################################### |
---|
2071 | class Task( object ): |
---|
2072 | ########################################################################################### |
---|
2073 | def __init__( self, |
---|
2074 | name, |
---|
2075 | trdid, |
---|
2076 | x, |
---|
2077 | y, |
---|
2078 | p, |
---|
2079 | stackname, |
---|
2080 | heapname, |
---|
2081 | startid ): |
---|
2082 | |
---|
2083 | self.index = 0 # global index value set by addTask() |
---|
2084 | self.name = name # tsk name |
---|
2085 | self.trdid = trdid # task index (unique in vspace) |
---|
2086 | self.x = x # cluster x coordinate |
---|
2087 | self.y = y # cluster y coordinate |
---|
2088 | self.p = p # processor local index |
---|
2089 | self.stackname = stackname # name of vobj containing the stack |
---|
2090 | self.heapname = heapname # name of vobj containing the heap |
---|
2091 | self.startid = startid # index in start_vector |
---|
2092 | return |
---|
2093 | |
---|
2094 | ################ |
---|
2095 | def xml( self ): # xml for one task |
---|
2096 | |
---|
2097 | s = ' <task name="%s"' % self.name |
---|
2098 | s += ' trdid="%d"' % self.trdid |
---|
2099 | s += ' x="%d"' % self.x |
---|
2100 | s += ' y="%d"' % self.y |
---|
2101 | s += ' p="%d"' % self.p |
---|
2102 | s += ' stackname="%s"' % self.stackname |
---|
2103 | s += ' heapname="%s"' % self.heapname |
---|
2104 | s += ' startid="%d"' % self.startid |
---|
2105 | s += ' />\n' |
---|
2106 | |
---|
2107 | return s |
---|
2108 | |
---|
2109 | ##################################################### |
---|
2110 | def cbin( self, mapping, verbose, expected, vspace ): # C binary data structure for Task |
---|
2111 | |
---|
2112 | if ( verbose ): |
---|
2113 | print '*** cbin for task %s in vspace %s' % (self.name, vspace.name) |
---|
2114 | |
---|
2115 | # check index |
---|
2116 | if (self.index != expected): |
---|
2117 | print '[genmap error] in Task.cbin() : task global index = %d / expected = %d' \ |
---|
2118 | % (self.index, expected ) |
---|
2119 | sys.exit(1) |
---|
2120 | |
---|
2121 | # compute cluster global index |
---|
2122 | cluster_id = (self.x * mapping.y_size) + self.y |
---|
2123 | |
---|
2124 | # compute vobj local index for stack |
---|
2125 | vobj_stack_id = 0xFFFFFFFF |
---|
2126 | for vseg in vspace.vsegs: |
---|
2127 | if ( vseg.vobjs[0].name == self.stackname ): |
---|
2128 | vobj_stack_id = vseg.vobjs[0].index |
---|
2129 | if ( vobj_stack_id == 0xFFFFFFFF ): |
---|
2130 | print '[genmap error] in Task.cbin() : stackname %s not found for task %s in vspace %s' \ |
---|
2131 | % ( self.stackname, self.name, vspace.name ) |
---|
2132 | sys.exit(1) |
---|
2133 | |
---|
2134 | # compute vobj local index for heap |
---|
2135 | if ( self.heapname == '' ): |
---|
2136 | vobj_heap_id = 0 |
---|
2137 | else: |
---|
2138 | vobj_heap_id = 0xFFFFFFFF |
---|
2139 | for vseg in vspace.vsegs: |
---|
2140 | if ( vseg.vobjs[0].name == self.heapname ): |
---|
2141 | vobj_heap_id = vseg.vobjs[0].index |
---|
2142 | if ( vobj_heap_id == 0xFFFFFFFF ): |
---|
2143 | print '[genmap error] in Task.cbin() : heapname %s not found for task %s in vspace %s' \ |
---|
2144 | % ( self.heapname, self.name, vspace.name ) |
---|
2145 | sys.exit(1) |
---|
2146 | |
---|
2147 | byte_stream = bytearray() |
---|
2148 | byte_stream += mapping.str2bytes( 32, self.name ) # task name in vspace |
---|
2149 | byte_stream += mapping.int2bytes( 4, cluster_id ) # cluster global index |
---|
2150 | byte_stream += mapping.int2bytes( 4, self.p ) # processor local index in cluster |
---|
2151 | byte_stream += mapping.int2bytes( 4, self.trdid ) # thread local index in vspace |
---|
2152 | byte_stream += mapping.int2bytes( 4, vobj_stack_id ) # stack vobj local index |
---|
2153 | byte_stream += mapping.int2bytes( 4, vobj_heap_id ) # heap vobj local index |
---|
2154 | byte_stream += mapping.int2bytes( 4, self.startid ) # index in start vector |
---|
2155 | |
---|
2156 | if ( verbose ): |
---|
2157 | print 'clusterid = %d' % cluster_id |
---|
2158 | print 'lpid = %d' % self.p |
---|
2159 | print 'trdid = %d' % self.trdid |
---|
2160 | print 'stackid = %d' % vobj_stack_id |
---|
2161 | print 'heapid = %d' % vobj_heap_id |
---|
2162 | print 'startid = %d' % self.startid |
---|
2163 | |
---|
2164 | return byte_stream |
---|
2165 | |
---|
2166 | ########################################################################################### |
---|
2167 | class Vseg( object ): |
---|
2168 | ########################################################################################### |
---|
2169 | def __init__( self, |
---|
2170 | name, |
---|
2171 | vbase, |
---|
2172 | mode, |
---|
2173 | x, |
---|
2174 | y, |
---|
2175 | psegname, |
---|
2176 | identity = False, |
---|
2177 | local = False, |
---|
2178 | big = False ): |
---|
2179 | |
---|
2180 | assert mode in VSEGMODES |
---|
2181 | |
---|
2182 | self.index = 0 # global index ( set by addVseg() ) |
---|
2183 | self.name = name # vseg name |
---|
2184 | self.vbase = vbase & 0xFFFFFFFF # virtual base address in vspace |
---|
2185 | self.mode = mode # CXWU access rights |
---|
2186 | self.x = x # x coordinate of destination cluster |
---|
2187 | self.y = y # y coordinate of destination cluster |
---|
2188 | self.psegname = psegname # name of pseg in destination cluster |
---|
2189 | self.identity = identity # identity mapping required |
---|
2190 | self.local = local # only mapped in local PTAB when true |
---|
2191 | self.big = big # to be mapped in a big physical page |
---|
2192 | self.vobjs = [] |
---|
2193 | return |
---|
2194 | |
---|
2195 | ################ |
---|
2196 | def xml( self ): # xml for one vseg |
---|
2197 | |
---|
2198 | s = ' <vseg name="%s" vbase="0x%x" mode="%s" x="%d" y="%d" psegname="%s"' \ |
---|
2199 | % ( self.name, self.vbase, self.mode, self.x, self.y, self.psegname ) |
---|
2200 | if ( self.identity ): s += ' ident="1"' |
---|
2201 | if ( self.local ): s += ' local="1"' |
---|
2202 | if ( self.big ): s += ' big="1"' |
---|
2203 | s += ' >\n' |
---|
2204 | for vobj in self.vobjs: s += vobj.xml() |
---|
2205 | s += ' </vseg>\n' |
---|
2206 | |
---|
2207 | return s |
---|
2208 | |
---|
2209 | ############################################# |
---|
2210 | def cbin( self, mapping, verbose, expected ): # C binary structure for Vseg |
---|
2211 | |
---|
2212 | if ( verbose ): |
---|
2213 | print '*** cbin for vseg[%d] %s' % (self.index, self.name) |
---|
2214 | |
---|
2215 | # check index |
---|
2216 | if (self.index != expected): |
---|
2217 | print '[genmap error] in Vseg.cbin() : vseg global index = %d / expected = %d' \ |
---|
2218 | % (self.index, expected ) |
---|
2219 | sys.exit(1) |
---|
2220 | |
---|
2221 | # compute pseg_id |
---|
2222 | pseg_id = 0xFFFFFFFF |
---|
2223 | cluster_id = (self.x * mapping.y_size) + self.y |
---|
2224 | cluster = mapping.clusters[cluster_id] |
---|
2225 | for pseg in cluster.psegs: |
---|
2226 | if (self.psegname == pseg.name): |
---|
2227 | pseg_id = pseg.index |
---|
2228 | if (pseg_id == 0xFFFFFFFF): |
---|
2229 | print '[genmap error] in Vseg.cbin() : psegname %s not found for vseg %s in cluster %d' \ |
---|
2230 | % ( self.psegname, self.name, cluster_id ) |
---|
2231 | sys.exit(1) |
---|
2232 | |
---|
2233 | # compute numerical value for mode |
---|
2234 | mode_id = 0xFFFFFFFF |
---|
2235 | for x in xrange( len(VSEGMODES) ): |
---|
2236 | if ( self.mode == VSEGMODES[x] ): |
---|
2237 | mode_id = x |
---|
2238 | if ( mode_id == 0xFFFFFFFF ): |
---|
2239 | print '[genmap error] in Vseg.cbin() : undefined vseg mode %s' % self.mode |
---|
2240 | sys.exit(1) |
---|
2241 | |
---|
2242 | # compute vobj_id |
---|
2243 | vobj_id = self.vobjs[0].index |
---|
2244 | |
---|
2245 | byte_stream = bytearray() |
---|
2246 | byte_stream += mapping.str2bytes( 32, self.name ) # vseg name |
---|
2247 | byte_stream += mapping.int2bytes( 4, self.vbase ) # virtual base address |
---|
2248 | byte_stream += mapping.int2bytes( 8, 0 ) # physical base address |
---|
2249 | byte_stream += mapping.int2bytes( 4, 0 ) # vseg size (bytes) |
---|
2250 | byte_stream += mapping.int2bytes( 4, pseg_id ) # physical segment global index |
---|
2251 | byte_stream += mapping.int2bytes( 4, mode_id ) # CXWU flags |
---|
2252 | byte_stream += mapping.int2bytes( 4, len(self.vobjs) ) # number of vobjs in vseg |
---|
2253 | byte_stream += mapping.int2bytes( 4, vobj_id ) # first vobj global index |
---|
2254 | byte_stream += mapping.int2bytes( 4, 0 ) # linked list of vsegs on pseg |
---|
2255 | byte_stream += mapping.int2bytes( 1, 0 ) # mapped when non zero |
---|
2256 | byte_stream += mapping.int2bytes( 1, self.identity ) # identity mapping if non zero |
---|
2257 | byte_stream += mapping.int2bytes( 1, self.local ) # only mapped in local PTAB |
---|
2258 | byte_stream += mapping.int2bytes( 1, self.big ) # to be mapped in big physical page |
---|
2259 | |
---|
2260 | if ( verbose ): |
---|
2261 | print 'vbase = %x' % self.vbase |
---|
2262 | print 'pseg_id = %d' % pseg_id |
---|
2263 | print 'mode = %s' % self.mode |
---|
2264 | print 'nb_vobjs = %d' % len(self.vobjs) |
---|
2265 | print 'vobj_id = %d' % vobj_id |
---|
2266 | |
---|
2267 | return byte_stream |
---|
2268 | |
---|
2269 | ########################################################################################### |
---|
2270 | class Vobj( object ): |
---|
2271 | ########################################################################################### |
---|
2272 | def __init__( self, |
---|
2273 | name, |
---|
2274 | length, |
---|
2275 | vtype, |
---|
2276 | binpath = '', |
---|
2277 | align = 0, |
---|
2278 | init = 0 ): |
---|
2279 | |
---|
2280 | assert vtype in ['ELF','BLOB','PTAB','PERI','MWMR','LOCK', \ |
---|
2281 | 'BUFFER','BARRIER','CONST','MEMSPACE','SCHED','HEAP'] |
---|
2282 | |
---|
2283 | assert (vtype != 'ELF') or (binpath != '') |
---|
2284 | |
---|
2285 | self.index = 0 # global index ( set by addVobj() ) |
---|
2286 | self.name = name # vobj name (unique in vspace) |
---|
2287 | self.vtype = vtype # vobj type (defined in mapping_info.h) |
---|
2288 | self.length = length # vobj size (bytes) |
---|
2289 | self.binpath = binpath # pathname for (ELF type) |
---|
2290 | self.align = align # required alignment (logarithm of 2) |
---|
2291 | self.init = init # initialisation value (for BARRIER or MWMR types) |
---|
2292 | |
---|
2293 | return |
---|
2294 | |
---|
2295 | ################ |
---|
2296 | def xml( self ): # xml for a vobj |
---|
2297 | |
---|
2298 | s = ' <vobj name="%s" type="%s" length="0x%x"' \ |
---|
2299 | % ( self.name, self.vtype, self.length ) |
---|
2300 | if (self.binpath != ''): s += ' binpath="%s"' % (self.binpath) |
---|
2301 | if (self.align != 0 ): s += ' align="%d"' % (self.align) |
---|
2302 | if (self.init != 0 ): s += ' init="%d"' % (self.init) |
---|
2303 | s += ' />\n' |
---|
2304 | |
---|
2305 | return s |
---|
2306 | |
---|
2307 | ############################################# |
---|
2308 | def cbin( self, mapping, verbose, expected ): # C binary structure for Vobj |
---|
2309 | |
---|
2310 | # check index |
---|
2311 | if (self.index != expected): |
---|
2312 | print '[genmap error] in Vobj.cbin() : vobj global index = %d / expected = %d' \ |
---|
2313 | % (self.index, expected ) |
---|
2314 | sys.exit(1) |
---|
2315 | elif ( verbose ): |
---|
2316 | print '*** cbin for vobj[%d] %s' % (self.index, self.name) |
---|
2317 | |
---|
2318 | # compute numerical value for vtype |
---|
2319 | vtype_int = 0xFFFFFFFF |
---|
2320 | for x in xrange( len(VOBJTYPES) ): |
---|
2321 | if ( self.vtype == VOBJTYPES[x] ): |
---|
2322 | vtype_int = x |
---|
2323 | if ( vtype_int == 0xFFFFFFFF ): |
---|
2324 | print '[genmap error] in Vobj.cbin() : undefined vobj type %s' % self.vtype |
---|
2325 | sys.exit(1) |
---|
2326 | |
---|
2327 | byte_stream = bytearray() |
---|
2328 | byte_stream += mapping.str2bytes( 32, self.name ) # vobj name |
---|
2329 | byte_stream += mapping.str2bytes( 64, self.binpath ) # pathname for .elf file |
---|
2330 | byte_stream += mapping.int2bytes( 4 , vtype_int ) # vobj type |
---|
2331 | byte_stream += mapping.int2bytes( 4 , self.length ) # vobj size |
---|
2332 | byte_stream += mapping.int2bytes( 4 , self.align ) # required alignment |
---|
2333 | byte_stream += mapping.int2bytes( 4 , 0 ) # virtual base address |
---|
2334 | byte_stream += mapping.int2bytes( 4 , self.init ) # init value |
---|
2335 | |
---|
2336 | if ( verbose ): |
---|
2337 | print 'binpath = %s' % self.binpath |
---|
2338 | print 'type = %s' % self.vtype |
---|
2339 | print 'length = %x' % self.length |
---|
2340 | |
---|
2341 | return byte_stream |
---|
2342 | |
---|
2343 | ########################################################################################### |
---|
2344 | class Processor ( object ): |
---|
2345 | ########################################################################################### |
---|
2346 | def __init__( self, |
---|
2347 | x, |
---|
2348 | y, |
---|
2349 | lpid ): |
---|
2350 | |
---|
2351 | self.index = 0 # global index ( set by addProc() ) |
---|
2352 | self.x = x # x cluster coordinate |
---|
2353 | self.y = y # y cluster coordinate |
---|
2354 | self.lpid = lpid # processor local index |
---|
2355 | |
---|
2356 | return |
---|
2357 | |
---|
2358 | ################ |
---|
2359 | def xml( self ): # xml for a processor |
---|
2360 | return ' <proc index="%d" />\n' % (self.lpid) |
---|
2361 | |
---|
2362 | ############################################# |
---|
2363 | def cbin( self, mapping, verbose, expected ): # C binary structure for Proc |
---|
2364 | |
---|
2365 | if ( verbose ): |
---|
2366 | print '*** cbin for proc %d in cluster (%d,%d)' % (self.lpid, self.x, self.y) |
---|
2367 | |
---|
2368 | # check index |
---|
2369 | if (self.index != expected): |
---|
2370 | print '[genmap error] in Proc.cbin() : proc global index = %d / expected = %d' \ |
---|
2371 | % (self.index, expected ) |
---|
2372 | sys.exit(1) |
---|
2373 | |
---|
2374 | byte_stream = bytearray() |
---|
2375 | byte_stream += mapping.int2bytes( 4 , self.lpid ) # local index |
---|
2376 | |
---|
2377 | return byte_stream |
---|
2378 | |
---|
2379 | ########################################################################################### |
---|
2380 | class Pseg ( object ): |
---|
2381 | ########################################################################################### |
---|
2382 | def __init__( self, |
---|
2383 | name, |
---|
2384 | base, |
---|
2385 | size, |
---|
2386 | x, |
---|
2387 | y, |
---|
2388 | segtype ): |
---|
2389 | |
---|
2390 | assert( segtype in PSEGTYPES ) |
---|
2391 | |
---|
2392 | self.index = 0 # global index ( set by addPseg() ) |
---|
2393 | self.name = name # pseg name (unique in cluster) |
---|
2394 | self.base = base # physical base address |
---|
2395 | self.size = size # segment size (bytes) |
---|
2396 | self.x = x # cluster x coordinate |
---|
2397 | self.y = y # cluster y coordinate |
---|
2398 | self.segtype = segtype # RAM / PERI (defined in mapping_info.h) |
---|
2399 | |
---|
2400 | return |
---|
2401 | |
---|
2402 | ################ |
---|
2403 | def xml( self ): # xml for a pseg |
---|
2404 | |
---|
2405 | return ' <pseg name="%s" type="%s" base="0x%x" length="0x%x" />\n' \ |
---|
2406 | % (self.name, self.segtype, self.base, self.size) |
---|
2407 | |
---|
2408 | ###################################################### |
---|
2409 | def cbin( self, mapping, verbose, expected, cluster ): # C binary structure for Pseg |
---|
2410 | |
---|
2411 | if ( verbose ): |
---|
2412 | print '*** cbin for pseg[%d] %s in cluster[%d,%d]' \ |
---|
2413 | % (self.index, self.name, cluster.x, cluster.y) |
---|
2414 | |
---|
2415 | # check index |
---|
2416 | if (self.index != expected): |
---|
2417 | print '[genmap error] in Pseg.cbin() : pseg global index = %d / expected = %d' \ |
---|
2418 | % (self.index, expected ) |
---|
2419 | sys.exit(1) |
---|
2420 | |
---|
2421 | # compute numerical value for segtype |
---|
2422 | segtype_int = 0xFFFFFFFF |
---|
2423 | for x in xrange( len(PSEGTYPES) ): |
---|
2424 | if ( self.segtype == PSEGTYPES[x] ): |
---|
2425 | segtype_int = x |
---|
2426 | if ( segtype_int == 0xFFFFFFFF ): |
---|
2427 | print '[genmap error] in Pseg.cbin() : undefined segment type %s' % self.segtype |
---|
2428 | sys.exit(1) |
---|
2429 | |
---|
2430 | byte_stream = bytearray() |
---|
2431 | byte_stream += mapping.str2bytes( 32, self.name ) # pseg name |
---|
2432 | byte_stream += mapping.int2bytes( 8 , self.base ) # physical base address |
---|
2433 | byte_stream += mapping.int2bytes( 8 , self.size ) # segment length |
---|
2434 | byte_stream += mapping.int2bytes( 4 , segtype_int ) # segment type |
---|
2435 | byte_stream += mapping.int2bytes( 4 , cluster.index ) # cluster global index |
---|
2436 | byte_stream += mapping.int2bytes( 4 , 0 ) # linked list of vsegs |
---|
2437 | |
---|
2438 | if ( verbose ): |
---|
2439 | print 'pbase = %x' % self.base |
---|
2440 | print 'size = %x' % self.size |
---|
2441 | print 'type = %s' % self.segtype |
---|
2442 | |
---|
2443 | return byte_stream |
---|
2444 | |
---|
2445 | ########################################################################################### |
---|
2446 | class Periph ( object ): |
---|
2447 | ########################################################################################### |
---|
2448 | def __init__( self, |
---|
2449 | pseg, # associated pseg |
---|
2450 | ptype, # peripheral type |
---|
2451 | subtype = 'NONE', # peripheral subtype |
---|
2452 | channels = 1, # for multi-channels peripherals |
---|
2453 | arg = 0 ): # optional argument (semantic depends on ptype) |
---|
2454 | |
---|
2455 | assert ptype in PERIPHTYPES |
---|
2456 | |
---|
2457 | assert subtype in PERIPHSUBTYPES |
---|
2458 | |
---|
2459 | self.index = 0 # global index ( set by addPeriph() ) |
---|
2460 | self.channels = channels |
---|
2461 | self.ptype = ptype |
---|
2462 | self.subtype = subtype |
---|
2463 | self.arg = arg |
---|
2464 | self.pseg = pseg |
---|
2465 | self.irqs = [] |
---|
2466 | return |
---|
2467 | |
---|
2468 | ################ |
---|
2469 | def xml( self ): # xml for a periph |
---|
2470 | |
---|
2471 | s = ' <periph type="%s"' % self.ptype |
---|
2472 | s += ' subtype="%s"' % self.subtype |
---|
2473 | s += ' psegname="%s"' % self.pseg.name |
---|
2474 | s += ' channels="%d"' % self.channels |
---|
2475 | s += ' arg="%d" >\n' % self.arg |
---|
2476 | if ( (self.ptype == 'PIC') or (self.ptype == 'XCU') ): |
---|
2477 | for irq in self.irqs: s += irq.xml() |
---|
2478 | s += ' </periph>\n' |
---|
2479 | |
---|
2480 | return s |
---|
2481 | |
---|
2482 | ############################################# |
---|
2483 | def cbin( self, mapping, verbose, expected ): # C binary structure for Periph |
---|
2484 | |
---|
2485 | if ( verbose ): |
---|
2486 | print '*** cbin for periph %s in cluster [%d,%d]' \ |
---|
2487 | % (self.ptype, self.pseg.x, self.pseg.y) |
---|
2488 | |
---|
2489 | # check index |
---|
2490 | if (self.index != expected): |
---|
2491 | print '[genmap error] in Periph.cbin() : periph global index = %d / expected = %d' \ |
---|
2492 | % (self.index, expected ) |
---|
2493 | sys.exit(1) |
---|
2494 | |
---|
2495 | # compute pseg global index |
---|
2496 | pseg_id = self.pseg.index |
---|
2497 | |
---|
2498 | # compute first irq global index |
---|
2499 | if ( len(self.irqs) > 0 ): |
---|
2500 | irq_id = self.irqs[0].index |
---|
2501 | else: |
---|
2502 | irq_id = 0 |
---|
2503 | |
---|
2504 | # compute numerical value for ptype |
---|
2505 | ptype_id = 0xFFFFFFFF |
---|
2506 | for x in xrange( len(PERIPHTYPES) ): |
---|
2507 | if ( self.ptype == PERIPHTYPES[x] ): ptype_id = x |
---|
2508 | if ( ptype_id == 0xFFFFFFFF ): |
---|
2509 | print '[genmap error] in Periph.cbin() : undefined peripheral type %s' % self.ptype |
---|
2510 | sys.exit(1) |
---|
2511 | |
---|
2512 | # compute numerical value for subtype |
---|
2513 | subtype_id = 0xFFFFFFFF |
---|
2514 | for x in xrange( len(PERIPHSUBTYPES) ): |
---|
2515 | if ( self.subtype == PERIPHSUBTYPES[x] ): subtype_id = x |
---|
2516 | |
---|
2517 | # compute |
---|
2518 | byte_stream = bytearray() |
---|
2519 | byte_stream += mapping.int2bytes( 4 , ptype_id ) # peripheral type |
---|
2520 | byte_stream += mapping.int2bytes( 4 , subtype_id ) # peripheral subtype |
---|
2521 | byte_stream += mapping.int2bytes( 4 , pseg_id ) # pseg global index |
---|
2522 | byte_stream += mapping.int2bytes( 4 , self.channels ) # number of channels |
---|
2523 | byte_stream += mapping.int2bytes( 4 , self.arg ) # optionnal argument |
---|
2524 | byte_stream += mapping.int2bytes( 4 , len( self.irqs ) ) # number of input irqs |
---|
2525 | byte_stream += mapping.int2bytes( 4 , irq_id ) # first irq global index |
---|
2526 | |
---|
2527 | if ( verbose ): |
---|
2528 | print 'ptype = %d' % ptype_id |
---|
2529 | print 'pseg_id = %d' % pseg_id |
---|
2530 | print 'nb_irqs = %d' % len( self.irqs ) |
---|
2531 | print 'irq_id = %d' % irq_id |
---|
2532 | return byte_stream |
---|
2533 | |
---|
2534 | ########################################################################################### |
---|
2535 | class Irq ( object ): |
---|
2536 | ########################################################################################### |
---|
2537 | def __init__( self, |
---|
2538 | irqtype, # input IRQ type : HWI / WTI / PTI (for XCU only) |
---|
2539 | srcid, # input IRQ index (for XCU or PIC) |
---|
2540 | isrtype, # Type of ISR to be executed |
---|
2541 | channel = 0 ): # channel index for multi-channel ISR |
---|
2542 | |
---|
2543 | assert irqtype in IRQTYPES |
---|
2544 | assert isrtype in ISRTYPES |
---|
2545 | assert srcid < 32 |
---|
2546 | |
---|
2547 | self.index = 0 # global index ( set by addIrq() ) |
---|
2548 | self.irqtype = irqtype # IRQ type |
---|
2549 | self.srcid = srcid # source IRQ index |
---|
2550 | self.isrtype = isrtype # ISR type |
---|
2551 | self.channel = channel # channel index (for multi-channels ISR) |
---|
2552 | return |
---|
2553 | |
---|
2554 | ################ |
---|
2555 | def xml( self ): # xml for Irq |
---|
2556 | |
---|
2557 | return ' <irq srctype="%s" srcid="%d" isr="%s" channel="%d" />\n' \ |
---|
2558 | % ( self.irqtype, self.srcid, self.isrtype, self.channel ) |
---|
2559 | |
---|
2560 | ############################################# |
---|
2561 | def cbin( self, mapping, verbose, expected ): # C binary structure for Irq |
---|
2562 | |
---|
2563 | if ( verbose ): |
---|
2564 | print '*** cbin for irq[%d]' % (self.index) |
---|
2565 | |
---|
2566 | # check index |
---|
2567 | if (self.index != expected): |
---|
2568 | print '[genmap error] in Irq.cbin() : irq global index = %d / expected = %d' \ |
---|
2569 | % (self.index, expected ) |
---|
2570 | sys.exit(1) |
---|
2571 | |
---|
2572 | # compute numerical value for irqtype |
---|
2573 | irqtype_id = 0xFFFFFFFF |
---|
2574 | for x in xrange( len(IRQTYPES) ): |
---|
2575 | if ( self.irqtype == IRQTYPES[x] ): |
---|
2576 | irqtype_id = x |
---|
2577 | if ( irqtype_id == 0xFFFFFFFF ): |
---|
2578 | print '[genmap error] in Irq.cbin() : undefined irqtype %s' % self.irqtype |
---|
2579 | sys.exit(1) |
---|
2580 | |
---|
2581 | # compute numerical value for isrtype |
---|
2582 | isrtype_id = 0xFFFFFFFF |
---|
2583 | for x in xrange( len(ISRTYPES) ): |
---|
2584 | if ( self.isrtype == ISRTYPES[x] ): |
---|
2585 | isrtype_id = x |
---|
2586 | if ( isrtype_id == 0xFFFFFFFF ): |
---|
2587 | print '[genmap error] in Irq.cbin() : undefined isrtype %s' % self.isrtype |
---|
2588 | sys.exit(1) |
---|
2589 | |
---|
2590 | byte_stream = bytearray() |
---|
2591 | byte_stream += mapping.int2bytes( 4, irqtype_id ) |
---|
2592 | byte_stream += mapping.int2bytes( 4, self.srcid ) |
---|
2593 | byte_stream += mapping.int2bytes( 4, isrtype_id ) |
---|
2594 | byte_stream += mapping.int2bytes( 4, self.channel ) |
---|
2595 | byte_stream += mapping.int2bytes( 4, 0 ) |
---|
2596 | byte_stream += mapping.int2bytes( 4, 0 ) |
---|
2597 | |
---|
2598 | if ( verbose ): |
---|
2599 | print 'irqtype = %s' % self.irqtype |
---|
2600 | print 'srcid = %d' % self.srcid |
---|
2601 | print 'isrtype = %s' % self.isrtype |
---|
2602 | print 'channel = %d' % self.channel |
---|
2603 | |
---|
2604 | return byte_stream |
---|
2605 | |
---|
2606 | ########################################################################################### |
---|
2607 | class Coproc ( object ): |
---|
2608 | ########################################################################################### |
---|
2609 | def __init__( self, |
---|
2610 | pseg ): # associated pseg |
---|
2611 | |
---|
2612 | self.index = 0 # global index value set by addCoproc() |
---|
2613 | self.pseg = pseg |
---|
2614 | self.ports = [] |
---|
2615 | |
---|
2616 | return |
---|
2617 | |
---|
2618 | ################ |
---|
2619 | def xml( self ): # xml for Coproc |
---|
2620 | |
---|
2621 | print '[genmap error] in Coproc.xml() : not defined yet' |
---|
2622 | sys.exit(1) |
---|
2623 | |
---|
2624 | return |
---|
2625 | |
---|
2626 | ############################################# |
---|
2627 | def cbin( self, mapping, verbose, expected ): # C binary structure for Coproc |
---|
2628 | |
---|
2629 | if ( verbose ): |
---|
2630 | print '*** cbin for coproc in cluster (%d,%d)' % (self.pseg.x, self.pseg.y) |
---|
2631 | |
---|
2632 | # check index |
---|
2633 | if (self.index != expected): |
---|
2634 | print '[genmap error] in Coproc.cbin() : coproc global index = %d / expected = %d' \ |
---|
2635 | % (self.index, expected ) |
---|
2636 | sys.exit(1) |
---|
2637 | |
---|
2638 | # compute pseg global index |
---|
2639 | pseg_id = self.pseg.index |
---|
2640 | |
---|
2641 | # compute first port global index |
---|
2642 | port_id = self.ports[0].index |
---|
2643 | |
---|
2644 | byte_stream = bytearray() |
---|
2645 | byte_stream += mapping.str2bytes( 32, self.pseg.name ) # probablement inutile (AG) |
---|
2646 | byte_stream += mapping.int2bytes( 4 , pseg_id ) # pseg global index |
---|
2647 | byte_stream += mapping.int2bytes( 4 , len( self.ports ) ) # number of input irqs |
---|
2648 | byte_stream += mapping.int2bytes( 4 , port_id ) # first port global index |
---|
2649 | |
---|
2650 | if ( verbose ): |
---|
2651 | print 'irqtype = %s' % self.irqtype |
---|
2652 | print 'pseg_id = %d' % pseg_id |
---|
2653 | print 'nb_ports = %d' % len( self.ports ) |
---|
2654 | print 'port_id %d' % port_id |
---|
2655 | |
---|
2656 | return byte_stream |
---|
2657 | |
---|
2658 | ########################################################################################### |
---|
2659 | class Cpport ( object ): |
---|
2660 | ########################################################################################### |
---|
2661 | def __init__( self, |
---|
2662 | direction, |
---|
2663 | vspacename, |
---|
2664 | mwmrname ): |
---|
2665 | |
---|
2666 | self.index = 0 # global index ( set by addCpport() ) |
---|
2667 | self.direction = direction # TO_COPROC / FROM_COPROC |
---|
2668 | self.vspacename = vspacename # name of vspace containing mwmr channel |
---|
2669 | self.mwmrname = mwmrname # name of vobj defining mwmr channel |
---|
2670 | |
---|
2671 | return |
---|
2672 | |
---|
2673 | ################ |
---|
2674 | def xml( self ): # xml for Cpport |
---|
2675 | |
---|
2676 | print '[genmap error] in Cpport.xml() : not defined yet' |
---|
2677 | sys.exit(1) |
---|
2678 | |
---|
2679 | return |
---|
2680 | |
---|
2681 | ############################################# |
---|
2682 | def cbin( self, mapping, verbose, expected ): # C binary structure for Cpport |
---|
2683 | |
---|
2684 | if ( verbose ): |
---|
2685 | print '*** cbin for cpport[%d]' % (self.index) |
---|
2686 | |
---|
2687 | # check index |
---|
2688 | if ( self.index != expected ): |
---|
2689 | print '[genmap error] in Cpport.cbin() : port global index = %d / expected = %d' \ |
---|
2690 | % ( self.index, expected ) |
---|
2691 | sys.exit(1) |
---|
2692 | |
---|
2693 | # compute numerical value for direction |
---|
2694 | if ( self.direction == 'TO_COPROC' ): |
---|
2695 | dir_int = 0 |
---|
2696 | else: |
---|
2697 | dir_int = 1 |
---|
2698 | |
---|
2699 | # compute vspace global index |
---|
2700 | vspace_id = 0xFFFFFFFF |
---|
2701 | for vspace in mapping.vspaces: |
---|
2702 | if ( self.vspacename == vspace.name ): |
---|
2703 | vspace_id = vspace.index |
---|
2704 | if (vspace_id == 0xFFFFFFFF): |
---|
2705 | print '[genmap error] in Cpport.cbin() : vspace name %s not found' \ |
---|
2706 | % ( self.vspacename ) |
---|
2707 | sys.exit(1) |
---|
2708 | |
---|
2709 | # compute mwmr global index |
---|
2710 | mwmr_id = 0xFFFFFFFF |
---|
2711 | for vseg in mapping.vspace[vspace_id].vsegs: |
---|
2712 | for vobj in vseg.vobjs: |
---|
2713 | if (self.mwmrname == vobj.name): |
---|
2714 | mwmr_id = vobj.index |
---|
2715 | if (mwmr_id == 0xFFFFFFFF): |
---|
2716 | print '[genmap error] in Cpport.cbin() : mwmr vobj name %s not found in vspace %s' \ |
---|
2717 | % ( self.mwmrname, self.vspacename ) |
---|
2718 | sys.exit(1) |
---|
2719 | |
---|
2720 | byte_stream = bytearray() |
---|
2721 | byte_stream += mapping.int2bytes( 4 , dir_int ) # pseg global index |
---|
2722 | byte_stream += mapping.int2bytes( 4 , vspace_id ) # vspace global index |
---|
2723 | byte_stream += mapping.int2bytes( 4 , mwmr_id ) # mwmr vobj global index |
---|
2724 | |
---|
2725 | if ( verbose ): |
---|
2726 | print 'direction = %s' % self.direction |
---|
2727 | print 'vspace_id = %d' % vspace_id |
---|
2728 | print 'mwmr_id = %d' % mwmr_id |
---|
2729 | |
---|
2730 | return byte_stream |
---|
2731 | |
---|
2732 | |
---|
2733 | # Local Variables: |
---|
2734 | # tab-width: 4; |
---|
2735 | # c-basic-offset: 4; |
---|
2736 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); |
---|
2737 | # indent-tabs-mode: nil; |
---|
2738 | # End: |
---|
2739 | # |
---|
2740 | # vim: filetype=python:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
2741 | |
---|