2 * Copyright (c) 2010,2013,2015 ARM Limited
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.
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.
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.
40 #include "base/trace.hh"
41 #include "debug/RVCTRL.hh"
42 #include "dev/arm/rv_ctrl.hh"
43 #include "mem/packet.hh"
44 #include "mem/packet_access.hh"
45 #include "sim/voltage_domain.hh"
47 RealViewCtrl::RealViewCtrl(Params
*p
)
48 : BasicPioDevice(p
, 0xD4), flags(0), scData(0)
53 RealViewCtrl::read(PacketPtr pkt
)
55 assert(pkt
->getAddr() >= pioAddr
&& pkt
->getAddr() < pioAddr
+ pioSize
);
56 assert(pkt
->getSize() == 4);
57 Addr daddr
= pkt
->getAddr() - pioAddr
;
61 pkt
->set(params()->proc_id0
);
64 pkt
->set(params()->proc_id1
);
68 clk
= SimClock::Float::MHz
* curTick() * 24;
69 pkt
->set((uint32_t)(clk
));
73 clk100
= SimClock::Float::MHz
* curTick() * 100;
74 pkt
->set((uint32_t)(clk100
));
77 pkt
->set
<uint32_t>(0);
80 pkt
->set
<uint32_t>(0x00001F00);
83 pkt
->set
<uint32_t>(0x00012C5C);
86 pkt
->set
<uint32_t>(0x00002CC0);
89 pkt
->set
<uint32_t>(0x00002C75);
92 pkt
->set
<uint32_t>(0x00020211);
95 pkt
->set
<uint32_t>(0x00002C75);
98 pkt
->set
<uint32_t>(sysLock
);
101 pkt
->set
<uint32_t>(flags
);
104 pkt
->set
<uint32_t>(params()->idreg
);
107 pkt
->set
<uint32_t>(1);
110 pkt
->set
<uint32_t>(scData
);
111 DPRINTF(RVCTRL
, "Read %#x from SCReg\n", scData
);
114 pkt
->set
<uint32_t>(0); // not busy
115 DPRINTF(RVCTRL
, "Read 0 from CfgCtrl\n");
118 warn("Tried to read RealView I/O at offset %#x that doesn't exist\n",
120 pkt
->set
<uint32_t>(0);
123 pkt
->makeAtomicResponse();
129 RealViewCtrl::write(PacketPtr pkt
)
131 assert(pkt
->getAddr() >= pioAddr
&& pkt
->getAddr() < pioAddr
+ pioSize
);
133 Addr daddr
= pkt
->getAddr() - pioAddr
;
144 sysLock
.lockVal
= pkt
->get
<uint16_t>();
147 flags
= pkt
->get
<uint32_t>();
153 scData
= pkt
->get
<uint32_t>();
156 // A request is being submitted to read/write the system control
158 // http://infocenter.arm.com/help/topic/com.arm.doc.dui0447h/CACDEFGH.html
159 CfgCtrlReg req
= pkt
->get
<uint32_t>();
161 DPRINTF(RVCTRL
, "SCReg: write %#x to ctrl but not starting\n",
166 auto it_dev(devices
.find(req
& CFG_CTRL_ADDR_MASK
));
167 if (it_dev
== devices
.end()) {
168 warn_once("SCReg: Access to unknown device "
169 "dcc%d:site%d:pos%d:fn%d:dev%d\n",
170 req
.dcc
, req
.site
, req
.pos
, req
.func
, req
.dev
);
174 // Service the request as a read or write depending on the
175 // wr bit in the control register.
176 Device
&dev(*it_dev
->second
);
178 DPRINTF(RVCTRL
, "SCReg: Writing %#x (ctrlWr %#x)\n",
184 DPRINTF(RVCTRL
, "SCReg: Reading %#x (ctrlRd %#x)\n",
188 case CfgStat
: // Weird to write this
190 warn("Tried to write RVIO at offset %#x (data %#x) that doesn't exist\n",
191 daddr
, pkt
->get
<uint32_t>());
194 pkt
->makeAtomicResponse();
199 RealViewCtrl::serialize(CheckpointOut
&cp
) const
201 SERIALIZE_SCALAR(flags
);
205 RealViewCtrl::unserialize(CheckpointIn
&cp
)
207 UNSERIALIZE_SCALAR(flags
);
211 RealViewCtrl::registerDevice(DeviceFunc func
, uint8_t site
, uint8_t pos
,
212 uint8_t dcc
, uint16_t dev
,
222 if (devices
.find(addr
) != devices
.end()) {
223 fatal("Platform device dcc%d:site%d:pos%d:fn%d:dev%d "
224 "already registered.",
225 addr
.dcc
, addr
.site
, addr
.pos
, addr
.func
, addr
.dev
);
228 devices
[addr
] = handler
;
232 RealViewOsc::RealViewOsc(RealViewOscParams
*p
)
233 : ClockDomain(p
, p
->voltage_domain
),
234 RealViewCtrl::Device(*p
->parent
, RealViewCtrl::FUNC_OSC
,
235 p
->site
, p
->position
, p
->dcc
, p
->device
)
237 if (SimClock::Float::s
/ p
->freq
> UINT32_MAX
) {
238 fatal("Oscillator frequency out of range: %f\n",
239 SimClock::Float::s
/ p
->freq
/ 1E6
);
242 _clockPeriod
= p
->freq
;
246 RealViewOsc::startup()
248 // Tell dependent object to set their clock frequency
249 for (auto m
: members
)
250 m
->updateClockPeriod();
254 RealViewOsc::serialize(CheckpointOut
&cp
) const
256 SERIALIZE_SCALAR(_clockPeriod
);
260 RealViewOsc::unserialize(CheckpointIn
&cp
)
262 UNSERIALIZE_SCALAR(_clockPeriod
);
266 RealViewOsc::clockPeriod(Tick clock_period
)
268 panic_if(clock_period
== 0, "%s has a clock period of zero\n", name());
270 // Align all members to the current tick
271 for (auto m
: members
)
272 m
->updateClockPeriod();
274 _clockPeriod
= clock_period
;
276 // inform any derived clocks they need to updated their period
277 for (auto m
: children
)
278 m
->updateClockPeriod();
282 RealViewOsc::read() const
284 const uint32_t freq(SimClock::Float::s
/ _clockPeriod
);
285 DPRINTF(RVCTRL
, "Reading OSC frequency: %f MHz\n", freq
/ 1E6
);
290 RealViewOsc::write(uint32_t freq
)
292 DPRINTF(RVCTRL
, "Setting new OSC frequency: %f MHz\n", freq
/ 1E6
);
293 clockPeriod(SimClock::Float::s
/ freq
);
299 RealViewCtrlParams::create()
301 return new RealViewCtrl(this);
305 RealViewOscParams::create()
307 return new RealViewOsc(this);