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 "dev/arm/rv_ctrl.hh"
42 #include "base/trace.hh"
43 #include "debug/RVCTRL.hh"
44 #include "mem/packet.hh"
45 #include "mem/packet_access.hh"
46 #include "sim/power/thermal_model.hh"
47 #include "sim/system.hh"
48 #include "sim/voltage_domain.hh"
50 RealViewCtrl::RealViewCtrl(Params
*p
)
51 : BasicPioDevice(p
, 0xD4), flags(0), scData(0)
56 RealViewCtrl::read(PacketPtr pkt
)
58 assert(pkt
->getAddr() >= pioAddr
&& pkt
->getAddr() < pioAddr
+ pioSize
);
59 assert(pkt
->getSize() == 4);
60 Addr daddr
= pkt
->getAddr() - pioAddr
;
64 pkt
->set(params()->proc_id0
);
67 pkt
->set(params()->proc_id1
);
71 clk
= SimClock::Float::MHz
* curTick() * 24;
72 pkt
->set((uint32_t)(clk
));
76 clk100
= SimClock::Float::MHz
* curTick() * 100;
77 pkt
->set((uint32_t)(clk100
));
80 pkt
->set
<uint32_t>(0);
83 pkt
->set
<uint32_t>(0x00001F00);
86 pkt
->set
<uint32_t>(0x00012C5C);
89 pkt
->set
<uint32_t>(0x00002CC0);
92 pkt
->set
<uint32_t>(0x00002C75);
95 pkt
->set
<uint32_t>(0x00020211);
98 pkt
->set
<uint32_t>(0x00002C75);
101 pkt
->set
<uint32_t>(sysLock
);
104 pkt
->set
<uint32_t>(flags
);
107 pkt
->set
<uint32_t>(params()->idreg
);
110 pkt
->set
<uint32_t>(1);
113 pkt
->set
<uint32_t>(scData
);
114 DPRINTF(RVCTRL
, "Read %#x from SCReg\n", scData
);
117 pkt
->set
<uint32_t>(0); // not busy
118 DPRINTF(RVCTRL
, "Read 0 from CfgCtrl\n");
121 warn("Tried to read RealView I/O at offset %#x that doesn't exist\n",
123 pkt
->set
<uint32_t>(0);
126 pkt
->makeAtomicResponse();
132 RealViewCtrl::write(PacketPtr pkt
)
134 assert(pkt
->getAddr() >= pioAddr
&& pkt
->getAddr() < pioAddr
+ pioSize
);
136 Addr daddr
= pkt
->getAddr() - pioAddr
;
147 sysLock
.lockVal
= pkt
->get
<uint16_t>();
150 flags
= pkt
->get
<uint32_t>();
156 scData
= pkt
->get
<uint32_t>();
159 // A request is being submitted to read/write the system control
161 // http://infocenter.arm.com/help/topic/com.arm.doc.dui0447h/CACDEFGH.html
162 CfgCtrlReg req
= pkt
->get
<uint32_t>();
164 DPRINTF(RVCTRL
, "SCReg: write %#x to ctrl but not starting\n",
169 auto it_dev(devices
.find(req
& CFG_CTRL_ADDR_MASK
));
170 if (it_dev
== devices
.end()) {
171 warn_once("SCReg: Access to unknown device "
172 "dcc%d:site%d:pos%d:fn%d:dev%d\n",
173 req
.dcc
, req
.site
, req
.pos
, req
.func
, req
.dev
);
177 // Service the request as a read or write depending on the
178 // wr bit in the control register.
179 Device
&dev(*it_dev
->second
);
181 DPRINTF(RVCTRL
, "SCReg: Writing %#x (ctrlWr %#x)\n",
187 DPRINTF(RVCTRL
, "SCReg: Reading %#x (ctrlRd %#x)\n",
191 case CfgStat
: // Weird to write this
193 warn("Tried to write RVIO at offset %#x (data %#x) that doesn't exist\n",
194 daddr
, pkt
->get
<uint32_t>());
197 pkt
->makeAtomicResponse();
202 RealViewCtrl::serialize(CheckpointOut
&cp
) const
204 SERIALIZE_SCALAR(flags
);
208 RealViewCtrl::unserialize(CheckpointIn
&cp
)
210 UNSERIALIZE_SCALAR(flags
);
214 RealViewCtrl::registerDevice(DeviceFunc func
, uint8_t site
, uint8_t pos
,
215 uint8_t dcc
, uint16_t dev
,
225 if (devices
.find(addr
) != devices
.end()) {
226 fatal("Platform device dcc%d:site%d:pos%d:fn%d:dev%d "
227 "already registered.",
228 addr
.dcc
, addr
.site
, addr
.pos
, addr
.func
, addr
.dev
);
231 devices
[addr
] = handler
;
235 RealViewOsc::RealViewOsc(RealViewOscParams
*p
)
236 : ClockDomain(p
, p
->voltage_domain
),
237 RealViewCtrl::Device(*p
->parent
, RealViewCtrl::FUNC_OSC
,
238 p
->site
, p
->position
, p
->dcc
, p
->device
)
240 if (SimClock::Float::s
/ p
->freq
> UINT32_MAX
) {
241 fatal("Oscillator frequency out of range: %f\n",
242 SimClock::Float::s
/ p
->freq
/ 1E6
);
245 _clockPeriod
= p
->freq
;
249 RealViewOsc::startup()
251 // Tell dependent object to set their clock frequency
252 for (auto m
: members
)
253 m
->updateClockPeriod();
257 RealViewOsc::serialize(CheckpointOut
&cp
) const
259 SERIALIZE_SCALAR(_clockPeriod
);
263 RealViewOsc::unserialize(CheckpointIn
&cp
)
265 UNSERIALIZE_SCALAR(_clockPeriod
);
269 RealViewOsc::clockPeriod(Tick clock_period
)
271 panic_if(clock_period
== 0, "%s has a clock period of zero\n", name());
273 // Align all members to the current tick
274 for (auto m
: members
)
275 m
->updateClockPeriod();
277 _clockPeriod
= clock_period
;
279 // inform any derived clocks they need to updated their period
280 for (auto m
: children
)
281 m
->updateClockPeriod();
285 RealViewOsc::read() const
287 const uint32_t freq(SimClock::Float::s
/ _clockPeriod
);
288 DPRINTF(RVCTRL
, "Reading OSC frequency: %f MHz\n", freq
/ 1E6
);
293 RealViewOsc::write(uint32_t freq
)
295 DPRINTF(RVCTRL
, "Setting new OSC frequency: %f MHz\n", freq
/ 1E6
);
296 clockPeriod(SimClock::Float::s
/ freq
);
300 RealViewTemperatureSensor::read() const
302 // Temperature reported in uC
303 ThermalModel
* tm
= system
->getThermalModel();
305 double t
= tm
->getTemp();
307 warn("Temperature below zero!\n");
308 return fmax(0, t
) * 1000000;
311 // Report a dummy 25 degrees temperature
316 RealViewCtrlParams::create()
318 return new RealViewCtrl(this);
322 RealViewOscParams::create()
324 return new RealViewOsc(this);
327 RealViewTemperatureSensor
*
328 RealViewTemperatureSensorParams::create()
330 return new RealViewTemperatureSensor(this);