gem5  v20.1.0.0
rv_ctrl.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010,2013,2015 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/rv_ctrl.hh"
39 
40 #include "base/trace.hh"
41 #include "debug/RVCTRL.hh"
42 #include "mem/packet.hh"
43 #include "mem/packet_access.hh"
45 #include "sim/system.hh"
46 #include "sim/voltage_domain.hh"
47 
49  : BasicPioDevice(p, 0xD4), flags(0), scData(0)
50 {
51 }
52 
53 Tick
55 {
56  assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
57  assert(pkt->getSize() == 4);
58  Addr daddr = pkt->getAddr() - pioAddr;
59 
60  switch(daddr) {
61  case ProcId0:
62  pkt->setLE(params()->proc_id0);
63  break;
64  case ProcId1:
65  pkt->setLE(params()->proc_id1);
66  break;
67  case Clock24:
68  Tick clk;
69  clk = SimClock::Float::MHz * curTick() * 24;
70  pkt->setLE((uint32_t)(clk));
71  break;
72  case Clock100:
73  Tick clk100;
74  clk100 = SimClock::Float::MHz * curTick() * 100;
75  pkt->setLE((uint32_t)(clk100));
76  break;
77  case Flash:
78  pkt->setLE<uint32_t>(0);
79  break;
80  case Clcd:
81  pkt->setLE<uint32_t>(0x00001F00);
82  break;
83  case Osc0:
84  pkt->setLE<uint32_t>(0x00012C5C);
85  break;
86  case Osc1:
87  pkt->setLE<uint32_t>(0x00002CC0);
88  break;
89  case Osc2:
90  pkt->setLE<uint32_t>(0x00002C75);
91  break;
92  case Osc3:
93  pkt->setLE<uint32_t>(0x00020211);
94  break;
95  case Osc4:
96  pkt->setLE<uint32_t>(0x00002C75);
97  break;
98  case Lock:
99  pkt->setLE<uint32_t>(sysLock);
100  break;
101  case Flags:
102  pkt->setLE<uint32_t>(flags);
103  break;
104  case IdReg:
105  pkt->setLE<uint32_t>(params()->idreg);
106  break;
107  case CfgStat:
108  pkt->setLE<uint32_t>(1);
109  break;
110  case CfgData:
111  pkt->setLE<uint32_t>(scData);
112  DPRINTF(RVCTRL, "Read %#x from SCReg\n", scData);
113  break;
114  case CfgCtrl:
115  pkt->setLE<uint32_t>(0); // not busy
116  DPRINTF(RVCTRL, "Read 0 from CfgCtrl\n");
117  break;
118  default:
119  warn("Tried to read RealView I/O at offset %#x that doesn't exist\n",
120  daddr);
121  pkt->setLE<uint32_t>(0);
122  break;
123  }
124  pkt->makeAtomicResponse();
125  return pioDelay;
126 
127 }
128 
129 Tick
131 {
132  assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
133 
134  Addr daddr = pkt->getAddr() - pioAddr;
135  switch (daddr) {
136  case Flash:
137  case Clcd:
138  case Osc0:
139  case Osc1:
140  case Osc2:
141  case Osc3:
142  case Osc4:
143  break;
144  case Lock:
145  sysLock.lockVal = pkt->getLE<uint16_t>();
146  break;
147  case ResetCtl:
148  // Ignore writes to reset control
149  warn_once("Ignoring write to reset control\n");
150  break;
151  case Flags:
152  flags = pkt->getLE<uint32_t>();
153  break;
154  case FlagsClr:
155  flags = 0;
156  break;
157  case CfgData:
158  scData = pkt->getLE<uint32_t>();
159  break;
160  case CfgCtrl: {
161  // A request is being submitted to read/write the system control
162  // registers. See
163  // http://infocenter.arm.com/help/topic/com.arm.doc.dui0447h/CACDEFGH.html
164  CfgCtrlReg req = pkt->getLE<uint32_t>();
165  if (!req.start) {
166  DPRINTF(RVCTRL, "SCReg: write %#x to ctrl but not starting\n",
167  req);
168  break;
169  }
170 
171  auto it_dev(devices.find(req & CFG_CTRL_ADDR_MASK));
172  if (it_dev == devices.end()) {
173  warn_once("SCReg: Access to unknown device "
174  "dcc%d:site%d:pos%d:fn%d:dev%d\n",
175  req.dcc, req.site, req.pos, req.func, req.dev);
176  break;
177  }
178 
179  // Service the request as a read or write depending on the
180  // wr bit in the control register.
181  Device &dev(*it_dev->second);
182  if (req.wr) {
183  DPRINTF(RVCTRL, "SCReg: Writing %#x (ctrlWr %#x)\n",
184  scData, req);
185  dev.write(scData);
186 
187  } else {
188  scData = dev.read();
189  DPRINTF(RVCTRL, "SCReg: Reading %#x (ctrlRd %#x)\n",
190  scData, req);
191  }
192  } break;
193  case CfgStat: // Weird to write this
194  default:
195  warn("Tried to write RVIO at offset %#x (data %#x) that doesn't exist\n",
196  daddr, pkt->getLE<uint32_t>());
197  break;
198  }
199  pkt->makeAtomicResponse();
200  return pioDelay;
201 }
202 
203 void
205 {
207 }
208 
209 void
211 {
213 }
214 
215 void
216 RealViewCtrl::registerDevice(DeviceFunc func, uint8_t site, uint8_t pos,
217  uint8_t dcc, uint16_t dev,
218  Device *handler)
219 {
220  CfgCtrlReg addr = 0;
221  addr.func = func;
222  addr.site = site;
223  addr.pos = pos;
224  addr.dcc = dcc;
225  addr.dev = dev;
226 
227  if (devices.find(addr) != devices.end()) {
228  fatal("Platform device dcc%d:site%d:pos%d:fn%d:dev%d "
229  "already registered.",
230  addr.dcc, addr.site, addr.pos, addr.func, addr.dev);
231  }
232 
233  devices[addr] = handler;
234 }
235 
236 
237 RealViewOsc::RealViewOsc(RealViewOscParams *p)
238  : ClockDomain(p, p->voltage_domain),
239  RealViewCtrl::Device(*p->parent, RealViewCtrl::FUNC_OSC,
240  p->site, p->position, p->dcc, p->device)
241 {
242  if (SimClock::Float::s / p->freq > UINT32_MAX) {
243  fatal("Oscillator frequency out of range: %f\n",
244  SimClock::Float::s / p->freq / 1E6);
245  }
246 
247  _clockPeriod = p->freq;
248 }
249 
250 void
252 {
253  // Tell dependent object to set their clock frequency
254  for (auto m : members)
255  m->updateClockPeriod();
256 }
257 
258 void
260 {
262 }
263 
264 void
266 {
268 }
269 
270 void
272 {
273  panic_if(clock_period == 0, "%s has a clock period of zero\n", name());
274 
275  // Align all members to the current tick
276  for (auto m : members)
277  m->updateClockPeriod();
278 
279  _clockPeriod = clock_period;
280 
281  // inform any derived clocks they need to updated their period
282  for (auto m : children)
283  m->updateClockPeriod();
284 }
285 
286 uint32_t
288 {
289  const uint32_t freq(SimClock::Float::s / _clockPeriod);
290  DPRINTF(RVCTRL, "Reading OSC frequency: %f MHz\n", freq / 1E6);
291  return freq;
292 }
293 
294 void
295 RealViewOsc::write(uint32_t freq)
296 {
297  DPRINTF(RVCTRL, "Setting new OSC frequency: %f MHz\n", freq / 1E6);
299 }
300 
301 uint32_t
303 {
304  // Temperature reported in uC
306  if (tm) {
307  double t = tm->getTemp();
308  if (t < 0)
309  warn("Temperature below zero!\n");
310  return fmax(0, t) * 1000000;
311  }
312 
313  // Report a dummy 25 degrees temperature
314  return 25000000;
315 }
316 
317 RealViewCtrl *
318 RealViewCtrlParams::create()
319 {
320  return new RealViewCtrl(this);
321 }
322 
323 RealViewOsc *
324 RealViewOscParams::create()
325 {
326  return new RealViewOsc(this);
327 }
328 
330 RealViewTemperatureSensorParams::create()
331 {
332  return new RealViewTemperatureSensor(this);
333 }
fatal
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:183
RealViewCtrl::registerDevice
void registerDevice(DeviceFunc func, uint8_t site, uint8_t pos, uint8_t dcc, uint16_t dev, Device *handler)
Definition: rv_ctrl.cc:216
ThermalModel
Definition: thermal_model.hh:147
Packet::makeAtomicResponse
void makeAtomicResponse()
Definition: packet.hh:1016
RealViewTemperatureSensor
This device implements the temperature sensor used in the RealView/Versatile Express platform.
Definition: rv_ctrl.hh:227
SimClock::Float::s
double s
These variables equal the number of ticks in the unit of time they're named after in a double.
Definition: core.cc:49
BasicPioDevice::pioAddr
Addr pioAddr
Address that the device listens to.
Definition: io_device.hh:154
RealViewOsc::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: rv_ctrl.cc:259
warn
#define warn(...)
Definition: logging.hh:239
system.hh
voltage_domain.hh
RealViewCtrl::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: rv_ctrl.cc:204
UNSERIALIZE_SCALAR
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:797
Packet::getAddr
Addr getAddr() const
Definition: packet.hh:754
RealViewCtrl::RealViewCtrl
RealViewCtrl(Params *p)
The constructor for RealView just registers itself with the MMU.
Definition: rv_ctrl.cc:48
warn_once
#define warn_once(...)
Definition: logging.hh:243
RealViewCtrl::params
const Params * params() const
Definition: rv_ctrl.hh:158
SimClock::Float::MHz
double MHz
MHz.
Definition: core.cc:57
RealViewCtrl::pos
Bitfield< 15, 12 > pos
Definition: rv_ctrl.hh:132
RealViewCtrl::Osc3
@ Osc3
Definition: rv_ctrl.hh:92
RealViewCtrl::Params
RealViewCtrlParams Params
Definition: rv_ctrl.hh:156
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:63
thermal_model.hh
Packet::getSize
unsigned getSize() const
Definition: packet.hh:764
RealViewOsc::read
uint32_t read() const override
Definition: rv_ctrl.cc:287
RealViewCtrl::Osc2
@ Osc2
Definition: rv_ctrl.hh:91
RealViewCtrl::Flash
@ Flash
Definition: rv_ctrl.hh:105
RealViewCtrl::func
Bitfield< 25, 20 > func
Definition: rv_ctrl.hh:134
RealViewCtrl::CfgData
@ CfgData
Definition: rv_ctrl.hh:114
ClockDomain
The ClockDomain provides clock to group of clocked objects bundled under the same clock domain.
Definition: clock_domain.hh:68
packet.hh
RealViewCtrl::Lock
@ Lock
Definition: rv_ctrl.hh:94
RealViewCtrl::site
Bitfield< 17, 16 > site
Definition: rv_ctrl.hh:133
RealViewCtrl::flags
uint32_t flags
This register is used for smp booting.
Definition: rv_ctrl.hh:149
RealViewCtrl::CfgStat
@ CfgStat
Definition: rv_ctrl.hh:116
RealViewCtrl::dcc
Bitfield< 29, 26 > dcc
Definition: rv_ctrl.hh:135
RealViewCtrl::FlagsClr
@ FlagsClr
Definition: rv_ctrl.hh:99
cp
Definition: cprintf.cc:40
RealViewOsc::startup
void startup() override
startup() is the final initialization call before simulation.
Definition: rv_ctrl.cc:251
ClockDomain::members
std::vector< Clocked * > members
Pointers to members of this clock domain, so that when the clock period changes, we can update each m...
Definition: clock_domain.hh:93
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:234
RealViewCtrl::Osc1
@ Osc1
Definition: rv_ctrl.hh:90
rv_ctrl.hh
RealViewCtrl::scData
uint32_t scData
This register contains the result from a system control reg access.
Definition: rv_ctrl.hh:153
ThermalModel::getTemp
double getTemp() const
Definition: thermal_model.cc:296
RealViewCtrl
Definition: rv_ctrl.hh:51
RealViewCtrl::ProcId0
@ ProcId0
Definition: rv_ctrl.hh:112
RealViewCtrl::read
Tick read(PacketPtr pkt) override
Handle a read to the device.
Definition: rv_ctrl.cc:54
BasicPioDevice::pioSize
Addr pioSize
Size that the device's address range.
Definition: io_device.hh:157
RealViewCtrl::Clock24
@ Clock24
Definition: rv_ctrl.hh:109
RealViewCtrl::ResetCtl
@ ResetCtl
Definition: rv_ctrl.hh:102
RealViewCtrl::CfgCtrl
@ CfgCtrl
Definition: rv_ctrl.hh:115
RealViewCtrl::Clcd
@ Clcd
Definition: rv_ctrl.hh:106
System::getThermalModel
ThermalModel * getThermalModel() const
The thermal model used for this system (if any).
Definition: system.hh:406
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
RealViewOsc::RealViewOsc
RealViewOsc(RealViewOscParams *p)
Definition: rv_ctrl.cc:237
RealViewOsc::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: rv_ctrl.cc:265
SERIALIZE_SCALAR
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:790
packet_access.hh
RealViewCtrl::write
Tick write(PacketPtr pkt) override
All writes are simply ignored.
Definition: rv_ctrl.cc:130
RealViewCtrl::dev
dev
Definition: rv_ctrl.hh:131
RealViewCtrl::IdReg
@ IdReg
Definition: rv_ctrl.hh:86
RealViewOsc::write
void write(uint32_t freq) override
Definition: rv_ctrl.cc:295
SimObject::name
virtual const std::string name() const
Definition: sim_object.hh:133
RealViewTemperatureSensor::system
System * system
The system this RV device belongs to.
Definition: rv_ctrl.hh:245
RealViewCtrl::Flags
@ Flags
Definition: rv_ctrl.hh:98
panic_if
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:197
RealViewCtrl::Clock100
@ Clock100
Definition: rv_ctrl.hh:95
Packet::getLE
T getLE() const
Get the data in the packet byte swapped from little endian to host endian.
Definition: packet_access.hh:75
RealViewCtrl::Osc4
@ Osc4
Definition: rv_ctrl.hh:93
ArmISA::t
Bitfield< 5 > t
Definition: miscregs_types.hh:67
ClockDomain::children
std::vector< DerivedClockDomain * > children
Pointers to potential derived clock domains so we can propagate changes.
Definition: clock_domain.hh:87
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:257
BasicPioDevice
Definition: io_device.hh:150
RealViewCtrl::devices
std::map< uint32_t, Device * > devices
Definition: rv_ctrl.hh:191
RealViewCtrl::ProcId1
@ ProcId1
Definition: rv_ctrl.hh:113
addr
ip6_addr_t addr
Definition: inet.hh:423
RealViewCtrl::DeviceFunc
DeviceFunc
Definition: rv_ctrl.hh:54
BasicPioDevice::pioDelay
Tick pioDelay
Delay that the device experinces on an access.
Definition: io_device.hh:160
Packet::setLE
void setLE(T v)
Set the value in the data pointer to v as little endian.
Definition: packet_access.hh:105
CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:63
RealViewCtrl::Device
Definition: rv_ctrl.hh:69
trace.hh
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
CheckpointIn
Definition: serialize.hh:67
RealViewOsc
This is an implementation of a programmable oscillator on the that can be configured through the Real...
Definition: rv_ctrl.hh:201
RealViewTemperatureSensor::read
uint32_t read() const override
Definition: rv_ctrl.cc:302
RealViewCtrl::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: rv_ctrl.cc:210
ClockDomain::clockPeriod
Tick clockPeriod() const
Get the clock period.
Definition: clock_domain.hh:105
RealViewCtrl::Osc0
@ Osc0
Definition: rv_ctrl.hh:89
ClockDomain::_clockPeriod
Tick _clockPeriod
Pre-computed clock period in ticks.
Definition: clock_domain.hh:76
ArmISA::m
Bitfield< 0 > m
Definition: miscregs_types.hh:389
RealViewCtrl::sysLock
SysLockReg sysLock
Definition: rv_ctrl.hh:142
curTick
Tick curTick()
The current simulated tick.
Definition: core.hh:45

Generated on Wed Sep 30 2020 14:02:10 for gem5 by doxygen 1.8.17