params.py (13783:e9a2fef479e7) | params.py (13869:cd9d6b36ded0) |
---|---|
1# Copyright (c) 2012-2014, 2017, 2018 ARM Limited 2# All rights reserved. 3# 4# The license below extends only to copyright in the software and shall 5# not be construed as granting a license to any other intellectual 6# property including but not limited to intellectual property relating 7# to a hardware implementation of the functionality of the software 8# licensed hereunder. You may use the software subject to the license --- 1820 unchanged lines hidden (view full) --- 1829# 1830# Ports are used to interconnect objects in the memory system. 1831# 1832##################################################################### 1833 1834# Port reference: encapsulates a reference to a particular port on a 1835# particular SimObject. 1836class PortRef(object): | 1# Copyright (c) 2012-2014, 2017, 2018 ARM Limited 2# All rights reserved. 3# 4# The license below extends only to copyright in the software and shall 5# not be construed as granting a license to any other intellectual 6# property including but not limited to intellectual property relating 7# to a hardware implementation of the functionality of the software 8# licensed hereunder. You may use the software subject to the license --- 1820 unchanged lines hidden (view full) --- 1829# 1830# Ports are used to interconnect objects in the memory system. 1831# 1832##################################################################### 1833 1834# Port reference: encapsulates a reference to a particular port on a 1835# particular SimObject. 1836class PortRef(object): |
1837 def __init__(self, simobj, name, role): | 1837 def __init__(self, simobj, name, role, is_source): |
1838 assert(isSimObject(simobj) or isSimObjectClass(simobj)) 1839 self.simobj = simobj 1840 self.name = name 1841 self.role = role | 1838 assert(isSimObject(simobj) or isSimObjectClass(simobj)) 1839 self.simobj = simobj 1840 self.name = name 1841 self.role = role |
1842 self.is_source = is_source |
|
1842 self.peer = None # not associated with another port yet 1843 self.ccConnected = False # C++ port connection done? 1844 self.index = -1 # always -1 for non-vector ports 1845 1846 def __str__(self): 1847 return '%s.%s' % (self.simobj, self.name) 1848 1849 def __len__(self): 1850 # Return the number of connected ports, i.e. 0 is we have no 1851 # peer and 1 if we do. 1852 return int(self.peer != None) 1853 1854 # for config.ini, print peer's name (not ours) 1855 def ini_str(self): 1856 return str(self.peer) 1857 1858 # for config.json 1859 def get_config_as_dict(self): | 1843 self.peer = None # not associated with another port yet 1844 self.ccConnected = False # C++ port connection done? 1845 self.index = -1 # always -1 for non-vector ports 1846 1847 def __str__(self): 1848 return '%s.%s' % (self.simobj, self.name) 1849 1850 def __len__(self): 1851 # Return the number of connected ports, i.e. 0 is we have no 1852 # peer and 1 if we do. 1853 return int(self.peer != None) 1854 1855 # for config.ini, print peer's name (not ours) 1856 def ini_str(self): 1857 return str(self.peer) 1858 1859 # for config.json 1860 def get_config_as_dict(self): |
1860 return {'role' : self.role, 'peer' : str(self.peer)} | 1861 return {'role' : self.role, 'peer' : str(self.peer), 1862 'is_source' : str(self.is_source)} |
1861 1862 def __getattr__(self, attr): 1863 if attr == 'peerObj': 1864 # shorthand for proxies 1865 return self.peer.simobj 1866 raise AttributeError("'%s' object has no attribute '%s'" % \ 1867 (self.__class__.__name__, attr)) 1868 --- 4 unchanged lines hidden (view full) --- 1873 def connect(self, other): 1874 if isinstance(other, VectorPortRef): 1875 # reference to plain VectorPort is implicit append 1876 other = other._get_next() 1877 if self.peer and not proxy.isproxy(self.peer): 1878 fatal("Port %s is already connected to %s, cannot connect %s\n", 1879 self, self.peer, other); 1880 self.peer = other | 1863 1864 def __getattr__(self, attr): 1865 if attr == 'peerObj': 1866 # shorthand for proxies 1867 return self.peer.simobj 1868 raise AttributeError("'%s' object has no attribute '%s'" % \ 1869 (self.__class__.__name__, attr)) 1870 --- 4 unchanged lines hidden (view full) --- 1875 def connect(self, other): 1876 if isinstance(other, VectorPortRef): 1877 # reference to plain VectorPort is implicit append 1878 other = other._get_next() 1879 if self.peer and not proxy.isproxy(self.peer): 1880 fatal("Port %s is already connected to %s, cannot connect %s\n", 1881 self, self.peer, other); 1882 self.peer = other |
1883 |
|
1881 if proxy.isproxy(other): 1882 other.set_param_desc(PortParamDesc()) | 1884 if proxy.isproxy(other): 1885 other.set_param_desc(PortParamDesc()) |
1883 elif isinstance(other, PortRef): 1884 if other.peer is not self: 1885 other.connect(self) 1886 else: | 1886 return 1887 elif not isinstance(other, PortRef): |
1887 raise TypeError("assigning non-port reference '%s' to port '%s'" \ 1888 % (other, self)) 1889 | 1888 raise TypeError("assigning non-port reference '%s' to port '%s'" \ 1889 % (other, self)) 1890 |
1891 if not Port.is_compat(self, other): 1892 fatal("Ports %s and %s with roles '%s' and '%s' " 1893 "are not compatible", self, other, self.role, other.role) 1894 1895 if other.peer is not self: 1896 other.connect(self) 1897 |
|
1890 # Allow a master/slave port pair to be spliced between 1891 # a port and its connected peer. Useful operation for connecting 1892 # instrumentation structures into a system when it is necessary 1893 # to connect the instrumentation after the full system has been 1894 # constructed. 1895 def splice(self, new_master_peer, new_slave_peer): 1896 if not self.peer or proxy.isproxy(self.peer): 1897 fatal("Port %s not connected, cannot splice in new peers\n", self) --- 56 unchanged lines hidden (view full) --- 1954 peer_port = peer.simobj.getPort(peer.name, peer.index) 1955 port.bind(peer_port) 1956 1957 self.ccConnected = True 1958 1959# A reference to an individual element of a VectorPort... much like a 1960# PortRef, but has an index. 1961class VectorPortElementRef(PortRef): | 1898 # Allow a master/slave port pair to be spliced between 1899 # a port and its connected peer. Useful operation for connecting 1900 # instrumentation structures into a system when it is necessary 1901 # to connect the instrumentation after the full system has been 1902 # constructed. 1903 def splice(self, new_master_peer, new_slave_peer): 1904 if not self.peer or proxy.isproxy(self.peer): 1905 fatal("Port %s not connected, cannot splice in new peers\n", self) --- 56 unchanged lines hidden (view full) --- 1962 peer_port = peer.simobj.getPort(peer.name, peer.index) 1963 port.bind(peer_port) 1964 1965 self.ccConnected = True 1966 1967# A reference to an individual element of a VectorPort... much like a 1968# PortRef, but has an index. 1969class VectorPortElementRef(PortRef): |
1962 def __init__(self, simobj, name, role, index): 1963 PortRef.__init__(self, simobj, name, role) | 1970 def __init__(self, simobj, name, role, is_source, index): 1971 PortRef.__init__(self, simobj, name, role, is_source) |
1964 self.index = index 1965 1966 def __str__(self): 1967 return '%s.%s[%d]' % (self.simobj, self.name, self.index) 1968 1969# A reference to a complete vector-valued port (not just a single element). 1970# Can be indexed to retrieve individual VectorPortElementRef instances. 1971class VectorPortRef(object): | 1972 self.index = index 1973 1974 def __str__(self): 1975 return '%s.%s[%d]' % (self.simobj, self.name, self.index) 1976 1977# A reference to a complete vector-valued port (not just a single element). 1978# Can be indexed to retrieve individual VectorPortElementRef instances. 1979class VectorPortRef(object): |
1972 def __init__(self, simobj, name, role): | 1980 def __init__(self, simobj, name, role, is_source): |
1973 assert(isSimObject(simobj) or isSimObjectClass(simobj)) 1974 self.simobj = simobj 1975 self.name = name 1976 self.role = role | 1981 assert(isSimObject(simobj) or isSimObjectClass(simobj)) 1982 self.simobj = simobj 1983 self.name = name 1984 self.role = role |
1985 self.is_source = is_source |
|
1977 self.elements = [] 1978 1979 def __str__(self): 1980 return '%s.%s[:]' % (self.simobj, self.name) 1981 1982 def __len__(self): 1983 # Return the number of connected peers, corresponding the the 1984 # length of the elements. 1985 return len(self.elements) 1986 1987 # for config.ini, print peer's name (not ours) 1988 def ini_str(self): 1989 return ' '.join([el.ini_str() for el in self.elements]) 1990 1991 # for config.json 1992 def get_config_as_dict(self): 1993 return {'role' : self.role, | 1986 self.elements = [] 1987 1988 def __str__(self): 1989 return '%s.%s[:]' % (self.simobj, self.name) 1990 1991 def __len__(self): 1992 # Return the number of connected peers, corresponding the the 1993 # length of the elements. 1994 return len(self.elements) 1995 1996 # for config.ini, print peer's name (not ours) 1997 def ini_str(self): 1998 return ' '.join([el.ini_str() for el in self.elements]) 1999 2000 # for config.json 2001 def get_config_as_dict(self): 2002 return {'role' : self.role, |
1994 'peer' : [el.ini_str() for el in self.elements]} | 2003 'peer' : [el.ini_str() for el in self.elements], 2004 'is_source' : str(self.is_source)} |
1995 1996 def __getitem__(self, key): 1997 if not isinstance(key, int): 1998 raise TypeError("VectorPort index must be integer") 1999 if key >= len(self.elements): 2000 # need to extend list | 2005 2006 def __getitem__(self, key): 2007 if not isinstance(key, int): 2008 raise TypeError("VectorPort index must be integer") 2009 if key >= len(self.elements): 2010 # need to extend list |
2001 ext = [VectorPortElementRef(self.simobj, self.name, self.role, i) | 2011 ext = [VectorPortElementRef( 2012 self.simobj, self.name, self.role, self.is_source, i) |
2002 for i in range(len(self.elements), key+1)] 2003 self.elements.extend(ext) 2004 return self.elements[key] 2005 2006 def _get_next(self): 2007 return self[len(self.elements)] 2008 2009 def __setitem__(self, key, value): --- 27 unchanged lines hidden (view full) --- 2037 2038 def ccConnect(self): 2039 [el.ccConnect() for el in self.elements] 2040 2041# Port description object. Like a ParamDesc object, this represents a 2042# logical port in the SimObject class, not a particular port on a 2043# SimObject instance. The latter are represented by PortRef objects. 2044class Port(object): | 2013 for i in range(len(self.elements), key+1)] 2014 self.elements.extend(ext) 2015 return self.elements[key] 2016 2017 def _get_next(self): 2018 return self[len(self.elements)] 2019 2020 def __setitem__(self, key, value): --- 27 unchanged lines hidden (view full) --- 2048 2049 def ccConnect(self): 2050 [el.ccConnect() for el in self.elements] 2051 2052# Port description object. Like a ParamDesc object, this represents a 2053# logical port in the SimObject class, not a particular port on a 2054# SimObject instance. The latter are represented by PortRef objects. 2055class Port(object): |
2056 # Port("role", "description") 2057 2058 _compat_dict = { } 2059 2060 @classmethod 2061 def compat(cls, role, peer): 2062 cls._compat_dict.setdefault(role, set()).add(peer) 2063 cls._compat_dict.setdefault(peer, set()).add(role) 2064 2065 @classmethod 2066 def is_compat(cls, one, two): 2067 for port in one, two: 2068 if not port.role in Port._compat_dict: 2069 fatal("Unrecognized role '%s' for port %s\n", port.role, port) 2070 return one.role in Port._compat_dict[two.role] 2071 2072 def __init__(self, role, desc, is_source=False): 2073 self.desc = desc 2074 self.role = role 2075 self.is_source = is_source 2076 |
|
2045 # Generate a PortRef for this port on the given SimObject with the 2046 # given name 2047 def makeRef(self, simobj): | 2077 # Generate a PortRef for this port on the given SimObject with the 2078 # given name 2079 def makeRef(self, simobj): |
2048 return PortRef(simobj, self.name, self.role) | 2080 return PortRef(simobj, self.name, self.role, self.is_source) |
2049 2050 # Connect an instance of this port (on the given SimObject with 2051 # the given name) with the port described by the supplied PortRef 2052 def connect(self, simobj, ref): 2053 self.makeRef(simobj).connect(ref) 2054 2055 # No need for any pre-declarations at the moment as we merely rely 2056 # on an unsigned int. --- 4 unchanged lines hidden (view full) --- 2061 cls.cxx_predecls(self, code) 2062 2063 # Declare an unsigned int with the same name as the port, that 2064 # will eventually hold the number of connected ports (and thus the 2065 # number of elements for a VectorPort). 2066 def cxx_decl(self, code): 2067 code('unsigned int port_${{self.name}}_connection_count;') 2068 | 2081 2082 # Connect an instance of this port (on the given SimObject with 2083 # the given name) with the port described by the supplied PortRef 2084 def connect(self, simobj, ref): 2085 self.makeRef(simobj).connect(ref) 2086 2087 # No need for any pre-declarations at the moment as we merely rely 2088 # on an unsigned int. --- 4 unchanged lines hidden (view full) --- 2093 cls.cxx_predecls(self, code) 2094 2095 # Declare an unsigned int with the same name as the port, that 2096 # will eventually hold the number of connected ports (and thus the 2097 # number of elements for a VectorPort). 2098 def cxx_decl(self, code): 2099 code('unsigned int port_${{self.name}}_connection_count;') 2100 |
2101Port.compat('MASTER', 'SLAVE') 2102 |
|
2069class MasterPort(Port): 2070 # MasterPort("description") | 2103class MasterPort(Port): 2104 # MasterPort("description") |
2071 def __init__(self, *args): 2072 if len(args) == 1: 2073 self.desc = args[0] 2074 self.role = 'MASTER' 2075 else: 2076 raise TypeError('wrong number of arguments') | 2105 def __init__(self, desc): 2106 super(MasterPort, self).__init__('MASTER', desc, is_source=True) |
2077 2078class SlavePort(Port): 2079 # SlavePort("description") | 2107 2108class SlavePort(Port): 2109 # SlavePort("description") |
2080 def __init__(self, *args): 2081 if len(args) == 1: 2082 self.desc = args[0] 2083 self.role = 'SLAVE' 2084 else: 2085 raise TypeError('wrong number of arguments') | 2110 def __init__(self, desc): 2111 super(SlavePort, self).__init__('SLAVE', desc) |
2086 2087# VectorPort description object. Like Port, but represents a vector 2088# of connections (e.g., as on a XBar). 2089class VectorPort(Port): | 2112 2113# VectorPort description object. Like Port, but represents a vector 2114# of connections (e.g., as on a XBar). 2115class VectorPort(Port): |
2090 def __init__(self, *args): | 2116 # VectorPort("role", "description") 2117 def __init__(self, role, desc, is_source=False): 2118 super(VectorPort, self).__init__(role, desc, is_source) |
2091 self.isVec = True 2092 2093 def makeRef(self, simobj): | 2119 self.isVec = True 2120 2121 def makeRef(self, simobj): |
2094 return VectorPortRef(simobj, self.name, self.role) | 2122 return VectorPortRef(simobj, self.name, self.role, self.is_source) |
2095 2096class VectorMasterPort(VectorPort): 2097 # VectorMasterPort("description") | 2123 2124class VectorMasterPort(VectorPort): 2125 # VectorMasterPort("description") |
2098 def __init__(self, *args): 2099 if len(args) == 1: 2100 self.desc = args[0] 2101 self.role = 'MASTER' 2102 VectorPort.__init__(self, *args) 2103 else: 2104 raise TypeError('wrong number of arguments') | 2126 def __init__(self, desc): 2127 super(VectorMasterPort, self).__init__('MASTER', desc, is_source=True) |
2105 2106class VectorSlavePort(VectorPort): 2107 # VectorSlavePort("description") | 2128 2129class VectorSlavePort(VectorPort): 2130 # VectorSlavePort("description") |
2108 def __init__(self, *args): 2109 if len(args) == 1: 2110 self.desc = args[0] 2111 self.role = 'SLAVE' 2112 VectorPort.__init__(self, *args) 2113 else: 2114 raise TypeError('wrong number of arguments') | 2131 def __init__(self, desc): 2132 super(VectorSlavePort, self).__init__('SLAVE', desc) |
2115 2116# 'Fake' ParamDesc for Port references to assign to the _pdesc slot of 2117# proxy objects (via set_param_desc()) so that proxy error messages 2118# make sense. 2119class PortParamDesc(object): 2120 __metaclass__ = Singleton 2121 2122 ptype_str = 'Port' --- 17 unchanged lines hidden (view full) --- 2140 'IpAddress', 'IpNetmask', 'IpWithPort', 2141 'MemorySize', 'MemorySize32', 2142 'Latency', 'Frequency', 'Clock', 'Voltage', 'Current', 'Energy', 2143 'NetworkBandwidth', 'MemoryBandwidth', 2144 'AddrRange', 2145 'MaxAddr', 'MaxTick', 'AllMemory', 2146 'Time', 2147 'NextEthernetAddr', 'NULL', | 2133 2134# 'Fake' ParamDesc for Port references to assign to the _pdesc slot of 2135# proxy objects (via set_param_desc()) so that proxy error messages 2136# make sense. 2137class PortParamDesc(object): 2138 __metaclass__ = Singleton 2139 2140 ptype_str = 'Port' --- 17 unchanged lines hidden (view full) --- 2158 'IpAddress', 'IpNetmask', 'IpWithPort', 2159 'MemorySize', 'MemorySize32', 2160 'Latency', 'Frequency', 'Clock', 'Voltage', 'Current', 'Energy', 2161 'NetworkBandwidth', 'MemoryBandwidth', 2162 'AddrRange', 2163 'MaxAddr', 'MaxTick', 'AllMemory', 2164 'Time', 2165 'NextEthernetAddr', 'NULL', |
2148 'MasterPort', 'SlavePort', 2149 'VectorMasterPort', 'VectorSlavePort'] | 2166 'Port', 'MasterPort', 'SlavePort', 2167 'VectorPort', 'VectorMasterPort', 'VectorSlavePort'] |