gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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->set(params()->proc_id0);
65  break;
66  case ProcId1:
67  pkt->set(params()->proc_id1);
68  break;
69  case Clock24:
70  Tick clk;
71  clk = SimClock::Float::MHz * curTick() * 24;
72  pkt->set((uint32_t)(clk));
73  break;
74  case Clock100:
75  Tick clk100;
76  clk100 = SimClock::Float::MHz * curTick() * 100;
77  pkt->set((uint32_t)(clk100));
78  break;
79  case Flash:
80  pkt->set<uint32_t>(0);
81  break;
82  case Clcd:
83  pkt->set<uint32_t>(0x00001F00);
84  break;
85  case Osc0:
86  pkt->set<uint32_t>(0x00012C5C);
87  break;
88  case Osc1:
89  pkt->set<uint32_t>(0x00002CC0);
90  break;
91  case Osc2:
92  pkt->set<uint32_t>(0x00002C75);
93  break;
94  case Osc3:
95  pkt->set<uint32_t>(0x00020211);
96  break;
97  case Osc4:
98  pkt->set<uint32_t>(0x00002C75);
99  break;
100  case Lock:
101  pkt->set<uint32_t>(sysLock);
102  break;
103  case Flags:
104  pkt->set<uint32_t>(flags);
105  break;
106  case IdReg:
107  pkt->set<uint32_t>(params()->idreg);
108  break;
109  case CfgStat:
110  pkt->set<uint32_t>(1);
111  break;
112  case CfgData:
113  pkt->set<uint32_t>(scData);
114  DPRINTF(RVCTRL, "Read %#x from SCReg\n", scData);
115  break;
116  case CfgCtrl:
117  pkt->set<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->set<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->get<uint16_t>();
148  break;
149  case Flags:
150  flags = pkt->get<uint32_t>();
151  break;
152  case FlagsClr:
153  flags = 0;
154  break;
155  case CfgData:
156  scData = pkt->get<uint32_t>();
157  break;
158  case CfgCtrl: {
159  // A request is being submitted to read/write the system control
160  // registers. See
161  // http://infocenter.arm.com/help/topic/com.arm.doc.dui0447h/CACDEFGH.html
162  CfgCtrlReg req = pkt->get<uint32_t>();
163  if (!req.start) {
164  DPRINTF(RVCTRL, "SCReg: write %#x to ctrl but not starting\n",
165  req);
166  break;
167  }
168 
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);
174  break;
175  }
176 
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);
180  if (req.wr) {
181  DPRINTF(RVCTRL, "SCReg: Writing %#x (ctrlWr %#x)\n",
182  scData, req);
183  dev.write(scData);
184 
185  } else {
186  scData = dev.read();
187  DPRINTF(RVCTRL, "SCReg: Reading %#x (ctrlRd %#x)\n",
188  scData, req);
189  }
190  } break;
191  case CfgStat: // Weird to write this
192  default:
193  warn("Tried to write RVIO at offset %#x (data %#x) that doesn't exist\n",
194  daddr, pkt->get<uint32_t>());
195  break;
196  }
197  pkt->makeAtomicResponse();
198  return pioDelay;
199 }
200 
201 void
203 {
205 }
206 
207 void
209 {
211 }
212 
213 void
214 RealViewCtrl::registerDevice(DeviceFunc func, uint8_t site, uint8_t pos,
215  uint8_t dcc, uint16_t dev,
216  Device *handler)
217 {
218  CfgCtrlReg addr = 0;
219  addr.func = func;
220  addr.site = site;
221  addr.pos = pos;
222  addr.dcc = dcc;
223  addr.dev = dev;
224 
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);
229  }
230 
231  devices[addr] = handler;
232 }
233 
234 
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)
239 {
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);
243  }
244 
245  _clockPeriod = p->freq;
246 }
247 
248 void
250 {
251  // Tell dependent object to set their clock frequency
252  for (auto m : members)
253  m->updateClockPeriod();
254 }
255 
256 void
258 {
260 }
261 
262 void
264 {
266 }
267 
268 void
270 {
271  panic_if(clock_period == 0, "%s has a clock period of zero\n", name());
272 
273  // Align all members to the current tick
274  for (auto m : members)
275  m->updateClockPeriod();
276 
277  _clockPeriod = clock_period;
278 
279  // inform any derived clocks they need to updated their period
280  for (auto m : children)
281  m->updateClockPeriod();
282 }
283 
284 uint32_t
286 {
287  const uint32_t freq(SimClock::Float::s / _clockPeriod);
288  DPRINTF(RVCTRL, "Reading OSC frequency: %f MHz\n", freq / 1E6);
289  return freq;
290 }
291 
292 void
293 RealViewOsc::write(uint32_t freq)
294 {
295  DPRINTF(RVCTRL, "Setting new OSC frequency: %f MHz\n", freq / 1E6);
297 }
298 
299 uint32_t
301 {
302  // Temperature reported in uC
304  if (tm) {
305  double t = tm->getTemp();
306  if (t < 0)
307  warn("Temperature below zero!\n");
308  return fmax(0, t) * 1000000;
309  }
310 
311  // Report a dummy 25 degrees temperature
312  return 25000000;
313 }
314 
315 RealViewCtrl *
316 RealViewCtrlParams::create()
317 {
318  return new RealViewCtrl(this);
319 }
320 
321 RealViewOsc *
322 RealViewOscParams::create()
323 {
324  return new RealViewOsc(this);
325 }
326 
328 RealViewTemperatureSensorParams::create()
329 {
330  return new RealViewTemperatureSensor(this);
331 }
#define DPRINTF(x,...)
Definition: trace.hh:212
void set(T v, ByteOrder endian)
Set the value in the data pointer to v using the specified endianness.
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: rv_ctrl.cc:257
Bitfield< 0 > m
Definition: miscregs.hh:1577
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
panic_if(!root,"Invalid expression\n")
uint32_t read() const override
Definition: rv_ctrl.cc:285
#define warn_once(...)
Definition: misc.hh:226
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're named after in a double...
Definition: core.cc:50
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:249
double MHz
MHz.
Definition: core.cc:58
T get(ByteOrder endian) const
Get the data in the packet byte swapped from the specified endianness.
Tick read(PacketPtr pkt) override
Handle a read to the device.
Definition: rv_ctrl.cc:56
#define warn(...)
Definition: misc.hh:219
This implements the simple real view registers on a PBXA9.
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:145
Tick curTick()
The current simulated tick.
Definition: core.hh:47
Addr pioSize
Size that the device's address range.
Definition: io_device.hh:142
void makeAtomicResponse()
Definition: packet.hh:857
Definition: flags.hh:35
uint64_t Tick
Tick count type.
Definition: types.hh:63
const Params * params() const
Definition: rv_ctrl.hh:160
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: rv_ctrl.cc:208
#define fatal(...)
Definition: misc.hh:163
Bitfield< 25, 20 > func
Definition: rv_ctrl.hh:136
System * system
The system this RV device belongs to.
Definition: rv_ctrl.hh:247
void registerDevice(DeviceFunc func, uint8_t site, uint8_t pos, uint8_t dcc, uint16_t dev, Device *handler)
Definition: rv_ctrl.cc:214
#define scData
Definition: coff_symconst.h:95
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: rv_ctrl.cc:202
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:245
void write(uint32_t freq) override
Definition: rv_ctrl.cc:293
RealViewCtrlParams Params
Definition: rv_ctrl.hh:158
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:143
virtual void write(uint32_t value)=0
ThermalModel * getThermalModel() const
The thermal model used for this system (if any).
Definition: system.hh:301
Bitfield< 15, 12 > pos
Definition: rv_ctrl.hh:134
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: rv_ctrl.cc:263
virtual const std::string name() const
Definition: sim_object.hh:117
std::vector< DerivedClockDomain * > children
Pointers to potential derived clock domains so we can propagate changes.
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...
Declaration of the Packet class.
std::ostream CheckpointOut
Definition: serialize.hh:67
RealViewOsc(RealViewOscParams *p)
Definition: rv_ctrl.cc:235
uint32_t read() const override
Definition: rv_ctrl.cc:300
Tick pioDelay
Delay that the device experinces on an access.
Definition: io_device.hh:145
Bitfield< 17, 16 > site
Definition: rv_ctrl.hh:135
double getTemp() const
Tick _clockPeriod
Pre-computed clock period in ticks.
Definition: clock_domain.hh:89
Bitfield< 5 > t
Definition: miscregs.hh:1382
unsigned getSize() const
Definition: packet.hh:649
Bitfield< 0 > p
uint32_t scData
This register contains the result from a system control reg access.
Definition: rv_ctrl.hh:155
Addr pioAddr
Address that the device listens to.
Definition: io_device.hh:139
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.
Addr getAddr() const
Definition: packet.hh:639
A ThermalModel is the element which ties all thermal objects together and provides the thermal solver...

Generated on Fri Jun 9 2017 13:03:45 for gem5 by doxygen 1.8.6