gem5  v20.0.0.2
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 
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  intRaised(false),
53  writeAccessEnabled(true),
54  integrationTestEnabled(false),
55  timeoutEvent([this] { timeoutExpired(); }, name())
56 {
57 }
58 
59 Tick
61 {
62  const Addr addr = pkt->getAddr() - pioAddr;
63  const size_t size = pkt->getSize();
64  panic_if(size != 4, "Sp805::read: Invalid size %i\n", size);
65 
66  uint64_t resp = 0;
67  switch (addr) {
68  case WDOGLOAD:
69  resp = timeoutInterval;
70  break;
71  case WDOGVALUE:
72  resp = value();
73  break;
74  case WDOGCONTROL:
75  resp = enabled | (resetEnabled << 1);
76  break;
77  case WDOGINTCLR:
78  warn("Sp805::read: WO reg (0x%x) [WDOGINTCLR]\n", addr);
79  break;
80  case WDOGRIS:
81  resp = intRaised;
82  break;
83  case WDOGMIS:
84  resp = intRaised & enabled;
85  break;
86  case WDOGLOCK:
87  resp = writeAccessEnabled;
88  break;
89  case WDOGITCR:
91  break;
92  case WDOGITOP:
93  warn("Sp805::read: WO reg (0x%x) [WDOGITOP]\n", addr);
94  break;
95  default:
96  if (readId(pkt, ambaId, pioAddr))
97  resp = pkt->getUintX(LittleEndianByteOrder);
98  else
99  warn("Sp805::read: Unexpected address (0x%x:%i), assuming RAZ\n",
100  addr, size);
101  }
102 
103  DPRINTF(Sp805, "Sp805::read: 0x%x<-0x%x(%i)\n", resp, addr, size);
104 
105  pkt->setUintX(resp, LittleEndianByteOrder);
106  pkt->makeResponse();
107  return pioDelay;
108 }
109 
110 Tick
112 {
113  const Addr addr = pkt->getAddr() - pioAddr;
114  const size_t size = pkt->getSize();
115  panic_if(size != 4, "Sp805::write: Invalid size %i\n", size);
116 
117  uint64_t data = pkt->getUintX(LittleEndianByteOrder);
118  switch (addr) {
119  case WDOGLOAD:
120  if (writeAccessEnabled) {
121  // When WdogLoad is written 0x0, immediately trigger an interrupt
122  if (!timeoutInterval)
123  sendInt();
124  else
126  if (enabled)
127  restartCounter();
128  }
129  break;
130  case WDOGVALUE:
131  warn("Sp805::write: RO reg (0x%x) [WDOGVALUE]\n", addr);
132  break;
133  case WDOGCONTROL:
134  if (writeAccessEnabled) {
135  bool was_enabled = enabled;
136  enabled = bits(data, 0);
137  resetEnabled = bits(data, 1);
138  // If watchdog becomes enabled, restart the counter
139  if (!was_enabled && enabled)
140  restartCounter();
141  // If watchdog becomes disabled, stop the counter
142  else if (timeoutEvent.scheduled() && !enabled)
143  stopCounter();
144  }
145  break;
146  case WDOGINTCLR:
147  if (writeAccessEnabled) {
148  // Clear the interrupt and restart the counter if enabled
149  clearInt();
150  if (enabled)
151  restartCounter();
152  }
153  break;
154  case WDOGRIS:
155  warn("Sp805::write: RO reg (0x%x) [WDOGRIS]\n", addr);
156  break;
157  case WDOGMIS:
158  warn("Sp805::write: RO reg (0x%x) [WDOGMIS]\n", addr);
159  break;
160  case WDOGLOCK:
162  break;
163  case WDOGITCR ... WDOGITOP:
164  warn("Sp805::write: No support for integration test harness\n");
165  break;
166  default:
167  warn("Sp805::write: Unexpected address (0x%x:%i), assuming WI\n",
168  addr, size);
169  }
170 
171  DPRINTF(Sp805, "Sp805::write: 0x%x->0x%x(%i)\n", data, addr, size);
172 
173  pkt->makeResponse();
174  return pioDelay;
175 }
176 
177 uint32_t
179 {
182  : persistedValue;
183 }
184 
185 void
187 {
189  sendInt();
190  restartCounter();
191 }
192 
193 void
195 {
198 }
199 
200 void
202 {
203  persistedValue = value();
206 }
207 
208 void
210 {
211  // If the previously sent interrupt has not been served,
212  // assert system reset if enabled
213  if (intRaised & enabled) {
214  if (resetEnabled)
215  warn("Watchdog timed out, system reset asserted\n");
216  } else {
217  intRaised = true;
218  gic->sendInt(intNum);
219  }
220 }
221 
222 void
224 {
225  intRaised = false;
226  gic->clearInt(intNum);
227 }
228 
229 void
231 {
240 
241  bool ev_scheduled = timeoutEvent.scheduled();
242  SERIALIZE_SCALAR(ev_scheduled);
243  if (ev_scheduled)
245 }
246 
247 void
249 {
258 
259  bool ev_scheduled;
260  UNSERIALIZE_SCALAR(ev_scheduled);
261  if (ev_scheduled) {
262  Tick when;
263  UNSERIALIZE_SCALAR(when);
264  reschedule(timeoutEvent, when, true);
265  }
266 }
267 
268 Sp805 *
269 Sp805Params::create()
270 {
271  return new Sp805(this);
272 }
#define DPRINTF(x,...)
Definition: trace.hh:222
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:351
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:81
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.
void stopCounter(void)
Stops the counter when watchdog becomes disabled.
ip6_addr_t addr
Definition: inet.hh:330
Tick timeoutStartTick
Timeout start tick to keep track of the counter value.
Definition: cprintf.cc:40
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.
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:334
Sp805(Sp805Params const *params)
unsigned getSize() const
Definition: packet.hh:730
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:770
EventFunctionWrapper timeoutEvent
Timeout event, triggered when the counter value reaches 0.
const Tick MaxTick
Definition: types.hh:63
Tick curTick()
The current simulated tick.
Definition: core.hh:44
bool resetEnabled
Indicates if reset behaviour is enabled when counter reaches 0.
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:61
uint32_t timeoutInterval
Timeout interval (in cycles) as specified in WdogLoad.
void deschedule(Event &event)
Definition: eventq.hh:1007
Addr getAddr() const
Definition: packet.hh:720
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:72
void reschedule(Event &event, Tick when, bool always=false)
Definition: eventq.hh:1016
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:140
bool enabled
Indicates if watchdog (counter and interrupt) is enabled.
uint64_t ambaId
Definition: amba_device.hh:79
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:249
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:545
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:763
bool scheduled() const
Determine if the current event is scheduled.
Definition: eventq.hh:460
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:931
virtual const std::string name() const
Definition: sim_object.hh:128
uint32_t persistedValue
Value as persisted when the watchdog is stopped.
std::ostream CheckpointOut
Definition: serialize.hh:63
bool integrationTestEnabled
Indicates if integration test harness is enabled.
Tick pioDelay
Delay that the device experinces on an access.
Definition: io_device.hh:160
void serialize(CheckpointOut &cp) const override
Serialize an object.
bool writeAccessEnabled
Indicates if write access to registers is enabled.
#define warn(...)
Definition: logging.hh:208
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:71
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:181
Tick when() const
Get the time that the event is scheduled.
Definition: eventq.hh:500
Addr pioAddr
Address that the device listens to.
Definition: io_device.hh:154
const char data[]
BaseGic * gic
Definition: amba_device.hh:90
Arm Watchdog Module (SP805) Reference: Arm Watchdog Module (SP805) - Technical Reference Manual - rev...
void sendInt(void)
Raises an interrupt.

Generated on Mon Jun 8 2020 15:45:10 for gem5 by doxygen 1.8.13