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

Generated on Wed Dec 21 2022 10:22:33 for gem5 by doxygen 1.9.1