gem5  v21.0.1.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
watchdog_generic.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 "dev/arm/base_gic.hh"
41 #include "params/GenericWatchdog.hh"
42 
43 
44 GenericWatchdog::GenericWatchdog(const GenericWatchdogParams &p)
45  : PioDevice(p),
46  timeoutEvent([this]{ timeout(); }, name()),
47  controlStatus(0),
48  offset(0),
49  compare(0),
50  iidr(0),
51  refreshFrame(p.refresh_start, p.refresh_start + 0x10000),
52  controlFrame(p.control_start, p.control_start + 0x10000),
53  pioLatency(p.pio_latency),
54  cnt(*p.system_counter),
55  cntListener(*this),
56  ws0(p.ws0->get()),
57  ws1(p.ws1->get())
58 {
59  cnt.registerListener(&cntListener);
60 }
61 
64 {
65  AddrRangeList ranges;
66  ranges.push_back(refreshFrame);
67  ranges.push_back(controlFrame);
68  return ranges;
69 }
70 
71 Tick
73 {
74  const Addr addr = pkt->getAddr();
75  const size_t size = pkt->getSize();
76  panic_if(size != 4, "GenericWatchdog::read: Invalid size %i\n", size);
77 
78  uint32_t resp = 0;
79 
80  if (refreshFrame.contains(addr)) {
81  resp = readRefresh(addr);
82  } else if (controlFrame.contains(addr)) {
83  resp = readControl(addr);
84  } else {
85  panic("%s unknown address %#x\n", __func__, addr);
86  }
87 
88  pkt->setUintX(resp, ByteOrder::little);
89  pkt->makeResponse();
90  return pioLatency;
91 }
92 
93 uint32_t
95 {
96  const auto daddr = static_cast<RefreshOffset>(
97  addr - refreshFrame.start());
98 
99  switch (daddr) {
100  case RefreshOffset::WRR:
101  // A read of the refresh register has no effect and returns 0
102  return 0;
104  return iidr;
105  default:
106  panic("%s unknown address %#x\n", __func__, addr);
107  }
108 }
109 
110 uint32_t
112 {
113  const auto daddr = static_cast<ControlOffset>(
114  addr - controlFrame.start());
115 
116  switch (daddr) {
117  case ControlOffset::WCS:
118  return controlStatus;
119  case ControlOffset::WOR:
120  return offset;
122  return bits(compare, 31, 0);
124  return bits(compare, 63, 32);
126  return iidr;
127  default:
128  panic("%s unknown address %#x\n", __func__, addr);
129  }
130 }
131 
132 Tick
134 {
135  const Addr addr = pkt->getAddr();
136  const size_t size = pkt->getSize();
137  panic_if(size != 4, "GenericWatchdog::write: Invalid size %i\n", size);
138 
139  uint32_t data = pkt->getUintX(ByteOrder::little);
140 
141  if (refreshFrame.contains(addr)) {
143  } else if (controlFrame.contains(addr)) {
145  } else {
146  panic("%s unknown address %#x\n", __func__, addr);
147  }
148 
149  pkt->makeResponse();
150  return pioLatency;
151 }
152 
153 void
155 {
156  const auto daddr = static_cast<RefreshOffset>(
157  addr - refreshFrame.start());
158 
159  switch (daddr) {
160  case RefreshOffset::WRR:
161  explicitRefresh();
162  break;
163  default:
164  panic("%s unknown address %#x\n", __func__, addr);
165  }
166 }
167 
168 void
170 {
171  const auto daddr = static_cast<ControlOffset>(
172  addr - controlFrame.start());
173 
174  switch (daddr) {
175  case ControlOffset::WCS:
176  controlStatus = data & 0x1;
177  explicitRefresh();
178  break;
179  case ControlOffset::WOR:
180  offset = data;
181  explicitRefresh();
182  break;
184  compare = insertBits(compare, 31, 0, data);
185  break;
187  compare = insertBits(compare, 63, 32, data);
188  break;
189  default:
190  panic("%s unknown address %#x\n", __func__, addr);
191  }
192 }
193 
194 void
196 {
197  // Watchdog signals are cleared in case of an explicit refresh
198  controlStatus.ws0 = 0;
199  controlStatus.ws1 = 0;
200  ws0->clear();
201  ws1->clear();
202 
203  refresh();
204 }
205 
206 void
208 {
209  // Update compare value
210  compare = cnt.value() + offset;
211 
212  // Ask the System Counter how long we have to wait until
213  // it reaches the new compare value
214  Tick timeout_time = cnt.whenValue(compare);
215 
216  reschedule(timeoutEvent, timeout_time, true);
217 }
218 
219 void
221 {
222  if (!controlStatus.enabled)
223  return;
224 
225  if (!controlStatus.ws0) {
226  controlStatus.ws0 = 1;
227  ws0->raise();
228  } else {
229  controlStatus.ws1 = 1;
230  ws1->raise();
231  }
232 
233  refresh();
234 }
235 
236 void
238 {
239  SERIALIZE_SCALAR(controlStatus);
242 
243  bool ev_scheduled = timeoutEvent.scheduled();
244  SERIALIZE_SCALAR(ev_scheduled);
245  if (ev_scheduled)
247 }
248 
249 void
251 {
252  UNSERIALIZE_SCALAR(controlStatus);
255 
256  bool ev_scheduled;
257  UNSERIALIZE_SCALAR(ev_scheduled);
258  if (ev_scheduled) {
259  Tick when;
260  UNSERIALIZE_SCALAR(when);
261  reschedule(timeoutEvent, when, true);
262  }
263 }
GenericWatchdog::timeoutEvent
EventFunctionWrapper timeoutEvent
Definition: watchdog_generic.hh:107
Event::scheduled
bool scheduled() const
Determine if the current event is scheduled.
Definition: eventq.hh:462
insertBits
constexpr T insertBits(T val, unsigned first, unsigned last, B bit_val)
Returns val with bits first to last set to the LSBs of bit_val.
Definition: bitfield.hh:143
SystemCounter::whenValue
Tick whenValue(uint64_t target_val)
Returns the tick at which a certain counter value is reached.
Definition: generic_timer.cc:151
GenericWatchdog::RefreshOffset
RefreshOffset
Definition: watchdog_generic.hh:110
data
const char data[]
Definition: circlebuf.test.cc:47
UNSERIALIZE_SCALAR
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:591
Packet::getAddr
Addr getAddr() const
Definition: packet.hh:755
EventManager::reschedule
void reschedule(Event &event, Tick when, bool always=false)
Definition: eventq.hh:1034
GenericWatchdog::ControlOffset::WCS
@ WCS
ArmInterruptPin::clear
virtual void clear()=0
Clear a signalled interrupt.
GenericWatchdog::getAddrRanges
AddrRangeList getAddrRanges() const override
Every PIO device is obliged to provide an implementation that returns the address ranges the device r...
Definition: watchdog_generic.cc:63
GenericWatchdog::offset
uint32_t offset
Offset Register.
Definition: watchdog_generic.hh:135
base_gic.hh
ArmInterruptPin::raise
virtual void raise()=0
Signal an interrupt.
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:59
watchdog_generic.hh
GenericWatchdog::ControlOffset::WCV_HI
@ WCV_HI
AddrRange::contains
bool contains(const Addr &a) const
Determine if the range contains an address.
Definition: addr_range.hh:435
Packet::getSize
unsigned getSize() const
Definition: packet.hh:765
GenericWatchdog::read
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: watchdog_generic.cc:72
GenericWatchdog::ws1
ArmInterruptPin *const ws1
Definition: watchdog_generic.hh:153
Event::when
Tick when() const
Get the time that the event is scheduled.
Definition: eventq.hh:505
GenericWatchdog::writeControl
void writeControl(Addr addr, uint32_t data)
Definition: watchdog_generic.cc:169
cp
Definition: cprintf.cc:37
PioDevice
This device is the base class which all devices senstive to an address range inherit from.
Definition: io_device.hh:99
GenericWatchdog::GenericWatchdog
GenericWatchdog(const GenericWatchdogParams &params)
Definition: watchdog_generic.cc:44
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
GenericWatchdog::compare
uint64_t compare
Compare Register.
Definition: watchdog_generic.hh:138
GenericWatchdog::cnt
SystemCounter & cnt
Definition: watchdog_generic.hh:148
GenericWatchdog::pioLatency
const Tick pioLatency
Definition: watchdog_generic.hh:146
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
GenericWatchdog::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: watchdog_generic.cc:237
SystemCounter::value
uint64_t value()
Updates and returns the counter value.
Definition: generic_timer.cc:104
GenericWatchdog::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: watchdog_generic.cc:250
GenericWatchdog::ControlOffset
ControlOffset
Definition: watchdog_generic.hh:116
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:148
GenericWatchdog::refreshFrame
const AddrRange refreshFrame
Definition: watchdog_generic.hh:143
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:1005
name
const std::string & name()
Definition: trace.cc:48
GenericWatchdog::controlFrame
const AddrRange controlFrame
Definition: watchdog_generic.hh:144
SERIALIZE_SCALAR
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:584
GenericWatchdog::readControl
uint32_t readControl(Addr addr)
Definition: watchdog_generic.cc:111
GenericWatchdog::ws0
Bitfield< 1 > ws0
Definition: watchdog_generic.hh:127
X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:80
GenericWatchdog::RefreshOffset::WRR
@ WRR
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
GenericWatchdog::readRefresh
uint32_t readRefresh(Addr addr)
Definition: watchdog_generic.cc:94
AddrRange::start
Addr start() const
Get the start address of the range.
Definition: addr_range.hh:314
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:258
GenericWatchdog::timeout
void timeout()
Definition: watchdog_generic.cc:220
GenericWatchdog::explicitRefresh
void explicitRefresh()
Definition: watchdog_generic.cc:195
GenericWatchdog::writeRefresh
void writeRefresh(Addr addr, uint32_t data)
Definition: watchdog_generic.cc:154
CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:64
bits
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:73
GenericWatchdog::RefreshOffset::W_IIDR
@ W_IIDR
GenericWatchdog::write
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: watchdog_generic.cc:133
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
GenericWatchdog::iidr
const uint32_t iidr
Interface Identification Register.
Definition: watchdog_generic.hh:141
std::list< AddrRange >
CheckpointIn
Definition: serialize.hh:68
GenericWatchdog::refresh
void refresh()
Definition: watchdog_generic.cc:207
GenericWatchdog::ControlOffset::W_IIDR
@ W_IIDR
GenericWatchdog::ControlOffset::WCV_LO
@ WCV_LO
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171
ArmISA::offset
Bitfield< 23, 0 > offset
Definition: types.hh:153
GenericWatchdog::ControlOffset::WOR
@ WOR

Generated on Tue Jun 22 2021 15:28:27 for gem5 by doxygen 1.8.17