gem5  v20.1.0.0
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 
45 Sp805::Sp805(Sp805Params const* params)
46  : AmbaIntDevice(params, 0x1000),
47  timeoutInterval(0xffffffff),
48  timeoutStartTick(MaxTick),
49  persistedValue(timeoutInterval),
50  enabled(false),
51  resetEnabled(false),
52  writeAccessEnabled(true),
53  integrationTestEnabled(false),
54  timeoutEvent([this] { timeoutExpired(); }, name())
55 {
56 }
57 
58 Tick
60 {
61  const Addr addr = pkt->getAddr() - pioAddr;
62  const size_t size = pkt->getSize();
63  panic_if(size != 4, "Sp805::read: Invalid size %i\n", size);
64 
65  uint64_t resp = 0;
66  switch (addr) {
67  case WDOGLOAD:
68  resp = timeoutInterval;
69  break;
70  case WDOGVALUE:
71  resp = value();
72  break;
73  case WDOGCONTROL:
74  resp = enabled | (resetEnabled << 1);
75  break;
76  case WDOGINTCLR:
77  warn("Sp805::read: WO reg (0x%x) [WDOGINTCLR]\n", addr);
78  break;
79  case WDOGRIS:
80  resp = interrupt->active();
81  break;
82  case WDOGMIS:
83  resp = interrupt->active() && enabled;
84  break;
85  case WDOGLOCK:
86  resp = writeAccessEnabled;
87  break;
88  case WDOGITCR:
90  break;
91  case WDOGITOP:
92  warn("Sp805::read: WO reg (0x%x) [WDOGITOP]\n", addr);
93  break;
94  default:
95  if (readId(pkt, ambaId, pioAddr))
96  resp = pkt->getUintX(ByteOrder::little);
97  else
98  warn("Sp805::read: Unexpected address (0x%x:%i), assuming RAZ\n",
99  addr, size);
100  }
101 
102  DPRINTF(Sp805, "Sp805::read: 0x%x<-0x%x(%i)\n", resp, addr, size);
103 
104  pkt->setUintX(resp, ByteOrder::little);
105  pkt->makeResponse();
106  return pioDelay;
107 }
108 
109 Tick
111 {
112  const Addr addr = pkt->getAddr() - pioAddr;
113  const size_t size = pkt->getSize();
114  panic_if(size != 4, "Sp805::write: Invalid size %i\n", size);
115 
116  uint64_t data = pkt->getUintX(ByteOrder::little);
117  switch (addr) {
118  case WDOGLOAD:
119  if (writeAccessEnabled) {
120  // When WdogLoad is written 0x0, immediately trigger an interrupt
121  if (!timeoutInterval)
122  sendInt();
123  else
125  if (enabled)
126  restartCounter();
127  }
128  break;
129  case WDOGVALUE:
130  warn("Sp805::write: RO reg (0x%x) [WDOGVALUE]\n", addr);
131  break;
132  case WDOGCONTROL:
133  if (writeAccessEnabled) {
134  bool was_enabled = enabled;
135  enabled = bits(data, 0);
136  resetEnabled = bits(data, 1);
137  // If watchdog becomes enabled, restart the counter
138  if (!was_enabled && enabled)
139  restartCounter();
140  // If watchdog becomes disabled, stop the counter
141  else if (timeoutEvent.scheduled() && !enabled)
142  stopCounter();
143  }
144  break;
145  case WDOGINTCLR:
146  if (writeAccessEnabled) {
147  // Clear the interrupt and restart the counter if enabled
148  clearInt();
149  if (enabled)
150  restartCounter();
151  }
152  break;
153  case WDOGRIS:
154  warn("Sp805::write: RO reg (0x%x) [WDOGRIS]\n", addr);
155  break;
156  case WDOGMIS:
157  warn("Sp805::write: RO reg (0x%x) [WDOGMIS]\n", addr);
158  break;
159  case WDOGLOCK:
161  break;
162  case WDOGITCR ... WDOGITOP:
163  warn("Sp805::write: No support for integration test harness\n");
164  break;
165  default:
166  warn("Sp805::write: Unexpected address (0x%x:%i), assuming WI\n",
167  addr, size);
168  }
169 
170  DPRINTF(Sp805, "Sp805::write: 0x%x->0x%x(%i)\n", data, addr, size);
171 
172  pkt->makeResponse();
173  return pioDelay;
174 }
175 
176 uint32_t
178 {
181  : persistedValue;
182 }
183 
184 void
186 {
188  sendInt();
189  restartCounter();
190 }
191 
192 void
194 {
197 }
198 
199 void
201 {
202  persistedValue = value();
205 }
206 
207 void
209 {
210  // If the previously sent interrupt has not been served,
211  // assert system reset if enabled
212  if (interrupt->active() && enabled) {
213  if (resetEnabled)
214  warn("Watchdog timed out, system reset asserted\n");
215  } else {
216  interrupt->raise();
217  }
218 }
219 
220 void
222 {
223  interrupt->clear();
224 }
225 
226 void
228 {
236 
237  bool ev_scheduled = timeoutEvent.scheduled();
238  SERIALIZE_SCALAR(ev_scheduled);
239  if (ev_scheduled)
241 }
242 
243 void
245 {
253 
254  bool ev_scheduled;
255  UNSERIALIZE_SCALAR(ev_scheduled);
256  if (ev_scheduled) {
257  Tick when;
258  UNSERIALIZE_SCALAR(when);
259  reschedule(timeoutEvent, when, true);
260  }
261 }
262 
263 Sp805 *
264 Sp805Params::create()
265 {
266  return new Sp805(this);
267 }
Event::scheduled
bool scheduled() const
Determine if the current event is scheduled.
Definition: eventq.hh:460
Sp805::sendInt
void sendInt(void)
Raises an interrupt.
Definition: watchdog_sp805.cc:208
BasicPioDevice::pioAddr
Addr pioAddr
Address that the device listens to.
Definition: io_device.hh:154
warn
#define warn(...)
Definition: logging.hh:239
Sp805::timeoutStartTick
Tick timeoutStartTick
Timeout start tick to keep track of the counter value.
Definition: watchdog_sp805.hh:85
data
const char data[]
Definition: circlebuf.test.cc:42
UNSERIALIZE_SCALAR
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:797
Sp805::WDOGCONTROL
@ WDOGCONTROL
Definition: watchdog_sp805.hh:68
Packet::getAddr
Addr getAddr() const
Definition: packet.hh:754
Sp805::WDOGITOP
@ WDOGITOP
Definition: watchdog_sp805.hh:76
EventManager::reschedule
void reschedule(Event &event, Tick when, bool always=false)
Definition: eventq.hh:1023
AmbaPioDevice::ambaId
uint64_t ambaId
Definition: amba_device.hh:79
ArmInterruptPin::clear
virtual void clear()=0
Clear a signalled interrupt.
Sp805::stopCounter
void stopCounter(void)
Stops the counter when watchdog becomes disabled.
Definition: watchdog_sp805.cc:200
Sp805::write
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: watchdog_sp805.cc:110
ArmInterruptPin::raise
virtual void raise()=0
Signal an interrupt.
Sp805::WDOGLOCK_MAGIC
static constexpr uint32_t WDOGLOCK_MAGIC
If written into WdogLock, registers are unlocked for writes.
Definition: watchdog_sp805.hh:127
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:63
Sp805::restartCounter
void restartCounter(void)
Restarts the counter to the current timeout interval.
Definition: watchdog_sp805.cc:193
EventManager::deschedule
void deschedule(Event &event)
Definition: eventq.hh:1014
Packet::getSize
unsigned getSize() const
Definition: packet.hh:764
Sp805::WDOGLOCK
@ WDOGLOCK
Definition: watchdog_sp805.hh:73
Sp805::resetEnabled
bool resetEnabled
Indicates if reset behaviour is enabled when counter reaches 0.
Definition: watchdog_sp805.hh:94
Sp805::WDOGITCR
@ WDOGITCR
Definition: watchdog_sp805.hh:75
Event::when
Tick when() const
Get the time that the event is scheduled.
Definition: eventq.hh:503
Sp805::value
uint32_t value(void) const
Returns the current counter value.
Definition: watchdog_sp805.cc:177
Sp805::read
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: watchdog_sp805.cc:59
Sp805::WDOGRIS
@ WDOGRIS
Definition: watchdog_sp805.hh:70
Sp805::timeoutExpired
void timeoutExpired(void)
Triggered when value reaches 0.
Definition: watchdog_sp805.cc:185
Sp805::Sp805
Sp805(Sp805Params const *params)
Definition: watchdog_sp805.cc:45
cp
Definition: cprintf.cc:40
Stats::enabled
bool enabled()
Definition: statistics.cc:545
AmbaIntDevice::interrupt
ArmInterruptPin *const interrupt
Definition: amba_device.hh:89
Packet::getUintX
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:350
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:234
Clocked::clockEdge
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...
Definition: clocked_object.hh:174
Sp805::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: watchdog_sp805.cc:244
Packet::setUintX
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:367
AmbaDevice::readId
bool readId(PacketPtr pkt, uint64_t amba_id, Addr pio_addr)
Definition: amba_device.cc:72
Sp805::timeoutEvent
EventFunctionWrapper timeoutEvent
Timeout event, triggered when the counter value reaches 0.
Definition: watchdog_sp805.hh:103
Sp805::timeoutInterval
uint32_t timeoutInterval
Timeout interval (in cycles) as specified in WdogLoad.
Definition: watchdog_sp805.hh:82
AmbaIntDevice
Definition: amba_device.hh:86
Sp805::WDOGVALUE
@ WDOGVALUE
Definition: watchdog_sp805.hh:67
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
Packet::makeResponse
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:1004
name
const std::string & name()
Definition: trace.cc:50
SERIALIZE_SCALAR
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:790
Clocked::clockPeriod
Tick clockPeriod() const
Definition: clocked_object.hh:214
packet_access.hh
ArmInterruptPin::active
bool active() const
True if interrupt pin is active, false otherwise.
Definition: base_gic.hh:197
Sp805::enabled
bool enabled
Indicates if watchdog (counter and interrupt) is enabled.
Definition: watchdog_sp805.hh:91
Sp805::clearInt
void clearInt(void)
Clears any active interrupts.
Definition: watchdog_sp805.cc:221
panic_if
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:197
Sp805::WDOGMIS
@ WDOGMIS
Definition: watchdog_sp805.hh:71
Sp805::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: watchdog_sp805.cc:227
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:257
Sp805::integrationTestEnabled
bool integrationTestEnabled
Indicates if integration test harness is enabled.
Definition: watchdog_sp805.hh:100
Sp805
Definition: watchdog_sp805.hh:52
addr
ip6_addr_t addr
Definition: inet.hh:423
logging.hh
Cycles
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:83
BasicPioDevice::pioDelay
Tick pioDelay
Delay that the device experinces on an access.
Definition: io_device.hh:160
CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:63
Sp805::persistedValue
uint32_t persistedValue
Value as persisted when the watchdog is stopped.
Definition: watchdog_sp805.hh:88
Sp805::WDOGINTCLR
@ WDOGINTCLR
Definition: watchdog_sp805.hh:69
CheckpointIn
Definition: serialize.hh:67
Sp805::WDOGLOAD
@ WDOGLOAD
Definition: watchdog_sp805.hh:66
MaxTick
const Tick MaxTick
Definition: types.hh:65
Sp805::writeAccessEnabled
bool writeAccessEnabled
Indicates if write access to registers is enabled.
Definition: watchdog_sp805.hh:97
curTick
Tick curTick()
The current simulated tick.
Definition: core.hh:45
bits
T bits(T val, int first, int last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
Definition: bitfield.hh:75
watchdog_sp805.hh

Generated on Wed Sep 30 2020 14:02:10 for gem5 by doxygen 1.8.17