gem5 v24.0.0.0
Loading...
Searching...
No Matches
watchdog_sp805.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 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
39
40#include "base/logging.hh"
41#include "debug/Sp805.hh"
42#include "mem/packet_access.hh"
43#include "params/Sp805.hh"
44
45namespace gem5
46{
47
48Sp805::Sp805(const Sp805Params &params)
49 : AmbaIntDevice(params, 0x1000),
50 timeoutInterval(0xffffffff),
51 timeoutStartTick(MaxTick),
52 persistedValue(timeoutInterval),
53 enabled(false),
54 resetEnabled(false),
55 writeAccessEnabled(true),
56 integrationTestEnabled(false),
57 timeoutEvent([this] { timeoutExpired(); }, name())
58{
59}
60
61Tick
63{
64 const Addr addr = pkt->getAddr() - pioAddr;
65 const size_t size = pkt->getSize();
66 panic_if(size != 4, "Sp805::read: Invalid size %i\n", size);
67
68 uint64_t resp = 0;
69 switch (addr) {
70 case WDOGLOAD:
71 resp = timeoutInterval;
72 break;
73 case WDOGVALUE:
74 resp = value();
75 break;
76 case WDOGCONTROL:
77 resp = enabled | (resetEnabled << 1);
78 break;
79 case WDOGINTCLR:
80 warn("Sp805::read: WO reg (0x%x) [WDOGINTCLR]\n", addr);
81 break;
82 case WDOGRIS:
83 resp = interrupt->active();
84 break;
85 case WDOGMIS:
86 resp = interrupt->active() && enabled;
87 break;
88 case WDOGLOCK:
89 resp = writeAccessEnabled;
90 break;
91 case WDOGITCR:
93 break;
94 case WDOGITOP:
95 warn("Sp805::read: WO reg (0x%x) [WDOGITOP]\n", addr);
96 break;
97 default:
98 if (readId(pkt, ambaId, pioAddr))
99 resp = pkt->getUintX(ByteOrder::little);
100 else
101 warn("Sp805::read: Unexpected address (0x%x:%i), assuming RAZ\n",
102 addr, size);
103 }
104
105 DPRINTF(Sp805, "Sp805::read: 0x%x<-0x%x(%i)\n", resp, addr, size);
106
107 pkt->setUintX(resp, ByteOrder::little);
108 pkt->makeResponse();
109 return pioDelay;
110}
111
112Tick
114{
115 const Addr addr = pkt->getAddr() - pioAddr;
116 const size_t size = pkt->getSize();
117 panic_if(size != 4, "Sp805::write: Invalid size %i\n", size);
118
119 uint64_t data = pkt->getUintX(ByteOrder::little);
120 switch (addr) {
121 case WDOGLOAD:
122 if (writeAccessEnabled) {
123 // When WdogLoad is written 0x0, immediately trigger an interrupt
124 if (!timeoutInterval)
125 sendInt();
126 else
128 if (enabled)
130 }
131 break;
132 case WDOGVALUE:
133 warn("Sp805::write: RO reg (0x%x) [WDOGVALUE]\n", addr);
134 break;
135 case WDOGCONTROL:
136 if (writeAccessEnabled) {
137 bool was_enabled = enabled;
138 enabled = bits(data, 0);
139 resetEnabled = bits(data, 1);
140 // If watchdog becomes enabled, restart the counter
141 if (!was_enabled && enabled)
143 // If watchdog becomes disabled, stop the counter
144 else if (timeoutEvent.scheduled() && !enabled)
145 stopCounter();
146 }
147 break;
148 case WDOGINTCLR:
149 if (writeAccessEnabled) {
150 // Clear the interrupt and restart the counter if enabled
151 clearInt();
152 if (enabled)
154 }
155 break;
156 case WDOGRIS:
157 warn("Sp805::write: RO reg (0x%x) [WDOGRIS]\n", addr);
158 break;
159 case WDOGMIS:
160 warn("Sp805::write: RO reg (0x%x) [WDOGMIS]\n", addr);
161 break;
162 case WDOGLOCK:
164 break;
165 case WDOGITCR ... WDOGITOP:
166 warn("Sp805::write: No support for integration test harness\n");
167 break;
168 default:
169 warn("Sp805::write: Unexpected address (0x%x:%i), assuming WI\n",
170 addr, size);
171 }
172
173 DPRINTF(Sp805, "Sp805::write: 0x%x->0x%x(%i)\n", data, addr, size);
174
175 pkt->makeResponse();
176 return pioDelay;
177}
178
179uint32_t
186
187void
194
195void
201
202void
209
210void
212{
213 // If the previously sent interrupt has not been served,
214 // assert system reset if enabled
215 if (interrupt->active() && enabled) {
216 if (resetEnabled)
217 warn("Watchdog timed out, system reset asserted\n");
218 } else {
219 interrupt->raise();
220 }
221}
222
223void
225{
226 interrupt->clear();
227}
228
229void
245
246void
265
266} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:210
const char data[]
bool readId(PacketPtr pkt, uint64_t amba_id, Addr pio_addr)
ArmInterruptPin *const interrupt
virtual void clear()=0
Clear a signalled interrupt.
virtual void raise()=0
Signal an interrupt.
bool active() const
True if interrupt pin is active, false otherwise.
Definition base_gic.hh:219
Addr pioAddr
Address that the device listens to.
Definition io_device.hh:151
Tick pioDelay
Delay that the device experinces on an access.
Definition io_device.hh:157
Tick clockEdge(Cycles cycles=Cycles(0)) const
Determine the tick when a cycle begins, by default the current one, but the argument also enables the...
Tick clockPeriod() const
Cycles is a wrapper class for representing cycle counts, i.e.
Definition types.hh:79
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
Addr getAddr() const
Definition packet.hh:807
void setUintX(uint64_t w, ByteOrder endian)
Set the value in the word w after truncating it to the length of the packet and then byteswapping it ...
Definition packet.cc:361
void makeResponse()
Take a request packet and modify it in place to be suitable for returning as a response to that reque...
Definition packet.hh:1062
unsigned getSize() const
Definition packet.hh:817
uint64_t getUintX(ByteOrder endian) const
Get the data in the packet byte swapped from the specified endianness and zero-extended to 64 bits.
Definition packet.cc:352
bool integrationTestEnabled
Indicates if integration test harness is enabled.
uint32_t value(void) const
Returns the current counter value.
uint32_t persistedValue
Value as persisted when the watchdog is stopped.
static constexpr uint32_t WDOGLOCK_MAGIC
If written into WdogLock, registers are unlocked for writes.
bool resetEnabled
Indicates if reset behaviour is enabled when counter reaches 0.
void restartCounter(void)
Restarts the counter to the current timeout interval.
void stopCounter(void)
Stops the counter when watchdog becomes disabled.
void clearInt(void)
Clears any active interrupts.
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
void serialize(CheckpointOut &cp) const override
Serialize an object.
uint32_t timeoutInterval
Timeout interval (in cycles) as specified in WdogLoad.
void sendInt(void)
Raises an interrupt.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
bool enabled
Indicates if watchdog (counter and interrupt) is enabled.
Tick timeoutStartTick
Timeout start tick to keep track of the counter value.
void timeoutExpired(void)
Triggered when value reaches 0.
bool writeAccessEnabled
Indicates if write access to registers is enabled.
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
EventFunctionWrapper timeoutEvent
Timeout event, triggered when the counter value reaches 0.
Sp805(const Sp805Params &params)
constexpr T bits(T val, unsigned first, unsigned last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
Definition bitfield.hh:79
void deschedule(Event &event)
Definition eventq.hh:1021
bool scheduled() const
Determine if the current event is scheduled.
Definition eventq.hh:458
void reschedule(Event &event, Tick when, bool always=false)
Definition eventq.hh:1030
Tick when() const
Get the time that the event is scheduled.
Definition eventq.hh:501
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition logging.hh:214
#define warn(...)
Definition logging.hh:256
Bitfield< 3 > addr
Definition types.hh:84
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
Tick curTick()
The universal simulation clock.
Definition cur_tick.hh:46
std::ostream CheckpointOut
Definition serialize.hh:66
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
uint64_t Tick
Tick count type.
Definition types.hh:58
const Tick MaxTick
Definition types.hh:60
#define UNSERIALIZE_SCALAR(scalar)
Definition serialize.hh:575
#define SERIALIZE_SCALAR(scalar)
Definition serialize.hh:568
const std::string & name()
Definition trace.cc:48
Arm Watchdog Module (SP805) Reference: Arm Watchdog Module (SP805) - Technical Reference Manual - rev...

Generated on Tue Jun 18 2024 16:24:03 for gem5 by doxygen 1.11.0