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 --- 26 unchanged lines hidden (view full) --- 37 * Authors: Ali Saidi 38 */ 39 40#include "base/trace.hh" 41#include "debug/RVCTRL.hh" 42#include "dev/arm/rv_ctrl.hh" 43#include "mem/packet.hh" 44#include "mem/packet_access.hh" |
45#include "sim/voltage_domain.hh" |
46 47RealViewCtrl::RealViewCtrl(Params *p) 48 : BasicPioDevice(p, 0xD4), flags(0), scData(0) 49{ 50} 51 52Tick 53RealViewCtrl::read(PacketPtr pkt) --- 97 unchanged lines hidden (view full) --- 151 break; 152 case CfgData: 153 scData = pkt->get<uint32_t>(); 154 break; 155 case CfgCtrl: { 156 // A request is being submitted to read/write the system control 157 // registers. See 158 // http://infocenter.arm.com/help/topic/com.arm.doc.dui0447h/CACDEFGH.html |
159 CfgCtrlReg req = pkt->get<uint32_t>(); 160 if (!req.start) { 161 DPRINTF(RVCTRL, "SCReg: write %#x to ctrl but not starting\n", 162 req); 163 break; 164 } |
165 |
166 auto it_dev(devices.find(req & CFG_CTRL_ADDR_MASK)); 167 if (it_dev == devices.end()) { 168 warn_once("SCReg: Access to unknown device " 169 "dcc%d:site%d:pos%d:fn%d:dev%d\n", 170 req.dcc, req.site, req.pos, req.func, req.dev); 171 break; 172 } 173 174 // Service the request as a read or write depending on the 175 // wr bit in the control register. 176 Device &dev(*it_dev->second); 177 if (req.wr) { 178 DPRINTF(RVCTRL, "SCReg: Writing %#x (ctrlWr %#x)\n", 179 scData, req); 180 dev.write(scData); 181 |
182 } else { |
183 scData = dev.read(); 184 DPRINTF(RVCTRL, "SCReg: Reading %#x (ctrlRd %#x)\n", 185 scData, req); |
186 } 187 } break; 188 case CfgStat: // Weird to write this 189 default: 190 warn("Tried to write RVIO at offset %#x (data %#x) that doesn't exist\n", 191 daddr, pkt->get<uint32_t>()); 192 break; 193 } --- 8 unchanged lines hidden (view full) --- 202} 203 204void 205RealViewCtrl::unserialize(CheckpointIn &cp) 206{ 207 UNSERIALIZE_SCALAR(flags); 208} 209 |
210void 211RealViewCtrl::registerDevice(DeviceFunc func, uint8_t site, uint8_t pos, 212 uint8_t dcc, uint16_t dev, 213 Device *handler) 214{ 215 CfgCtrlReg addr = 0; 216 addr.func = func; 217 addr.site = site; 218 addr.pos = pos; 219 addr.dcc = dcc; 220 addr.dev = dev; 221 222 if (devices.find(addr) != devices.end()) { 223 fatal("Platform device dcc%d:site%d:pos%d:fn%d:dev%d " 224 "already registered.", 225 addr.dcc, addr.site, addr.pos, addr.func, addr.dev); 226 } 227 228 devices[addr] = handler; 229} 230 231 232RealViewOsc::RealViewOsc(RealViewOscParams *p) 233 : ClockDomain(p, p->voltage_domain), 234 RealViewCtrl::Device(*p->parent, RealViewCtrl::FUNC_OSC, 235 p->site, p->position, p->dcc, p->device) 236{ 237 if (SimClock::Float::s / p->freq > UINT32_MAX) { 238 fatal("Oscillator frequency out of range: %f\n", 239 SimClock::Float::s / p->freq / 1E6); 240 } 241 242 _clockPeriod = p->freq; 243} 244 245void 246RealViewOsc::startup() 247{ 248 // Tell dependent object to set their clock frequency 249 for (auto m : members) 250 m->updateClockPeriod(); 251} 252 253void 254RealViewOsc::serialize(CheckpointOut &cp) const 255{ 256 SERIALIZE_SCALAR(_clockPeriod); 257} 258 259void 260RealViewOsc::unserialize(CheckpointIn &cp) 261{ 262 UNSERIALIZE_SCALAR(_clockPeriod); 263} 264 265void 266RealViewOsc::clockPeriod(Tick clock_period) 267{ 268 panic_if(clock_period == 0, "%s has a clock period of zero\n", name()); 269 270 // Align all members to the current tick 271 for (auto m : members) 272 m->updateClockPeriod(); 273 274 _clockPeriod = clock_period; 275 276 // inform any derived clocks they need to updated their period 277 for (auto m : children) 278 m->updateClockPeriod(); 279} 280 281uint32_t 282RealViewOsc::read() const 283{ 284 const uint32_t freq(SimClock::Float::s / _clockPeriod); 285 DPRINTF(RVCTRL, "Reading OSC frequency: %f MHz\n", freq / 1E6); 286 return freq; 287} 288 289void 290RealViewOsc::write(uint32_t freq) 291{ 292 DPRINTF(RVCTRL, "Setting new OSC frequency: %f MHz\n", freq / 1E6); 293 clockPeriod(SimClock::Float::s / freq); 294} 295 296 297 |
298RealViewCtrl * 299RealViewCtrlParams::create() 300{ 301 return new RealViewCtrl(this); 302} |
303 304RealViewOsc * 305RealViewOscParams::create() 306{ 307 return new RealViewOsc(this); 308} |