1 # Copyright (c) 2016-2017, 2019 ARM Limited
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
9 # terms below provided that you ensure that this notice is replicated
10 # unmodified and in its entirety in all distributions of the software,
11 # modified or unmodified, in source code or in binary form.
13 # Redistribution and use in source and binary forms, with or without
14 # modification, are permitted provided that the following conditions are
15 # met: redistributions of source code must retain the above copyright
16 # notice, this list of conditions and the following disclaimer;
17 # redistributions in binary form must reproduce the above copyright
18 # notice, this list of conditions and the following disclaimer in the
19 # documentation and/or other materials provided with the distribution;
20 # neither the name of the copyright holders nor the names of its
21 # contributors may be used to endorse or promote products derived from
22 # this software without specific prior written permission.
24 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 # System components used by the bigLITTLE.py configuration script
38 from __future__
import print_function
39 from __future__
import absolute_import
44 from m5
.objects
import *
45 m5
.util
.addToPath('../../')
46 from common
.Caches
import *
47 from common
import ObjectList
52 have_kvm
= "ArmV8KvmCPU" in ObjectList
.cpu_list
.get_names()
53 have_fastmodel
= "FastModelCortexA76" in ObjectList
.cpu_list
.get_names()
76 class WalkCache(PageTableWalkerCache
):
96 clusivity
='mostly_excl'
104 response_latency
= 20
107 clusivity
='mostly_excl'
110 class MemBus(SystemXBar
):
111 badaddr_responder
= BadAddr(warn_access
="warn")
112 default
= Self
.badaddr_responder
.pio
115 class CpuCluster(SubSystem
):
116 def __init__(self
, system
, num_cpus
, cpu_clock
, cpu_voltage
,
117 cpu_type
, l1i_type
, l1d_type
, wcache_type
, l2_type
):
118 super(CpuCluster
, self
).__init
__()
119 self
._cpu
_type
= cpu_type
120 self
._l1i
_type
= l1i_type
121 self
._l1d
_type
= l1d_type
122 self
._wcache
_type
= wcache_type
123 self
._l2_type
= l2_type
127 self
.voltage_domain
= VoltageDomain(voltage
=cpu_voltage
)
128 self
.clk_domain
= SrcClockDomain(clock
=cpu_clock
,
129 voltage_domain
=self
.voltage_domain
)
131 self
.cpus
= [ self
._cpu
_type
(cpu_id
=system
.numCpus() + idx
,
132 clk_domain
=self
.clk_domain
)
133 for idx
in range(num_cpus
) ]
135 for cpu
in self
.cpus
:
137 cpu
.createInterruptController()
138 cpu
.socket_id
= system
.numCpuClusters()
139 system
.addCpuCluster(self
, num_cpus
)
141 def requireCaches(self
):
142 return self
._cpu
_type
.require_caches()
144 def memoryMode(self
):
145 return self
._cpu
_type
.memory_mode()
148 for cpu
in self
.cpus
:
149 l1i
= None if self
._l1i
_type
is None else self
._l1i
_type
()
150 l1d
= None if self
._l1d
_type
is None else self
._l1d
_type
()
151 iwc
= None if self
._wcache
_type
is None else self
._wcache
_type
()
152 dwc
= None if self
._wcache
_type
is None else self
._wcache
_type
()
153 cpu
.addPrivateSplitL1Caches(l1i
, l1d
, iwc
, dwc
)
155 def addL2(self
, clk_domain
):
156 if self
._l2_type
is None:
158 self
.toL2Bus
= L2XBar(width
=64, clk_domain
=clk_domain
)
159 self
.l2
= self
._l2_type
()
160 for cpu
in self
.cpus
:
161 cpu
.connectAllPorts(self
.toL2Bus
)
162 self
.toL2Bus
.master
= self
.l2
.cpu_side
164 def addPMUs(self
, ints
, events
=[]):
166 Instantiates 1 ArmPMU per PE. The method is accepting a list of
167 interrupt numbers (ints) used by the PMU and a list of events to
170 :param ints: List of interrupt numbers. The code will iterate over
171 the cpu list in order and will assign to every cpu in the cluster
172 a PMU with the matching interrupt.
173 :type ints: List[int]
174 :param events: Additional events to be measured by the PMUs
175 :type events: List[Union[ProbeEvent, SoftwareIncrement]]
177 assert len(ints
) == len(self
.cpus
)
178 for cpu
, pint
in zip(self
.cpus
, ints
):
179 int_cls
= ArmPPI
if pint
< 32 else ArmSPI
181 isa
.pmu
= ArmPMU(interrupt
=int_cls(num
=pint
))
182 isa
.pmu
.addArchEvents(cpu
=cpu
, itb
=cpu
.itb
, dtb
=cpu
.dtb
,
183 icache
=getattr(cpu
, 'icache', None),
184 dcache
=getattr(cpu
, 'dcache', None),
185 l2cache
=getattr(self
, 'l2', None))
189 def connectMemSide(self
, bus
):
192 self
.l2
.mem_side
= bus
.slave
193 except AttributeError:
194 for cpu
in self
.cpus
:
195 cpu
.connectAllPorts(bus
)
198 class AtomicCluster(CpuCluster
):
199 def __init__(self
, system
, num_cpus
, cpu_clock
, cpu_voltage
="1.0V"):
200 cpu_config
= [ ObjectList
.cpu_list
.get("AtomicSimpleCPU"), None,
202 super(AtomicCluster
, self
).__init
__(system
, num_cpus
, cpu_clock
,
203 cpu_voltage
, *cpu_config
)
207 class KvmCluster(CpuCluster
):
208 def __init__(self
, system
, num_cpus
, cpu_clock
, cpu_voltage
="1.0V"):
209 cpu_config
= [ ObjectList
.cpu_list
.get("ArmV8KvmCPU"), None, None,
211 super(KvmCluster
, self
).__init
__(system
, num_cpus
, cpu_clock
,
212 cpu_voltage
, *cpu_config
)
216 class FastmodelCluster(SubSystem
):
217 def __init__(self
, system
, num_cpus
, cpu_clock
, cpu_voltage
="1.0V"):
218 super(FastmodelCluster
, self
).__init
__()
221 gic
= system
.realview
.gic
222 gic
.sc_gic
.cpu_affinities
= ','.join(
223 [ '0.0.%d.0' % i
for i
in range(num_cpus
) ])
225 # Parse the base address of redistributor.
226 redist_base
= gic
.get_redist_bases()[0]
227 redist_frame_size
= 0x40000 if gic
.sc_gic
.has_gicv4_1
else 0x20000
228 gic
.sc_gic
.reg_base_per_redistributor
= ','.join([
229 '0.0.%d.0=%#x' % (i
, redist_base
+ redist_frame_size
* i
)
230 for i
in range(num_cpus
)
233 gic_a2t
= AmbaToTlmBridge64(amba
=gic
.amba_m
)
234 gic_t2g
= TlmToGem5Bridge64(tlm
=gic_a2t
.tlm
, gem5
=system
.iobus
.slave
)
235 gic_g2t
= Gem5ToTlmBridge64(gem5
=system
.membus
.master
)
236 gic_g2t
.addr_ranges
= gic
.get_addr_ranges()
237 gic_t2a
= AmbaFromTlmBridge64(tlm
=gic_g2t
.tlm
)
238 gic
.amba_s
= gic_t2a
.amba
240 system
.gic_hub
= SubSystem()
241 system
.gic_hub
.gic_a2t
= gic_a2t
242 system
.gic_hub
.gic_t2g
= gic_t2g
243 system
.gic_hub
.gic_g2t
= gic_g2t
244 system
.gic_hub
.gic_t2a
= gic_t2a
246 self
.voltage_domain
= VoltageDomain(voltage
=cpu_voltage
)
247 self
.clk_domain
= SrcClockDomain(clock
=cpu_clock
,
248 voltage_domain
=self
.voltage_domain
)
252 CpuClasses
= [FastModelCortexA76x1
, FastModelCortexA76x2
,
253 FastModelCortexA76x3
, FastModelCortexA76x4
]
254 CpuClass
= CpuClasses
[num_cpus
- 1]
256 cpu
= CpuClass(GICDISABLE
=False)
257 for core
in cpu
.cores
:
258 core
.semihosting_enable
= False
259 core
.RVBARADDR
= 0x10
260 core
.redistributor
= gic
.redistributor
263 a2t
= AmbaToTlmBridge64(amba
=cpu
.amba
)
264 t2g
= TlmToGem5Bridge64(tlm
=a2t
.tlm
, gem5
=system
.membus
.slave
)
265 system
.gic_hub
.a2t
= a2t
266 system
.gic_hub
.t2g
= t2g
268 system
.addCpuCluster(self
, num_cpus
)
270 def requireCaches(self
):
273 def memoryMode(self
):
274 return 'atomic_noncaching'
279 def addL2(self
, clk_domain
):
282 def connectMemSide(self
, bus
):
285 def simpleSystem(BaseSystem
, caches
, mem_size
, platform
=None, **kwargs
):
287 Create a simple system example. The base class in configurable so
288 that it is possible (e.g) to link the platform (hardware configuration)
289 with a baremetal ArmSystem or with a LinuxArmSystem.
291 class SimpleSystem(BaseSystem
):
294 def __init__(self
, caches
, mem_size
, platform
=None, **kwargs
):
295 super(SimpleSystem
, self
).__init
__(**kwargs
)
297 self
.voltage_domain
= VoltageDomain(voltage
="1.0V")
298 self
.clk_domain
= SrcClockDomain(
300 voltage_domain
=Parent
.voltage_domain
)
303 self
.realview
= VExpress_GEM5_V1()
305 self
.realview
= platform
307 if hasattr(self
.realview
.gic
, 'cpu_addr'):
308 self
.gic_cpu_addr
= self
.realview
.gic
.cpu_addr
309 self
.flags_addr
= self
.realview
.realview_io
.pio_addr
+ 0x30
311 self
.membus
= MemBus()
313 self
.intrctrl
= IntrControl()
314 self
.terminal
= Terminal()
315 self
.vncserver
= VncServer()
317 self
.iobus
= IOXBar()
319 self
.iobridge
= Bridge(delay
='50ns')
321 mem_range
= self
.realview
._mem
_regions
[0]
322 assert long(mem_range
.size()) >= long(Addr(mem_size
))
324 AddrRange(start
=mem_range
.start
, size
=mem_size
) ]
326 self
._caches
= caches
328 self
.iocache
= IOCache(addr_ranges
=[self
.mem_ranges
[0]])
330 self
.dmabridge
= Bridge(delay
='50ns',
331 ranges
=[self
.mem_ranges
[0]])
336 def attach_pci(self
, dev
):
337 self
.realview
.attachPciDevice(dev
, self
.iobus
)
340 self
.iobridge
.master
= self
.iobus
.slave
341 self
.iobridge
.slave
= self
.membus
.master
344 self
.iocache
.mem_side
= self
.membus
.slave
345 self
.iocache
.cpu_side
= self
.iobus
.master
347 self
.dmabridge
.master
= self
.membus
.slave
348 self
.dmabridge
.slave
= self
.iobus
.master
350 if hasattr(self
.realview
.gic
, 'cpu_addr'):
351 self
.gic_cpu_addr
= self
.realview
.gic
.cpu_addr
352 self
.realview
.attachOnChipIO(self
.membus
, self
.iobridge
)
353 self
.realview
.attachIO(self
.iobus
)
354 self
.system_port
= self
.membus
.slave
356 def numCpuClusters(self
):
357 return len(self
._clusters
)
359 def addCpuCluster(self
, cpu_cluster
, num_cpus
):
360 assert cpu_cluster
not in self
._clusters
362 self
._clusters
.append(cpu_cluster
)
363 self
._num
_cpus
+= num_cpus
366 return self
._num
_cpus
368 def addCaches(self
, need_caches
, last_cache_level
):
370 # connect each cluster to the memory hierarchy
371 for cluster
in self
._clusters
:
372 cluster
.connectMemSide(self
.membus
)
375 cluster_mem_bus
= self
.membus
376 assert last_cache_level
>= 1 and last_cache_level
<= 3
377 for cluster
in self
._clusters
:
379 if last_cache_level
> 1:
380 for cluster
in self
._clusters
:
381 cluster
.addL2(cluster
.clk_domain
)
382 if last_cache_level
> 2:
383 max_clock_cluster
= max(self
._clusters
,
384 key
=lambda c
: c
.clk_domain
.clock
[0])
385 self
.l3
= L3(clk_domain
=max_clock_cluster
.clk_domain
)
386 self
.toL3Bus
= L2XBar(width
=64)
387 self
.toL3Bus
.master
= self
.l3
.cpu_side
388 self
.l3
.mem_side
= self
.membus
.slave
389 cluster_mem_bus
= self
.toL3Bus
391 # connect each cluster to the memory hierarchy
392 for cluster
in self
._clusters
:
393 cluster
.connectMemSide(cluster_mem_bus
)
395 return SimpleSystem(caches
, mem_size
, platform
, **kwargs
)