2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 #include "base/trace.hh"
41 #include "dev/mips/malta_pchip.hh"
42 #include "dev/mips/maltareg.h"
43 #include "dev/mips/malta.hh"
44 #include "mem/packet.hh"
45 #include "mem/packet_access.hh"
46 #include "sim/system.hh"
49 using namespace TheISA
;
51 MaltaPChip::MaltaPChip(const Params
*p
)
56 for (int i
= 0; i
< 4; i
++) {
62 // initialize pchip control register
63 pctl
= (ULL(0x1) << 20) | (ULL(0x1) << 32) | (ULL(0x2) << 36);
65 //Set back pointer in malta
66 p
->malta
->pchip
= this;
70 MaltaPChip::read(PacketPtr pkt
)
72 assert(pkt
->getAddr() >= pioAddr
&& pkt
->getAddr() < pioAddr
+ pioSize
);
75 Addr daddr
= (pkt
->getAddr() - pioAddr
) >> 6;;
76 assert(pkt
->getSize() == sizeof(uint64_t));
79 DPRINTF(Malta
, "read va=%#x size=%d\n", pkt
->getAddr(), pkt
->getSize());
122 panic("PC_PLAT not implemented\n");
124 panic("PC_RES not implemented\n");
125 case TSDEV_PC_PERROR
:
126 pkt
->set((uint64_t)0x00);
128 case TSDEV_PC_PERRMASK
:
129 pkt
->set((uint64_t)0x00);
131 case TSDEV_PC_PERRSET
:
132 panic("PC_PERRSET not implemented\n");
134 panic("PC_TLBIV not implemented\n");
136 pkt
->set((uint64_t)0x00); // shouldn't be readable, but linux
138 case TSDEV_PC_PMONCTL
:
139 panic("PC_PMONCTL not implemented\n");
140 case TSDEV_PC_PMONCNT
:
141 panic("PC_PMONCTN not implemented\n");
143 panic("Default in PChip Read reached reading 0x%x\n", daddr
);
145 pkt
->makeAtomicResponse();
151 MaltaPChip::write(PacketPtr pkt
)
153 assert(pkt
->getAddr() >= pioAddr
&& pkt
->getAddr() < pioAddr
+ pioSize
);
154 Addr daddr
= (pkt
->getAddr() - pioAddr
) >> 6;
156 assert(pkt
->getSize() == sizeof(uint64_t));
158 DPRINTF(Malta
, "write - va=%#x size=%d \n", pkt
->getAddr(), pkt
->getSize());
162 wsba
[0] = pkt
->get
<uint64_t>();
165 wsba
[1] = pkt
->get
<uint64_t>();
168 wsba
[2] = pkt
->get
<uint64_t>();
171 wsba
[3] = pkt
->get
<uint64_t>();
174 wsm
[0] = pkt
->get
<uint64_t>();
177 wsm
[1] = pkt
->get
<uint64_t>();
180 wsm
[2] = pkt
->get
<uint64_t>();
183 wsm
[3] = pkt
->get
<uint64_t>();
186 tba
[0] = pkt
->get
<uint64_t>();
189 tba
[1] = pkt
->get
<uint64_t>();
192 tba
[2] = pkt
->get
<uint64_t>();
195 tba
[3] = pkt
->get
<uint64_t>();
198 pctl
= pkt
->get
<uint64_t>();
201 panic("PC_PLAT not implemented\n");
203 panic("PC_RES not implemented\n");
204 case TSDEV_PC_PERROR
:
206 case TSDEV_PC_PERRMASK
:
207 panic("PC_PERRMASK not implemented\n");
208 case TSDEV_PC_PERRSET
:
209 panic("PC_PERRSET not implemented\n");
211 panic("PC_TLBIV not implemented\n");
213 break; // value ignored, supposted to invalidate SG TLB
214 case TSDEV_PC_PMONCTL
:
215 panic("PC_PMONCTL not implemented\n");
216 case TSDEV_PC_PMONCNT
:
217 panic("PC_PMONCTN not implemented\n");
219 panic("Default in PChip write reached reading 0x%x\n", daddr
);
223 pkt
->makeAtomicResponse();
227 #define DMA_ADDR_MASK ULL(0x3ffffffff)
230 MaltaPChip::translatePciToDma(Addr busAddr
)
232 // compare the address to the window base registers
233 uint64_t tbaMask
= 0;
236 uint64_t windowMask
= 0;
237 uint64_t windowBase
= 0;
239 uint64_t pteEntry
= 0;
245 DPRINTF(IdeDisk
, "Translation for bus address: %#x\n", busAddr
);
246 for (int i
= 0; i
< 4; i
++) {
247 DPRINTF(IdeDisk
, "(%d) base:%#x mask:%#x\n",
250 windowBase
= wsba
[i
];
251 windowMask
= ~wsm
[i
] & (ULL(0xfff) << 20);
253 if ((busAddr
& windowMask
) == (windowBase
& windowMask
)) {
254 DPRINTF(IdeDisk
, "Would have matched %d (wb:%#x wm:%#x --> ba&wm:%#x wb&wm:%#x)\n",
255 i
, windowBase
, windowMask
, (busAddr
& windowMask
),
256 (windowBase
& windowMask
));
261 for (int i
= 0; i
< 4; i
++) {
263 windowBase
= wsba
[i
];
264 windowMask
= ~wsm
[i
] & (ULL(0xfff) << 20);
266 if ((busAddr
& windowMask
) == (windowBase
& windowMask
)) {
268 if (wsba
[i
] & 0x1) { // see if enabled
269 if (wsba
[i
] & 0x2) { // see if SG bit is set
271 This currently is faked by just doing a direct
272 read from memory, however, to be realistic, this
273 needs to actually do a bus transaction. The process
274 is explained in the malta documentation on page
275 10-12 and basically munges the address to look up a
276 PTE from a table in memory and then uses that mapping
277 to create an address for the SG page
280 tbaMask
= ~(((wsm
[i
] & (ULL(0xfff) << 20)) >> 10) | ULL(0x3ff));
281 baMask
= (wsm
[i
] & (ULL(0xfff) << 20)) | (ULL(0x7f) << 13);
282 pteAddr
= (tba
[i
] & tbaMask
) | ((busAddr
& baMask
) >> 10);
284 pioPort
->readBlob(pteAddr
, (uint8_t*)&pteEntry
, sizeof(uint64_t));
286 dmaAddr
= ((pteEntry
& ~ULL(0x1)) << 12) | (busAddr
& ULL(0x1fff));
289 baMask
= (wsm
[i
] & (ULL(0xfff) << 20)) | ULL(0xfffff);
291 dmaAddr
= (tba
[i
] & tbaMask
) | (busAddr
& baMask
);
294 return (dmaAddr
& DMA_ADDR_MASK
);
299 // if no match was found, then return the original address
303 MaltaPChip::calcConfigAddr(int bus
, int dev
, int func
)
309 return MaltaPciBus0Config
| (func
<< 8) | (dev
<< 11);
315 MaltaPChip::serialize(std::ostream
&os
)
317 SERIALIZE_SCALAR(pctl
);
318 SERIALIZE_ARRAY(wsba
, 4);
319 SERIALIZE_ARRAY(wsm
, 4);
320 SERIALIZE_ARRAY(tba
, 4);
324 MaltaPChip::unserialize(Checkpoint
*cp
, const std::string
§ion
)
326 UNSERIALIZE_SCALAR(pctl
);
327 UNSERIALIZE_ARRAY(wsba
, 4);
328 UNSERIALIZE_ARRAY(wsm
, 4);
329 UNSERIALIZE_ARRAY(tba
, 4);
334 MaltaPChipParams::create()
336 return new MaltaPChip(this);