1 # Copyright (c) 2012-2013 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 # Authors: Andreas Sandberg
39 from abc
import ABCMeta
, abstractmethod
41 from m5
.objects
import *
42 from m5
.proxy
import *
43 m5
.util
.addToPath('../configs/common')
47 _have_kvm_support
= 'BaseKvmCPU' in globals()
49 class BaseSystem(object):
50 """Base system builder.
52 This class provides some basic functionality for creating an ARM
53 system with the usual peripherals (caches, GIC, etc.). It allows
54 customization by defining separate methods for different parts of
55 the initialization process.
58 __metaclass__
= ABCMeta
60 def __init__(self
, mem_mode
='timing', mem_class
=SimpleMemory
,
61 cpu_class
=TimingSimpleCPU
, num_cpus
=1, num_threads
=1,
64 """Initialize a simple base system.
67 mem_mode -- String describing the memory mode (timing or atomic)
68 mem_class -- Memory controller class to use
69 cpu_class -- CPU class to use
70 num_cpus -- Number of CPUs to instantiate
71 checker -- Set to True to add checker CPUs
72 mem_size -- Override the default memory size
74 self
.mem_mode
= mem_mode
75 self
.mem_class
= mem_class
76 self
.cpu_class
= cpu_class
77 self
.num_cpus
= num_cpus
78 self
.num_threads
= num_threads
79 self
.checker
= checker
81 def create_cpus(self
, cpu_clk_domain
):
82 """Return a list of CPU objects to add to a system."""
83 cpus
= [ self
.cpu_class(clk_domain
=cpu_clk_domain
,
84 numThreads
=self
.num_threads
,
86 for i
in range(self
.num_cpus
) ]
92 def create_caches_private(self
, cpu
):
93 """Add private caches to a CPU.
96 cpu -- CPU instance to work on.
98 cpu
.addPrivateSplitL1Caches(L1_ICache(size
='32kB', assoc
=1),
99 L1_DCache(size
='32kB', assoc
=4))
101 def create_caches_shared(self
, system
):
102 """Add shared caches to a system.
105 system -- System to work on.
108 A bus that CPUs should use to connect to the shared cache.
110 system
.toL2Bus
= L2XBar(clk_domain
=system
.cpu_clk_domain
)
111 system
.l2c
= L2Cache(clk_domain
=system
.cpu_clk_domain
,
113 system
.l2c
.cpu_side
= system
.toL2Bus
.master
114 system
.l2c
.mem_side
= system
.membus
.slave
115 return system
.toL2Bus
117 def init_cpu(self
, system
, cpu
, sha_bus
):
121 system -- System to work on.
122 cpu -- CPU to initialize.
124 if not cpu
.switched_out
:
125 self
.create_caches_private(cpu
)
126 cpu
.createInterruptController()
127 cpu
.connectAllPorts(sha_bus
if sha_bus
!= None else system
.membus
,
130 def init_kvm(self
, system
):
131 """Do KVM-specific system initialization.
134 system -- System to work on.
138 def init_system(self
, system
):
139 """Initialize a system.
142 system -- System to initialize.
144 self
.create_clk_src(system
)
145 system
.cpu
= self
.create_cpus(system
.cpu_clk_domain
)
147 if _have_kvm_support
and \
148 any([isinstance(c
, BaseKvmCPU
) for c
in system
.cpu
]):
149 self
.init_kvm(system
)
151 sha_bus
= self
.create_caches_shared(system
)
152 for cpu
in system
.cpu
:
153 self
.init_cpu(system
, cpu
, sha_bus
)
155 def create_clk_src(self
,system
):
156 # Create system clock domain. This provides clock value to every
157 # clocked object that lies beneath it unless explicitly overwritten
158 # by a different clock domain.
159 system
.voltage_domain
= VoltageDomain()
160 system
.clk_domain
= SrcClockDomain(clock
= '1GHz',
162 system
.voltage_domain
)
164 # Create a seperate clock domain for components that should
165 # run at CPUs frequency
166 system
.cpu_clk_domain
= SrcClockDomain(clock
= '2GHz',
168 system
.voltage_domain
)
171 def create_system(self
):
172 """Create an return an initialized system."""
176 def create_root(self
):
177 """Create and return a simulation root using the system
178 defined by this class."""
181 class BaseSESystem(BaseSystem
):
182 """Basic syscall-emulation builder."""
184 def __init__(self
, **kwargs
):
185 BaseSystem
.__init
__(self
, **kwargs
)
187 def init_system(self
, system
):
188 BaseSystem
.init_system(self
, system
)
190 def create_system(self
):
191 system
= System(physmem
= self
.mem_class(),
192 membus
= SystemXBar(),
193 mem_mode
= self
.mem_mode
,
194 multi_thread
= (self
.num_threads
> 1))
195 system
.system_port
= system
.membus
.slave
196 system
.physmem
.port
= system
.membus
.master
197 self
.init_system(system
)
200 def create_root(self
):
201 system
= self
.create_system()
202 m5
.ticks
.setGlobalFrequency('1THz')
203 return Root(full_system
=False, system
=system
)
205 class BaseSESystemUniprocessor(BaseSESystem
):
206 """Basic syscall-emulation builder for uniprocessor systems.
208 Note: This class is only really needed to provide backwards
209 compatibility in existing test cases.
212 def __init__(self
, **kwargs
):
213 BaseSESystem
.__init
__(self
, **kwargs
)
215 def create_caches_private(self
, cpu
):
216 # The atomic SE configurations do not use caches
217 if self
.mem_mode
== "timing":
218 # @todo We might want to revisit these rather enthusiastic L1 sizes
219 cpu
.addTwoLevelCacheHierarchy(L1_ICache(size
='128kB'),
220 L1_DCache(size
='256kB'),
223 def create_caches_shared(self
, system
):
226 class BaseFSSystem(BaseSystem
):
227 """Basic full system builder."""
229 def __init__(self
, **kwargs
):
230 BaseSystem
.__init
__(self
, **kwargs
)
232 def init_system(self
, system
):
233 BaseSystem
.init_system(self
, system
)
235 # create the memory controllers and connect them, stick with
236 # the physmem name to avoid bumping all the reference stats
237 system
.physmem
= [self
.mem_class(range = r
)
238 for r
in system
.mem_ranges
]
239 for i
in xrange(len(system
.physmem
)):
240 system
.physmem
[i
].port
= system
.membus
.master
242 # create the iocache, which by default runs at the system clock
243 system
.iocache
= IOCache(addr_ranges
=system
.mem_ranges
)
244 system
.iocache
.cpu_side
= system
.iobus
.master
245 system
.iocache
.mem_side
= system
.membus
.slave
247 def create_root(self
):
248 system
= self
.create_system()
249 m5
.ticks
.setGlobalFrequency('1THz')
250 return Root(full_system
=True, system
=system
)
252 class BaseFSSystemUniprocessor(BaseFSSystem
):
253 """Basic full system builder for uniprocessor systems.
255 Note: This class is only really needed to provide backwards
256 compatibility in existing test cases.
259 def __init__(self
, **kwargs
):
260 BaseFSSystem
.__init
__(self
, **kwargs
)
262 def create_caches_private(self
, cpu
):
263 cpu
.addTwoLevelCacheHierarchy(L1_ICache(size
='32kB', assoc
=1),
264 L1_DCache(size
='32kB', assoc
=4),
265 L2Cache(size
='4MB', assoc
=8))
267 def create_caches_shared(self
, system
):
270 class BaseFSSwitcheroo(BaseFSSystem
):
271 """Uniprocessor system prepared for CPU switching"""
273 def __init__(self
, cpu_classes
, **kwargs
):
274 BaseFSSystem
.__init
__(self
, **kwargs
)
275 self
.cpu_classes
= tuple(cpu_classes
)
277 def create_cpus(self
, cpu_clk_domain
):
278 cpus
= [ cclass(clk_domain
= cpu_clk_domain
,
281 for cclass
in self
.cpu_classes
]
282 cpus
[0].switched_out
= False