gem5 [DEVELOP-FOR-25.1]
Loading...
Searching...
No Matches
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"
46#include "mem/packet.hh"
47#include "mem/packet_access.hh"
48#include "params/PL031.hh"
49
50namespace gem5
51{
52
54 : AmbaIntDevice(p, 0x1000), lastWrittenTick(0), loadVal(0), matchVal(0),
55 rawInt(false), maskInt(false), pendingInt(false),
56 matchEvent([this]{ counterMatch(); }, name())
57{
58 // Make a temporary copy so mkutctime can modify it.
59 struct tm local_time = p.time;
60 timeVal = mkutctime(&local_time);
61}
62
63
64Tick
66{
67 assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
68 assert(pkt->getSize() <= 4);
69 Addr daddr = pkt->getAddr() - pioAddr;
70 uint32_t data;
71
72 DPRINTF(Timer, "Reading from RTC at offset: %#x\n", daddr);
73
74 switch (daddr) {
75 case DataReg:
76 data = timeVal +
78 break;
79 case MatchReg:
80 data = matchVal;
81 break;
82 case LoadReg:
83 data = loadVal;
84 break;
85 case ControlReg:
86 data = 1; // Always enabled otherwise there is no point
87 break;
88 case IntMask:
89 data = maskInt;
90 break;
91 case RawISR:
92 data = rawInt;
93 break;
94 case MaskedISR:
96 break;
97 default:
98 if (readId(pkt, ambaId, pioAddr)) {
99 // Hack for variable sized access
100 data = pkt->getUintX(ByteOrder::little);
101 break;
102 }
103 panic("Tried to read PL031 at offset %#x that doesn't exist\n", daddr);
104 break;
105 }
106
107 pkt->setUintX(data, ByteOrder::little);
108 pkt->makeAtomicResponse();
109 return pioDelay;
110}
111
112Tick
114{
115 assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
116 assert(pkt->getSize() <= 4);
117 Addr daddr = pkt->getAddr() - pioAddr;
118 DPRINTF(Timer, "Writing to RTC at offset: %#x\n", daddr);
119
120 switch (daddr) {
121 case DataReg:
122 break;
123 case MatchReg:
124 matchVal = pkt->getLE<uint32_t>();
125 resyncMatch();
126 break;
127 case LoadReg:
129 timeVal = pkt->getLE<uint32_t>();
131 resyncMatch();
132 break;
133 case ControlReg:
134 break; // Can't stop when started
135 case IntMask:
136 maskInt = pkt->getLE<uint32_t>();
137 break;
138 case IntClear:
139 if (pkt->getLE<uint32_t>()) {
140 rawInt = false;
141 pendingInt = false;
142 }
143 break;
144 default:
145 if (readId(pkt, ambaId, pioAddr))
146 break;
147 panic("Tried to read PL031 at offset %#x that doesn't exist\n", daddr);
148 break;
149 }
150
151 pkt->makeAtomicResponse();
152 return pioDelay;
153}
154
155void
157{
158 DPRINTF(Timer, "Setting up new match event match=%d time=%d\n", matchVal,
159 timeVal);
160
161 uint32_t seconds_until = matchVal - timeVal;
162 Tick ticks_until = sim_clock::as_int::s * seconds_until;
163
164 if (matchEvent.scheduled()) {
165 DPRINTF(Timer, "-- Event was already schedule, de-scheduling\n");
167 }
168 schedule(matchEvent, curTick() + ticks_until);
169 DPRINTF(Timer, "-- Scheduling new event for: %d\n", curTick() + ticks_until);
170}
171
172void
174{
175 DPRINTF(Timer, "Counter reached zero\n");
176
177 rawInt = true;
178 bool old_pending = pendingInt;
180 if (pendingInt && !old_pending) {
181 DPRINTF(Timer, "-- Causing interrupt\n");
182 interrupt->raise();
183 }
184}
185
186void
188{
189 DPRINTF(Checkpoint, "Serializing Arm PL031\n");
197
198 bool is_in_event = matchEvent.scheduled();
199 SERIALIZE_SCALAR(is_in_event);
200
201 Tick event_time;
202 if (is_in_event){
203 event_time = matchEvent.when();
204 SERIALIZE_SCALAR(event_time);
205 }
206}
207
208void
210{
211 DPRINTF(Checkpoint, "Unserializing Arm PL031\n");
212
220
221 bool is_in_event;
222 UNSERIALIZE_SCALAR(is_in_event);
223
224 Tick event_time;
225 if (is_in_event){
226 UNSERIALIZE_SCALAR(event_time);
227 schedule(matchEvent, event_time);
228 }
229}
230
231} // 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:209
const char data[]
bool readId(PacketPtr pkt, uint64_t amba_id, Addr pio_addr)
AmbaIntDevice(const Params &p, Addr pio_size)
ArmInterruptPin *const 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:69
bool rawInt
If timer has caused an interrupt.
Definition rtc_pl031.hh:84
bool pendingInt
If an interrupt is currently pending.
Definition rtc_pl031.hh:93
Tick read(PacketPtr pkt) override
Handle a read to the device.
Definition rtc_pl031.cc:65
Tick write(PacketPtr pkt) override
Handle writes to the device.
Definition rtc_pl031.cc:113
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition rtc_pl031.cc:187
PL031(const Params &p)
The constructor for RealView just registers itself with the MMU.
Definition rtc_pl031.cc:53
void counterMatch()
Called when the counter reaches matches.
Definition rtc_pl031.cc:173
EventFunctionWrapper matchEvent
Definition rtc_pl031.hh:97
uint32_t loadVal
Definition rtc_pl031.hh:75
void resyncMatch()
Called to update the matchEvent when the load Value or match value are written.
Definition rtc_pl031.cc:156
uint32_t matchVal
Definition rtc_pl031.hh:80
Tick lastWrittenTick
Definition rtc_pl031.hh:72
bool maskInt
If the timer interrupt mask that is anded with the raw interrupt to generate a pending interrupt.
Definition rtc_pl031.hh:89
PL031Params Params
Definition rtc_pl031.hh:105
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition rtc_pl031.cc:209
Addr getAddr() const
Definition packet.hh:807
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:817
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:1074
T getLE() const
Get the data in the packet byte swapped from little endian to host endian.
void deschedule(Event &event)
Definition eventq.hh:1021
void schedule(Event &event, Tick when)
Definition eventq.hh:1012
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:220
Bitfield< 0 > p
Bitfield< 32 > tm
Definition misc.hh:112
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
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
Packet * PacketPtr
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:48

Generated on Mon Oct 27 2025 04:13:01 for gem5 by doxygen 1.14.0