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

Generated on Fri Feb 28 2020 16:27:00 for gem5 by doxygen 1.8.13