[1] | 1 | #!/usr/bin/env python |
---|
| 2 | |
---|
| 3 | import sys |
---|
| 4 | |
---|
| 5 | ########################################################################################## |
---|
| 6 | # File : arch_classes.py |
---|
| 7 | # Date : 2016 |
---|
| 8 | # Author : Alain Greiner |
---|
| 9 | # Copyright (c) UPMC Sorbonne Universites |
---|
| 10 | ######################################################################################### |
---|
| 11 | # This file contains the python classes required to define a generic hardware |
---|
| 12 | # architecture for the ALMOS-MK operating system. |
---|
| 13 | # It handle 4 types of objects: clusters, cores, devices and irqs. |
---|
| 14 | # - The number of cluster is variable (can be one). |
---|
[6] | 15 | # - The cluster topology can be a 2D mesh or a simple 1D array. |
---|
[1] | 16 | # - The number of cores per cluster is variable (can be zero). |
---|
| 17 | # - The number of addressable devices per cluster is variable. |
---|
| 18 | # - The size of the physical memory bank per cluster is variable. |
---|
| 19 | # An adressable device can be a physical memory bank or a peripheral. |
---|
| 20 | # Each cluster cover a fixed size segment in physical address space, |
---|
| 21 | # that is defined by (PADDR_WIDTH - X_WIDTH - Y_WIDTH) |
---|
| 22 | ######################################################################################### |
---|
| 23 | # Implementation Note: |
---|
| 24 | # The objects used to describe an architecture are distributed in the python structure: |
---|
| 25 | # For example the set of cores and the set of devices are split in several subsets |
---|
| 26 | # (one subset of cores and one subset of devices per cluster). |
---|
| 27 | # In the generated C binary data structure, all objects of same type |
---|
| 28 | # are stored in a linear array (one single array for all cores for example). |
---|
| 29 | # For all objects, we compute and store in the python object a "global index" |
---|
| 30 | # corresponding to the index in this global array, and this index can be used as |
---|
| 31 | # a pseudo-pointer to identify a specific object of a given type. |
---|
| 32 | ######################################################################################### |
---|
| 33 | |
---|
| 34 | ######################################################################################### |
---|
| 35 | # Define global parameters |
---|
| 36 | ######################################################################################### |
---|
| 37 | |
---|
| 38 | ARCHINFO_SIGNATURE = 0xBABE2016 # magic number indicating a valid C BLOB |
---|
| 39 | PAGE_SIZE = 0x1000 # to check peripherals alignment |
---|
| 40 | |
---|
| 41 | ######################################################################################### |
---|
| 42 | # These arrays define the supported types of peripherals. |
---|
[571] | 43 | # They must be kept consistent with values defined in file arch_info.h |
---|
[1] | 44 | ######################################################################################### |
---|
| 45 | |
---|
| 46 | DEVICE_TYPES_STR = [ |
---|
[6] | 47 | 'RAM_SCL', # 0.0 |
---|
| 48 | 'ROM_SCL', # 1.0 |
---|
| 49 | 'FBF_SCL', # 2.0 |
---|
[586] | 50 | 'FBF_LTI', # 2.1 |
---|
[6] | 51 | 'IOB_TSR', # 3.0 |
---|
| 52 | 'IOC_BDV', # 4.0 |
---|
| 53 | 'IOC_HBA', # 4.1 |
---|
| 54 | 'IOC_SDC', # 4.2 |
---|
| 55 | 'IOC_SPI', # 4.3 |
---|
| 56 | 'IOC_RDK', # 4.4 |
---|
| 57 | 'MMC_TSR', # 5.0 |
---|
| 58 | 'DMA_SCL', # 6.0 |
---|
| 59 | 'NIC_CBF', # 7.0 |
---|
| 60 | 'TIM_SCL', # 8.0 |
---|
| 61 | 'TXT_TTY', # 9.0 |
---|
[586] | 62 | 'TXT_RS2', # 9.1 |
---|
| 63 | 'TXT_MTY', # 9.2 |
---|
[6] | 64 | 'ICU_XCU', # A.0 |
---|
| 65 | 'PIC_TSR', # B.0 |
---|
[1] | 66 | ] |
---|
| 67 | |
---|
| 68 | DEVICE_TYPES_INT = [ |
---|
[6] | 69 | 0x00000000, # 0.0 |
---|
| 70 | 0x00010000, # 1.0 |
---|
[586] | 71 | 0x00020000, # 2.0 |
---|
| 72 | 0x00020001, # 2.1 |
---|
[6] | 73 | 0x00030000, # 3.0 |
---|
| 74 | 0x00040000, # 4.0 |
---|
| 75 | 0x00040001, # 4.1 |
---|
| 76 | 0x00040002, # 4.2 |
---|
| 77 | 0x00040003, # 4.3 |
---|
| 78 | 0x00040004, # 4.4 |
---|
| 79 | 0x00050000, # 5.0 |
---|
| 80 | 0x00060000, # 6.0 |
---|
| 81 | 0x00070000, # 7.0 |
---|
| 82 | 0x00080000, # 8.0 |
---|
| 83 | 0x00090000, # 9.0 |
---|
[534] | 84 | 0x00090001, # 9.1 |
---|
[586] | 85 | 0x00090002, # 9.2 |
---|
[6] | 86 | 0x000A0000, # A.0 |
---|
| 87 | 0x000B0000, # B.0 |
---|
[1] | 88 | ] |
---|
| 89 | |
---|
[586] | 90 | ######################################################################################### |
---|
[1] | 91 | class Archinfo( object ): |
---|
| 92 | ######################################################################################### |
---|
| 93 | def __init__( self, |
---|
| 94 | name, # architecture instance name |
---|
| 95 | x_size, # number of clusters in a row |
---|
| 96 | y_size, # number of clusters in a column |
---|
| 97 | cores_max, # max number of cores per cluster |
---|
| 98 | devices_max, # max number of devices per cluster |
---|
| 99 | paddr_width, # number of bits in physical address |
---|
| 100 | x_width, # number of bits for x coordinate |
---|
| 101 | y_width, # number of bits for y coordinate |
---|
[6] | 102 | irqs_per_core, # number or IRQs from ICU to one core |
---|
[1] | 103 | io_cxy, # IO cluster identifier |
---|
| 104 | boot_cxy, # boot cluster identifier |
---|
| 105 | cache_line, # number of bytes in cache line |
---|
| 106 | reset_address, # Preloader physical base address |
---|
| 107 | p_width ): # TSAR specific : number of bits to code core lid |
---|
| 108 | |
---|
| 109 | assert ( x_size <= (1<<x_width) ) |
---|
| 110 | assert ( y_size <= (1<<y_width) ) |
---|
| 111 | |
---|
| 112 | self.signature = ARCHINFO_SIGNATURE |
---|
| 113 | self.name = name |
---|
| 114 | self.x_size = x_size |
---|
| 115 | self.y_size = y_size |
---|
| 116 | self.cores_max = cores_max |
---|
| 117 | self.devices_max = devices_max |
---|
| 118 | self.paddr_width = paddr_width |
---|
| 119 | self.x_width = x_width |
---|
| 120 | self.y_width = y_width |
---|
| 121 | self.irqs_per_core = irqs_per_core |
---|
| 122 | self.io_cxy = io_cxy |
---|
| 123 | self.boot_cxy = boot_cxy |
---|
| 124 | self.cache_line = cache_line |
---|
| 125 | self.reset_address = reset_address |
---|
| 126 | self.p_width = p_width |
---|
| 127 | |
---|
| 128 | self.total_cores = 0 |
---|
| 129 | self.total_devices = 0 |
---|
| 130 | self.total_irqs = 0 |
---|
| 131 | |
---|
| 132 | self.clusters = [] |
---|
| 133 | |
---|
| 134 | for x in xrange( self.x_size ): |
---|
| 135 | for y in xrange( self.y_size ): |
---|
| 136 | |
---|
| 137 | # call cluster constructor |
---|
| 138 | cxy = (x<<y_width) + y |
---|
| 139 | cluster = Cluster( cxy ) |
---|
| 140 | |
---|
| 141 | # update cluster global index |
---|
| 142 | cluster.index = (x * self.y_size) + y |
---|
| 143 | |
---|
| 144 | # register cluster in Archinfo |
---|
| 145 | self.clusters.append( cluster ) |
---|
| 146 | |
---|
| 147 | return |
---|
| 148 | |
---|
| 149 | ########################## add a device in a cluster |
---|
| 150 | def addDevice( self, |
---|
| 151 | ptype, # device type |
---|
| 152 | base, # associated pseg base address |
---|
| 153 | size, # associated pseg length (bytes) |
---|
| 154 | channels = 1, # number of channels |
---|
| 155 | arg0 = 0, # optional argument (semantic depends on ptype) |
---|
| 156 | arg1 = 0, # optional argument (semantic depends on ptype) |
---|
| 157 | arg2 = 0, # optional argument (semantic depends on ptype) |
---|
| 158 | arg3 = 0 ): # optional argument (semantic depends on ptype) |
---|
| 159 | |
---|
| 160 | # computes cluster identifier and global index from the base address |
---|
| 161 | cxy = base >> (self.paddr_width - self.x_width - self.y_width) |
---|
| 162 | x = cxy >> (self.y_width); |
---|
| 163 | y = cxy & ((1 << self.y_width) - 1) |
---|
| 164 | cluster_id = (x * self.y_size) + y |
---|
| 165 | |
---|
| 166 | assert (x < self.x_size) and (y < self.y_size) |
---|
| 167 | assert (base & (PAGE_SIZE-1) == 0) |
---|
| 168 | assert (ptype in DEVICE_TYPES_STR) |
---|
| 169 | |
---|
| 170 | # call device constructor |
---|
| 171 | device = Device( base, size, ptype, channels, arg0, arg1, arg2, arg3 ) |
---|
| 172 | |
---|
| 173 | # register device in cluster |
---|
| 174 | self.clusters[cluster_id].devices.append( device ) |
---|
| 175 | |
---|
| 176 | # update device global index |
---|
| 177 | device.index = self.total_devices |
---|
| 178 | self.total_devices += 1 |
---|
| 179 | |
---|
| 180 | return device |
---|
| 181 | |
---|
| 182 | ################################ add an input IRQ in a device |
---|
| 183 | def addIrq( self, |
---|
[6] | 184 | dstdev, # destination device (PIC or ICU) |
---|
[1] | 185 | port, # input IRQ port index |
---|
| 186 | srcdev, # source device |
---|
| 187 | channel = 0, # source device channel |
---|
| 188 | is_rx = False ): # I/O operation direction |
---|
| 189 | |
---|
[6] | 190 | assert (dstdev.ptype == 'ICU_XCU') or (dstdev.ptype == 'PIC_TSR') |
---|
[1] | 191 | assert (port < dstdev.arg0) |
---|
| 192 | |
---|
| 193 | # call Irq constructor |
---|
| 194 | irq = Irq( port , srcdev, channel , is_rx ) |
---|
| 195 | |
---|
| 196 | # register IRQ in destination device |
---|
| 197 | dstdev.irqs.append( irq ) |
---|
| 198 | |
---|
| 199 | # update IRQ global index |
---|
| 200 | irq.index = self.total_irqs |
---|
| 201 | self.total_irqs += 1 |
---|
| 202 | |
---|
| 203 | # pointer from the source to the interrupt controller device |
---|
| 204 | if (srcdev.irq_ctrl == None): srcdev.irq_ctrl = dstdev |
---|
| 205 | |
---|
| 206 | if (srcdev.irq_ctrl != dstdev): |
---|
| 207 | print '[genarch error] in addIrq():' |
---|
| 208 | print ' two different interrupt controller for the same device' |
---|
| 209 | sys.exit(1) |
---|
| 210 | |
---|
| 211 | return irq |
---|
| 212 | |
---|
| 213 | ########################## add a core in a cluster |
---|
| 214 | def addCore( self, |
---|
| 215 | gid, # global hardware identifier |
---|
| 216 | cxy, # cluster identifier |
---|
| 217 | lid ): # local index in cluster |
---|
| 218 | |
---|
| 219 | assert ((cxy >> self.y_width) < self.x_size) |
---|
| 220 | assert ((cxy & ((1<<self.y_width)-1)) < self.y_size) |
---|
| 221 | assert (lid < self.cores_max) |
---|
| 222 | |
---|
| 223 | # call Core contructor |
---|
| 224 | core = Core( gid, cxy, lid ) |
---|
| 225 | |
---|
| 226 | # compute cluster global index from cluster identifier |
---|
| 227 | x = cxy>>self.y_width |
---|
| 228 | y = cxy & ((1<<self.y_width)-1) |
---|
| 229 | cluster_id = (x * self.y_size) + y |
---|
| 230 | |
---|
| 231 | # register core in cluster |
---|
| 232 | self.clusters[cluster_id].cores.append( core ) |
---|
| 233 | |
---|
| 234 | # update core global index |
---|
| 235 | core.index = self.total_cores |
---|
| 236 | self.total_cores += 1 |
---|
| 237 | |
---|
| 238 | return core |
---|
| 239 | |
---|
| 240 | ################################# |
---|
| 241 | def str2bytes( self, nbytes, s ): # string => nbytes_packed byte array |
---|
| 242 | |
---|
| 243 | byte_stream = bytearray() |
---|
| 244 | length = len( s ) |
---|
| 245 | if length < (nbytes - 1): |
---|
| 246 | for b in s: |
---|
| 247 | byte_stream.append( b ) |
---|
| 248 | for x in xrange(nbytes-length): |
---|
| 249 | byte_stream.append( '\0' ) |
---|
| 250 | else: |
---|
| 251 | print '[genarch error] in str2bytes()' |
---|
| 252 | print ' string %s too long' % s |
---|
| 253 | sys.exit(1) |
---|
| 254 | |
---|
| 255 | return byte_stream |
---|
| 256 | |
---|
| 257 | ################################### |
---|
| 258 | def int2bytes( self, nbytes, val ): # integer => nbytes litle endian byte array |
---|
| 259 | |
---|
| 260 | byte_stream = bytearray() |
---|
| 261 | for n in xrange( nbytes ): |
---|
| 262 | byte_stream.append( (val >> (n<<3)) & 0xFF ) |
---|
| 263 | |
---|
| 264 | return byte_stream |
---|
| 265 | |
---|
| 266 | ################ |
---|
| 267 | def xml( self ): # compute string for xml file generation |
---|
| 268 | |
---|
| 269 | s = '<?xml version="1.0"?>\n\n' |
---|
| 270 | s += '<arch_info signature = "0x%x"\n' % (self.signature) |
---|
| 271 | s += ' name = "%s"\n' % (self.name) |
---|
| 272 | s += ' x_size = "%d"\n' % (self.x_size) |
---|
| 273 | s += ' y_size = "%d"\n' % (self.y_size) |
---|
| 274 | s += ' cores = "%d"\n' % (self.cores_max) |
---|
| 275 | s += ' io_cxy = "%d" >\n' % (self.io_cxy) |
---|
| 276 | s += '\n' |
---|
| 277 | |
---|
| 278 | s += ' <clusterset>\n' |
---|
| 279 | for x in xrange ( self.x_size ): |
---|
| 280 | for y in xrange ( self.y_size ): |
---|
| 281 | cluster_id = (x * self.y_size) + y |
---|
| 282 | s += self.clusters[cluster_id].xml() |
---|
| 283 | s += ' </clusterset>\n' |
---|
| 284 | s += '\n' |
---|
| 285 | |
---|
| 286 | s += '</arch_info>\n' |
---|
| 287 | return s |
---|
| 288 | |
---|
| 289 | ########################## |
---|
| 290 | def cbin( self, verbose ): # C binary structure for "archinfo.bin" file generation |
---|
| 291 | |
---|
| 292 | byte_stream = bytearray() |
---|
| 293 | |
---|
| 294 | # header |
---|
| 295 | byte_stream += self.int2bytes(4, self.signature) |
---|
| 296 | byte_stream += self.int2bytes(4, self.x_size) |
---|
| 297 | byte_stream += self.int2bytes(4, self.y_size) |
---|
| 298 | byte_stream += self.int2bytes(4, self.paddr_width) |
---|
| 299 | byte_stream += self.int2bytes(4, self.x_width) |
---|
| 300 | byte_stream += self.int2bytes(4, self.y_width) |
---|
| 301 | byte_stream += self.int2bytes(4, self.cores_max) |
---|
| 302 | byte_stream += self.int2bytes(4, self.devices_max) |
---|
| 303 | |
---|
| 304 | byte_stream += self.int2bytes(4, self.total_cores) |
---|
| 305 | byte_stream += self.int2bytes(4, self.total_devices) |
---|
| 306 | byte_stream += self.int2bytes(4, self.total_irqs) |
---|
| 307 | byte_stream += self.int2bytes(4, self.io_cxy) |
---|
| 308 | byte_stream += self.int2bytes(4, self.boot_cxy) |
---|
| 309 | byte_stream += self.int2bytes(4, self.irqs_per_core) |
---|
| 310 | byte_stream += self.int2bytes(4, self.cache_line) |
---|
| 311 | byte_stream += self.int2bytes(4, 0) |
---|
| 312 | |
---|
| 313 | byte_stream += self.str2bytes(64, self.name) |
---|
| 314 | |
---|
| 315 | if ( verbose ): |
---|
| 316 | print '\n' |
---|
| 317 | print 'name = %s' % self.name |
---|
| 318 | print 'signature = %x' % self.signature |
---|
| 319 | print 'x_size = %d' % self.x_size |
---|
| 320 | print 'y_size = %d' % self.y_size |
---|
| 321 | print 'total_cores = %d' % self.total_cores |
---|
| 322 | print 'total_devices = %d' % self.total_devices |
---|
| 323 | print 'total_irqs = %d' % self.total_irqs |
---|
| 324 | print '\n' |
---|
| 325 | |
---|
| 326 | # cores array |
---|
| 327 | index = 0 |
---|
| 328 | for cluster in self.clusters: |
---|
| 329 | for core in cluster.cores: |
---|
| 330 | byte_stream += core.cbin( self, verbose, index ) |
---|
| 331 | index += 1 |
---|
| 332 | |
---|
| 333 | if ( verbose ): print '\n' |
---|
| 334 | |
---|
| 335 | # clusters array |
---|
| 336 | index = 0 |
---|
| 337 | for cluster in self.clusters: |
---|
| 338 | byte_stream += cluster.cbin( self, verbose, index ) |
---|
| 339 | index += 1 |
---|
| 340 | |
---|
| 341 | if ( verbose ): print '\n' |
---|
| 342 | |
---|
| 343 | # devices array |
---|
| 344 | index = 0 |
---|
| 345 | for cluster in self.clusters: |
---|
| 346 | for device in cluster.devices: |
---|
| 347 | byte_stream += device.cbin( self, verbose, index ) |
---|
| 348 | index += 1 |
---|
| 349 | |
---|
| 350 | if ( verbose ): print '\n' |
---|
| 351 | |
---|
| 352 | # irqs array |
---|
| 353 | index = 0 |
---|
| 354 | for cluster in self.clusters: |
---|
| 355 | for device in cluster.devices: |
---|
| 356 | for irq in device.irqs: |
---|
| 357 | byte_stream += irq.cbin( self, verbose, index ) |
---|
| 358 | index += 1 |
---|
| 359 | |
---|
| 360 | if ( verbose ): print '\n' |
---|
| 361 | |
---|
| 362 | return byte_stream |
---|
| 363 | # end of cbin() |
---|
| 364 | |
---|
| 365 | |
---|
| 366 | ###################################################################### |
---|
[571] | 367 | def hard_config( self ): # compute string for hard_config.h file |
---|
[1] | 368 | # required by |
---|
| 369 | # - top.cpp compilation |
---|
| 370 | # - almos-mk bootloader compilation |
---|
| 371 | # - tsar_preloader compilation |
---|
| 372 | |
---|
| 373 | # for each device type, define default values |
---|
| 374 | # for pbase address, size, number of components, and channels |
---|
| 375 | nb_ram = 0 |
---|
| 376 | ram_channels = 0 |
---|
| 377 | ram_base = 0xFFFFFFFFFFFFFFFF |
---|
| 378 | ram_size = 0 |
---|
| 379 | |
---|
[6] | 380 | nb_rom = 0 |
---|
| 381 | rom_channels = 0 |
---|
| 382 | rom_base = 0xFFFFFFFFFFFFFFFF |
---|
| 383 | rom_size = 0 |
---|
[1] | 384 | |
---|
| 385 | nb_fbf = 0 |
---|
| 386 | fbf_channels = 0 |
---|
| 387 | fbf_base = 0xFFFFFFFFFFFFFFFF |
---|
| 388 | fbf_size = 0 |
---|
| 389 | fbf_arg0 = 0 |
---|
| 390 | fbf_arg1 = 0 |
---|
[586] | 391 | use_fbf_scl = False |
---|
| 392 | use_fbf_lti = False |
---|
[1] | 393 | |
---|
| 394 | nb_iob = 0 |
---|
| 395 | iob_channels = 0 |
---|
| 396 | iob_base = 0xFFFFFFFFFFFFFFFF |
---|
| 397 | iob_size = 0 |
---|
| 398 | |
---|
| 399 | nb_ioc = 0 |
---|
| 400 | ioc_channels = 0 |
---|
| 401 | ioc_base = 0xFFFFFFFFFFFFFFFF |
---|
| 402 | ioc_size = 0 |
---|
| 403 | use_ioc_bdv = False |
---|
| 404 | use_ioc_sdc = False |
---|
| 405 | use_ioc_hba = False |
---|
| 406 | use_ioc_spi = False |
---|
| 407 | use_ioc_rdk = False |
---|
| 408 | |
---|
| 409 | nb_mmc = 0 |
---|
| 410 | mmc_channels = 0 |
---|
| 411 | mmc_base = 0xFFFFFFFFFFFFFFFF |
---|
| 412 | mmc_size = 0 |
---|
| 413 | |
---|
[6] | 414 | nb_dma = 0 |
---|
| 415 | dma_channels = 0 |
---|
| 416 | dma_base = 0xFFFFFFFFFFFFFFFF |
---|
| 417 | dma_size = 0 |
---|
[1] | 418 | |
---|
| 419 | nb_nic = 0 |
---|
| 420 | nic_channels = 0 |
---|
| 421 | nic_base = 0xFFFFFFFFFFFFFFFF |
---|
| 422 | nic_size = 0 |
---|
| 423 | |
---|
| 424 | nb_sim = 0 |
---|
| 425 | sim_channels = 0 |
---|
| 426 | sim_base = 0xFFFFFFFFFFFFFFFF |
---|
| 427 | sim_size = 0 |
---|
| 428 | |
---|
| 429 | nb_tim = 0 |
---|
| 430 | tim_channels = 0 |
---|
| 431 | tim_base = 0xFFFFFFFFFFFFFFFF |
---|
| 432 | tim_size = 0 |
---|
| 433 | |
---|
[6] | 434 | nb_txt = 0 |
---|
| 435 | txt_channels = 0 |
---|
| 436 | txt_base = 0xFFFFFFFFFFFFFFFF |
---|
| 437 | txt_size = 0 |
---|
[586] | 438 | use_txt_tty = False |
---|
| 439 | use_txt_rs2 = False |
---|
| 440 | use_txt_mty = False |
---|
[1] | 441 | |
---|
[6] | 442 | nb_icu = 0 |
---|
| 443 | icu_channels = 0 |
---|
| 444 | icu_base = 0xFFFFFFFFFFFFFFFF |
---|
| 445 | icu_size = 0 |
---|
| 446 | icu_arg0 = 0 |
---|
[1] | 447 | |
---|
[6] | 448 | nb_pic = 0 |
---|
| 449 | pic_channels = 0 |
---|
| 450 | pic_base = 0xFFFFFFFFFFFFFFFF |
---|
| 451 | pic_size = 0 |
---|
[1] | 452 | |
---|
[6] | 453 | nb_rom = 0 |
---|
| 454 | rom_channels = 0 |
---|
| 455 | rom_base = 0xFFFFFFFFFFFFFFFF |
---|
| 456 | rom_size = 0 |
---|
| 457 | |
---|
[1] | 458 | # get devices attributes |
---|
| 459 | for cluster in self.clusters: |
---|
| 460 | for device in cluster.devices: |
---|
| 461 | |
---|
[6] | 462 | if ( device.ptype == 'RAM_SCL' ): |
---|
[1] | 463 | ram_base = device.base |
---|
| 464 | ram_size = device.size |
---|
| 465 | ram_channels = device.channels |
---|
| 466 | nb_ram +=1 |
---|
| 467 | |
---|
[6] | 468 | elif ( device.ptype == 'ROM_SCL' ): |
---|
| 469 | rom_base = device.base |
---|
| 470 | rom_size = device.size |
---|
| 471 | rom_channels = device.channels |
---|
| 472 | nb_rom +=1 |
---|
[1] | 473 | |
---|
[6] | 474 | elif ( device.ptype == 'FBF_SCL' ): |
---|
[1] | 475 | fbf_base = device.base |
---|
| 476 | fbf_size = device.size |
---|
| 477 | fbf_channels = device.channels |
---|
[586] | 478 | use_fbf_scl = True |
---|
[1] | 479 | fbf_arg0 = device.arg0 |
---|
| 480 | fbf_arg1 = device.arg1 |
---|
| 481 | nb_fbf +=1 |
---|
[586] | 482 | elif ( device.ptype == 'FBF_LTI' ): |
---|
| 483 | fbf_base = device.base |
---|
| 484 | fbf_size = device.size |
---|
| 485 | fbf_channels = device.channels |
---|
| 486 | use_fbf_lti = True |
---|
| 487 | fbf_arg0 = device.arg0 |
---|
| 488 | fbf_arg1 = device.arg1 |
---|
| 489 | nb_fbf +=1 |
---|
[1] | 490 | |
---|
[6] | 491 | elif ( device.ptype == 'IOB_TSR' ): |
---|
[1] | 492 | iob_base = device.base |
---|
| 493 | iob_size = device.size |
---|
| 494 | iob_channels = device.channels |
---|
| 495 | nb_iob +=1 |
---|
| 496 | |
---|
| 497 | elif ( device.ptype == 'IOC_BDV' ): |
---|
| 498 | ioc_base = device.base |
---|
| 499 | ioc_size = device.size |
---|
| 500 | ioc_channels = device.channels |
---|
| 501 | use_ioc_bdv = True |
---|
| 502 | nb_ioc += 1 |
---|
| 503 | elif ( device.ptype == 'IOC_HBA' ): |
---|
| 504 | ioc_base = device.base |
---|
| 505 | ioc_size = device.size |
---|
| 506 | ioc_channels = device.channels |
---|
| 507 | use_ioc_hba = True |
---|
| 508 | nb_ioc += 1 |
---|
| 509 | elif ( device.ptype == 'IOC_SDC' ): |
---|
| 510 | ioc_base = device.base |
---|
| 511 | ioc_size = device.size |
---|
| 512 | ioc_channels = device.channels |
---|
| 513 | use_ioc_sdc = True |
---|
| 514 | nb_ioc += 1 |
---|
| 515 | elif ( device.ptype == 'IOC_SPI' ): |
---|
| 516 | ioc_base = device.base |
---|
| 517 | ioc_size = device.size |
---|
| 518 | ioc_channels = device.channels |
---|
| 519 | use_ioc_spi = True |
---|
| 520 | nb_ioc += 1 |
---|
| 521 | elif ( device.ptype == 'IOC_RDK' ): |
---|
| 522 | ioc_base = device.base |
---|
| 523 | ioc_size = device.size |
---|
| 524 | ioc_channels = device.channels |
---|
| 525 | use_ioc_rdk = True |
---|
| 526 | nb_ioc += 1 |
---|
| 527 | |
---|
[6] | 528 | elif ( device.ptype == 'MMC_TSR' ): |
---|
[1] | 529 | mmc_base = device.base |
---|
| 530 | mmc_size = device.size |
---|
| 531 | mmc_channels = device.channels |
---|
| 532 | nb_mmc +=1 |
---|
| 533 | |
---|
[6] | 534 | elif ( device.ptype == 'DMA_SCL' ): |
---|
| 535 | dma_base = device.base |
---|
| 536 | dma_size = device.size |
---|
| 537 | dma_channels = device.channels |
---|
| 538 | nb_dma +=1 |
---|
[1] | 539 | |
---|
[6] | 540 | elif ( device.ptype == 'NIC_CBF' ): |
---|
[1] | 541 | nic_base = device.base |
---|
| 542 | nic_size = device.size |
---|
| 543 | nic_channels = device.channels |
---|
| 544 | nb_nic +=1 |
---|
| 545 | |
---|
[6] | 546 | elif ( device.ptype == 'TIM_SCL' ): |
---|
[1] | 547 | tim_base = device.pseg.base |
---|
| 548 | tim_size = device.pseg.size |
---|
| 549 | tim_channels = device.channels |
---|
| 550 | nb_tim +=1 |
---|
| 551 | |
---|
[6] | 552 | elif ( device.ptype == 'TXT_TTY' ): |
---|
| 553 | txt_base = device.base |
---|
| 554 | txt_size = device.size |
---|
| 555 | txt_channels = device.channels |
---|
[586] | 556 | use_txt_tty = True |
---|
[6] | 557 | nb_txt +=1 |
---|
[586] | 558 | elif ( device.ptype == 'TXT_RS2' ): |
---|
| 559 | txt_base = device.base |
---|
| 560 | txt_size = device.size |
---|
| 561 | txt_channels = device.channels |
---|
| 562 | use_txt_rs2 = True |
---|
| 563 | nb_txt +=1 |
---|
| 564 | elif ( device.ptype == 'TXT_MTY' ): |
---|
| 565 | txt_base = device.base |
---|
| 566 | txt_size = device.size |
---|
| 567 | txt_channels = device.channels |
---|
| 568 | use_txt_mty = True |
---|
| 569 | nb_txt +=1 |
---|
[1] | 570 | |
---|
[6] | 571 | elif ( device.ptype == 'ICU_XCU' ): |
---|
| 572 | icu_base = device.base |
---|
| 573 | icu_size = device.size |
---|
| 574 | icu_channels = device.channels |
---|
| 575 | icu_arg0 = device.arg0 |
---|
| 576 | icu_arg1 = device.arg1 |
---|
| 577 | icu_arg2 = device.arg2 |
---|
| 578 | icu_arg3 = device.arg3 |
---|
| 579 | nb_icu +=1 |
---|
[1] | 580 | |
---|
[6] | 581 | elif ( device.ptype == 'PIC_TSR' ): |
---|
| 582 | pic_base = device.base |
---|
| 583 | pic_size = device.size |
---|
| 584 | pic_channels = device.channels |
---|
| 585 | nb_pic +=1 |
---|
[1] | 586 | |
---|
| 587 | # one and only one IOC controller |
---|
[571] | 588 | assert ( nb_ioc == 1 ) |
---|
[1] | 589 | |
---|
| 590 | # compute rdk_base and rdk_size |
---|
| 591 | if( use_ioc_rdk ): |
---|
| 592 | rdk_base = ioc_base |
---|
| 593 | rdk_size = ioc_size |
---|
| 594 | else: |
---|
| 595 | rdk_base = 0 |
---|
| 596 | rdk_size = 0 |
---|
| 597 | |
---|
| 598 | # Compute total number of cores, devices and irqs |
---|
| 599 | nb_total_cores = self.total_cores |
---|
| 600 | nb_total_devices = self.total_devices |
---|
| 601 | nb_total_irqs = self.total_irqs |
---|
| 602 | |
---|
| 603 | # boot core has (cxy == boot_cxy) and (lid == 0) |
---|
| 604 | for cluster in self.clusters: |
---|
| 605 | if( cluster.cxy == self.boot_cxy ): boot_core_gid = cluster.cores[0].gid |
---|
| 606 | |
---|
| 607 | # compute mask to get local physical address (cluster independant) |
---|
| 608 | local_paddr_width = self.paddr_width - self.x_width - self.y_width |
---|
| 609 | local_physical_mask = (1<<local_paddr_width)-1 |
---|
| 610 | |
---|
| 611 | # build string |
---|
| 612 | s = '/* Generated by genarch for %s */\n' % self.name |
---|
| 613 | s += '\n' |
---|
| 614 | s += '#ifndef HARD_CONFIG_H\n' |
---|
| 615 | s += '#define HARD_CONFIG_H\n' |
---|
| 616 | s += '\n' |
---|
| 617 | |
---|
| 618 | s += '/* General platform parameters */\n' |
---|
| 619 | s += '\n' |
---|
| 620 | s += '#define X_SIZE %d\n' % self.x_size |
---|
| 621 | s += '#define Y_SIZE %d\n' % self.y_size |
---|
| 622 | s += '#define PADDR_WIDTH %d\n' % self.paddr_width |
---|
| 623 | s += '#define X_WIDTH %d\n' % self.x_width |
---|
| 624 | s += '#define Y_WIDTH %d\n' % self.y_width |
---|
| 625 | s += '#define P_WIDTH %d\n' % self.p_width |
---|
| 626 | s += '#define X_IO %d\n' % (self.io_cxy >> self.y_width) |
---|
| 627 | s += '#define Y_IO %d\n' % (self.io_cxy & ((1<<self.y_width)-1)) |
---|
| 628 | s += '#define NB_PROCS_MAX %d\n' % self.cores_max |
---|
| 629 | s += '#define NB_DEVICES_MAX %d\n' % self.devices_max |
---|
| 630 | s += '#define IRQ_PER_PROCESSOR %d\n' % self.irqs_per_core |
---|
| 631 | s += '#define RESET_ADDRESS 0x%x\n' % self.reset_address |
---|
| 632 | s += '#define NB_TOTAL_PROCS %d\n' % nb_total_cores |
---|
| 633 | s += '#define BOOT_CORE_GID %d\n' % boot_core_gid |
---|
| 634 | s += '#define BOOT_CORE_CXY %d\n' % self.boot_cxy |
---|
| 635 | s += '#define CACHE_LINE_SIZE %d\n' % self.cache_line |
---|
| 636 | s += '\n' |
---|
| 637 | |
---|
| 638 | s += '/* Peripherals */\n' |
---|
| 639 | s += '\n' |
---|
[6] | 640 | s += '#define NB_TXT_CHANNELS %d\n' % txt_channels |
---|
[1] | 641 | s += '#define NB_IOC_CHANNELS %d\n' % ioc_channels |
---|
| 642 | s += '#define NB_NIC_CHANNELS %d\n' % nic_channels |
---|
| 643 | s += '#define NB_TIM_CHANNELS %d\n' % tim_channels |
---|
| 644 | s += '\n' |
---|
[6] | 645 | s += '#define USE_ICU %d\n' % ( nb_icu != 0 ) |
---|
[1] | 646 | s += '#define USE_IOB %d\n' % ( nb_iob != 0 ) |
---|
| 647 | s += '#define USE_PIC %d\n' % ( nb_pic != 0 ) |
---|
| 648 | s += '#define USE_FBF %d\n' % ( nb_fbf != 0 ) |
---|
| 649 | s += '#define USE_NIC %d\n' % ( nb_nic != 0 ) |
---|
[6] | 650 | s += '#define USE_DMA %d\n' % ( nb_dma != 0 ) |
---|
[1] | 651 | s += '\n' |
---|
[571] | 652 | s += '#define USE_IOC_BDV %d\n' % use_ioc_bdv |
---|
| 653 | s += '#define USE_IOC_SDC %d\n' % use_ioc_sdc |
---|
| 654 | s += '#define USE_IOC_HBA %d\n' % use_ioc_hba |
---|
| 655 | s += '#define USE_IOC_SPI %d\n' % use_ioc_spi |
---|
[1] | 656 | s += '#define USE_IOC_RDK %d\n' % use_ioc_rdk |
---|
| 657 | s += '\n' |
---|
[586] | 658 | s += '#define USE_TXT_TTY %d\n' % use_txt_tty |
---|
| 659 | s += '#define USE_TXT_RS2 %d\n' % use_txt_rs2 |
---|
| 660 | s += '#define USE_TXT_MTY %d\n' % use_txt_mty |
---|
| 661 | s += '\n' |
---|
| 662 | s += '#define USE_FBF_SCL %d\n' % use_fbf_scl |
---|
| 663 | s += '#define USE_FBF_LTI %d\n' % use_fbf_lti |
---|
| 664 | s += '\n' |
---|
[1] | 665 | s += '#define FBUF_X_SIZE %d\n' % fbf_arg0 |
---|
| 666 | s += '#define FBUF_Y_SIZE %d\n' % fbf_arg1 |
---|
| 667 | s += '\n' |
---|
[6] | 668 | s += '#define ICU_NB_HWI %d\n' % icu_arg0 |
---|
| 669 | s += '#define ICU_NB_PTI %d\n' % icu_arg1 |
---|
| 670 | s += '#define ICU_NB_WTI %d\n' % icu_arg2 |
---|
| 671 | s += '#define ICU_NB_OUT %d\n' % icu_arg3 |
---|
[1] | 672 | s += '\n' |
---|
| 673 | |
---|
| 674 | s += '/* local physical base address and size for devices */\n' |
---|
| 675 | s += '\n' |
---|
| 676 | s += '#define SEG_RAM_BASE 0x%x\n' % (ram_base & local_physical_mask) |
---|
| 677 | s += '#define SEG_RAM_SIZE 0x%x\n' % ram_size |
---|
| 678 | s += '\n' |
---|
| 679 | s += '#define SEG_FBF_BASE 0x%x\n' % (fbf_base & local_physical_mask) |
---|
| 680 | s += '#define SEG_FBF_SIZE 0x%x\n' % fbf_size |
---|
| 681 | s += '\n' |
---|
| 682 | s += '#define SEG_IOB_BASE 0x%x\n' % (iob_base & local_physical_mask) |
---|
| 683 | s += '#define SEG_IOB_SIZE 0x%x\n' % iob_size |
---|
| 684 | s += '\n' |
---|
| 685 | s += '#define SEG_IOC_BASE 0x%x\n' % (ioc_base & local_physical_mask) |
---|
| 686 | s += '#define SEG_IOC_SIZE 0x%x\n' % ioc_size |
---|
| 687 | s += '\n' |
---|
| 688 | s += '#define SEG_MMC_BASE 0x%x\n' % (mmc_base & local_physical_mask) |
---|
| 689 | s += '#define SEG_MMC_SIZE 0x%x\n' % mmc_size |
---|
| 690 | s += '\n' |
---|
[6] | 691 | s += '#define SEG_DMA_BASE 0x%x\n' % (dma_base & local_physical_mask) |
---|
| 692 | s += '#define SEG_DMA_SIZE 0x%x\n' % dma_size |
---|
[1] | 693 | s += '\n' |
---|
| 694 | s += '#define SEG_ROM_BASE 0x%x\n' % (rom_base & local_physical_mask) |
---|
| 695 | s += '#define SEG_ROM_SIZE 0x%x\n' % rom_size |
---|
| 696 | s += '\n' |
---|
| 697 | s += '#define SEG_SIM_BASE 0x%x\n' % (sim_base & local_physical_mask) |
---|
| 698 | s += '#define SEG_SIM_SIZE 0x%x\n' % sim_size |
---|
| 699 | s += '\n' |
---|
| 700 | s += '#define SEG_NIC_BASE 0x%x\n' % (nic_base & local_physical_mask) |
---|
| 701 | s += '#define SEG_NIC_SIZE 0x%x\n' % nic_size |
---|
| 702 | s += '\n' |
---|
| 703 | s += '#define SEG_PIC_BASE 0x%x\n' % (pic_base & local_physical_mask) |
---|
| 704 | s += '#define SEG_PIC_SIZE 0x%x\n' % pic_size |
---|
| 705 | s += '\n' |
---|
| 706 | s += '#define SEG_TIM_BASE 0x%x\n' % (tim_base & local_physical_mask) |
---|
| 707 | s += '#define SEG_TIM_SIZE 0x%x\n' % tim_size |
---|
| 708 | s += '\n' |
---|
[6] | 709 | s += '#define SEG_TXT_BASE 0x%x\n' % (txt_base & local_physical_mask) |
---|
| 710 | s += '#define SEG_TXT_SIZE 0x%x\n' % txt_size |
---|
[1] | 711 | s += '\n' |
---|
[6] | 712 | s += '#define SEG_ICU_BASE 0x%x\n' % (icu_base & local_physical_mask) |
---|
| 713 | s += '#define SEG_ICU_SIZE 0x%x\n' % icu_size |
---|
[1] | 714 | s += '\n' |
---|
| 715 | s += '#define SEG_RDK_BASE 0x%x\n' % (rdk_base & local_physical_mask) |
---|
| 716 | s += '#define SEG_RDK_SIZE 0x%x\n' % rdk_size |
---|
| 717 | s += '\n' |
---|
| 718 | s += '#endif\n' |
---|
| 719 | |
---|
| 720 | return s |
---|
| 721 | |
---|
| 722 | # end of hard_config() |
---|
| 723 | |
---|
| 724 | |
---|
| 725 | |
---|
| 726 | |
---|
| 727 | |
---|
| 728 | ################################################################################### |
---|
| 729 | class Cluster ( object ): |
---|
| 730 | ################################################################################### |
---|
| 731 | def __init__( self, |
---|
| 732 | cxy ): |
---|
| 733 | |
---|
| 734 | self.index = 0 # global index (set by Archinfo constructor) |
---|
| 735 | self.cxy = cxy # cluster identifier |
---|
| 736 | self.cores = [] # local cores (filled by addCore) |
---|
| 737 | self.devices = [] # local devices(filled by addDevice) |
---|
| 738 | |
---|
| 739 | return |
---|
| 740 | |
---|
| 741 | ################ |
---|
| 742 | def xml( self ): # xml for a cluster |
---|
| 743 | |
---|
| 744 | s = ' <cluster cxy = "%x" >\n' % (self.cxy) |
---|
| 745 | for core in self.cores: s += core.xml() |
---|
| 746 | for device in self.devices: s += device.xml() |
---|
| 747 | s += ' </cluster>\n' |
---|
| 748 | |
---|
| 749 | return s |
---|
| 750 | |
---|
| 751 | ############################################# |
---|
| 752 | def cbin( self, mapping, verbose, expected ): # C binary structure for Cluster |
---|
| 753 | |
---|
| 754 | if ( verbose ): |
---|
| 755 | print '*** cbin for cluster[%d] / identifier = %x' \ |
---|
| 756 | % (self.index , self.cxy) |
---|
| 757 | |
---|
| 758 | # check index |
---|
| 759 | if (self.index != expected): |
---|
| 760 | print '[genarch error] in Cluster.cbin()' |
---|
| 761 | print ' cluster global index = %d / expected = %d' \ |
---|
| 762 | % (self.index,expected) |
---|
| 763 | sys.exit(1) |
---|
| 764 | |
---|
| 765 | # compute global index for first core in cluster |
---|
| 766 | if ( len(self.cores) > 0 ): |
---|
| 767 | core_id = self.cores[0].index |
---|
| 768 | else: |
---|
| 769 | core_id = 0 |
---|
| 770 | |
---|
| 771 | # compute global index for first device in cluster |
---|
| 772 | if ( len(self.devices) > 0 ): |
---|
| 773 | device_id = self.devices[0].index |
---|
| 774 | else: |
---|
| 775 | device_id = 0 |
---|
| 776 | |
---|
| 777 | byte_stream = bytearray() |
---|
| 778 | byte_stream += mapping.int2bytes(4,self.cxy) # cxy |
---|
| 779 | byte_stream += mapping.int2bytes(4,len(self.cores)) # cores in cluster |
---|
| 780 | byte_stream += mapping.int2bytes(4,core_id ) # first core global index |
---|
| 781 | byte_stream += mapping.int2bytes(4,len(self.devices)) # devices in cluster |
---|
| 782 | byte_stream += mapping.int2bytes(4, device_id ) # first device global index |
---|
| 783 | |
---|
| 784 | if ( verbose ): |
---|
| 785 | print 'nb_cores = %d' % len( self.cores ) |
---|
| 786 | print 'core_id = %d' % core_id |
---|
| 787 | print 'nb_devices = %d' % len( self.devices ) |
---|
| 788 | print 'device_id = %d' % device_id |
---|
| 789 | |
---|
| 790 | return byte_stream |
---|
| 791 | |
---|
| 792 | |
---|
| 793 | |
---|
| 794 | |
---|
| 795 | ################################################################################## |
---|
| 796 | class Core ( object ): |
---|
| 797 | ################################################################################## |
---|
| 798 | def __init__( self, |
---|
| 799 | gid, |
---|
| 800 | cxy, |
---|
| 801 | lid ): |
---|
| 802 | |
---|
| 803 | self.index = 0 # global index / set by addProc() |
---|
| 804 | self.gid = gid # hardware identifier |
---|
| 805 | self.cxy = cxy # cluster identifier |
---|
| 806 | self.lid = lid # local index in cluster |
---|
| 807 | |
---|
| 808 | return |
---|
| 809 | |
---|
| 810 | ################################### |
---|
| 811 | def xml( self ): # xml for a core |
---|
| 812 | return ' <core gid="%x" lid="%d" />\n' % (self.gid, self.lid) |
---|
| 813 | |
---|
| 814 | #################################################################### |
---|
| 815 | def cbin( self, mapping, verbose, expected ): # C binary for Proc |
---|
| 816 | |
---|
| 817 | if ( verbose ): |
---|
| 818 | print '*** cbin for core [%d] in cluster %x' \ |
---|
| 819 | % (self.lid, self.cxy) |
---|
| 820 | |
---|
| 821 | # check index |
---|
| 822 | if (self.index != expected): |
---|
| 823 | print '[genarch error] in Core.cbin()' |
---|
| 824 | print ' core global index = %d / expected = %d' \ |
---|
| 825 | % (self.index,expected) |
---|
| 826 | sys.exit(1) |
---|
| 827 | |
---|
| 828 | byte_stream = bytearray() |
---|
| 829 | byte_stream += mapping.int2bytes( 4 , self.gid ) # hardware identifier |
---|
| 830 | byte_stream += mapping.int2bytes( 2 , self.cxy ) # cluster identifier |
---|
| 831 | byte_stream += mapping.int2bytes( 2 , self.lid ) # local index |
---|
| 832 | |
---|
| 833 | return byte_stream |
---|
| 834 | |
---|
| 835 | |
---|
| 836 | |
---|
| 837 | |
---|
| 838 | ################################################################################## |
---|
| 839 | class Device ( object ): |
---|
| 840 | ################################################################################## |
---|
| 841 | def __init__( self, |
---|
| 842 | base, |
---|
| 843 | size, |
---|
| 844 | ptype, |
---|
| 845 | channels = 1, |
---|
| 846 | arg0 = 0, |
---|
| 847 | arg1 = 0, |
---|
| 848 | arg2 = 0, |
---|
| 849 | arg3 = 0 ): |
---|
| 850 | |
---|
| 851 | self.index = 0 # global device index ( set by addDevice() ) |
---|
| 852 | self.base = base # associated segment base |
---|
| 853 | self.size = size # associated segment size (bytes) |
---|
| 854 | self.ptype = ptype # device type |
---|
| 855 | self.channels = channels # number of channels |
---|
| 856 | self.arg0 = arg0 # optional (semantic depends on ptype) |
---|
| 857 | self.arg1 = arg1 # optional (semantic depends on ptype) |
---|
| 858 | self.arg2 = arg2 # optional (semantic depends on ptype) |
---|
| 859 | self.arg3 = arg3 # optional (semantic depends on ptype) |
---|
[6] | 860 | self.irqs = [] # set of input IRQs (for PIC and ICU only) |
---|
[1] | 861 | self.irq_ctrl = None # interrupt controller for this device |
---|
| 862 | return |
---|
| 863 | |
---|
| 864 | ###################################### |
---|
| 865 | def xml( self ): # xml for a device |
---|
| 866 | |
---|
| 867 | s = ' <device type="%s"' % self.ptype |
---|
| 868 | s += ' base="%x"' % self.base |
---|
| 869 | s += ' size="%x"' % self.size |
---|
| 870 | s += ' channels="%d"' % self.channels |
---|
| 871 | s += ' arg0="%d"' % self.arg0 |
---|
| 872 | s += ' arg1="%d"' % self.arg1 |
---|
| 873 | s += ' arg2="%d"' % self.arg2 |
---|
| 874 | s += ' arg3="%d"' % self.arg3 |
---|
[6] | 875 | if ( (self.ptype == 'PIC_TSR') or (self.ptype == 'ICU_XCU') ): |
---|
[1] | 876 | s += ' >\n' |
---|
| 877 | for irq in self.irqs: s += irq.xml() |
---|
| 878 | s += ' </device>\n' |
---|
| 879 | else: |
---|
| 880 | s += ' />\n' |
---|
| 881 | return s |
---|
| 882 | |
---|
| 883 | ###################################################################### |
---|
| 884 | def cbin( self, mapping, verbose, expected ): # C binary for Periph |
---|
| 885 | |
---|
| 886 | if ( verbose ): |
---|
[6] | 887 | print '*** cbin for device[%d] / type = %s / base = %x' \ |
---|
| 888 | % (self.index , self.ptype , self.base) |
---|
[1] | 889 | |
---|
| 890 | # check index |
---|
| 891 | if (self.index != expected): |
---|
| 892 | print '[genarch error] in Periph.cbin()' |
---|
| 893 | print ' device global index = %d / expected = %d' \ |
---|
| 894 | % (self.index,expected) |
---|
| 895 | sys.exit(1) |
---|
| 896 | |
---|
| 897 | # compute first irq global index |
---|
| 898 | if ( len(self.irqs) > 0 ): |
---|
| 899 | irq_id = self.irqs[0].index |
---|
| 900 | else: |
---|
| 901 | irq_id = 0 |
---|
| 902 | |
---|
| 903 | # compute device type numerical value |
---|
| 904 | ptype_id = 0xFFFFFFFF |
---|
| 905 | for x in xrange( len(DEVICE_TYPES_STR) ): |
---|
| 906 | if ( self.ptype == DEVICE_TYPES_STR[x] ): ptype_id = DEVICE_TYPES_INT[x] |
---|
| 907 | |
---|
| 908 | if ( ptype_id == 0xFFFFFFFF ): |
---|
| 909 | print '[genarch error] in Device.cbin()' |
---|
| 910 | print ' undefined device type %s' % self.ptype |
---|
| 911 | sys.exit(1) |
---|
| 912 | |
---|
| 913 | byte_stream = bytearray() |
---|
| 914 | byte_stream += mapping.int2bytes(8,self.base) # segment base address |
---|
| 915 | byte_stream += mapping.int2bytes(8,self.size) # segment size |
---|
[6] | 916 | byte_stream += mapping.int2bytes(4,ptype_id) # device type |
---|
[1] | 917 | byte_stream += mapping.int2bytes(4,self.channels) # number of channels |
---|
| 918 | byte_stream += mapping.int2bytes(4,self.arg0) # optionnal arg0 |
---|
| 919 | byte_stream += mapping.int2bytes(4,self.arg1) # optionnal arg1 |
---|
| 920 | byte_stream += mapping.int2bytes(4,self.arg2) # optionnal arg2 |
---|
| 921 | byte_stream += mapping.int2bytes(4,self.arg3) # optionnal arg3 |
---|
| 922 | byte_stream += mapping.int2bytes(4,len(self.irqs)) # number of input irqs |
---|
| 923 | byte_stream += mapping.int2bytes(4 ,irq_id) # first irq global index |
---|
| 924 | |
---|
| 925 | if ( verbose ): |
---|
| 926 | print 'base = %x' % self.base |
---|
| 927 | print 'size = %x' % self.size |
---|
| 928 | print 'nb_irqs = %d' % len( self.irqs ) |
---|
| 929 | print 'irq_id = %d' % irq_id |
---|
| 930 | |
---|
| 931 | return byte_stream |
---|
| 932 | |
---|
| 933 | ################################################################################## |
---|
| 934 | class Irq ( object ): |
---|
| 935 | ################################################################################## |
---|
| 936 | def __init__( self, |
---|
| 937 | port, |
---|
| 938 | dev, |
---|
| 939 | channel, |
---|
| 940 | is_rx ): |
---|
| 941 | |
---|
| 942 | assert port < 32 |
---|
| 943 | |
---|
| 944 | self.index = 0 # global index ( set by addIrq() ) |
---|
| 945 | self.port = port # input IRQ port index |
---|
| 946 | self.dev = dev # source device |
---|
| 947 | self.channel = channel # source device channel |
---|
| 948 | self.is_rx = is_rx # source device direction |
---|
| 949 | |
---|
| 950 | return |
---|
| 951 | |
---|
| 952 | ################################ |
---|
| 953 | def xml( self ): # xml for Irq |
---|
| 954 | s = ' <irq port="%d" devtype="%s" channel="%d" is_rx="%d" />\n' \ |
---|
| 955 | % ( self.port, self.dev.ptype, self.channel, self.is_rx ) |
---|
| 956 | return s |
---|
| 957 | |
---|
| 958 | #################################################################### |
---|
| 959 | def cbin( self, mapping, verbose, expected ): # C binary for Irq |
---|
| 960 | |
---|
| 961 | if ( verbose ): |
---|
[6] | 962 | print '*** cbin for irq[%d] / src_dev = %s' \ |
---|
| 963 | % (self.port , self.dev.ptype) |
---|
[1] | 964 | |
---|
| 965 | # check index |
---|
| 966 | if (self.index != expected): |
---|
| 967 | print '[genarch error] in Irq.cbin()' |
---|
| 968 | print ' irq global index = %d / expected = %d' \ |
---|
[6] | 969 | % (self.index , expected) |
---|
[1] | 970 | # compute source device type numerical value |
---|
| 971 | dev_id = 0xFFFFFFFF |
---|
| 972 | for x in xrange( len(DEVICE_TYPES_STR) ): |
---|
| 973 | if ( self.dev.ptype == DEVICE_TYPES_STR[x] ): dev_id = DEVICE_TYPES_INT[x] |
---|
| 974 | |
---|
| 975 | if ( dev_id == 0xFFFFFFFF ): |
---|
| 976 | print '[genarch error] in Irq.cbin()' |
---|
| 977 | print ' undefined device type %s' % self.dev.ptype |
---|
| 978 | sys.exit(1) |
---|
| 979 | |
---|
| 980 | byte_stream = bytearray() |
---|
| 981 | byte_stream += mapping.int2bytes( 4, dev_id ) |
---|
| 982 | byte_stream += mapping.int2bytes( 1, self.channel ) |
---|
| 983 | byte_stream += mapping.int2bytes( 1, self.is_rx ) |
---|
| 984 | byte_stream += mapping.int2bytes( 1, self.port ) |
---|
| 985 | byte_stream += mapping.int2bytes( 1, 0 ) |
---|
| 986 | |
---|
| 987 | if ( verbose ): |
---|
| 988 | print 'dev_id = %d' % dev_id |
---|
| 989 | print 'channel = %d' % self.channel |
---|
| 990 | print 'is_rx = %d' % self.is_rx |
---|
| 991 | print 'port = %s' % self.port |
---|
| 992 | |
---|
| 993 | return byte_stream |
---|
| 994 | |
---|
| 995 | # Local Variables: |
---|
| 996 | # tab-width: 4; |
---|
| 997 | # c-basic-offset: 4; |
---|
| 998 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); |
---|
| 999 | # indent-tabs-mode: nil; |
---|
| 1000 | # End: |
---|
| 1001 | # |
---|
| 1002 | # vim: filetype=python:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 1003 | |
---|