#!/usr/bin/env python ####################################################################################### # file : giet_mapping.py # date : april 2014 # author : Alain Greiner ####################################################################################### # This file contains the classes required to define a generic mapping in python # for the GIET_VM. # - A 'Mapping' contains + various structural constants, # + a 'Cluster' set, (hardware architecture) # + a 'Vseg' set, (kernel virtual segments mapping) # + a 'Vspace' set (several user applications). # - A 'Cluster' contains + coordinates (x,y), # + a 'Pseg' set, (all physical segments in cluster) # + a 'Proc' set, (processors in cluster) # + a 'Peripheral' set (peripherals in cluster) # - A 'Vspace' contains + a 'Vseg' set, (user virtual segments mapping) # + a 'Task' set (user tasks mapping) #################################################################################### ######################### class Mapping( object ): ######################### def __init__( self, name, # mapping name x_size, # number of clusters in a row y_size, # number of clusters in a column nb_procs, # max number of processors per cluster x_width = 4, # number of bits encoding x coordinate y_width = 4, # number of bits encoding y coordinate paddr_width = 32, # number of bits for physical address coherence = False, # hardware cache coherence irq_per_proc = 1, # number or IRQ lines from XCU to processor use_ram_disk = False, # architecture contains ram_disk when true x_io = 0, # cluster_io x coordinate y_io = 0 ): # cluster_io y coordinate self.name = name self.paddr_width = paddr_width self.coherence = coherence self.x_size = x_size self.y_size = y_size self.x_width = x_width self.y_width = y_width self.irq_per_proc = irq_per_proc self.nb_procs = nb_procs self.use_ram_disk = use_ram_disk self.x_io = x_io self.y_io = y_io self.total_procs = 0 self.total_globs = 0 # clusters array self.clusters = [] for x in xrange (1<> (self.paddr_width - self.x_width - self.y_width) x = cluster_xy >> (self.y_width); y = cluster_xy & ((1 << self.y_width) - 1) if (x >= self.x_size) or (y >= self.y_size): print '(x,y) coordinates too large for pdeg %s' % str(pseg) self.clusters[cluster_xy].psegs.append( pseg ) return ###################################### def addPeripheral( self, peripheral ): cluster_xy = peripheral.pseg.base >> (self.paddr_width - self.x_width - self.y_width) x = cluster_xy >> (self.y_width); y = cluster_xy & ((1 << self.y_width) - 1) if (x >= self.x_size) or (y >= self.y_size): print '(x,y) coordinates too large for pdeg %s' % str(pseg) self.clusters[cluster_xy].peripherals.append( peripheral ) return ########################### def addProc ( self, proc ): cluster_xy = (proc.x << self.y_width) + proc.y self.clusters[cluster_xy].procs.append( proc ) self.total_procs += 1 if (proc.x >= self.x_size) or (proc.y >= self.y_size): print '(x,y) coordinates too large for node %s' % str(proc) return ############################ def addGlobal( self, vseg ): self.globs.append( vseg ) return ############################## def addVspace( self, vspace ): self.vspaces.append( vspace ) return #################### def __str__( self ): # xml generation for mapping s = '\n\n' s += '\n' % (self.lpid) ###################### class Pseg ( object ): ###################### def __init__( self, name, base, size, segtype ): self.name = name self.base = base self.size = size self.segtype = segtype assert segtype in ['RAM','PERI'] return #################### def __str__( self ): # xml for a pseg return ' \n' \ % (self.name, self.segtype, self.base, self.size) ############################ class Peripheral ( object ): ############################ def __init__( self, name, base, size, ptype, subtype, channels = 1): self.channels = channels self.ptype = ptype self.subtype = subtype self.pseg = Pseg( name, base, size, 'PERI' ) return #################### def __str__( self ): # xml for a peripheral s = ' \n' \ % ( self.ptype, self.subtype, self.pseg.name, self.channels ) if ( self.ptype == 'PIC' ): for i in self.irqs: s += str( i ) # picIrq if ( (self.ptype == 'XCU') or (self.ptype == 'ICU') ): for i in self.irqs: s += str( i ) # xcuIrq s += ' \n' return s ######################## class Tty( Peripheral ): ######################## def __init__( self, name, base, size, channels ): Peripheral.__init__( self, name, base, size, 'TTY', 'NONE', channels ) return ######################## class Dma( Peripheral ): ######################## def __init__( self, name, base, size, channels ): Peripheral.__init__( self, name, base, size, 'DMA', 'NONE', channels ) return ######################## class Bdv( Peripheral ): ######################## def __init__( self, name, base, size ): Peripheral.__init__( self, name, base, size, 'IOC', 'BDV' ) return ######################## class Spi( Peripheral ): ######################## def __init__( self, name, base, size ): Peripheral.__init__( self, name, base, size, 'IOC', 'SPI' ) return ######################## class Hba( Peripheral ): ######################## def __init__( self, name, base, size, channels ): Peripheral.__init__( self, name, base, size, 'IOC', 'HBA', channels ) return ######################## class Nic( Peripheral ): ######################## def __init__( self, name, base, size, channels ): Peripheral.__init__( self, name, base, size, 'NIC', 'NONE', channels ) return ######################## class Cma( Peripheral ): ######################## def __init__( self, name, base, size, channels ): Peripheral.__init__( self, name, base, size, 'CMA', 'NONE', channels ) return ######################## class Fbf( Peripheral ): ######################## def __init__( self, name, base, size ): Peripheral.__init__( self, name, base, size, 'FBF', 'NONE' ) return ######################## class Tim( Peripheral ): ######################## def __init__( self, name, base, size, channels ): Peripheral.__init__( self, name, base, size, 'TIM', 'NONE', channels ) return ######################## class Iob( Peripheral ): ######################## def __init__( self, name, base, size ): Peripheral.__init__( self, name, base, size, 'IOB', 'NONE' ) return ######################## class Rom( Peripheral ): ######################## def __init__( self, name, base, size ): Peripheral.__init__( self, name, base, size, 'ROM', 'NONE' ) return ######################## class Mmc( Peripheral ): ######################## def __init__( self, name, base, size ): Peripheral.__init__( self, name, base, size, 'MMC', 'NONE' ) return ######################## class Xcu( Peripheral ): ######################## def __init__( self, name, base, size, channels ): Peripheral.__init__( self, name, base, size, 'XCU', 'NONE', channels ) self.irqs = [] return def add ( self, irq ): self.irqs.append( irq ) return ######################## class Icu( Peripheral ): ######################## def __init__( self, name, base, size, channels ): Peripheral.__init__( self, name, base, size, 'ICU', 'NONE', channels ) self.irqs = [] return ###################### def add ( self, irq ): self.irqs.append( irq ) return ######################## class Pic( Peripheral ): ######################## def __init__( self, name, base, size, channels ): Peripheral.__init__( self, name, base, size, 'PIC', 'NONE', channels ) self.irqs = [] return ###################### def add ( self, irq ): self.irqs.append( irq ) return ######################## class XcuIrq ( object ): ######################## def __init__( self, srctype, srcid, isrtype, channel = 0, dstid = 0 ): assert srctype in ['HWI','WTI','PTI'] assert isrtype in ['ISR_DEFAULT','ISR_TICK','ISR_TTY_RX','ISR_TTY_TX', 'ISR_BDV', 'ISR_TIMER', 'ISR_WAKUP', 'ISR_NIC_RX', 'ISR_NIC_TX','ISR_CMA','ISR_MMC'] assert srcid < 32 self.srctype = srctype self.srcid = srcid self.isrtype = isrtype self.channel = channel self.dstid = dstid return #################### def __str__( self ): # xml for an xcuIrq s = ' \n' \ % (self.srctype, self.srcid, self.isrtype, self.channel, self.dstid) return s ######################## class PicIrq ( object ): ######################## def __init__( self, srcid, dstx, dsty, dstid ): assert srcid < 32 self.srcid = srcid self.dstx = dstx self.dsty = dsty self.dstid = dstid return #################### def __str__( self ): # xml for a picIrq s = ' \n' \ % (self.srcid, self.dstx, self.dsty, self.dstid) return s # Local Variables: # tab-width: 4; # c-basic-offset: 4; # c-file-offsets:((innamespace . 0)(inline-open . 0)); # indent-tabs-mode: nil; # End: # # vim: filetype=python:expandtab:shiftwidth=4:tabstop=4:softtabstop=4