2 * Copyright (c) 2010,2013 ARM Limited
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.
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.
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.
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"
46 RealViewCtrl::RealViewCtrl(Params
*p
)
47 : BasicPioDevice(p
, 0xD4), flags(0), scData(0)
52 RealViewCtrl::read(PacketPtr pkt
)
54 assert(pkt
->getAddr() >= pioAddr
&& pkt
->getAddr() < pioAddr
+ pioSize
);
55 assert(pkt
->getSize() == 4);
56 Addr daddr
= pkt
->getAddr() - pioAddr
;
61 pkt
->set(params()->proc_id0
);
64 pkt
->set(params()->proc_id1
);
68 clk
= SimClock::Float::MHz
* curTick() * 24;
69 pkt
->set((uint32_t)(clk
));
73 clk100
= SimClock::Float::MHz
* curTick() * 100;
74 pkt
->set((uint32_t)(clk100
));
77 pkt
->set
<uint32_t>(0);
80 pkt
->set
<uint32_t>(0x00001F00);
83 pkt
->set
<uint32_t>(0x00012C5C);
86 pkt
->set
<uint32_t>(0x00002CC0);
89 pkt
->set
<uint32_t>(0x00002C75);
92 pkt
->set
<uint32_t>(0x00020211);
95 pkt
->set
<uint32_t>(0x00002C75);
98 pkt
->set
<uint32_t>(sysLock
);
101 pkt
->set
<uint32_t>(flags
);
104 pkt
->set
<uint32_t>(params()->idreg
);
107 pkt
->set
<uint32_t>(1);
110 pkt
->set
<uint32_t>(scData
);
111 DPRINTF(RVCTRL
, "Read %#x from SCReg\n", scData
);
114 pkt
->set
<uint32_t>(0); // not busy
115 DPRINTF(RVCTRL
, "Read 0 from CfgCtrl\n");
118 warn("Tried to read RealView I/O at offset %#x that doesn't exist\n",
120 pkt
->set
<uint32_t>(0);
123 pkt
->makeAtomicResponse();
129 RealViewCtrl::write(PacketPtr pkt
)
131 assert(pkt
->getAddr() >= pioAddr
&& pkt
->getAddr() < pioAddr
+ pioSize
);
133 Addr daddr
= pkt
->getAddr() - pioAddr
;
144 sysLock
.lockVal
= pkt
->get
<uint16_t>();
147 flags
= pkt
->get
<uint32_t>();
153 scData
= pkt
->get
<uint32_t>();
156 // A request is being submitted to read/write the system control
158 // http://infocenter.arm.com/help/topic/com.arm.doc.dui0447h/CACDEFGH.html
159 // For now, model as much of the OSC regs (can't find docs) as Linux
160 // seems to require (can't find docs); some clocks are deemed to be 0,
161 // giving all kinds of /0 problems booting Linux 3.9. Return a
162 // vaguely plausible number within the range the device trees state:
163 uint32_t data
= pkt
->get
<uint32_t>();
164 uint16_t dev
= bits(data
, 11, 0);
165 uint8_t pos
= bits(data
, 15, 12);
166 uint8_t site
= bits(data
, 17, 16);
167 uint8_t func
= bits(data
, 25, 20);
168 uint8_t dcc
= bits(data
, 29, 26);
169 bool wr
= bits(data
, 30);
170 bool start
= bits(data
, 31);
174 warn_once("SCReg: Writing %#x to dcc%d:site%d:pos%d:fn%d:dev%d\n",
175 scData
, dcc
, site
, pos
, func
, dev
);
176 // Only really support reading, for now!
178 // Only deal with function 1 (oscillators) so far!
179 if (dcc
!= 0 || pos
!= 0 || func
!= 1) {
180 warn("SCReg: read from unknown area "
181 "(dcc %d:site%d:pos%d:fn%d:dev%d)\n",
182 dcc
, site
, pos
, func
, dev
);
185 case 0: { // Motherboard regs
193 case 2: // PeriphClk 24MHz
198 warn("SCReg: read from unknown dev %d "
199 "(site%d:pos%d:fn%d)\n",
200 dev
, site
, pos
, func
);
203 case 1: { // Coretile 1 regs
205 case 0: // CPU PLL ref
208 case 4: // Muxed AXI master clock
217 case 7: // SYS PLL (also used for pl011 UART!)
220 case 8: // DDR PLL 40MHz fixed
225 warn("SCReg: read from unknown dev %d "
226 "(site%d:pos%d:fn%d)\n",
227 dev
, site
, pos
, func
);
231 warn("SCReg: Read from unknown site %d (pos%d:fn%d:dev%d)\n",
232 site
, pos
, func
, dev
);
234 DPRINTF(RVCTRL
, "SCReg: Will read %#x (ctrlWr %#x)\n", scData
, data
);
238 DPRINTF(RVCTRL
, "SCReg: write %#x to ctrl but not starting\n", data
);
241 case CfgStat
: // Weird to write this
243 warn("Tried to write RVIO at offset %#x (data %#x) that doesn't exist\n",
244 daddr
, pkt
->get
<uint32_t>());
247 pkt
->makeAtomicResponse();
252 RealViewCtrl::serialize(std::ostream
&os
)
254 SERIALIZE_SCALAR(flags
);
258 RealViewCtrl::unserialize(Checkpoint
*cp
, const std::string
§ion
)
260 UNSERIALIZE_SCALAR(flags
);
264 RealViewCtrlParams::create()
266 return new RealViewCtrl(this);