38#ifndef __DEV_ARM_GENERIC_TIMER_HH__
39#define __DEV_ARM_GENERIC_TIMER_HH__
69struct SystemCounterParams;
70struct GenericTimerParams;
71struct GenericTimerFrameParams;
72struct GenericTimerMemParams;
191 const std::string _name;
226 std::string
name()
const {
return _name; }
246 uint64_t
value()
const;
251 void notify(
void)
override;
361 return ret_val + incr_val;
372 void notify(
void)
override;
500 AccessBits accessBits;
509 AccessBitsEl0 accessBitsEl0;
553 static const
Addr COUNTER_CTRL_CNTCR = 0x00;
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
Base class for ARM GIC implementations.
The AddrRange class encapsulates an address range, and supports a number of tests to check if two ran...
ArchTimerKvm(const std::string &name, ArmSystem &system, SimObject &parent, SystemCounter &sysctr, ArmInterruptPin *interrupt)
bool scheduleEvents() override
Per-CPU architected timer.
EventFunctionWrapper _counterLimitReachedEvent
void setTimerValue(uint32_t val)
Sets the TimerValue view of the timer.
uint32_t timerValue() const
Returns the TimerValue view of the timer.
virtual bool scheduleEvents()
DrainState drain() override
Draining is the process of clearing out the states of SimObjects.These are the SimObjects that are pa...
EndBitUnion(ArchTimerCtrl) const std SimObject & _parent
Name of this timer.
std::string name() const
Returns the timer name.
void drainResume() override
Resume execution after a successful drain.
uint64_t compareValue() const
Returns the CompareValue view of the timer.
uint64_t _offset
Offset relative to the physical timer (CNTVOFF)
void notify(void) override
Called from the SystemCounter when a change in counting speed occurred Events should be rescheduled p...
void setCompareValue(uint64_t val)
Sets the CompareValue view of the timer.
ArchTimer(const std::string &name, SimObject &parent, SystemCounter &sysctr, ArmInterruptPin *interrupt)
ArchTimerCtrl _control
Value of the control register ({CNTP/CNTHP/CNTV}_CTL).
void setOffset(uint64_t val)
void serialize(CheckpointOut &cp) const override
Serialize an object.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
uint64_t value() const
Returns the value of the counter which this timer relies on.
void setControl(uint32_t val)
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...
ArchTimer(const ArchTimer &t)
BitUnion32(ArchTimerCtrl) Bitfield< 0 > enable
Control register.
SystemCounter & _systemCounter
void counterLimitReached()
Called when the upcounter reaches the programmed value.
ArmInterruptPin *const _interrupt
uint64_t _counterLimit
Programmed limit value for the upcounter ({CNTP/CNTHP/CNTV}_CVAL).
Tick whenValue(uint64_t target_val)
Base class for devices that use the MiscReg interfaces.
Generic representation of an Arm interrupt pin.
Interface for objects that might require draining before checkpointing.
GenericTimerFrame(const GenericTimerFrameParams &p)
static const Addr TIMER_CNTP_CTL
void serialize(CheckpointOut &cp) const override
Serialize an object.
static const Addr TIMER_CNTV_TVAL
bool nonSecureAccess
Reports whether non-secure accesses are allowed to this frame.
bool hasVirtualTimer() const
Indicates if this frame implements a virtual timer.
uint64_t timerRead(Addr addr, size_t size, bool is_sec, bool to_el0) const
CNTBase/CNTEL0Base (Memory-mapped timer frame)
bool hasEl0View() const
Indicates if this frame implements a second EL0 view.
static const Addr TIMER_CNTP_CVAL_HI
void unserialize(CheckpointIn &cp) override
Unserialize an object.
BitUnion8(AccessBits) Bitfield< 5 > rwpt
Reports access properties of the CNTBase register frame elements.
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
static const Addr TIMER_CNTV_CVAL_LO
static const Addr TIMER_CNTVCT_LO
uint8_t getAccessBits() const
Returns the access bits for this frame.
static const Addr TIMER_CNTFRQ
SystemCounter & systemCounter
System counter reference.
bool hasNonSecureAccess() const
Indicates if non-secure accesses are allowed to this frame.
ArchTimer physTimer
Physical and virtual timers.
BitUnion16(AccessBitsEl0) Bitfield< 9 > pten
static const Addr TIMER_CNTP_CVAL_LO
void setAccessBits(uint8_t data)
Updates the access bits after a write to CNTCTLBase.CNTACR.
static const Addr TIMER_CNTV_CVAL_HI
void setVirtOffset(uint64_t new_offset)
Sets the virtual offset for this frame's virtual timer after a write to CNTVOFF.
const AddrRange timerRange
AddrRangeList getAddrRanges() const override
Every PIO device is obliged to provide an implementation that returns the address ranges the device r...
static const Addr TIMER_CNTP_TVAL
static const Addr TIMER_CNTVOFF_HI
static const Addr TIMER_CNTVCT_HI
AddrRangeList addrRanges
All MMIO ranges GenericTimerFrame responds to.
bool hasReadableVoff() const
Indicates if CNTVOFF is readable for this frame.
static const Addr TIMER_CNTPCT_LO
static const Addr TIMER_CNTVOFF_LO
static const Addr TIMER_CNTPCT_HI
EndBitUnion(AccessBits) AccessBits accessBits
uint64_t getVirtOffset() const
Returns the virtual offset for this frame if a virtual timer is implemented.
static const Addr TIMER_CNTEL0ACR
EndBitUnion(AccessBitsEl0) AccessBitsEl0 accessBitsEl0
void setNonSecureAccess()
Allows non-secure accesses after an enabling write to CNTCTLBase.CNTNSAR.
static const Addr TIMER_CNTV_CTL
void timerWrite(Addr addr, size_t size, uint64_t data, bool is_sec, bool to_el0)
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
RegVal readMiscReg(int misc_reg) override
Read a system register belonging to this device.
GenericTimerISA(GenericTimer &_parent, unsigned _cpu)
void setMiscReg(int misc_reg, RegVal val) override
Write to a system register belonging to this device.
void counterCtrlWrite(Addr addr, size_t size, uint64_t data, bool is_sec)
static const Addr COUNTER_CTRL_CNTID
BitUnion32(CNTCR) Bitfield< 17
uint64_t counterCtrlRead(Addr addr, size_t size, bool is_sec) const
CNTControlBase (System counter control frame)
const AddrRange timerCtrlRange
static const Addr TIMER_CTRL_CNTTIDR
static const Addr COUNTER_CTRL_CNTCV_HI
static const Addr COUNTER_CTRL_CNTFID
GenericTimerMem(const GenericTimerMemParams &p)
static const Addr COUNTER_CTRL_CNTCV_LO
void counterStatusWrite(Addr addr, size_t size, uint64_t data)
std::vector< GenericTimerFrame * > frames
Timer frame references.
static const Addr TIMER_CTRL_CNTFRQ
static const Addr COUNTER_STATUS_CNTCV_HI
static const Addr COUNTER_CTRL_CNTSCR
const AddrRange counterStatusRange
static const Addr TIMER_CTRL_CNTACR
uint64_t timerCtrlRead(Addr addr, size_t size, bool is_sec) const
CNTCTLBase (Memory-mapped timer global control frame)
const AddrRange counterCtrlRange
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
static const Addr TIMER_CTRL_CNTVOFF_LO
static void validateFrameRange(const AddrRange &range)
Validates a Generic Timer register frame address range.
uint64_t counterStatusRead(Addr addr, size_t size) const
CNTReadBase (System counter status frame)
static const Addr COUNTER_STATUS_CNTCV_LO
AddrRangeList getAddrRanges() const override
Every PIO device is obliged to provide an implementation that returns the address ranges the device r...
void timerCtrlWrite(Addr addr, size_t size, uint64_t data, bool is_sec)
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
uint32_t cnttidr
ID register for reporting features of implemented timer frames.
static const Addr COUNTER_CTRL_CNTSR
SystemCounter & systemCounter
System counter reference.
const AddrRangeList addrRanges
All MMIO ranges GenericTimerMem responds to.
static constexpr size_t MAX_TIMER_FRAMES
Maximum architectural number of memory-mapped timer frames.
static const Addr TIMER_CTRL_CNTNSAR
static bool validateAccessPerm(ArmSystem &sys, bool is_sec)
Validates an MMIO access permissions.
static const Addr TIMER_CTRL_CNTVOFF_HI
ThreadContext * threadContext
Thread (HW) context associated to this PE implementation.
ArmInterruptPin const * irqPhysNsEL2
GenericTimer & parent
Generic Timer parent reference.
ArmInterruptPin const * irqVirtSEL2
void notify(void) override
Called from the SystemCounter when a change in counting speed occurred Events should be rescheduled p...
void serialize(CheckpointOut &cp) const override
Serialize an object.
void schedNextEvent(EventStream &ev_stream, ArchTimer &timer)
ArmInterruptPin const * irqVirtEL1
void virtEventStreamCallback()
uint32_t cntfrq
System counter frequency as visible from this core.
void eventStreamCallback() const
ArmInterruptPin const * irqPhysEL3
ArmInterruptPin const * irqPhysSEL2
CoreTimers(const CoreTimers &c)
ArmInterruptPin const * irqVirtNsEL2
void unserialize(CheckpointIn &cp) override
Unserialize an object.
CoreTimers(GenericTimer &_parent, ArmSystem &system, unsigned cpu, ArmInterruptPin *irq_el3_phys, ArmInterruptPin *irq_el1_phys, ArmInterruptPin *irq_el1_virt, ArmInterruptPin *irq_el2_ns_phys, ArmInterruptPin *irq_el2_ns_virt, ArmInterruptPin *irq_el2_s_phys, ArmInterruptPin *irq_el2_s_virt)
ArmInterruptPin const * irqPhysEL1
ArmISA::CNTHCTL cnthctl
Hypervisor control register.
ArmISA::CNTKCTL cntkctl
Kernel control register.
void physEventStreamCallback()
std::vector< std::unique_ptr< CoreTimers > > timers
Per-CPU physical architected timers.
void serialize(CheckpointOut &cp) const override
Serialize an object.
void setMiscReg(int misc_reg, unsigned cpu, RegVal val)
CoreTimers & getTimers(int cpu_id)
RegVal readMiscReg(int misc_reg, unsigned cpu)
void unserialize(CheckpointIn &cp) override
Unserialize an object.
void createTimers(unsigned cpus)
SystemCounter & systemCounter
System counter reference.
void handleStream(CoreTimers::EventStream *ev_stream, ArchTimer *timer, RegVal old_cnt_ctl, RegVal cnt_ctl)
ArmSystem & system
ARM system containing this timer.
GenericTimer(const Params &p)
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
This device is the base class which all devices senstive to an address range inherit from.
Basic support for object serialization.
Abstract superclass for simulation objects.
Abstract class for elements whose events depend on the counting speed of the System Counter.
virtual void notify(void)=0
Called from the SystemCounter when a change in counting speed occurred Events should be rescheduled p...
void updateValue(void)
Updates the counter value.
uint32_t _freq
Counter frequency (as specified by CNTFRQ).
std::vector< uint32_t > _freqTable
Frequency modes table with all possible frequencies for the counter.
bool enabled() const
Indicates if the counter is enabled.
std::vector< SystemCounterListener * > _listeners
Listeners to changes in counting speed.
void setValue(uint64_t new_value)
Sets the value explicitly from writes to CNTCR.CNTCV.
Tick _period
Cached copy of the counter period (inverse of the frequency).
Tick whenValue(uint64_t target_val)
Returns the tick at which a certain counter value is reached.
SystemCounter(const SystemCounterParams &p)
EventFunctionWrapper _freqUpdateEvent
Frequency update event handling.
size_t activeFreqEntry() const
Returns the currently active frequency table entry.
static constexpr size_t MAX_FREQ_ENTRIES
Maximum architectural number of frequency table entries.
static void validateCounterRef(SystemCounter *sys_cnt)
Validates a System Counter reference.
void updateTick(void)
Updates the update tick, normalizes to the lower cycle start tick.
uint64_t value()
Updates and returns the counter value.
Tick period() const
Returns the counter period.
void disable()
Disables the counter after a CNTCR.EN == 0.
void notifyListeners(void) const
Notifies counting speed changes to listeners.
SystemCounter(const SystemCounter &c)
void serialize(CheckpointOut &cp) const override
Serialize an object.
std::vector< uint32_t > & freqTable()
Returns a reference to the frequency modes table.
void enable()
Enables the counter after a CNTCR.EN == 1.
uint64_t _value
Counter value (as specified in CNTCV).
uint64_t increment() const
Returns the value increment.
uint32_t freq() const
Returns the counter frequency.
void freqUpdateCallback()
Callback for the frequency update.
Tick _updateTick
Counter cycle start Tick when the counter status affecting its value has been updated.
uint64_t _increment
Value increment in each counter cycle.
size_t _activeFreqEntry
Currently selected entry in the table, its contents should match _freq.
void registerListener(SystemCounterListener *listener)
Called from System Counter Listeners to register.
void freqUpdateSchedule(size_t new_freq_entry)
Schedules a counter frequency update after a CNTCR.FCREQ == 1 This complies with frequency transition...
void unserialize(CheckpointIn &cp) override
Unserialize an object.
bool _enabled
Indicates if the counter is enabled.
ThreadContext is the external interface to all thread state for anything outside of the CPU.
constexpr T bits(T val, unsigned first, unsigned last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
constexpr T mbits(T val, unsigned first, unsigned last)
Mask off the given bits in place like bits() but without shifting.
#define EndBitUnion(name)
This closes off the class and union started by the above macro.
DrainState
Object drain/handover states.
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
std::ostream CheckpointOut
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
uint64_t Tick
Tick count type.
Overload hash function for BasicBlockRange type.
EventFunctionWrapper event
uint64_t eventTargetValue(uint64_t val) const