gem5  v22.1.0.0
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 namespace gem5
44 {
45 
46 GenericWatchdog::GenericWatchdog(const GenericWatchdogParams &p)
47  : PioDevice(p),
48  timeoutEvent([this]{ timeout(); }, name()),
49  controlStatus(0),
50  offset(0),
51  compare(0),
52  iidr(0),
53  refreshFrame(p.refresh_start, p.refresh_start + 0x10000),
54  controlFrame(p.control_start, p.control_start + 0x10000),
55  pioLatency(p.pio_latency),
56  cnt(*p.system_counter),
57  cntListener(*this),
58  ws0(p.ws0->get()),
59  ws1(p.ws1->get())
60 {
61  cnt.registerListener(&cntListener);
62 }
63 
66 {
67  AddrRangeList ranges;
68  ranges.push_back(refreshFrame);
69  ranges.push_back(controlFrame);
70  return ranges;
71 }
72 
73 Tick
75 {
76  const Addr addr = pkt->getAddr();
77  const size_t size = pkt->getSize();
78  panic_if(size != 4, "GenericWatchdog::read: Invalid size %i\n", size);
79 
80  uint32_t resp = 0;
81 
82  if (refreshFrame.contains(addr)) {
83  resp = readRefresh(addr);
84  } else if (controlFrame.contains(addr)) {
85  resp = readControl(addr);
86  } else {
87  panic("%s unknown address %#x\n", __func__, addr);
88  }
89 
90  pkt->setUintX(resp, ByteOrder::little);
91  pkt->makeResponse();
92  return pioLatency;
93 }
94 
95 uint32_t
97 {
98  const auto daddr = static_cast<RefreshOffset>(
99  addr - refreshFrame.start());
100 
101  switch (daddr) {
102  case RefreshOffset::WRR:
103  // A read of the refresh register has no effect and returns 0
104  return 0;
106  return iidr;
107  default:
108  panic("%s unknown address %#x\n", __func__, addr);
109  }
110 }
111 
112 uint32_t
114 {
115  const auto daddr = static_cast<ControlOffset>(
116  addr - controlFrame.start());
117 
118  switch (daddr) {
119  case ControlOffset::WCS:
120  return controlStatus;
121  case ControlOffset::WOR:
122  return offset;
124  return bits(compare, 31, 0);
126  return bits(compare, 63, 32);
128  return iidr;
129  default:
130  panic("%s unknown address %#x\n", __func__, addr);
131  }
132 }
133 
134 Tick
136 {
137  const Addr addr = pkt->getAddr();
138  const size_t size = pkt->getSize();
139  panic_if(size != 4, "GenericWatchdog::write: Invalid size %i\n", size);
140 
141  uint32_t data = pkt->getUintX(ByteOrder::little);
142 
143  if (refreshFrame.contains(addr)) {
145  } else if (controlFrame.contains(addr)) {
147  } else {
148  panic("%s unknown address %#x\n", __func__, addr);
149  }
150 
151  pkt->makeResponse();
152  return pioLatency;
153 }
154 
155 void
157 {
158  const auto daddr = static_cast<RefreshOffset>(
159  addr - refreshFrame.start());
160 
161  switch (daddr) {
162  case RefreshOffset::WRR:
163  explicitRefresh();
164  break;
165  default:
166  panic("%s unknown address %#x\n", __func__, addr);
167  }
168 }
169 
170 void
172 {
173  const auto daddr = static_cast<ControlOffset>(
174  addr - controlFrame.start());
175 
176  switch (daddr) {
177  case ControlOffset::WCS:
178  controlStatus = data & 0x1;
179  explicitRefresh();
180  break;
181  case ControlOffset::WOR:
182  offset = data;
183  explicitRefresh();
184  break;
186  compare = insertBits(compare, 31, 0, data);
187  break;
189  compare = insertBits(compare, 63, 32, data);
190  break;
191  default:
192  panic("%s unknown address %#x\n", __func__, addr);
193  }
194 }
195 
196 void
198 {
199  // Watchdog signals are cleared in case of an explicit refresh
200  controlStatus.ws0 = 0;
201  controlStatus.ws1 = 0;
202  ws0->clear();
203  ws1->clear();
204 
205  refresh();
206 }
207 
208 void
210 {
211  // Update compare value
212  compare = cnt.value() + offset;
213 
214  // Ask the System Counter how long we have to wait until
215  // it reaches the new compare value
216  Tick timeout_time = cnt.whenValue(compare);
217 
218  reschedule(timeoutEvent, timeout_time, true);
219 }
220 
221 void
223 {
224  if (!controlStatus.enabled)
225  return;
226 
227  if (!controlStatus.ws0) {
228  controlStatus.ws0 = 1;
229  ws0->raise();
230  } else {
231  controlStatus.ws1 = 1;
232  ws1->raise();
233  }
234 
235  refresh();
236 }
237 
238 void
240 {
241  SERIALIZE_SCALAR(controlStatus);
244 
245  bool ev_scheduled = timeoutEvent.scheduled();
246  SERIALIZE_SCALAR(ev_scheduled);
247  if (ev_scheduled)
249 }
250 
251 void
253 {
254  UNSERIALIZE_SCALAR(controlStatus);
257 
258  bool ev_scheduled;
259  UNSERIALIZE_SCALAR(ev_scheduled);
260  if (ev_scheduled) {
261  Tick when;
262  UNSERIALIZE_SCALAR(when);
263  reschedule(timeoutEvent, when, true);
264  }
265 }
266 
267 } // namespace gem5
Base class for ARM GIC implementations.
const char data[]
virtual void clear()=0
Clear a signalled interrupt.
virtual void raise()=0
Signal an interrupt.
const uint32_t iidr
Interface Identification Register.
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
const AddrRange controlFrame
EventFunctionWrapper timeoutEvent
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
ArmInterruptPin *const ws1
void writeRefresh(Addr addr, uint32_t data)
uint64_t compare
Compare Register.
const AddrRange refreshFrame
uint32_t readControl(Addr addr)
GenericWatchdog(const GenericWatchdogParams &params)
AddrRangeList getAddrRanges() const override
Every PIO device is obliged to provide an implementation that returns the address ranges the device r...
void writeControl(Addr addr, uint32_t data)
uint32_t offset
Offset Register.
void serialize(CheckpointOut &cp) const override
Serialize an object.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
uint32_t readRefresh(Addr addr)
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
Addr getAddr() const
Definition: packet.hh:805
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:1059
unsigned getSize() const
Definition: packet.hh:815
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
This device is the base class which all devices senstive to an address range inherit from.
Definition: io_device.hh:103
Tick whenValue(uint64_t target_val)
Returns the tick at which a certain counter value is reached.
uint64_t value()
Updates and returns the counter value.
std::list< AddrRange > AddrRangeList
Convenience typedef for a collection of address ranges.
Definition: addr_range.hh:57
bool contains(const Addr &a) const
Determine if the range contains an address.
Definition: addr_range.hh:471
Addr start() const
Get the start address of the range.
Definition: addr_range.hh:343
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:76
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:166
bool scheduled() const
Determine if the current event is scheduled.
Definition: eventq.hh:465
void reschedule(Event &event, Tick when, bool always=false)
Definition: eventq.hh:1037
Tick when() const
Get the time that the event is scheduled.
Definition: eventq.hh:508
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:178
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:204
Bitfield< 23, 0 > offset
Definition: types.hh:144
Bitfield< 54 > p
Definition: pagetable.hh:70
Bitfield< 3 > addr
Definition: types.hh:84
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
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
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:575
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:568
const std::string & name()
Definition: trace.cc:49
Arm SBSA Generic Watchdog Reference: Arm Server Base System Architecture (SBSA) Doc.

Generated on Wed Dec 21 2022 10:22:33 for gem5 by doxygen 1.9.1