#!/usr/bin/env python import sys ########################################################################################## # file : giet_mapping.py # date : april 2014 # author : Alain Greiner ########################################################################################## # This file contains the classes required to define a mapping for the GIET_VM. # - A 'Mapping' contains a set of 'Cluster' (hardware architecture) # a set of 'Vseg' (kernel virtual segments mapping) # a set of 'Vspace' (several user applications). # - A 'Cluster' contains a set of 'Pseg' (all physical segments in cluster) # a set of 'Proc' (processors in cluster) # a set of 'Periph' (peripherals in cluster) # a set of 'Coproc' (coprocessors in cluster) # - A 'Vspace' contains a set of 'Vseg' (user virtual segments mapping) # a set of 'Task' (user tasks mapping) # - A 'Vseg' contains a set of 'Vobj' # - A 'Periph' contains a set of 'Irq' (only for XCU and PIC types ) # - A 'Coproc' contains a set of 'Cpports' (one port per MWMR channel) ########################################################################################## # Implementation Note # The various objects used to describe a mapping are distributed in the PYTHON structure: # For example the psegs set is split in several subsets (one subset per cluster), # or the tasks set is split in several subsets (one subset per vspace), etc... # In the C binary data structure used by the giet_vm, all objects of same type # are stored in a linear array (one single array for all psegs for example). # For all objects, we compute and store in the PYTHON object itsel a "global index" # corresponding to the index in this global array, and this index can be used as # a pseudo-pointer to identify a specific object of a given type. ########################################################################################## ########################################################################################## # Various constants ########################################################################################## PADDR_WIDTH = 40 # number of bits for physical address X_WIDTH = 4 # number of bits encoding x coordinate Y_WIDTH = 4 # number of bits encoding y coordinate P_WIDTH = 4 # number of bits encoding local proc_id VPN_ANTI_MASK = 0x00000FFF # mask virtual address to get offset in a small page BPN_MASK = 0xFFE00000 # mask virtual address to get the BPN (big page) PERI_INCREMENT = 0x10000 # virtual address increment for replicated global vsegs RESET_ADDRESS = 0xBFC00000 # Processor wired boot_address MAPPING_SIGNATURE = 0xDACE2014 # Magic number indicating a valid C binary struture ########################################################################################## # These global lists must be consistent with enums in mapping_info.h or irq_handler. ########################################################################################## PERIPHTYPES = [ 'CMA', 'DMA', 'FBF', 'IOB', 'IOC', 'MMC', 'MWR', 'NIC', 'ROM', 'SIM', 'TIM', 'TTY', 'XCU', 'PIC', 'DROM', ] PERIPHSUBTYPES = [ 'BDV', 'HBA', 'SPI', 'NONE', ] IRQTYPES = [ 'HWI', 'WTI', 'PTI', ] ISRTYPES = [ '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', 'ISR_DMA', 'ISR_SPI', ] VOBJTYPES = [ 'ELF', 'BLOB', 'PTAB', 'PERI', 'MWMR', 'LOCK', 'BUFFER', 'BARRIER', 'CONST', 'MEMSPACE', 'SCHED', 'HEAP', ] VSEGMODES = [ '____', '___U', '__W_', '__WU', '_X__', '_X_U', '_XW_', '_XWU', 'C___', 'C__U', 'C_W_', 'C_WU', 'CX__', 'CX_U', 'CXW_', 'CXWU', ] PSEGTYPES = [ 'RAM', 'ROM', # deprecated => use PERI 'PERI', ] CP_PORT_DIRS = [ 'TO_COPROC', 'FROM_COPROC', ] ########################################################################################## 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 nprocs, # max number of processors per cluster x_width = X_WIDTH, # number of bits encoding x coordinate y_width = Y_WIDTH, # number of bits encoding y coordinate p_width = P_WIDTH, # number of bits encoding local proc_id paddr_width = PADDR_WIDTH, # number of bits for physical address coherence = 1, # hardware cache coherence when non-zero irq_per_proc = 1, # number or IRQs from XCU to processor use_ramdisk = False, # use ramdisk when true x_io = 0, # cluster_io x coordinate y_io = 0, # cluster_io y coordinate peri_increment = PERI_INCREMENT, # address increment for globals reset_address = RESET_ADDRESS, # Processor wired boot_address ram_base = 0, # RAM physical base in cluster[0,0] ram_size = 0 ): # RAM size in each cluster (bytes) assert ( x_size <= (1<> paddr_lsb_width x = cluster_xy >> (self.y_width); y = cluster_xy & ((1 << self.y_width) - 1) assert (base & VPN_ANTI_MASK) == 0 assert (x < self.x_size) and (y < self.y_size) assert ( (base & ((1<> (self.paddr_width - self.x_width - self.y_width) x = cluster_xy >> (self.y_width); y = cluster_xy & ((1 << self.y_width) - 1) assert (x < self.x_size) and (y < self.y_size) assert (base & VPN_ANTI_MASK) == 0 assert ptype in PERIPHTYPES assert subtype in PERIPHSUBTYPES cluster_id = (x * self.y_size) + y # add one pseg into mapping pseg = Pseg( name, base, size, x, y, 'PERI' ) self.clusters[cluster_id].psegs.append( pseg ) pseg.index = self.total_psegs self.total_psegs += 1 # add one periph into mapping periph = Periph( pseg, ptype, subtype, channels, arg ) self.clusters[cluster_id].periphs.append( periph ) periph.index = self.total_periphs self.total_periphs += 1 return periph ################################ add an IRQ in a peripheral def addIrq( self, periph, # peripheral containing IRQ (PIC or XCU) index, # peripheral input port index isrtype, # ISR type channel = 0 ): # channel for multi-channels ISR assert isrtype in ISRTYPES assert index < 32 # add one irq into mapping irq = Irq( 'HWI', index , isrtype, channel ) periph.irqs.append( irq ) irq.index = self.total_irqs self.total_irqs += 1 return irq ########################## add a processor in a cluster def addProc( self, x, # cluster x coordinate y, # cluster y coordinate p ): # processor local index assert (x < self.x_size) and (y < self.y_size) cluster_id = (x * self.y_size) + y # add one proc into mapping proc = Processor( x, y, p ) self.clusters[cluster_id].procs.append( proc ) proc.index = self.total_procs self.total_procs += 1 return proc ############################## add a coprocessor in a cluster def addCoproc( self, name, # associated pseg name base, # associated pseg base address size ): # associated pseg length # check cluster coordinates (obtained from the base address) cluster_xy = base >> (self.paddr_width - self.x_width - self.y_width) x = cluster_xy >> (self.y_width); y = cluster_xy & ((1 << self.y_width) - 1) assert (x < self.x_size) and (y < self.y_size) cluster_id = (x * self.y_size) + y # add one pseg into mapping pseg = Pseg( name, base, size, x, y, 'PERI' ) self.clusters[cluster_id].psegs.append( pseg ) pseg.index = self.total_psegs self.total_psegs += 1 # add one coproc into mapping periph = Coproc( pseg ) self.clusters[cluster_id].coprocs.append( coproc ) periph.index = self.total_coprocs self.total_coprocs += 1 return coproc ################################## add a port in a coprocessor def addPort( self, coproc, # coprocessor containing the port direction, # direction (TO_COPROC / FROM_COPROC) vspacename, # name of vspace using the coproc mwmrname ): # name of the vobj defining the MWMR channel assert direction in CP_PORT_DIRS # add one cpport into mapping port = Cpport( direction, vspacename, mwmrname ) coproc.ports.append( port ) port.index = self.total_cpports self.total_cpports += 1 return port ############################ add one global vseg into mapping def addGlobal( self, name, # vseg name vbase, # virtual base address size, # vobj length (bytes) mode, # CXWU flags vtype, # vobj type x, # destination x coordinate y, # destination y coordinate pseg, # destination pseg name identity = False, # identity mapping required if true binpath = '', # pathname for binary code if required align = 0, # alignment required local = False, # only mapped in local PTAB if true big = False ): # to be mapped in a big physical page assert mode in VSEGMODES assert vtype in VOBJTYPES assert (x < self.x_size) and (y < self.y_size) # two global vsegs must not overlap if they have different names for prev in self.globs: prev_vbase = prev.vbase prev_size = prev.vobjs[0].length if ( ((prev_vbase + prev_size) > vbase ) and ((vbase + size) > prev_vbase) and (prev.name != name) ): print '[genmap error] in addGlobal() : %s overlap %s' % (name, prev.name) print ' %s : base = %x / size = %x' %( name, vbase, size ) print ' %s : base = %x / size = %x' %( prev.name, prev_vbase, prev_size ) sys.exit(1) # add one vseg into mapping vseg = Vseg( name, vbase, mode, x, y, pseg, identity = identity, local = local, big = big ) self.globs.append( vseg ) self.total_globals += 1 vseg.index = self.total_vsegs self.total_vsegs += 1 # add one vobj into mapping vobj = Vobj( name, size, vtype, binpath, 0, 0 ) vseg.vobjs.append( vobj ) vobj.index = self.total_vobjs self.total_vobjs += 1 return ################################ add a vspace into mapping def addVspace( self, name, # vspace name startname ): # name of vobj containing start_vector # add one vspace into mapping vspace = Vspace( name, startname ) self.vspaces.append( vspace ) vspace.index = self.total_vspaces self.total_vspaces += 1 return vspace ################################# add a private vseg and a vobj in a vspace def addVseg( self, vspace, # vspace containing the vseg name, # vseg name vbase, # virtual base address size, # vobj length (bytes) mode, # CXWU flags vtype, # vobj type x, # destination x coordinate y, # destination y coordinate pseg, # destination pseg name binpath = '', # pathname for binary code align = 0, # alignment required init = 0, # initial value local = False, # only mapped in local PTAB if true big = False ): # to be mapped in a big physical page assert mode in VSEGMODES assert vtype in VOBJTYPES assert (x < self.x_size) and (y < self.y_size) # add one vseg into mapping vseg = Vseg( name, vbase, mode, x, y, pseg, local = local, big = big ) vspace.vsegs.append( vseg ) vseg.index = self.total_vsegs self.total_vsegs += 1 # add one vobj into mapping vobj = Vobj( name, size, vtype, binpath, align, init ) vseg.vobjs.append( vobj ) vobj.index = self.total_vobjs self.total_vobjs += 1 return vseg ################################ add a vobj in a private vseg def addVobj( self, vseg, # vseg containing vobj name, # vobj name size, # vobj length (bytes) vtype, # vobj type binpath = '', # pathname to binary align = 0, # alignment constraint init = 0 ): # initial value assert vtype in VOBJTYPES # add one vobj into mapping vobj = Vobj( name, size, vtype, binpath, align, init ) vseg.vobjs.append( vobj ) vobj.index = self.total_vobjs self.total_vobjs += 1 return vobj ################################ add a task in a vspace def addTask( self, vspace, # vspace containing task name, # task name trdid, # task index in vspace x, # destination x coordinate y, # destination y coordinate lpid, # destination processor local index stackname, # name of vobj containing stack heapname, # name of vobj containing heap startid ): # index in start_vector assert (x < self.x_size) and (y < self.y_size) assert lpid < self.nprocs # add one task into mapping task = Task( name, trdid, x, y, lpid, stackname, heapname, startid ) vspace.tasks.append( task ) task.index = self.total_tasks self.total_tasks += 1 return task ################################# def str2bytes( self, nbytes, s ): # string => nbytes_packed byte array byte_stream = bytearray() length = len( s ) if length < (nbytes - 1): for b in s: byte_stream.append( b ) for x in xrange(nbytes-length): byte_stream.append( '\0' ) else: print '[genmap error] in str2bytes() : string %s too long' % s sys.exit(1) return byte_stream ################################### def int2bytes( self, nbytes, val ): # integer => nbytes litle endian byte array byte_stream = bytearray() for n in xrange( nbytes ): byte_stream.append( (val >> (n<<3)) & 0xFF ) return byte_stream #################################################################################### def xml( self ): # compute string for map.xml file generation s = '\n\n' s += '> 32 lsb = pseg.base & 0xFFFFFFFF size = pseg.size s += ' ram_%d_%d: ram@0x%x {\n' % (x, y, pseg.base) s += ' device_type = "memory";\n' s += ' reg = <0x%x 0x%x 0x%x>;\n' % (msb, lsb, size) s += ' };\n\n' # scan all periphs to find XCU or PIC in current cluster for periph in cluster.periphs: msb = periph.pseg.base >> 32 lsb = periph.pseg.base & 0xFFFFFFFF size = periph.pseg.size # search XCU (can be replicated) if ( (periph.ptype == 'XCU') ): found_xcu = True xcu = periph irq_ctrl_name = 'xcu_%d_%d' % (x, y) s += ' %s: xcu@0x%x {\n' % (irq_ctrl_name, periph.pseg.base) s += ' compatible = "soclib,vci_xicu","soclib,vci_xicu_timer";\n' s += ' interrupt-controller;\n' s += ' #interrupt-cells = <1>;\n' s += ' clocks = <&freq>;\n' # the XCU component contains a timer s += ' reg = <0x%x 0x%x 0x%x>;\n' % (msb, lsb, size) s += ' };\n\n' # search PIC (non replicated) if ( periph.ptype == 'PIC' ): found_pic = True pic = periph irq_ctrl_name = 'pic' s += ' %s: pic@0x%x {\n' % (irq_ctrl_name, periph.pseg.base) s += ' compatible = "soclib,vci_iopic";\n' s += ' interrupt-controller;\n' s += ' #interrupt-cells = <1>;\n' s += ' reg = <0x%x 0x%x 0x%x>;\n' % (msb, lsb, size) s += ' };\n\n' # we need one interrupt controler in any cluster containing peripherals if ( (found_xcu == False) and (found_pic == False) and (len(cluster.periphs) > 0) ): print '[genmap error] in linux_dts() : No XCU/PIC in cluster(%d,%d)' % (x,y) sys.exit(1) if ( found_pic == True ): irq_ctrl = pic else: irq_ctrl = xcu # scan all periphs to find TTY and IOC in current cluster for periph in cluster.periphs: msb = periph.pseg.base >> 32 lsb = periph.pseg.base & 0xFFFFFFFF size = periph.pseg.size # search TTY (non replicated) if ( periph.ptype == 'TTY' ): # get HWI index to XCU or PIC (only TTY channel 0 is used by Linux) hwi_id = 0xFFFFFFFF for irq in irq_ctrl.irqs: if ( (irq.isrtype == 'ISR_TTY_RX') and (irq.channel == 0) ): hwi_id = irq.srcid if ( hwi_id == 0xFFFFFFFF ): print '[genmap error] in linux.dts() IRQ_TTY_RX not found' sys.exit(1) s += ' tty: tty {\n' s += ' compatible = "soclib,vci_multi_tty";\n' s += ' interrupt-parent = <&%s>;\n' % (irq_ctrl_name) s += ' interrupts = <%d>;\n' % hwi_id s += ' reg = <0x%x 0x%x 0x%x>;\n' % (msb, lsb, size) s += ' };\n\n' # search IOC (non replicated) elif ( periph.ptype == 'IOC' ): if ( periph.subtype == 'BDV' ): # get irq line index associated to bdv hwi_id = 0xFFFFFFFF for irq in irq_ctrl.irqs: if ( irq.isrtype == 'ISR_BDV' ): hwi_id = irq.srcid if ( hwi_id == 0xFFFFFFFF ): print '[genmap error] in linux.dts() ISR_BDV not found' sys.exit(1) s += ' bdv: bdv {\n' s += ' compatible = "soclib,vci_blockdevice";\n' s += ' interrupt-parent = <&%s>;\n' % (irq_ctrl_name) s += ' interrupts = <%d>;\n' % hwi_id s += ' reg = <0x%x 0x%x 0x%x>;\n' % (msb, lsb, size) s += ' };\n\n' elif ( periph.subtype == 'HBA' ): print '[genmap error] in linux_dts() : HBA peripheral not supported by LINUX' sys.exit(1) elif ( periph.subtype == 'SPI' ): print '[genmap error] in linux_dts() : SPI peripheral not supported by LINUX' sys.exit(1) # XCU or PIC have been already parsed elif ( periph.ptype == 'XCU' ) or ( periph.ptype == 'PIC' ): pass # other peripherals else: type = periph.ptype print '[genmap warning] in linux_dts() : %s peripheral not supported by LINUX' % (type) # clocks s += ' /*** clocks ***/\n\n' s += ' clocks {\n' s += ' freq: freq@50MHZ {\n' s += ' #clock-cells = <0>;\n' s += ' compatible = "fixed-clock";\n' s += ' clock-frequency = <50000000>;\n' s += ' };\n' s += ' };\n\n' s += ' cpuclk {\n' s += ' compatible = "soclib,mips32_clksrc";\n' s += ' clocks = <&freq>;\n' s += ' };\n' s += '};\n' return s # end linux_dts() ############################################################################# def netbsd_dts( self ): # compute string for netbsd.dts file generation, # used for netbsd configuration # header s = '/dts-v1/;\n' s += '\n' s += '/{\n' s += ' #address-cells = <2>;\n' s += ' #size-cells = <1>;\n' # cpus (for each cluster) s += ' cpus {\n' s += ' #address-cells = <1>;\n' s += ' #size-cells = <0>;\n' for cluster in self.clusters: for proc in cluster.procs: proc_id = (((cluster.x << self.y_width) + cluster.y) << self.p_width) + proc.lpid s += ' Mips,32@0x%x {\n' % proc_id s += ' device_type = "cpu";\n' s += ' icudev_type = "cpu:mips";\n' s += ' name = "Mips,32";\n' s += ' reg = <0x%x>;\n' % proc_id s += ' };\n' s += '\n' s += ' };\n' # physical memory banks (for each cluster) for cluster in self.clusters: for pseg in cluster.psegs: if ( pseg.segtype == 'RAM' ): msb = pseg.base >> 32 lsb = pseg.base & 0xFFFFFFFF size = pseg.size s += ' %s@0x%x {\n' % (pseg.name, pseg.base) s += ' cached = <1>;\n' s += ' device_type = "memory";\n' s += ' reg = <0x%x 0x%x 0x%x>;\n' % (msb, lsb, size) s += ' };\n' # peripherals (for each cluster) for cluster in self.clusters: x = cluster.x y = cluster.y # research XCU component found_xcu = False for periph in cluster.periphs: if ( (periph.ptype == 'XCU') ): found_xcu = True xcu = periph msb = periph.pseg.base >> 32 lsb = periph.pseg.base & 0xFFFFFFFF size = periph.pseg.size s += ' %s@0x%x {\n' % (periph.pseg.name, periph.pseg.base) s += ' device_type = "soclib:xicu:root";\n' s += ' reg = <0x%x 0x%x 0x%x>;\n' % (msb, lsb, size) s += ' input_lines = <%d>;\n' % periph.arg s += ' ipis = <%d>;\n' % periph.arg s += ' timers = <%d>;\n' % periph.arg output_id = 0 # output index from XCU for lpid in xrange ( len(cluster.procs) ): # destination processor index for itid in xrange ( self.irq_per_proc ): # input irq index on processor cluster_xy = (cluster.x << self.y_width) + cluster.y proc_id = (cluster_xy << self.p_width) + lpid s += ' out@%d {\n' % output_id s += ' device_type = "soclib:xicu:filter";\n' s += ' irq = <&{/cpus/Mips,32@0x%x} %d>;\n' % (proc_id, itid) s += ' output_line = <%d>;\n' % output_id s += ' parent = <&{/%s@0x%x}>;\n' % (periph.pseg.name, periph.pseg.base) s += ' };\n' output_id += 1 s += ' };\n' # research PIC component found_pic = False for periph in cluster.periphs: if ( periph.ptype == 'PIC' ): found_pic = True pic = periph msb = periph.pseg.base >> 32 lsb = periph.pseg.base & 0xFFFFFFFF size = periph.pseg.size s += ' %s@0x%x {\n' % (periph.pseg.name, periph.pseg.base) s += ' device_type = "soclib:pic:root";\n' s += ' reg = <0x%x 0x%x 0x%x>;\n' % (msb, lsb, size) s += ' input_lines = <%d>;\n' % periph.channels s += ' };\n' # at least one interrupt controller if ( (found_xcu == False) and (found_pic == False) and (len(cluster.periphs) > 0) ): print '[genmap error] in netbsd_dts() : No XCU/PIC in cluster(%d,%d)' % (x,y) sys.exit(1) if ( found_pic == True ): irq_tgt = pic else: irq_tgt = xcu # get all others peripherals in cluster for periph in cluster.periphs: msb = periph.pseg.base >> 32 lsb = periph.pseg.base & 0xFFFFFFFF size = periph.pseg.size # research DMA component if ( periph.ptype == 'DMA' ): s += ' %s@0x%x {\n' % (periph.pseg.name, periph.pseg.base) s += ' device_type = "soclib:dma";\n' s += ' reg = <0x%x 0x%x 0x%x>;\n' % (msb, lsb, size) s += ' channel_count = <%d>;\n' % periph.channels # multi-channels : get HWI index (to XCU) for each channel for channel in xrange( periph.channels ): hwi_id = 0xFFFFFFFF for irq in xcu.irqs: if ( (irq.isrtype == 'ISR_DMA') and (irq.channel == channel) ): hwi_id = irq.srcid if ( hwi_id == 0xFFFFFFFF ): print '[genmap error] in netbsd.dts() ISR_DMA channel %d not found' % channel sys.exit(1) name = '%s@0x%x' % (xcu.pseg.name, xcu.pseg.base) s += ' irq@%d{\n' % channel s += ' device_type = "soclib:periph:irq";\n' s += ' output_line = <%d>;\n' % channel s += ' irq = <&{/%s} %d>;\n' % (name, hwi_id) s += ' parent = <&{/%s@0x%x}>;\n' % (periph.pseg.name, periph.pseg.base) s += ' };\n' s += ' };\n' # research MMC component elif ( periph.ptype == 'MMC' ): # get irq line index associated to MMC in XCU irq_in = 0xFFFFFFFF for irq in xcu.irqs: if ( irq.isrtype == 'ISR_MMC' ): irq_in = irq.srcid if ( irq_in == 0xFFFFFFFF ): print '[genmap error] in netbsd.dts() ISR_MMC not found' sys.exit(1) s += ' %s@0x%x {\n' % (periph.pseg.name, periph.pseg.base) s += ' device_type = "soclib:mmc";\n' s += ' irq = <&{/%s@0x%x} %d>;\n' % (irq_tgt.pseg.name, irq_tgt.pseg.base, irq_in) s += ' reg = <0x%x 0x%x 0x%x>;\n' % (msb, lsb, size) s += ' };\n' # research FBF component elif ( periph.ptype == 'FBF' ): s += ' %s@0x%x {\n' % (periph.pseg.name, periph.pseg.base) s += ' device_type = "soclib:framebuffer";\n' s += ' mode = <32>;\n' # bits par pixel s += ' width = <%d>;\n' % periph.arg s += ' height = <%d>;\n' % periph.arg s += ' reg = <0x%x 0x%x 0x%x>;\n' % (msb, lsb, size) s += ' };\n' # research IOC component elif ( periph.ptype == 'IOC' ): if ( periph.subtype == 'BDV' ): # get irq line index associated to bdv irq_in = 0xFFFFFFFF for irq in irq_tgt.irqs: if ( irq.isrtype == 'ISR_BDV' ): irq_in = irq.srcid if ( irq_in == 0xFFFFFFFF ): print '[genmap error] in netbsd.dts() ISR_BDV not found' sys.exit(1) s += ' %s@0x%x {\n' % (periph.pseg.name, periph.pseg.base) s += ' device_type = "soclib:blockdevice";\n' s += ' irq = <&{/%s@0x%x} %d>;\n' % (irq_tgt.pseg.name,irq_tgt.pseg.base,irq_in) s += ' reg = <0x%x 0x%x 0x%x>;\n' % (msb, lsb, size) s += ' };\n' elif ( periph.subtype == 'HBA' ): print '[genmap error] in netbsd_dts() : HBA peripheral not supported by NetBSD' sys.exit(1) elif ( periph.subtype == 'SPI' ): # get irq line index associated to spi irq_in = 0xFFFFFFFF for irq in irq_tgt.irqs: if ( irq.isrtype == 'ISR_SPI' ): irq_in = irq.srcid if ( irq_in == 0xFFFFFFFF ): print '[genmap error] in netbsd.dts() ISR_SPI not found' sys.exit(1) s += ' %s@0x%x {\n' % (periph.pseg.name, periph.pseg.base) s += ' device_type = "soclib:spi";\n' s += ' irq = <&{/%s@0x%x} %d>;\n' % (irq_tgt.pseg.name,irq_tgt.pseg.base,irq_in) s += ' reg = <0x%x 0x%x 0x%x>;\n' % (msb, lsb, size) s += ' };\n' # research ROM component elif ( periph.ptype == 'ROM' ): s += ' %s@0x%x {\n' % (periph.pseg.name, periph.pseg.base) s += ' device_type = "rom";\n' s += ' cached = <1>;\n' s += ' reg = <0x%x 0x%x 0x%x>;\n' % (msb, lsb, size) s += ' };\n' # research SIM component elif ( periph.ptype == 'SIM' ): s += ' %s@0x%x {\n' % (periph.pseg.name, periph.pseg.base) s += ' device_type = "soclib:simhelper";\n' s += ' reg = <0x%x 0x%x 0x%x>;\n' % (msb, lsb, size) s += ' };\n' # research TTY component elif ( periph.ptype == 'TTY' ): s += ' %s@0x%x {\n' % (periph.pseg.name, periph.pseg.base) s += ' device_type = "soclib:tty";\n' s += ' channel_count = < %d >;\n' % periph.channels s += ' reg = <0x%x 0x%x 0x%x>;\n' % (msb, lsb, size) # multi-channels : get HWI index (to XCU or PIC) for each channel for channel in xrange( periph.channels ): hwi_id = 0xFFFFFFFF for irq in irq_tgt.irqs: if ( (irq.isrtype == 'ISR_TTY_RX') and (irq.channel == channel) ): hwi_id = irq.srcid if ( hwi_id == 0xFFFFFFFF ): print '[genmap error] in netbsd.dts() ISR_TTY_RX channel %d not found' % channel sys.exit(1) name = '%s@0x%x' % (irq_tgt.pseg.name, irq_tgt.pseg.base) s += ' irq@%d{\n' % channel s += ' device_type = "soclib:periph:irq";\n' s += ' output_line = <%d>;\n' % channel s += ' irq = <&{/%s} %d>;\n' % (name, hwi_id) s += ' parent = <&{/%s@0x%x}>;\n' % (periph.pseg.name, periph.pseg.base) s += ' };\n' s += ' };\n' # research IOB component elif ( periph.ptype == 'IOB' ): s += ' %s@0x%x {\n' % (periph.pseg.name, periph.pseg.base) s += ' device_type = "soclib:iob";\n' s += ' reg = <0x%x 0x%x 0x%x>;\n' % (msb, lsb, size) s += ' };\n' # research NIC component elif ( periph.ptype == 'NIC' ): s += ' %s@0x%x {\n' % (periph.pseg.name, periph.pseg.base) s += ' device_type = "soclib:nic";\n' s += ' reg = <0x%x 0x%x 0x%x>;\n' % (msb, lsb, size) s += ' channel_count = < %d >;\n' % periph.channels # multi-channels : get HWI index (to XCU or PIC) for RX & TX IRQs # RX IRQ : (2*channel) / TX IRQs : (2*channel + 1) for channel in xrange( periph.channels ): hwi_id = 0xFFFFFFFF for irq in irq_tgt.irqs: if ( (irq.isrtype == 'ISR_NIC_RX') and (irq.channel == channel) ): hwi_id = irq.srcid if ( hwi_id == 0xFFFFFFFF ): print '[genmap error] in netbsd.dts() ISR_NIC_RX channel %d not found' % channel sys.exit(1) name = '%s@0x%x' % (irq_tgt.pseg.name, irq_tgt.pseg.base) s += ' irq_rx@%d{\n' % channel s += ' device_type = "soclib:periph:irq";\n' s += ' output_line = <%d>;\n' % (2*channel) s += ' irq = <&{/%s} %d>;\n' % (name, hwi_id) s += ' parent = <&{/%s@0x%x}>;\n' % (periph.pseg.name, periph.pseg.base) s += ' };\n' hwi_id = 0xFFFFFFFF for irq in irq_tgt.irqs: if ( (irq.isrtype == 'ISR_NIC_TX') and (irq.channel == channel) ): hwi_id = irq.srcid if ( hwi_id == 0xFFFFFFFF ): print '[genmap error] in netbsd.dts() ISR_NIC_TX channel %d not found' % channel sys.exit(1) name = '%s@0x%x' % (irq_tgt.pseg.name, irq_tgt.pseg.base) s += ' irq_tx@%d{\n' % channel s += ' device_type = "soclib:periph:irq";\n' s += ' output_line = <%d>;\n' % (2*channel + 1) s += ' irq = <&{/%s} %d>;\n' % (name, hwi_id) s += ' parent = <&{/%s@0x%x}>;\n' % (periph.pseg.name, periph.pseg.base) s += ' };\n' s += ' };\n' # research CMA component elif ( periph.ptype == 'CMA' ): s += ' %s@0x%x {\n' % (periph.pseg.name, periph.pseg.base) s += ' device_type = "soclib:cma";\n' s += ' reg = <0x%x 0x%x 0x%x>;\n' % (msb, lsb, size) s += ' channel_count = < %d >;\n' % periph.channels # multi-channels : get HWI index (to XCU or PIC) for each channel for channel in xrange( periph.channels ): hwi_id = 0xFFFFFFFF for irq in irq_tgt.irqs: if ( (irq.isrtype == 'ISR_CMA') and (irq.channel == channel) ): hwi_id = irq.srcid if ( hwi_id == 0xFFFFFFFF ): print '[genmap error] in netbsd.dts() ISR_CMA channel %d not found' % channel sys.exit(1) name = '%s@0x%x' % (irq_tgt.pseg.name, irq_tgt.pseg.base) s += ' irq@%d{\n' % channel s += ' device_type = "soclib:periph:irq";\n' s += ' output_line = <%d>;\n' % channel s += ' irq = <&{/%s} %d>;\n' % (name, hwi_id) s += ' parent = <&{/%s@0x%x}>;\n' % (periph.pseg.name, periph.pseg.base) s += ' };\n' s += ' };\n' # research TIM component elif ( periph.ptype == 'TIM' ): print '[genmap error] in netbsd_dts() : TIM peripheral not supported by NetBSD' sys.exit(1) # research MWR component elif ( periph.ptype == 'MWR' ): print '[genmap error] in netbsd_dts() : MWR peripheral not supported by NetBSD' sys.exit(1) # topology s += '\n' s += ' topology {\n' s += ' #address-cells = <2>;\n' s += ' #size-cells = <0>;\n' for cluster in self.clusters: s += ' cluster@%d,%d {\n' % (cluster.x, cluster.y) s += ' reg = <%d %d>;\n' % (cluster.x, cluster.y) s += ' devices = <\n' offset = ((cluster.x << self.y_width) + cluster.y) << self.p_width for proc in cluster.procs: s += ' &{/cpus/Mips,32@0x%x}\n' % (offset + proc.lpid) for periph in cluster.periphs: s += ' &{/%s@0x%x}\n' % (periph.pseg.name, periph.pseg.base) for pseg in cluster.psegs: if ( pseg.segtype == 'RAM' ): s += ' &{/%s@0x%x}\n' % (pseg.name, pseg.base) s += ' >;\n' s += ' };\n' s += ' };\n' s += '};\n' return s # end netbsd_dts() ########################### def almos_archinfo( self ): # compute string for arch.info file generation, # used for almos configuration # header s = '# arch.info file generated by genmap for %s\n' % self.name s += '\n' s += '[HEADER]\n' s += ' REVISION=1\n' s += ' ARCH=%s\n' % self.name s += ' XMAX=%d\n' % self.x_size s += ' YMAX=%d\n' % self.y_size s += ' CPU_NR=%d\n' % self.nprocs s += '\n' # clusters cluster_id = 0 for cluster in self.clusters: ram = None nb_cpus = len( cluster.procs ) nb_devs = len( cluster.periphs ) if ( len( cluster.coprocs ) != 0 ): print 'Error in almos_archinfo() coprocessors not supported yet' sys.exit(1) # search a RAM for pseg in cluster.psegs: if ( pseg.segtype == 'RAM' ): ram = pseg nb_devs += 1 # search XCU to get IRQs indexes if cluster contains peripherals if ( len( cluster.periphs ) != 0 ): tty_irq_id = None bdv_irq_id = None dma_irq_id = None for periph in cluster.periphs: if ( periph.ptype == 'XCU' ): # scan irqs for irq in periph.irqs: if ( irq.isrtype == 'ISR_TTY_RX' ) : tty_irq_id = irq.srcid if ( irq.isrtype == 'ISR_BDV' ) : bdv_irq_id = irq.srcid if ( irq.isrtype == 'ISR_DMA' ) : dma_irq_id = irq.srcid # Build the cluster description s += '[CLUSTER]\n' s += ' CID=%d\n' % cluster_id s += ' ARCH_CID=0x%x\n' % ((cluster.x << self.y_width) + cluster.y) s += ' CPU_NR=%d\n' % nb_cpus s += ' DEV_NR=%d\n' % nb_devs # Handling RAM when cluster contain a RAM if (ram != None ): base = ram.base size = ram.size irqid = -1 s += ' DEVID=RAM' s += ' BASE=0x%x SIZE=0x%x IRQ=-1\n' % ( base, size ) # Handling peripherals for periph in cluster.periphs: base = periph.pseg.base size = periph.pseg.size if ( periph.ptype == 'XCU' ): s += ' DEVID=XICU' s += ' BASE=0x%x SIZE=0x%x IRQ=-1\n' % ( base, size ) elif ( (periph.ptype == 'TTY') and (tty_irq_id != None) ): s += ' DEVID=TTY' s += ' BASE=0x%x SIZE=0x%x IRQ=%d\n' % ( base, size, tty_irq_id ) elif ( (periph.ptype == 'DMA') and (dma_irq_id != None) ): s += ' DEVID=DMA' s += ' BASE=0x%x SIZE=0x%x IRQ=%d\n' % ( base, size, dma_irq_id ) elif ( periph.ptype == 'FBF' ): s += ' DEVID=FB' s += ' BASE=0x%x SIZE=0x%x IRQ=-1\n' % ( base, size ) elif ( (periph.ptype == 'IOC') and (periph.subtype == 'BDV') and (bdv_irq_id != None) ): s += ' DEVID=BLKDEV' s += ' BASE=0x%x SIZE=0x%x IRQ=%d\n' % ( base, size, bdv_irq_id ) elif ( periph.ptype == 'PIC' ): s += ' DEVID=IOPIC' s += ' BASE=0x%x SIZE=0x%x IRQ=-1\n' % ( base, size ) else: print '# Warning from almos_archinfo() in cluster[%d,%d]' \ % (cluster.x, cluster.y) print '# peripheral type %s/%s not supported yet\n' \ % ( periph.ptype, periph.subtype ) cluster_id += 1 return s # end of almos_archinfo() ########################################################################################### class Cluster ( object ): ########################################################################################### def __init__( self, x, y ): self.index = 0 # global index (set by Mapping constructor) self.x = x # x coordinate self.y = y # y coordinate self.psegs = [] # filled by addRam() or addPeriph() self.procs = [] # filled by addProc() self.coprocs = [] # filled by addCoproc() self.periphs = [] # filled by addPeriph() return ################ def xml( self ): # xml for a cluster s = ' \n' % (self.x, self.y) for pseg in self.psegs: s += pseg.xml() for proc in self.procs: s += proc.xml() for copr in self.coprocs: s += copr.xml() for peri in self.periphs: s += peri.xml() s += ' \n' return s ############################################# def cbin( self, mapping, verbose, expected ): # C binary structure for Cluster if ( verbose ): print '*** cbin for cluster [%d,%d]' % (self.x, self.y) # check index if (self.index != expected): print '[genmap error] in Cluster.cbin() : cluster global index = %d / expected = %d' \ % (self.index, expected ) sys.exit(1) # compute global index for first pseg if ( len(self.psegs) > 0 ): pseg_id = self.psegs[0].index else: pseg_id = 0 # compute global index for first proc if ( len(self.procs) > 0 ): proc_id = self.procs[0].index else: proc_id = 0 # compute global index for first coproc if ( len(self.coprocs) > 0 ): coproc_id = self.coprocs[0].index else: coproc_id = 0 # compute global index for first periph if ( len(self.periphs) > 0 ): periph_id = self.periphs[0].index else: periph_id = 0 byte_stream = bytearray() byte_stream += mapping.int2bytes( 4 , self.x ) # x coordinate byte_stream += mapping.int2bytes( 4 , self.y ) # x coordinate byte_stream += mapping.int2bytes( 4 , len( self.psegs ) ) # number of psegs in cluster byte_stream += mapping.int2bytes( 4 , pseg_id ) # first pseg global index byte_stream += mapping.int2bytes( 4 , len( self.procs ) ) # number of procs in cluster byte_stream += mapping.int2bytes( 4 , proc_id ) # first proc global index byte_stream += mapping.int2bytes( 4 , len( self.coprocs ) ) # number of coprocs in cluster byte_stream += mapping.int2bytes( 4 , coproc_id ) # first coproc global index byte_stream += mapping.int2bytes( 4 , len( self.periphs ) ) # number of periphs in cluster byte_stream += mapping.int2bytes( 4 , periph_id ) # first periph global index if ( verbose ): print 'nb_psegs = %d' % len( self.psegs ) print 'pseg_id = %d' % pseg_id print 'nb_procs = %d' % len( self.procs ) print 'proc_id = %d' % proc_id print 'nb_coprocs = %d' % len( self.coprocs ) print 'coproc_id = %d' % coproc_id print 'nb_periphs = %d' % len( self.periphs ) print 'periph_id = %d' % periph_id return byte_stream ########################################################################################### class Vspace( object ): ########################################################################################### def __init__( self, name, startname ): self.index = 0 # global index ( set by addVspace() ) self.name = name # vspace name self.startname = startname # name of vobj containing the start_vector self.vsegs = [] self.tasks = [] return ################ def xml( self ): # xml for one vspace s = ' \n' % ( self.name, self.startname ) for vseg in self.vsegs: s += vseg.xml() for task in self.tasks: s += task.xml() s += ' \n' return s ############################################# def cbin( self, mapping, verbose, expected ): # C binary structure for Vspace if ( verbose ): print '*** cbin for vspace %s' % (self.name) # check index if (self.index != expected): print '[genmap error] in Vspace.cbin() : vspace global index = %d / expected = %d' \ % (self.index, expected ) sys.exit(1) # compute global index for vobj containing start_vector vobj_start_id = 0xFFFFFFFF for vseg in self.vsegs: if ( vseg.vobjs[0].name == self.startname ): vobj_start_id = vseg.vobjs[0].index if ( vobj_start_id == 0xFFFFFFFF ): print '[genmap error] in Vspace.cbin() : startname %s not found for vspace %s' \ % ( self.startname, self.name ) sys.exit(1) # compute first vseg, vobj, task global index first_vseg_id = self.vsegs[0].index first_vobj_id = self.vsegs[0].vobjs[0].index first_task_id = self.tasks[0].index # compute number of vobjs, tasks, vsegs nb_vsegs = len( self.vsegs ) nb_tasks = len( self.tasks ) nb_vobjs = 0 for vseg in self.vsegs: nb_vobjs += len( vseg.vobjs ) byte_stream = bytearray() byte_stream += mapping.str2bytes( 32, self.name ) # vspace name byte_stream += mapping.int2bytes( 4, vobj_start_id ) # vobj start_vector byte_stream += mapping.int2bytes( 4, nb_vsegs ) # number of vsegs byte_stream += mapping.int2bytes( 4, nb_vobjs ) # number of vobjs byte_stream += mapping.int2bytes( 4, nb_tasks ) # number of tasks byte_stream += mapping.int2bytes( 4, first_vseg_id ) # first vseg global index byte_stream += mapping.int2bytes( 4, first_vobj_id ) # first vobj global index byte_stream += mapping.int2bytes( 4, first_task_id ) # first task global index if ( verbose ): print 'start_id = %d' % vobj_start_id print 'nb_vsegs = %d' % nb_vsegs print 'nb_vobjs = %d' % nb_vobjs print 'nb_tasks = %d' % nb_tasks print 'vseg_id = %d' % first_vseg_id print 'vobj_id = %d' % first_vobj_id print 'task_id = %d' % first_task_id return byte_stream ########################################################################################### class Task( object ): ########################################################################################### def __init__( self, name, trdid, x, y, p, stackname, heapname, startid ): self.index = 0 # global index value set by addTask() self.name = name # tsk name self.trdid = trdid # task index (unique in vspace) self.x = x # cluster x coordinate self.y = y # cluster y coordinate self.p = p # processor local index self.stackname = stackname # name of vobj containing the stack self.heapname = heapname # name of vobj containing the heap self.startid = startid # index in start_vector return ################ def xml( self ): # xml for one task s = ' \n' % (self.lpid) ############################################# def cbin( self, mapping, verbose, expected ): # C binary structure for Proc if ( verbose ): print '*** cbin for proc %d in cluster (%d,%d)' % (self.lpid, self.x, self.y) # check index if (self.index != expected): print '[genmap error] in Proc.cbin() : proc global index = %d / expected = %d' \ % (self.index, expected ) sys.exit(1) byte_stream = bytearray() byte_stream += mapping.int2bytes( 4 , self.lpid ) # local index return byte_stream ########################################################################################### class Pseg ( object ): ########################################################################################### def __init__( self, name, base, size, x, y, segtype ): assert( segtype in PSEGTYPES ) self.index = 0 # global index ( set by addPseg() ) self.name = name # pseg name (unique in cluster) self.base = base # physical base address self.size = size # segment size (bytes) self.x = x # cluster x coordinate self.y = y # cluster y coordinate self.segtype = segtype # RAM / PERI (defined in mapping_info.h) return ################ def xml( self ): # xml for a pseg return ' \n' \ % (self.name, self.segtype, self.base, self.size) ###################################################### def cbin( self, mapping, verbose, expected, cluster ): # C binary structure for Pseg if ( verbose ): print '*** cbin for pseg[%d] %s in cluster[%d,%d]' \ % (self.index, self.name, cluster.x, cluster.y) # check index if (self.index != expected): print '[genmap error] in Pseg.cbin() : pseg global index = %d / expected = %d' \ % (self.index, expected ) sys.exit(1) # compute numerical value for segtype segtype_int = 0xFFFFFFFF for x in xrange( len(PSEGTYPES) ): if ( self.segtype == PSEGTYPES[x] ): segtype_int = x if ( segtype_int == 0xFFFFFFFF ): print '[genmap error] in Pseg.cbin() : undefined segment type %s' % self.segtype sys.exit(1) byte_stream = bytearray() byte_stream += mapping.str2bytes( 32, self.name ) # pseg name byte_stream += mapping.int2bytes( 8 , self.base ) # physical base address byte_stream += mapping.int2bytes( 8 , self.size ) # segment length byte_stream += mapping.int2bytes( 4 , segtype_int ) # segment type byte_stream += mapping.int2bytes( 4 , cluster.index ) # cluster global index byte_stream += mapping.int2bytes( 4 , 0 ) # linked list of vsegs if ( verbose ): print 'pbase = %x' % self.base print 'size = %x' % self.size print 'type = %s' % self.segtype return byte_stream ########################################################################################### class Periph ( object ): ########################################################################################### def __init__( self, pseg, # associated pseg ptype, # peripheral type subtype = 'NONE', # peripheral subtype channels = 1, # for multi-channels peripherals arg = 0 ): # optional argument (semantic depends on ptype) assert ptype in PERIPHTYPES assert subtype in PERIPHSUBTYPES self.index = 0 # global index ( set by addPeriph() ) self.channels = channels self.ptype = ptype self.subtype = subtype self.arg = arg self.pseg = pseg self.irqs = [] return ################ def xml( self ): # xml for a periph s = ' 0 ): irq_id = self.irqs[0].index else: irq_id = 0 # compute numerical value for ptype ptype_id = 0xFFFFFFFF for x in xrange( len(PERIPHTYPES) ): if ( self.ptype == PERIPHTYPES[x] ): ptype_id = x if ( ptype_id == 0xFFFFFFFF ): print '[genmap error] in Periph.cbin() : undefined peripheral type %s' % self.ptype sys.exit(1) # compute numerical value for subtype subtype_id = 0xFFFFFFFF for x in xrange( len(PERIPHSUBTYPES) ): if ( self.subtype == PERIPHSUBTYPES[x] ): subtype_id = x # compute byte_stream = bytearray() byte_stream += mapping.int2bytes( 4 , ptype_id ) # peripheral type byte_stream += mapping.int2bytes( 4 , subtype_id ) # peripheral subtype byte_stream += mapping.int2bytes( 4 , pseg_id ) # pseg global index byte_stream += mapping.int2bytes( 4 , self.channels ) # number of channels byte_stream += mapping.int2bytes( 4 , self.arg ) # optionnal argument byte_stream += mapping.int2bytes( 4 , len( self.irqs ) ) # number of input irqs byte_stream += mapping.int2bytes( 4 , irq_id ) # first irq global index if ( verbose ): print 'ptype = %d' % ptype_id print 'pseg_id = %d' % pseg_id print 'nb_irqs = %d' % len( self.irqs ) print 'irq_id = %d' % irq_id return byte_stream ########################################################################################### class Irq ( object ): ########################################################################################### def __init__( self, irqtype, # input IRQ type : HWI / WTI / PTI (for XCU only) srcid, # input IRQ index (for XCU or PIC) isrtype, # Type of ISR to be executed channel = 0 ): # channel index for multi-channel ISR assert irqtype in IRQTYPES assert isrtype in ISRTYPES assert srcid < 32 self.index = 0 # global index ( set by addIrq() ) self.irqtype = irqtype # IRQ type self.srcid = srcid # source IRQ index self.isrtype = isrtype # ISR type self.channel = channel # channel index (for multi-channels ISR) return ################ def xml( self ): # xml for Irq return ' \n' \ % ( self.irqtype, self.srcid, self.isrtype, self.channel ) ############################################# def cbin( self, mapping, verbose, expected ): # C binary structure for Irq if ( verbose ): print '*** cbin for irq[%d]' % (self.index) # check index if (self.index != expected): print '[genmap error] in Irq.cbin() : irq global index = %d / expected = %d' \ % (self.index, expected ) sys.exit(1) # compute numerical value for irqtype irqtype_id = 0xFFFFFFFF for x in xrange( len(IRQTYPES) ): if ( self.irqtype == IRQTYPES[x] ): irqtype_id = x if ( irqtype_id == 0xFFFFFFFF ): print '[genmap error] in Irq.cbin() : undefined irqtype %s' % self.irqtype sys.exit(1) # compute numerical value for isrtype isrtype_id = 0xFFFFFFFF for x in xrange( len(ISRTYPES) ): if ( self.isrtype == ISRTYPES[x] ): isrtype_id = x if ( isrtype_id == 0xFFFFFFFF ): print '[genmap error] in Irq.cbin() : undefined isrtype %s' % self.isrtype sys.exit(1) byte_stream = bytearray() byte_stream += mapping.int2bytes( 4, irqtype_id ) byte_stream += mapping.int2bytes( 4, self.srcid ) byte_stream += mapping.int2bytes( 4, isrtype_id ) byte_stream += mapping.int2bytes( 4, self.channel ) byte_stream += mapping.int2bytes( 4, 0 ) byte_stream += mapping.int2bytes( 4, 0 ) if ( verbose ): print 'irqtype = %s' % self.irqtype print 'srcid = %d' % self.srcid print 'isrtype = %s' % self.isrtype print 'channel = %d' % self.channel return byte_stream ########################################################################################### class Coproc ( object ): ########################################################################################### def __init__( self, pseg ): # associated pseg self.index = 0 # global index value set by addCoproc() self.pseg = pseg self.ports = [] return ################ def xml( self ): # xml for Coproc print '[genmap error] in Coproc.xml() : not defined yet' sys.exit(1) return ############################################# def cbin( self, mapping, verbose, expected ): # C binary structure for Coproc if ( verbose ): print '*** cbin for coproc in cluster (%d,%d)' % (self.pseg.x, self.pseg.y) # check index if (self.index != expected): print '[genmap error] in Coproc.cbin() : coproc global index = %d / expected = %d' \ % (self.index, expected ) sys.exit(1) # compute pseg global index pseg_id = self.pseg.index # compute first port global index port_id = self.ports[0].index byte_stream = bytearray() byte_stream += mapping.str2bytes( 32, self.pseg.name ) # probablement inutile (AG) byte_stream += mapping.int2bytes( 4 , pseg_id ) # pseg global index byte_stream += mapping.int2bytes( 4 , len( self.ports ) ) # number of input irqs byte_stream += mapping.int2bytes( 4 , port_id ) # first port global index if ( verbose ): print 'irqtype = %s' % self.irqtype print 'pseg_id = %d' % pseg_id print 'nb_ports = %d' % len( self.ports ) print 'port_id %d' % port_id return byte_stream ########################################################################################### class Cpport ( object ): ########################################################################################### def __init__( self, direction, vspacename, mwmrname ): self.index = 0 # global index ( set by addCpport() ) self.direction = direction # TO_COPROC / FROM_COPROC self.vspacename = vspacename # name of vspace containing mwmr channel self.mwmrname = mwmrname # name of vobj defining mwmr channel return ################ def xml( self ): # xml for Cpport print '[genmap error] in Cpport.xml() : not defined yet' sys.exit(1) return ############################################# def cbin( self, mapping, verbose, expected ): # C binary structure for Cpport if ( verbose ): print '*** cbin for cpport[%d]' % (self.index) # check index if ( self.index != expected ): print '[genmap error] in Cpport.cbin() : port global index = %d / expected = %d' \ % ( self.index, expected ) sys.exit(1) # compute numerical value for direction if ( self.direction == 'TO_COPROC' ): dir_int = 0 else: dir_int = 1 # compute vspace global index vspace_id = 0xFFFFFFFF for vspace in mapping.vspaces: if ( self.vspacename == vspace.name ): vspace_id = vspace.index if (vspace_id == 0xFFFFFFFF): print '[genmap error] in Cpport.cbin() : vspace name %s not found' \ % ( self.vspacename ) sys.exit(1) # compute mwmr global index mwmr_id = 0xFFFFFFFF for vseg in mapping.vspace[vspace_id].vsegs: for vobj in vseg.vobjs: if (self.mwmrname == vobj.name): mwmr_id = vobj.index if (mwmr_id == 0xFFFFFFFF): print '[genmap error] in Cpport.cbin() : mwmr vobj name %s not found in vspace %s' \ % ( self.mwmrname, self.vspacename ) sys.exit(1) byte_stream = bytearray() byte_stream += mapping.int2bytes( 4 , dir_int ) # pseg global index byte_stream += mapping.int2bytes( 4 , vspace_id ) # vspace global index byte_stream += mapping.int2bytes( 4 , mwmr_id ) # mwmr vobj global index if ( verbose ): print 'direction = %s' % self.direction print 'vspace_id = %d' % vspace_id print 'mwmr_id = %d' % mwmr_id return byte_stream # 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