gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
generic_timer.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013, 2015 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  */
40 
41 #ifndef __DEV_ARM_GENERIC_TIMER_HH__
42 #define __DEV_ARM_GENERIC_TIMER_HH__
43 
44 #include "arch/arm/isa_device.hh"
45 #include "base/bitunion.hh"
46 #include "dev/arm/base_gic.hh"
47 #include "sim/core.hh"
48 #include "sim/sim_object.hh"
49 
54 
55 class Checkpoint;
56 class GenericTimerParams;
57 class GenericTimerMemParams;
58 
62 {
63  protected:
65  uint64_t _freq;
70 
71  uint32_t _regCntkctl;
72 
73  public:
74  SystemCounter();
75 
77  uint64_t value() const
78  {
79  if (_freq == 0)
80  return 0; // Counter is still off.
81  return (curTick() - _resetTick) / _period;
82  }
83 
85  uint64_t freq() const { return _freq; }
88  void setFreq(uint32_t freq);
89 
91  Tick period() const { return _period; }
92 
93  void setKernelControl(uint32_t val) { _regCntkctl = val; }
94  uint32_t getKernelControl() { return _regCntkctl; }
95 
96  void serialize(CheckpointOut &cp) const override;
97  void unserialize(CheckpointIn &cp) override;
98 
99  private:
100  // Disable copying
101  SystemCounter(const SystemCounter &c);
102 };
103 
105 class ArchTimer : public Serializable
106 {
107  public:
108  class Interrupt
109  {
110  public:
111  Interrupt(BaseGic &gic, unsigned irq)
112  : _gic(gic), _ppi(false), _irq(irq), _cpu(0) {}
113 
114  Interrupt(BaseGic &gic, unsigned irq, unsigned cpu)
115  : _gic(gic), _ppi(true), _irq(irq), _cpu(cpu) {}
116 
117  void send();
118  void clear();
119 
120  private:
122  const bool _ppi;
123  const unsigned _irq;
124  const unsigned _cpu;
125  };
126 
127  protected:
129  BitUnion32(ArchTimerCtrl)
130  Bitfield<0> enable;
131  Bitfield<1> imask;
132  Bitfield<2> istatus;
133  EndBitUnion(ArchTimerCtrl)
134 
136  const std::string _name;
137 
140 
142 
144 
146  ArchTimerCtrl _control;
148  uint64_t _counterLimit;
150  uint64_t _offset;
151 
156  void updateCounter();
157 
159  void counterLimitReached();
160  EventWrapper<ArchTimer, &ArchTimer::counterLimitReached>
162 
163  public:
164  ArchTimer(const std::string &name,
165  SimObject &parent,
166  SystemCounter &sysctr,
167  const Interrupt &interrupt);
168 
170  std::string name() const { return _name; }
171 
173  uint64_t compareValue() const { return _counterLimit; }
175  void setCompareValue(uint64_t val);
176 
178  uint32_t timerValue() const { return _counterLimit - value(); }
180  void setTimerValue(uint32_t val);
181 
183  uint32_t control() const { return _control; }
184  void setControl(uint32_t val);
185 
186  uint64_t offset() const { return _offset; }
187  void setOffset(uint64_t val);
188 
190  uint64_t value() const;
191 
192  void serialize(CheckpointOut &cp) const override;
193  void unserialize(CheckpointIn &cp) override;
194 
195  private:
196  // Disable copying
197  ArchTimer(const ArchTimer &t);
198 };
199 
200 class GenericTimer : public SimObject
201 {
202  public:
203  GenericTimer(GenericTimerParams *p);
204 
205  void serialize(CheckpointOut &cp) const override;
206  void unserialize(CheckpointIn &cp) override;
207 
208  public:
209  void setMiscReg(int misc_reg, unsigned cpu, ArmISA::MiscReg val);
210  ArmISA::MiscReg readMiscReg(int misc_reg, unsigned cpu);
211 
212  protected:
213  struct CoreTimers {
214  CoreTimers(GenericTimer &parent, unsigned cpu,
215  unsigned _irqPhys, unsigned _irqVirt)
216  : irqPhys(*parent.gic, _irqPhys, cpu),
217  irqVirt(*parent.gic, _irqVirt, cpu),
218  // This should really be phys_timerN, but we are stuck with
219  // arch_timer for backwards compatibility.
220  phys(csprintf("%s.arch_timer%d", parent.name(), cpu),
221  parent, parent.systemCounter,
222  irqPhys),
223  virt(csprintf("%s.virt_timer%d", parent.name(), cpu),
224  parent, parent.systemCounter,
225  irqVirt)
226  {}
227 
230 
233 
234  private:
235  // Disable copying
236  CoreTimers(const CoreTimers &c);
237  };
238 
239  CoreTimers &getTimers(int cpu_id);
240  void createTimers(unsigned cpus);
241 
244 
247 
248  protected: // Configuration
250  BaseGic *const gic;
251 
253  const unsigned irqPhys;
254 
256  const unsigned irqVirt;
257 };
258 
260 {
261  public:
262  GenericTimerISA(GenericTimer &_parent, unsigned _cpu)
263  : parent(_parent), cpu(_cpu) {}
264 
265  void setMiscReg(int misc_reg, ArmISA::MiscReg val) override {
266  parent.setMiscReg(misc_reg, cpu, val);
267  }
268  ArmISA::MiscReg readMiscReg(int misc_reg) override {
269  return parent.readMiscReg(misc_reg, cpu);
270  }
271 
272  protected:
274  unsigned cpu;
275 };
276 
278 {
279  public:
280  GenericTimerMem(GenericTimerMemParams *p);
281 
282  void serialize(CheckpointOut &cp) const override;
283  void unserialize(CheckpointIn &cp) override;
284 
285  public: // PioDevice
286  AddrRangeList getAddrRanges() const override { return addrRanges; }
287  Tick read(PacketPtr pkt) override;
288  Tick write(PacketPtr pkt) override;
289 
290  protected:
291  uint64_t ctrlRead(Addr addr, size_t size) const;
292  void ctrlWrite(Addr addr, size_t size, uint64_t value);
293 
294  uint64_t timerRead(Addr addr, size_t size) const;
295  void timerWrite(Addr addr, size_t size, uint64_t value);
296 
297  protected: // Registers
298  static const Addr CTRL_CNTFRQ = 0x000;
299  static const Addr CTRL_CNTNSAR = 0x004;
300  static const Addr CTRL_CNTTIDR = 0x008;
301  static const Addr CTRL_CNTACR_BASE = 0x040;
302  static const Addr CTRL_CNTVOFF_LO_BASE = 0x080;
303  static const Addr CTRL_CNTVOFF_HI_BASE = 0x084;
304 
305  static const Addr TIMER_CNTPCT_LO = 0x000;
306  static const Addr TIMER_CNTPCT_HI = 0x004;
307  static const Addr TIMER_CNTVCT_LO = 0x008;
308  static const Addr TIMER_CNTVCT_HI = 0x00C;
309  static const Addr TIMER_CNTFRQ = 0x010;
310  static const Addr TIMER_CNTEL0ACR = 0x014;
311  static const Addr TIMER_CNTVOFF_LO = 0x018;
312  static const Addr TIMER_CNTVOFF_HI = 0x01C;
313  static const Addr TIMER_CNTP_CVAL_LO = 0x020;
314  static const Addr TIMER_CNTP_CVAL_HI = 0x024;
315  static const Addr TIMER_CNTP_TVAL = 0x028;
316  static const Addr TIMER_CNTP_CTL = 0x02C;
317  static const Addr TIMER_CNTV_CVAL_LO = 0x030;
318  static const Addr TIMER_CNTV_CVAL_HI = 0x034;
319  static const Addr TIMER_CNTV_TVAL = 0x038;
320  static const Addr TIMER_CNTV_CTL = 0x03C;
321 
322  protected: // Params
326 
327  protected:
332 };
333 
334 #endif // __DEV_ARM_GENERIC_TIMER_HH__
void unserialize(CheckpointIn &cp) override
Unserialize an object.
uint64_t timerRead(Addr addr, size_t size) const
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 _counterLimit
Programmed limit value for the upcounter ({CNTP/CNTHP/CNTV}_CVAL).
const unsigned _irq
ArchTimer::Interrupt irqVirt
Tick period() const
Returns the counter period.
GenericTimer(GenericTimerParams *p)
CoreTimers(GenericTimer &parent, unsigned cpu, unsigned _irqPhys, unsigned _irqVirt)
void unserialize(CheckpointIn &cp) override
Unserialize an object.
static const Addr TIMER_CNTVCT_LO
ArmISA::MiscReg readMiscReg(int misc_reg) override
Read a system register belonging to this device.
static const Addr TIMER_CNTFRQ
CoreTimers & getTimers(int cpu_id)
EndBitUnion(UserDescFlags) struct UserDesc32
Definition: process.cc:123
static const Addr TIMER_CNTP_TVAL
uint64_t compareValue() const
Returns the CompareValue view of the timer.
Per-CPU architected timer.
uint64_t MiscReg
Definition: registers.hh:70
static const Addr TIMER_CNTV_CVAL_LO
uint32_t _regCntkctl
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
ip6_addr_t addr
Definition: inet.hh:335
void timerWrite(Addr addr, size_t size, uint64_t value)
BitUnion32(ArchTimerCtrl) Bitfield< 0 > enable
Control register.
Base class for devices that use the MiscReg interfaces.
Definition: isa_device.hh:58
void setMiscReg(int misc_reg, unsigned cpu, ArmISA::MiscReg val)
const AddrRangeList addrRanges
GenericTimerMem(GenericTimerMemParams *p)
Bitfield< 1 > imask
const unsigned irqVirt
Virtual timer interrupt.
STL vector class.
Definition: stl.hh:40
void setTimerValue(uint32_t val)
Sets the TimerValue view of the timer.
Bitfield< 63 > val
Definition: misc.hh:770
ArchTimerCtrl _control
Value of the control register ({CNTP/CNTHP/CNTV}_CTL).
static const Addr TIMER_CNTV_CTL
ArmISA::MiscReg readMiscReg(int misc_reg, unsigned cpu)
void counterLimitReached()
Called when the upcounter reaches the programmed value.
Tick _resetTick
Tick when the counter was reset.
Tick _period
Cached copy of the counter period (inverse of the frequency).
The AddrRange class encapsulates an address range, and supports a number of tests to check if two ran...
Definition: addr_range.hh:72
static const Addr CTRL_CNTVOFF_HI_BASE
uint64_t _freq
Counter frequency (as specified by CNTFRQ).
void setOffset(uint64_t val)
Bitfield< 11 > enable
Definition: misc.hh:1004
const unsigned _cpu
Tick curTick()
The current simulated tick.
Definition: core.hh:47
Interrupt(BaseGic &gic, unsigned irq, unsigned cpu)
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:161
EventWrapper< ArchTimer,&ArchTimer::counterLimitReached > _counterLimitReachedEvent
uint64_t value() const
Returns the current value of the physical counter.
void serialize(CheckpointOut &cp) const override
Serialize an object.
const unsigned irqPhys
Physical timer interrupt.
static const Addr TIMER_CNTVOFF_LO
std::string name() const
Returns the timer name.
const AddrRange ctrlRange
uint64_t Tick
Tick count type.
Definition: types.hh:63
SystemCounter systemCounter
System counter.
void createTimers(unsigned cpus)
void serialize(CheckpointOut &cp) const override
Serialize an object.
uint32_t timerValue() const
Returns the TimerValue view of the timer.
void setCompareValue(uint64_t val)
Sets the CompareValue view of the timer.
uint64_t ctrlRead(Addr addr, size_t size) const
uint32_t getKernelControl()
void setKernelControl(uint32_t val)
static const Addr CTRL_CNTACR_BASE
void ctrlWrite(Addr addr, size_t size, uint64_t value)
ArchTimer physTimer
This device is the base class which all devices senstive to an address range inherit from...
Definition: io_device.hh:84
STL list class.
Definition: stl.hh:54
static const Addr TIMER_CNTEL0ACR
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:245
Basic support for object serialization.
Definition: serialize.hh:220
Interrupt _interrupt
ArchTimer virtTimer
cbk_int func interrupt
Definition: gpu_nomali.cc:94
ArchTimer::Interrupt irqPhys
int size()
Definition: pagetable.hh:146
Bitfield< 1 > irq
Definition: miscregs.hh:1520
virtual const std::string name() const
Definition: sim_object.hh:117
Bitfield< 29 > c
Definition: miscregs.hh:1365
Base class for ARM GIC implementations.
static const Addr TIMER_CNTPCT_LO
static const Addr CTRL_CNTTIDR
void serialize(CheckpointOut &cp) const override
Serialize an object.
std::ostream CheckpointOut
Definition: serialize.hh:67
static const Addr TIMER_CNTP_CTL
Interrupt(BaseGic &gic, unsigned irq)
void serialize(CheckpointOut &cp) const override
Serialize an object.
GenericTimer & parent
Bitfield< 2 > istatus
static const Addr TIMER_CNTP_CVAL_LO
static const Addr TIMER_CNTV_TVAL
static const Addr TIMER_CNTP_CVAL_HI
void unserialize(CheckpointIn &cp) override
Unserialize an object.
uint64_t offset() const
void unserialize(CheckpointIn &cp) override
Unserialize an object.
static const Addr CTRL_CNTNSAR
SystemCounter systemCounter
System counter.
uint64_t value() const
Returns the value of the counter which this timer relies on.
GenericTimerISA(GenericTimer &_parent, unsigned _cpu)
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
uint32_t control() const
Sets the control register.
ArchTimer(const std::string &name, SimObject &parent, SystemCounter &sysctr, const Interrupt &interrupt)
static const Addr TIMER_CNTVOFF_HI
void setMiscReg(int misc_reg, ArmISA::MiscReg val) override
Write to a system register belonging to this device.
void setControl(uint32_t val)
std::vector< std::unique_ptr< CoreTimers > > timers
Per-CPU physical architected timers.
BaseGic *const gic
Pointer to the GIC, needed to trigger timer interrupts.
const AddrRange timerRange
Bitfield< 5 > t
Definition: miscregs.hh:1382
static const Addr TIMER_CNTV_CVAL_HI
static const Addr CTRL_CNTFRQ
SystemCounter & _systemCounter
static const Addr TIMER_CNTVCT_HI
void updateCounter()
Timer settings or the offset has changed, re-evaluate trigger condition and raise interrupt if necess...
Global system counter.
Bitfield< 0 > p
static const Addr TIMER_CNTPCT_HI
Abstract superclass for simulation objects.
Definition: sim_object.hh:94
uint64_t _offset
Offset relative to the physical timer (CNTVOFF)
static const Addr CTRL_CNTVOFF_LO_BASE
EndBitUnion(ArchTimerCtrl) const std SimObject & _parent
Name of this timer.
uint64_t freq() const
Returns the counter frequency.

Generated on Fri Jun 9 2017 13:03:45 for gem5 by doxygen 1.8.6