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