44 #include "debug/Timer.hh"
47 #include "params/GenericTimer.hh"
48 #include "params/GenericTimerMem.hh"
51 : _freq(0), _period(0), _resetTick(0), _regCntkctl(0)
61 warn_once(
"The frequency of the system counter has already been set");
95 : _name(name), _parent(parent), _systemCounter(sysctr),
96 _interrupt(interrupt),
97 _control(0), _counterLimit(0), _offset(0),
98 _counterLimitReachedEvent(this)
110 DPRINTF(Timer,
"Counter limit reached\n");
112 DPRINTF(Timer,
"Causing interrupt\n");
148 ArchTimerCtrl new_ctl =
val;
149 if ((new_ctl.enable && !new_ctl.imask) &&
155 DPRINTF(Timer,
"Causing interrupt in control\n");
185 if (event_scheduled) {
200 bool event_scheduled;
202 if (event_scheduled) {
224 _gic.clearPPInt(_irq, _cpu);
234 irqPhys(p->int_phys),
237 fatal_if(!p->system,
"No system specified, can't instantiate timer.\n");
238 p->system->setGenericTimer(
this);
248 for (
int i = 0;
i <
timers.size(); ++
i) {
266 static const unsigned OLD_CPU_MAX = 8;
269 warn(
"Checkpoint does not contain CPU count, assuming %i CPUs\n",
271 cpu_count = OLD_CPU_MAX;
274 for (
int i = 0;
i < cpu_count; ++
i) {
287 if (cpu_id >=
timers.size())
296 assert(
timers.size() < cpus);
298 const unsigned old_cpu_count(
timers.size());
300 for (
unsigned i = old_cpu_count;
i < cpus; ++
i) {
352 warn(
"Ignoring write to read only count register: %s\n",
393 warn(
"Writing to unimplemented register: %s\n",
479 warn(
"Reading from unimplemented register: %s\n",
499 *
this, systemCounter,
502 *
this, systemCounter,
523 unsigned timer_count;
527 if (timer_count != 1)
528 panic(
"Incompatible checkpoint: Only one set of timers supported");
553 pkt->
set<uint64_t>(value);
554 }
else if (
size == 4) {
555 pkt->
set<uint32_t>(value);
557 panic(
"Unexpected access size: %i\n",
size);
568 panic(
"Unexpected access size\n");
571 const uint64_t value(
size == 8 ?
572 pkt->
get<uint64_t>() : pkt->
get<uint32_t>());
600 warn(
"Reading from unimplemented control register (0x%x)\n", addr);
610 warn(
"Unexpected address (0x%x:%i), assuming RAZ\n", addr, size);
613 }
else if (size == 8) {
619 warn(
"Unexpected address (0x%x:%i), assuming RAZ\n", addr, size);
623 panic(
"Invalid access size: %i\n", size);
636 warn(
"Write to unimplemented control register (0x%x)\n", addr);
650 warn(
"Ignoring write to unexpected address (0x%x:%i)\n",
654 }
else if (size == 8) {
661 warn(
"Ignoring write to unexpected address (0x%x:%i)\n",
666 panic(
"Invalid access size: %i\n", size);
691 warn(
"Read from unimplemented timer register (0x%x)\n", addr);
725 warn(
"Unexpected address (0x%x:%i), assuming RAZ\n", addr, size);
728 }
else if (size == 8) {
746 warn(
"Unexpected address (0x%x:%i), assuming RAZ\n", addr, size);
750 panic(
"Invalid access size: %i\n", size);
760 warn(
"Unimplemented timer register (0x%x)\n", addr);
800 warn(
"Unexpected address (0x%x:%i), ignoring write\n", addr, size);
803 }
else if (size == 8) {
812 warn(
"Unexpected address (0x%x:%i), ignoring write\n", addr, size);
816 panic(
"Invalid access size: %i\n", size);
821 GenericTimerParams::create()
827 GenericTimerMemParams::create()
void unserialize(CheckpointIn &cp) override
Unserialize an object.
AddrRange RangeSize(Addr start, Addr size)
uint64_t timerRead(Addr addr, size_t size) const
void setFreq(uint32_t freq)
Sets the counter frequency.
uint64_t _counterLimit
Programmed limit value for the upcounter ({CNTP/CNTHP/CNTV}_CVAL).
void set(T v, ByteOrder endian)
Set the value in the data pointer to v using the specified endianness.
Tick period() const
Returns the counter period.
GenericTimer(GenericTimerParams *p)
void unserialize(CheckpointIn &cp) override
Unserialize an object.
static const Addr TIMER_CNTVCT_LO
static const Addr TIMER_CNTFRQ
CoreTimers & getTimers(int cpu_id)
Addr start() const
Get the start address of the range.
const std::string & name()
This module implements the global system counter and the local per-CPU architected timers as specifie...
static const Addr TIMER_CNTP_TVAL
uint64_t compareValue() const
Returns the CompareValue view of the timer.
#define UNSERIALIZE_OPT_SCALAR(scalar)
void unserializeSection(CheckpointIn &cp, const char *name)
Unserialize an a child object.
static const Addr TIMER_CNTV_CVAL_LO
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
bool scheduled() const
Determine if the current event is scheduled.
void timerWrite(Addr addr, size_t size, uint64_t value)
void setMiscReg(int misc_reg, unsigned cpu, ArmISA::MiscReg val)
bool contains(const Addr &a) const
Determine if the range contains an address.
const char *const miscRegName[]
GenericTimerMem(GenericTimerMemParams *p)
Tick Frequency
The simulated frequency of curTick(). (In ticks per second)
const unsigned irqVirt
Virtual timer interrupt.
void setTimerValue(uint32_t val)
Sets the TimerValue view of the timer.
void deschedule(Event &event)
T get(ByteOrder endian) const
Get the data in the packet byte swapped from the specified endianness.
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).
static const Addr CTRL_CNTVOFF_HI_BASE
uint64_t _freq
Counter frequency (as specified by CNTFRQ).
#define UNSERIALIZE_SCALAR(scalar)
void setOffset(uint64_t val)
Tick curTick()
The current simulated tick.
Temporarily migrate execution to a different event queue.
std::string csprintf(const char *format, const Args &...args)
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.
virtual void sendPPInt(uint32_t num, uint32_t cpu)=0
Interface call for private peripheral interrupts.
Tick when() const
Get the time that the event is scheduled.
virtual void sendInt(uint32_t num)=0
Post an interrupt from a device that is connected to the GIC.
const unsigned irqPhys
Physical timer interrupt.
const AddrRange ctrlRange
uint64_t Tick
Tick count type.
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 paramOut(CheckpointOut &cp, const string &name, ExtMachInst const &machInst)
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 serializeSection(CheckpointOut &cp, const char *name) const
Serialize an object into a new section.
void setKernelControl(uint32_t val)
static const Addr CTRL_CNTACR_BASE
void ctrlWrite(Addr addr, size_t size, uint64_t value)
T insertBits(T val, int first, int last, B bit_val)
Return val with bits first to last set to bit_val.
This device is the base class which all devices senstive to an address range inherit from...
static const Addr TIMER_CNTEL0ACR
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
EventQueue * eventQueue() const
#define SERIALIZE_SCALAR(scalar)
void makeResponse()
Take a request packet and modify it in place to be suitable for returning as a response to that reque...
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
static const Addr TIMER_CNTP_CTL
void serialize(CheckpointOut &cp) const override
Serialize an object.
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.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
static const Addr CTRL_CNTNSAR
void schedule(Event &event, Tick when)
void paramIn(CheckpointIn &cp, const string &name, ExtMachInst &machInst)
SystemCounter systemCounter
System counter.
uint64_t value() const
Returns the value of the counter which this timer relies on.
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)
void setControl(uint32_t val)
std::vector< std::unique_ptr< CoreTimers > > timers
Per-CPU physical architected timers.
const AddrRange timerRange
static const Addr TIMER_CNTV_CVAL_HI
static const Addr CTRL_CNTFRQ
SystemCounter & _systemCounter
fatal_if(p->js_features.size() > 16,"Too many job slot feature registers specified (%i)\n", p->js_features.size())
static const Addr TIMER_CNTVCT_HI
void updateCounter()
Timer settings or the offset has changed, re-evaluate trigger condition and raise interrupt if necess...
static const Addr TIMER_CNTPCT_HI
Abstract superclass for simulation objects.
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.