gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
generic_timer.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013, 2015, 2017-2018, 2019 ARM Limited
3  * All rights reserved.
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions are
16  * met: redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer;
18  * redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution;
21  * neither the name of the copyright holders nor the names of its
22  * contributors may be used to endorse or promote products derived from
23  * this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  *
37  * Authors: Giacomo Gabrielli
38  * Andreas Sandberg
39  * Adrian Herrera
40  */
41 
42 #ifndef __DEV_ARM_GENERIC_TIMER_HH__
43 #define __DEV_ARM_GENERIC_TIMER_HH__
44 
45 #include "arch/arm/isa_device.hh"
46 #include "arch/arm/system.hh"
47 #include "base/bitunion.hh"
48 #include "dev/arm/base_gic.hh"
49 #include "sim/core.hh"
50 #include "sim/sim_object.hh"
51 
56 
57 class Checkpoint;
58 class GenericTimerParams;
59 class GenericTimerMemParams;
60 
64 {
65  protected:
67  uint32_t _freq;
74 
76  uint32_t _regCntkctl;
78  uint32_t _regCnthctl;
79 
81  static constexpr size_t MAX_FREQ_ENTRIES = 1004;
82 
83  public:
85 
87  uint64_t value() const
88  {
89  if (_freq == 0)
90  return 0; // Counter is still off.
91  return (curTick() - _resetTick) / _period;
92  }
93 
95  uint32_t freq() const { return _freq; }
98  void setFreq(uint32_t freq);
99 
101  Tick period() const { return _period; }
102 
103  void setKernelControl(uint32_t val) { _regCntkctl = val; }
104  uint32_t getKernelControl() { return _regCntkctl; }
105 
106  void setHypControl(uint32_t val) { _regCnthctl = val; }
107  uint32_t getHypControl() { return _regCnthctl; }
108 
109  void serialize(CheckpointOut &cp) const override;
110  void unserialize(CheckpointIn &cp) override;
111 
112  private:
113  // Disable copying
114  SystemCounter(const SystemCounter &c);
115 };
116 
118 class ArchTimer : public Serializable, public Drainable
119 {
120  protected:
122  BitUnion32(ArchTimerCtrl)
123  Bitfield<0> enable;
124  Bitfield<1> imask;
125  Bitfield<2> istatus;
126  EndBitUnion(ArchTimerCtrl)
127 
128 
129  const std::string _name;
130 
133 
135 
137 
139  ArchTimerCtrl _control;
141  uint64_t _counterLimit;
143  uint64_t _offset;
144 
149  void updateCounter();
150 
152  void counterLimitReached();
154 
155  virtual bool scheduleEvents() { return true; }
156 
157  public:
158  ArchTimer(const std::string &name,
159  SimObject &parent,
160  SystemCounter &sysctr,
161  ArmInterruptPin *interrupt);
162 
164  std::string name() const { return _name; }
165 
167  uint64_t compareValue() const { return _counterLimit; }
169  void setCompareValue(uint64_t val);
170 
172  uint32_t timerValue() const { return _counterLimit - value(); }
174  void setTimerValue(uint32_t val);
175 
177  uint32_t control() const { return _control; }
178  void setControl(uint32_t val);
179 
180  uint64_t offset() const { return _offset; }
181  void setOffset(uint64_t val);
182 
184  uint64_t value() const;
185 
186  // Serializable
187  void serialize(CheckpointOut &cp) const override;
188  void unserialize(CheckpointIn &cp) override;
189 
190  // Drainable
191  DrainState drain() override;
192  void drainResume() override;
193 
194  private:
195  // Disable copying
196  ArchTimer(const ArchTimer &t);
197 };
198 
199 class ArchTimerKvm : public ArchTimer
200 {
201  private:
203 
204  public:
205  ArchTimerKvm(const std::string &name,
206  ArmSystem &system,
207  SimObject &parent,
208  SystemCounter &sysctr,
209  ArmInterruptPin *interrupt)
210  : ArchTimer(name, parent, sysctr, interrupt), system(system) {}
211 
212  protected:
213  // For ArchTimer's in a GenericTimerISA with Kvm execution about
214  // to begin, skip rescheduling the event.
215  // Otherwise, we should reschedule the event (if necessary).
216  bool scheduleEvents() override {
217  return !system.validKvmEnvironment();
218  }
219 };
220 
222 {
223  public:
224  const GenericTimerParams * params() const;
225 
226  GenericTimer(GenericTimerParams *p);
227 
228  void serialize(CheckpointOut &cp) const override;
229  void unserialize(CheckpointIn &cp) override;
230 
231  public:
232  void setMiscReg(int misc_reg, unsigned cpu, RegVal val);
233  RegVal readMiscReg(int misc_reg, unsigned cpu);
234 
235  protected:
236  struct CoreTimers {
237  CoreTimers(GenericTimer &parent, ArmSystem &system, unsigned cpu,
238  ArmInterruptPin *_irqPhysS, ArmInterruptPin *_irqPhysNS,
239  ArmInterruptPin *_irqVirt, ArmInterruptPin *_irqHyp)
240  : irqPhysS(_irqPhysS),
241  irqPhysNS(_irqPhysNS),
242  irqVirt(_irqVirt),
243  irqHyp(_irqHyp),
244  physS(csprintf("%s.phys_s_timer%d", parent.name(), cpu),
245  system, parent, parent.systemCounter,
246  _irqPhysS),
247  // This should really be phys_timerN, but we are stuck with
248  // arch_timer for backwards compatibility.
249  physNS(csprintf("%s.arch_timer%d", parent.name(), cpu),
250  system, parent, parent.systemCounter,
251  _irqPhysNS),
252  virt(csprintf("%s.virt_timer%d", parent.name(), cpu),
253  system, parent, parent.systemCounter,
254  _irqVirt),
255  hyp(csprintf("%s.hyp_timer%d", parent.name(), cpu),
256  system, parent, parent.systemCounter,
257  _irqHyp)
258  {}
259 
264 
269 
270  private:
271  // Disable copying
272  CoreTimers(const CoreTimers &c);
273  };
274 
275  CoreTimers &getTimers(int cpu_id);
276  void createTimers(unsigned cpus);
277 
280 
283 
284  protected: // Configuration
287 };
288 
290 {
291  public:
292  GenericTimerISA(GenericTimer &_parent, unsigned _cpu)
293  : parent(_parent), cpu(_cpu) {}
294 
295  void setMiscReg(int misc_reg, RegVal val) override;
296  RegVal readMiscReg(int misc_reg) override;
297 
298  protected:
300  unsigned cpu;
301 };
302 
304 {
305  public:
306  GenericTimerMem(GenericTimerMemParams *p);
307 
308  void serialize(CheckpointOut &cp) const override;
309  void unserialize(CheckpointIn &cp) override;
310 
311  public: // PioDevice
312  AddrRangeList getAddrRanges() const override { return addrRanges; }
313  Tick read(PacketPtr pkt) override;
314  Tick write(PacketPtr pkt) override;
315 
316  protected:
317  uint64_t ctrlRead(Addr addr, size_t size) const;
318  void ctrlWrite(Addr addr, size_t size, uint64_t value);
319 
320  uint64_t timerRead(Addr addr, size_t size) const;
321  void timerWrite(Addr addr, size_t size, uint64_t value);
322 
323  protected: // Registers
324  static const Addr CTRL_CNTFRQ = 0x000;
325  static const Addr CTRL_CNTNSAR = 0x004;
326  static const Addr CTRL_CNTTIDR = 0x008;
327  static const Addr CTRL_CNTACR_BASE = 0x040;
328  static const Addr CTRL_CNTVOFF_LO_BASE = 0x080;
329  static const Addr CTRL_CNTVOFF_HI_BASE = 0x084;
330 
331  static const Addr TIMER_CNTPCT_LO = 0x000;
332  static const Addr TIMER_CNTPCT_HI = 0x004;
333  static const Addr TIMER_CNTVCT_LO = 0x008;
334  static const Addr TIMER_CNTVCT_HI = 0x00C;
335  static const Addr TIMER_CNTFRQ = 0x010;
336  static const Addr TIMER_CNTEL0ACR = 0x014;
337  static const Addr TIMER_CNTVOFF_LO = 0x018;
338  static const Addr TIMER_CNTVOFF_HI = 0x01C;
339  static const Addr TIMER_CNTP_CVAL_LO = 0x020;
340  static const Addr TIMER_CNTP_CVAL_HI = 0x024;
341  static const Addr TIMER_CNTP_TVAL = 0x028;
342  static const Addr TIMER_CNTP_CTL = 0x02C;
343  static const Addr TIMER_CNTV_CVAL_LO = 0x030;
344  static const Addr TIMER_CNTV_CVAL_HI = 0x034;
345  static const Addr TIMER_CNTV_TVAL = 0x038;
346  static const Addr TIMER_CNTV_CTL = 0x03C;
347 
348  protected: // Params
352 
353  protected:
358 };
359 
360 #endif // __DEV_ARM_GENERIC_TIMER_HH__
EventFunctionWrapper _counterLimitReachedEvent
void setFreq(uint32_t freq)
Sets the counter frequency.
AddrRangeList getAddrRanges() const override
Every PIO device is obliged to provide an implementation that returns the address ranges the device r...
uint64_t offset() const
uint64_t _counterLimit
Programmed limit value for the upcounter ({CNTP/CNTHP/CNTV}_CVAL).
std::vector< uint32_t > _freqTable
Frequency modes table with all possible frequencies for the counter.
const std::string & name()
Definition: trace.cc:54
EndBitUnion(UserDescFlags) struct UserDesc32
Definition: process.cc:160
ArmInterruptPin const * irqHyp
DrainState
Object drain/handover states.
Definition: drain.hh:71
Per-CPU architected timer.
CoreTimers(GenericTimer &parent, ArmSystem &system, unsigned cpu, ArmInterruptPin *_irqPhysS, ArmInterruptPin *_irqPhysNS, ArmInterruptPin *_irqVirt, ArmInterruptPin *_irqHyp)
uint32_t _regCntkctl
Kernel event stream control register.
ip6_addr_t addr
Definition: inet.hh:335
SystemCounter(std::vector< uint32_t > &freqs)
Base class for devices that use the MiscReg interfaces.
Definition: isa_device.hh:60
uint64_t RegVal
Definition: types.hh:168
uint32_t freq() const
Returns the counter frequency.
const AddrRangeList addrRanges
uint64_t value() const
Returns the current value of the physical counter.
Definition: cprintf.cc:42
ArmSystem & system
Bitfield< 1 > imask
ArmSystem & system
ARM system containing this timer.
Bitfield< 63 > val
Definition: misc.hh:771
ArchTimerCtrl _control
Value of the control register ({CNTP/CNTHP/CNTV}_CTL).
uint32_t getHypControl()
Tick _resetTick
Tick when the counter was reset.
Tick _period
Cached copy of the counter period (inverse of the frequency).
Interface for objects that might require draining before checkpointing.
Definition: drain.hh:223
The AddrRange class encapsulates an address range, and supports a number of tests to check if two ran...
Definition: addr_range.hh:72
Bitfield< 11 > enable
Definition: misc.hh:1053
Tick curTick()
The current simulated tick.
Definition: core.hh:47
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:162
bool scheduleEvents() override
const AddrRange ctrlRange
uint64_t Tick
Tick count type.
Definition: types.hh:63
SystemCounter systemCounter
System counter.
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
ArmInterruptPin const * irqPhysS
uint32_t getKernelControl()
static constexpr size_t MAX_FREQ_ENTRIES
Maximum architectural number of frequency table entries.
uint32_t _regCnthctl
Hypervisor event stream control register.
void setKernelControl(uint32_t val)
uint32_t timerValue() const
Returns the TimerValue view of the timer.
ArchTimer physTimer
This device is the base class which all devices senstive to an address range inherit from...
Definition: io_device.hh:102
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
virtual bool scheduleEvents()
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:255
Basic support for object serialization.
Definition: serialize.hh:153
Bitfield< 15 > system
Definition: misc.hh:999
ArchTimer virtTimer
ArmInterruptPin const * irqPhysNS
bool validKvmEnvironment() const
Verify gem5 configuration will support KVM emulation.
Definition: system.cc:410
std::string name() const
Returns the timer name.
Bitfield< 29 > c
Base class for ARM GIC implementations.
ArmInterruptPin const * irqVirt
std::ostream CheckpointOut
Definition: serialize.hh:68
void serialize(CheckpointOut &cp) const override
Serialize an object.
GenericTimer & parent
Bitfield< 2 > istatus
void unserialize(CheckpointIn &cp) override
Unserialize an object.
uint64_t compareValue() const
Returns the CompareValue view of the timer.
SystemCounter systemCounter
System counter.
void setHypControl(uint32_t val)
ArmInterruptPin *const _interrupt
GenericTimerISA(GenericTimer &_parent, unsigned _cpu)
std::vector< std::unique_ptr< CoreTimers > > timers
Per-CPU physical architected timers.
const AddrRange timerRange
BitUnion32(UserDescFlags) Bitfield< 0 > seg_32bit
Bitfield< 5 > t
SystemCounter & _systemCounter
ArchTimerKvm(const std::string &name, ArmSystem &system, SimObject &parent, SystemCounter &sysctr, ArmInterruptPin *interrupt)
uint32_t control() const
Sets the control register.
Global system counter.
Bitfield< 0 > p
Generic representation of an Arm interrupt pin.
Definition: base_gic.hh:178
Tick period() const
Returns the counter period.
Abstract superclass for simulation objects.
Definition: sim_object.hh:96
uint32_t _freq
Counter frequency (as specified by CNTFRQ).
uint64_t _offset
Offset relative to the physical timer (CNTVOFF)
EndBitUnion(ArchTimerCtrl) const std SimObject & _parent
Name of this timer.

Generated on Fri Feb 28 2020 16:27:00 for gem5 by doxygen 1.8.13