45 #include "debug/Timer.hh" 48 #include "params/GenericTimer.hh" 49 #include "params/GenericTimerMem.hh" 57 "frequency not provided\n");
61 "SystemCounter::SystemCounter: Architecture states a maximum of 1004 " 62 "frequency table entries, limit surpassed\n");
64 _freq = freqs.front();
73 warn_once(
"The frequency of the system counter has already been set");
110 : _name(name), _parent(parent), _systemCounter(sysctr),
111 _interrupt(interrupt),
112 _control(0), _counterLimit(0), _offset(0),
125 DPRINTF(Timer,
"Counter limit reached\n");
128 DPRINTF(Timer,
"Causing interrupt\n");
131 DPRINTF(Timer,
"Kvm mode; skipping simulated interrupt\n");
169 ArchTimerCtrl new_ctl =
val;
170 if ((new_ctl.enable && !new_ctl.imask) &&
176 DPRINTF(Timer,
"Causing interrupt in control\n");
236 systemCounter(p->freqs),
239 fatal_if(!p->system,
"No system specified, can't instantiate timer.\n");
243 const GenericTimerParams *
246 return dynamic_cast<const GenericTimerParams *
>(
_params);
256 for (
int i = 0;
i <
timers.size(); ++
i) {
276 static const unsigned OLD_CPU_MAX = 8;
279 warn(
"Checkpoint does not contain CPU count, assuming %i CPUs\n",
281 cpu_count = OLD_CPU_MAX;
284 for (
int i = 0;
i < cpu_count; ++
i) {
299 if (cpu_id >=
timers.size())
308 assert(
timers.size() < cpus);
309 auto p =
static_cast<const GenericTimerParams *
>(
_params);
311 const unsigned old_cpu_count(
timers.size());
313 for (
unsigned i = old_cpu_count;
i < cpus; ++
i) {
319 p->int_phys_s->get(tc),
320 p->int_phys_ns->get(tc),
321 p->int_virt->get(tc),
322 p->int_hyp->get(tc)));
369 warn(
"Ignoring write to read only count register: %s\n",
527 parent.setMiscReg(reg, cpu, val);
533 RegVal value = parent.readMiscReg(reg, cpu);
542 sys->getPageBytes())),
570 unsigned timer_count;
574 if (timer_count != 1)
575 panic(
"Incompatible checkpoint: Only one set of timers supported");
584 const unsigned size(pkt->
getSize());
597 DPRINTF(Timer,
"Read 0x%x <- 0x%x(%i)\n", value,
addr, size);
600 pkt->
setLE<uint64_t>(value);
601 }
else if (size == 4) {
602 pkt->
setLE<uint32_t>(value);
604 panic(
"Unexpected access size: %i\n", size);
613 const unsigned size(pkt->
getSize());
614 if (size != 8 && size != 4)
615 panic(
"Unexpected access size\n");
618 const uint64_t value(size == 8 ?
619 pkt->
getLE<uint64_t>() : pkt->
getLE<uint32_t>());
621 DPRINTF(Timer,
"Write 0x%x -> 0x%x(%i)\n", value,
addr, size);
647 warn(
"Reading from unimplemented control register (0x%x)\n", addr);
657 warn(
"Unexpected address (0x%x:%i), assuming RAZ\n", addr, size);
660 }
else if (size == 8) {
666 warn(
"Unexpected address (0x%x:%i), assuming RAZ\n", addr, size);
670 panic(
"Invalid access size: %i\n", size);
683 warn(
"Write to unimplemented control register (0x%x)\n", addr);
697 warn(
"Ignoring write to unexpected address (0x%x:%i)\n",
701 }
else if (size == 8) {
708 warn(
"Ignoring write to unexpected address (0x%x:%i)\n",
713 panic(
"Invalid access size: %i\n", size);
738 warn(
"Read from unimplemented timer register (0x%x)\n", addr);
772 warn(
"Unexpected address (0x%x:%i), assuming RAZ\n", addr, size);
775 }
else if (size == 8) {
793 warn(
"Unexpected address (0x%x:%i), assuming RAZ\n", addr, size);
797 panic(
"Invalid access size: %i\n", size);
807 warn(
"Unimplemented timer register (0x%x)\n", addr);
847 warn(
"Unexpected address (0x%x:%i), ignoring write\n", addr, size);
850 }
else if (size == 8) {
859 warn(
"Unexpected address (0x%x:%i), ignoring write\n", addr, size);
863 panic(
"Invalid access size: %i\n", size);
868 GenericTimerParams::create()
874 GenericTimerMemParams::create()
void unserialize(CheckpointIn &cp) override
Unserialize an object.
ArchTimer(const std::string &name, SimObject &parent, SystemCounter &sysctr, ArmInterruptPin *interrupt)
void setMiscReg(int misc_reg, RegVal val) override
Write to a system register belonging to this device.
#define panic(...)
This implements a cprintf based panic() function.
EventFunctionWrapper _counterLimitReachedEvent
AddrRange RangeSize(Addr start, Addr size)
void setFreq(uint32_t freq)
Sets the counter frequency.
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.
void setMiscReg(int misc_reg, unsigned cpu, RegVal val)
uint64_t ctrlRead(Addr addr, size_t size) const
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)
const std::string & name()
void serializeSection(CheckpointOut &cp, const char *name) const
Serialize an object into a new section.
This module implements the global system counter and the local per-CPU architected timers as specifie...
DrainState
Object drain/handover states.
static const Addr TIMER_CNTP_TVAL
DrainState drain() override
Notify an object that it needs to drain its state.
#define UNSERIALIZE_OPT_SCALAR(scalar)
RegVal readMiscReg(int misc_reg, unsigned cpu)
void unserializeSection(CheckpointIn &cp, const char *name)
Unserialize an a child object.
static const Addr TIMER_CNTV_CVAL_LO
uint32_t _regCntkctl
Kernel event stream control register.
bool contains(const Addr &a) const
Determine if the range contains an address.
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
SystemCounter(std::vector< uint32_t > &freqs)
void timerWrite(Addr addr, size_t size, uint64_t value)
uint64_t value() const
Returns the value of the counter which this timer relies on.
uint32_t freq() const
Returns the counter frequency.
const char *const miscRegName[]
uint64_t value() const
Returns the current value of the physical counter.
GenericTimerMem(GenericTimerMemParams *p)
Tick Frequency
The simulated frequency of curTick(). (In ticks per second)
ThreadContext is the external interface to all thread state for anything outside of the CPU...
ArmSystem & system
ARM system containing this timer.
void setTimerValue(uint32_t val)
Sets the TimerValue view of the timer.
void deschedule(Event &event)
const GenericTimerParams * params() const
void setGenericTimer(GenericTimer *generic_timer)
Sets the pointer to the Generic Timer.
ArchTimerCtrl _control
Value of the control register ({CNTP/CNTHP/CNTV}_CTL).
void setLE(T v)
Set the value in the data pointer to v as little endian.
static const Addr TIMER_CNTV_CTL
ThreadContext * getThreadContext(ContextID tid) const
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 timerRead(Addr addr, size_t size) const
#define UNSERIALIZE_SCALAR(scalar)
void setOffset(uint64_t val)
Tick curTick()
The current simulated tick.
std::string csprintf(const char *format, const Args &...args)
bool scheduled() const
Determine if the current event is scheduled.
void serialize(CheckpointOut &cp) const override
Serialize an object.
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.
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
void paramOut(CheckpointOut &cp, const string &name, ExtMachInst const &machInst)
void setCompareValue(uint64_t val)
Sets the CompareValue view of the timer.
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)
static const Addr CTRL_CNTACR_BASE
uint32_t timerValue() const
Returns the TimerValue view of the timer.
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
void ctrlWrite(Addr addr, size_t size, uint64_t value)
T insertBits(T val, int first, int last, B bit_val)
Returns val with bits first to last set to the LSBs of 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.
Draining buffers pending serialization/handover.
virtual bool scheduleEvents()
virtual const std::string name() const
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
RegVal readMiscReg(int misc_reg) override
Read a system register belonging to this device.
#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...
std::string name() const
Returns the timer name.
Base class for ARM GIC implementations.
static const Addr TIMER_CNTPCT_LO
static const Addr CTRL_CNTTIDR
virtual void raise()=0
Signal an interrupt.
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.
const SimObjectParams * _params
Cached copy of the object parameters.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
uint64_t compareValue() const
Returns the CompareValue view of the timer.
static const Addr CTRL_CNTNSAR
void schedule(Event &event, Tick when)
void drainResume() override
Resume execution after a successful drain.
void paramIn(CheckpointIn &cp, const string &name, ExtMachInst &machInst)
SystemCounter systemCounter
System counter.
void setHypControl(uint32_t val)
ArmInterruptPin *const _interrupt
T getLE() const
Get the data in the packet byte swapped from little endian to host endian.
Addr start() const
Get the start address of the range.
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
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
static const Addr TIMER_CNTVCT_HI
uint32_t control() const
Sets the control register.
void updateCounter()
Timer settings or the offset has changed, re-evaluate trigger condition and raise interrupt if necess...
static const Addr TIMER_CNTPCT_HI
Generic representation of an Arm interrupt pin.
Tick period() const
Returns the counter period.
Abstract superclass for simulation objects.
uint32_t _freq
Counter frequency (as specified by CNTFRQ).
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.