gem5  v22.1.0.0
rtc_pl031.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2012 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 
38 #include "dev/arm/rtc_pl031.hh"
39 
40 #include "base/intmath.hh"
41 #include "base/time.hh"
42 #include "base/trace.hh"
43 #include "debug/Checkpoint.hh"
44 #include "debug/Timer.hh"
45 #include "dev/arm/amba_device.hh"
46 #include "mem/packet.hh"
47 #include "mem/packet_access.hh"
48 
49 namespace gem5
50 {
51 
53  : AmbaIntDevice(p, 0x1000), lastWrittenTick(0), loadVal(0), matchVal(0),
54  rawInt(false), maskInt(false), pendingInt(false),
55  matchEvent([this]{ counterMatch(); }, name())
56 {
57  // Make a temporary copy so mkutctime can modify it.
58  struct tm local_time = p.time;
59  timeVal = mkutctime(&local_time);
60 }
61 
62 
63 Tick
65 {
66  assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
67  assert(pkt->getSize() <= 4);
68  Addr daddr = pkt->getAddr() - pioAddr;
69  uint32_t data;
70 
71  DPRINTF(Timer, "Reading from RTC at offset: %#x\n", daddr);
72 
73  switch (daddr) {
74  case DataReg:
75  data = timeVal +
77  break;
78  case MatchReg:
79  data = matchVal;
80  break;
81  case LoadReg:
82  data = loadVal;
83  break;
84  case ControlReg:
85  data = 1; // Always enabled otherwise there is no point
86  break;
87  case IntMask:
88  data = maskInt;
89  break;
90  case RawISR:
91  data = rawInt;
92  break;
93  case MaskedISR:
94  data = pendingInt;
95  break;
96  default:
97  if (readId(pkt, ambaId, pioAddr)) {
98  // Hack for variable sized access
99  data = pkt->getUintX(ByteOrder::little);
100  break;
101  }
102  panic("Tried to read PL031 at offset %#x that doesn't exist\n", daddr);
103  break;
104  }
105 
106  pkt->setUintX(data, ByteOrder::little);
107  pkt->makeAtomicResponse();
108  return pioDelay;
109 }
110 
111 Tick
113 {
114  assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
115  assert(pkt->getSize() <= 4);
116  Addr daddr = pkt->getAddr() - pioAddr;
117  DPRINTF(Timer, "Writing to RTC at offset: %#x\n", daddr);
118 
119  switch (daddr) {
120  case DataReg:
121  break;
122  case MatchReg:
123  matchVal = pkt->getLE<uint32_t>();
124  resyncMatch();
125  break;
126  case LoadReg:
128  timeVal = pkt->getLE<uint32_t>();
129  loadVal = timeVal;
130  resyncMatch();
131  break;
132  case ControlReg:
133  break; // Can't stop when started
134  case IntMask:
135  maskInt = pkt->getLE<uint32_t>();
136  break;
137  case IntClear:
138  if (pkt->getLE<uint32_t>()) {
139  rawInt = false;
140  pendingInt = false;
141  }
142  break;
143  default:
144  if (readId(pkt, ambaId, pioAddr))
145  break;
146  panic("Tried to read PL031 at offset %#x that doesn't exist\n", daddr);
147  break;
148  }
149 
150  pkt->makeAtomicResponse();
151  return pioDelay;
152 }
153 
154 void
156 {
157  DPRINTF(Timer, "Setting up new match event match=%d time=%d\n", matchVal,
158  timeVal);
159 
160  uint32_t seconds_until = matchVal - timeVal;
161  Tick ticks_until = sim_clock::as_int::s * seconds_until;
162 
163  if (matchEvent.scheduled()) {
164  DPRINTF(Timer, "-- Event was already schedule, de-scheduling\n");
166  }
167  schedule(matchEvent, curTick() + ticks_until);
168  DPRINTF(Timer, "-- Scheduling new event for: %d\n", curTick() + ticks_until);
169 }
170 
171 void
173 {
174  DPRINTF(Timer, "Counter reached zero\n");
175 
176  rawInt = true;
177  bool old_pending = pendingInt;
179  if (pendingInt && !old_pending) {
180  DPRINTF(Timer, "-- Causing interrupt\n");
181  interrupt->raise();
182  }
183 }
184 
185 void
187 {
188  DPRINTF(Checkpoint, "Serializing Arm PL031\n");
196 
197  bool is_in_event = matchEvent.scheduled();
198  SERIALIZE_SCALAR(is_in_event);
199 
200  Tick event_time;
201  if (is_in_event){
202  event_time = matchEvent.when();
203  SERIALIZE_SCALAR(event_time);
204  }
205 }
206 
207 void
209 {
210  DPRINTF(Checkpoint, "Unserializing Arm PL031\n");
211 
219 
220  bool is_in_event;
221  UNSERIALIZE_SCALAR(is_in_event);
222 
223  Tick event_time;
224  if (is_in_event){
225  UNSERIALIZE_SCALAR(event_time);
226  schedule(matchEvent, event_time);
227  }
228 }
229 
230 } // namespace gem5
This is a base class for AMBA devices that have to respond to Device and Implementer ID calls.
#define DPRINTF(x,...)
Definition: trace.hh:186
const char data[]
bool readId(PacketPtr pkt, uint64_t amba_id, Addr pio_addr)
Definition: amba_device.cc:75
ArmInterruptPin *const interrupt
Definition: amba_device.hh:91
AmbaPioDeviceParams Params
Definition: amba_device.hh:84
virtual void raise()=0
Signal an interrupt.
Addr pioAddr
Address that the device listens to.
Definition: io_device.hh:151
Tick pioDelay
Delay that the device experinces on an access.
Definition: io_device.hh:157
Addr pioSize
Size that the device's address range.
Definition: io_device.hh:154
uint32_t timeVal
Definition: rtc_pl031.hh:68
bool rawInt
If timer has caused an interrupt.
Definition: rtc_pl031.hh:83
bool pendingInt
If an interrupt is currently pending.
Definition: rtc_pl031.hh:92
Tick read(PacketPtr pkt) override
Handle a read to the device.
Definition: rtc_pl031.cc:64
Tick write(PacketPtr pkt) override
Handle writes to the device.
Definition: rtc_pl031.cc:112
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: rtc_pl031.cc:186
PL031(const Params &p)
The constructor for RealView just registers itself with the MMU.
Definition: rtc_pl031.cc:52
void counterMatch()
Called when the counter reaches matches.
Definition: rtc_pl031.cc:172
EventFunctionWrapper matchEvent
Definition: rtc_pl031.hh:96
uint32_t loadVal
Definition: rtc_pl031.hh:74
void resyncMatch()
Called to update the matchEvent when the load Value or match value are written.
Definition: rtc_pl031.cc:155
uint32_t matchVal
Definition: rtc_pl031.hh:79
Tick lastWrittenTick
Definition: rtc_pl031.hh:71
bool maskInt
If the timer interrupt mask that is anded with the raw interrupt to generate a pending interrupt.
Definition: rtc_pl031.hh:88
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: rtc_pl031.cc:208
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
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
void makeAtomicResponse()
Definition: packet.hh:1071
T getLE() const
Get the data in the packet byte swapped from little endian to host endian.
void deschedule(Event &event)
Definition: eventq.hh:1028
bool scheduled() const
Determine if the current event is scheduled.
Definition: eventq.hh:465
void schedule(Event &event, Tick when)
Definition: eventq.hh:1019
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
Bitfield< 32 > tm
Definition: misc.hh:112
Bitfield< 54 > p
Definition: pagetable.hh:70
Tick s
second
Definition: core.cc:68
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Tick curTick()
The universal simulation clock.
Definition: cur_tick.hh:46
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
time_t mkutctime(struct tm *time)
Definition: time.cc:154
uint64_t Tick
Tick count type.
Definition: types.hh:58
Declaration of the Packet class.
This implements the ARM Primecell 031 RTC.
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:575
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:568
const std::string & name()
Definition: trace.cc:49

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