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.
35 #include "dev/alpha/tsunami_pchip.hh"
41 #include "base/trace.hh"
42 #include "config/the_isa.hh"
43 #include "debug/Tsunami.hh"
44 #include "dev/alpha/tsunami.hh"
45 #include "dev/alpha/tsunami_cchip.hh"
46 #include "dev/alpha/tsunamireg.h"
47 #include "dev/pci/device.hh"
48 #include "mem/packet.hh"
49 #include "mem/packet_access.hh"
50 #include "sim/system.hh"
53 //Should this be AlphaISA?
54 using namespace TheISA
;
56 TsunamiPChip::TsunamiPChip(const Params
*p
)
58 pioRange(RangeSize(p
->pio_addr
, 0x1000)),
59 pioDelay(p
->pio_latency
)
61 for (int i
= 0; i
< 4; i
++) {
67 // initialize pchip control register
68 pctl
= (ULL(0x1) << 20) | (ULL(0x1) << 32) | (ULL(0x2) << 36);
70 //Set back pointer in tsunami
71 p
->tsunami
->pchip
= this;
75 TsunamiPChip::read(PacketPtr pkt
)
77 // We only need to handle our own configuration registers, pass
78 // unknown addresses to the generic code.
79 if (!pioRange
.contains(pkt
->getAddr()))
80 return GenericPciHost::read(pkt
);
82 Addr daddr
= (pkt
->getAddr() - pioRange
.start()) >> 6;;
83 assert(pkt
->getSize() == sizeof(uint64_t));
86 DPRINTF(Tsunami
, "read va=%#x size=%d\n", pkt
->getAddr(), pkt
->getSize());
129 panic("PC_PLAT not implemented\n");
131 panic("PC_RES not implemented\n");
132 case TSDEV_PC_PERROR
:
133 pkt
->set((uint64_t)0x00);
135 case TSDEV_PC_PERRMASK
:
136 pkt
->set((uint64_t)0x00);
138 case TSDEV_PC_PERRSET
:
139 panic("PC_PERRSET not implemented\n");
141 panic("PC_TLBIV not implemented\n");
143 pkt
->set((uint64_t)0x00); // shouldn't be readable, but linux
145 case TSDEV_PC_PMONCTL
:
146 panic("PC_PMONCTL not implemented\n");
147 case TSDEV_PC_PMONCNT
:
148 panic("PC_PMONCTN not implemented\n");
150 panic("Default in PChip Read reached reading 0x%x\n", daddr
);
153 pkt
->makeAtomicResponse();
159 TsunamiPChip::write(PacketPtr pkt
)
161 // We only need to handle our own configuration registers, pass
162 // unknown addresses to the generic code.
163 if (!pioRange
.contains(pkt
->getAddr()))
164 return GenericPciHost::write(pkt
);
166 Addr daddr
= (pkt
->getAddr() - pioRange
.start()) >> 6;
168 assert(pkt
->getSize() == sizeof(uint64_t));
170 DPRINTF(Tsunami
, "write - va=%#x size=%d \n", pkt
->getAddr(), pkt
->getSize());
174 wsba
[0] = pkt
->get
<uint64_t>();
177 wsba
[1] = pkt
->get
<uint64_t>();
180 wsba
[2] = pkt
->get
<uint64_t>();
183 wsba
[3] = pkt
->get
<uint64_t>();
186 wsm
[0] = pkt
->get
<uint64_t>();
189 wsm
[1] = pkt
->get
<uint64_t>();
192 wsm
[2] = pkt
->get
<uint64_t>();
195 wsm
[3] = pkt
->get
<uint64_t>();
198 tba
[0] = pkt
->get
<uint64_t>();
201 tba
[1] = pkt
->get
<uint64_t>();
204 tba
[2] = pkt
->get
<uint64_t>();
207 tba
[3] = pkt
->get
<uint64_t>();
210 pctl
= pkt
->get
<uint64_t>();
213 panic("PC_PLAT not implemented\n");
215 panic("PC_RES not implemented\n");
216 case TSDEV_PC_PERROR
:
218 case TSDEV_PC_PERRMASK
:
219 panic("PC_PERRMASK not implemented\n");
220 case TSDEV_PC_PERRSET
:
221 panic("PC_PERRSET not implemented\n");
223 panic("PC_TLBIV not implemented\n");
225 break; // value ignored, supposted to invalidate SG TLB
226 case TSDEV_PC_PMONCTL
:
227 panic("PC_PMONCTL not implemented\n");
228 case TSDEV_PC_PMONCNT
:
229 panic("PC_PMONCTN not implemented\n");
231 panic("Default in PChip write reached reading 0x%x\n", daddr
);
235 pkt
->makeAtomicResponse();
241 TsunamiPChip::getAddrRanges() const
243 return AddrRangeList({
244 RangeSize(confBase
, confSize
),
250 #define DMA_ADDR_MASK ULL(0x3ffffffff)
253 TsunamiPChip::dmaAddr(const PciBusAddr
&dev
, Addr busAddr
) const
255 // compare the address to the window base registers
256 uint64_t tbaMask
= 0;
259 uint64_t windowMask
= 0;
260 uint64_t windowBase
= 0;
262 uint64_t pteEntry
= 0;
268 DPRINTF(IdeDisk
, "Translation for bus address: %#x\n", busAddr
);
269 for (int i
= 0; i
< 4; i
++) {
270 DPRINTF(IdeDisk
, "(%d) base:%#x mask:%#x\n",
273 windowBase
= wsba
[i
];
274 windowMask
= ~wsm
[i
] & (ULL(0xfff) << 20);
276 if ((busAddr
& windowMask
) == (windowBase
& windowMask
)) {
277 DPRINTF(IdeDisk
, "Would have matched %d (wb:%#x wm:%#x --> ba&wm:%#x wb&wm:%#x)\n",
278 i
, windowBase
, windowMask
, (busAddr
& windowMask
),
279 (windowBase
& windowMask
));
284 for (int i
= 0; i
< 4; i
++) {
286 windowBase
= wsba
[i
];
287 windowMask
= ~wsm
[i
] & (ULL(0xfff) << 20);
289 if ((busAddr
& windowMask
) == (windowBase
& windowMask
)) {
291 if (wsba
[i
] & 0x1) { // see if enabled
292 if (wsba
[i
] & 0x2) { // see if SG bit is set
294 This currently is faked by just doing a direct
295 read from memory, however, to be realistic, this
296 needs to actually do a bus transaction. The process
297 is explained in the tsunami documentation on page
298 10-12 and basically munges the address to look up a
299 PTE from a table in memory and then uses that mapping
300 to create an address for the SG page
303 tbaMask
= ~(((wsm
[i
] & (ULL(0xfff) << 20)) >> 10) | ULL(0x3ff));
304 baMask
= (wsm
[i
] & (ULL(0xfff) << 20)) | (ULL(0x7f) << 13);
305 pteAddr
= (tba
[i
] & tbaMask
) | ((busAddr
& baMask
) >> 10);
307 sys
->physProxy
.readBlob(pteAddr
, (uint8_t*)&pteEntry
,
310 dmaAddr
= ((pteEntry
& ~ULL(0x1)) << 12) | (busAddr
& ULL(0x1fff));
313 baMask
= (wsm
[i
] & (ULL(0xfff) << 20)) | ULL(0xfffff);
315 dmaAddr
= (tba
[i
] & tbaMask
) | (busAddr
& baMask
);
318 return (dmaAddr
& DMA_ADDR_MASK
);
323 // if no match was found, then return the original address
328 TsunamiPChip::serialize(CheckpointOut
&cp
) const
330 SERIALIZE_SCALAR(pctl
);
331 SERIALIZE_ARRAY(wsba
, 4);
332 SERIALIZE_ARRAY(wsm
, 4);
333 SERIALIZE_ARRAY(tba
, 4);
337 TsunamiPChip::unserialize(CheckpointIn
&cp
)
339 UNSERIALIZE_SCALAR(pctl
);
340 UNSERIALIZE_ARRAY(wsba
, 4);
341 UNSERIALIZE_ARRAY(wsm
, 4);
342 UNSERIALIZE_ARRAY(tba
, 4);
347 TsunamiPChipParams::create()
349 return new TsunamiPChip(this);