gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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  * Authors: Adrian Herrera
38  */
39 
41 
42 #include "base/logging.hh"
43 #include "debug/Sp805.hh"
44 #include "mem/packet_access.hh"
45 #include "params/Sp805.hh"
46 
47 Sp805::Sp805(Sp805Params const* params)
48  : AmbaIntDevice(params, 0x1000),
49  timeoutInterval(0xffffffff),
50  timeoutStartTick(MaxTick),
51  persistedValue(timeoutInterval),
52  enabled(false),
53  resetEnabled(false),
54  intRaised(false),
55  writeAccessEnabled(true),
56  integrationTestEnabled(false),
57  timeoutEvent([this] { timeoutExpired(); }, name())
58 {
59 }
60 
61 Tick
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 = intRaised;
84  break;
85  case WDOGMIS:
86  resp = intRaised & 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(LittleEndianByteOrder);
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, LittleEndianByteOrder);
108  pkt->makeResponse();
109  return pioDelay;
110 }
111 
112 Tick
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(LittleEndianByteOrder);
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)
129  restartCounter();
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)
142  restartCounter();
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)
153  restartCounter();
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 
179 uint32_t
181 {
184  : persistedValue;
185 }
186 
187 void
189 {
191  sendInt();
192  restartCounter();
193 }
194 
195 void
197 {
200 }
201 
202 void
204 {
205  persistedValue = value();
208 }
209 
210 void
212 {
213  // If the previously sent interrupt has not been served,
214  // assert system reset if enabled
215  if (intRaised & enabled) {
216  if (resetEnabled)
217  warn("Watchdog timed out, system reset asserted\n");
218  } else {
219  intRaised = true;
220  gic->sendInt(intNum);
221  }
222 }
223 
224 void
226 {
227  intRaised = false;
228  gic->clearInt(intNum);
229 }
230 
231 void
233 {
242 
243  bool ev_scheduled = timeoutEvent.scheduled();
244  SERIALIZE_SCALAR(ev_scheduled);
245  if (ev_scheduled)
247 }
248 
249 void
251 {
260 
261  bool ev_scheduled;
262  UNSERIALIZE_SCALAR(ev_scheduled);
263  if (ev_scheduled) {
264  Tick when;
265  UNSERIALIZE_SCALAR(when);
266  reschedule(timeoutEvent, when, true);
267  }
268 }
269 
270 Sp805 *
271 Sp805Params::create()
272 {
273  return new Sp805(this);
274 }
#define DPRINTF(x,...)
Definition: trace.hh:229
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:354
static constexpr uint32_t WDOGLOCK_MAGIC
If written into WdogLock, registers are unlocked for writes.
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:83
virtual void clearInt(uint32_t num)=0
Clear an interrupt from a device that is connected to the GIC.
void restartCounter(void)
Restarts the counter to the current timeout interval.
Tick when() const
Get the time that the event is scheduled.
Definition: eventq.hh:401
void stopCounter(void)
Stops the counter when watchdog becomes disabled.
ip6_addr_t addr
Definition: inet.hh:335
Tick timeoutStartTick
Timeout start tick to keep track of the counter value.
Definition: cprintf.cc:42
uint32_t value(void) const
Returns the current counter value.
Tick clockPeriod() const
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
void timeoutExpired(void)
Triggered when value reaches 0.
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
void deschedule(Event &event)
Definition: eventq.hh:750
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:337
Sp805(Sp805Params const *params)
unsigned getSize() const
Definition: packet.hh:736
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:645
EventFunctionWrapper timeoutEvent
Timeout event, triggered when the counter value reaches 0.
const Tick MaxTick
Definition: types.hh:65
Tick curTick()
The current simulated tick.
Definition: core.hh:47
bool resetEnabled
Indicates if reset behaviour is enabled when counter reaches 0.
bool scheduled() const
Determine if the current event is scheduled.
Definition: eventq.hh:385
virtual void sendInt(uint32_t num)=0
Post an interrupt from a device that is connected to the GIC.
uint64_t Tick
Tick count type.
Definition: types.hh:63
uint32_t timeoutInterval
Timeout interval (in cycles) as specified in WdogLoad.
Addr getAddr() const
Definition: packet.hh:726
void clearInt(void)
Clears any active interrupts.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
bool readId(PacketPtr pkt, uint64_t amba_id, Addr pio_addr)
Definition: amba_device.cc:74
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
bool enabled
Indicates if watchdog (counter and interrupt) is enabled.
virtual const std::string name() const
Definition: sim_object.hh:120
uint64_t ambaId
Definition: amba_device.hh:81
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:255
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...
bool enabled()
Definition: statistics.cc:546
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:643
void reschedule(Event &event, Tick when, bool always=false)
Definition: eventq.hh:756
bool intRaised
Indicates if an interrupt has been raised by the counter reaching 0.
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:937
uint32_t persistedValue
Value as persisted when the watchdog is stopped.
std::ostream CheckpointOut
Definition: serialize.hh:68
bool integrationTestEnabled
Indicates if integration test harness is enabled.
Tick pioDelay
Delay that the device experinces on an access.
Definition: io_device.hh:163
void serialize(CheckpointOut &cp) const override
Serialize an object.
bool writeAccessEnabled
Indicates if write access to registers is enabled.
#define warn(...)
Definition: logging.hh:212
T bits(T val, int first, int last)
Extract the bitfield from position &#39;first&#39; to &#39;last&#39; (inclusive) from &#39;val&#39; and right justify it...
Definition: bitfield.hh:72
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:185
Addr pioAddr
Address that the device listens to.
Definition: io_device.hh:157
const char data[]
BaseGic * gic
Definition: amba_device.hh:92
Arm Watchdog Module (SP805) Reference: Arm Watchdog Module (SP805) - Technical Reference Manual - rev...
void sendInt(void)
Raises an interrupt.

Generated on Fri Feb 28 2020 16:27:00 for gem5 by doxygen 1.8.13