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.
37 #include "base/trace.hh"
38 #include "dev/tsunami_pchip.hh"
39 #include "dev/tsunamireg.h"
40 #include "dev/tsunami.hh"
41 #include "mem/packet.hh"
42 #include "sim/builder.hh"
43 #include "sim/system.hh"
46 //Should this be AlphaISA?
47 using namespace TheISA
;
49 TsunamiPChip::TsunamiPChip(Params
*p
)
54 for (int i
= 0; i
< 4; i
++) {
60 // initialize pchip control register
61 pctl
= (ULL(0x1) << 20) | (ULL(0x1) << 32) | (ULL(0x2) << 36);
63 //Set back pointer in tsunami
64 p
->tsunami
->pchip
= this;
68 TsunamiPChip::read(Packet
*pkt
)
70 assert(pkt
->result
== Packet::Unknown
);
71 assert(pkt
->getAddr() >= pioAddr
&& pkt
->getAddr() < pioAddr
+ pioSize
);
74 pkt
->time
+= pioDelay
;
76 Addr daddr
= (pkt
->getAddr() - pioAddr
) >> 6;;
77 assert(pkt
->getSize() == sizeof(uint64_t));
80 DPRINTF(Tsunami
, "read va=%#x size=%d\n", pkt
->getAddr(), pkt
->getSize());
123 panic("PC_PLAT not implemented\n");
125 panic("PC_RES not implemented\n");
126 case TSDEV_PC_PERROR
:
127 pkt
->set((uint64_t)0x00);
129 case TSDEV_PC_PERRMASK
:
130 pkt
->set((uint64_t)0x00);
132 case TSDEV_PC_PERRSET
:
133 panic("PC_PERRSET not implemented\n");
135 panic("PC_TLBIV not implemented\n");
137 pkt
->set((uint64_t)0x00); // shouldn't be readable, but linux
139 case TSDEV_PC_PMONCTL
:
140 panic("PC_PMONCTL not implemented\n");
141 case TSDEV_PC_PMONCNT
:
142 panic("PC_PMONCTN not implemented\n");
144 panic("Default in PChip Read reached reading 0x%x\n", daddr
);
146 pkt
->result
= Packet::Success
;
152 TsunamiPChip::write(Packet
*pkt
)
154 pkt
->time
+= pioDelay
;
156 assert(pkt
->result
== Packet::Unknown
);
157 assert(pkt
->getAddr() >= pioAddr
&& pkt
->getAddr() < pioAddr
+ pioSize
);
158 Addr daddr
= (pkt
->getAddr() - pioAddr
) >> 6;
160 assert(pkt
->getSize() == sizeof(uint64_t));
162 DPRINTF(Tsunami
, "write - va=%#x size=%d \n", pkt
->getAddr(), pkt
->getSize());
166 wsba
[0] = pkt
->get
<uint64_t>();
169 wsba
[1] = pkt
->get
<uint64_t>();
172 wsba
[2] = pkt
->get
<uint64_t>();
175 wsba
[3] = pkt
->get
<uint64_t>();
178 wsm
[0] = pkt
->get
<uint64_t>();
181 wsm
[1] = pkt
->get
<uint64_t>();
184 wsm
[2] = pkt
->get
<uint64_t>();
187 wsm
[3] = pkt
->get
<uint64_t>();
190 tba
[0] = pkt
->get
<uint64_t>();
193 tba
[1] = pkt
->get
<uint64_t>();
196 tba
[2] = pkt
->get
<uint64_t>();
199 tba
[3] = pkt
->get
<uint64_t>();
202 pctl
= pkt
->get
<uint64_t>();
205 panic("PC_PLAT not implemented\n");
207 panic("PC_RES not implemented\n");
208 case TSDEV_PC_PERROR
:
210 case TSDEV_PC_PERRMASK
:
211 panic("PC_PERRMASK not implemented\n");
212 case TSDEV_PC_PERRSET
:
213 panic("PC_PERRSET not implemented\n");
215 panic("PC_TLBIV not implemented\n");
217 break; // value ignored, supposted to invalidate SG TLB
218 case TSDEV_PC_PMONCTL
:
219 panic("PC_PMONCTL not implemented\n");
220 case TSDEV_PC_PMONCNT
:
221 panic("PC_PMONCTN not implemented\n");
223 panic("Default in PChip write reached reading 0x%x\n", daddr
);
227 pkt
->result
= Packet::Success
;
231 #define DMA_ADDR_MASK ULL(0x3ffffffff)
234 TsunamiPChip::translatePciToDma(Addr busAddr
)
236 // compare the address to the window base registers
237 uint64_t tbaMask
= 0;
240 uint64_t windowMask
= 0;
241 uint64_t windowBase
= 0;
243 uint64_t pteEntry
= 0;
249 DPRINTF(IdeDisk
, "Translation for bus address: %#x\n", busAddr
);
250 for (int i
= 0; i
< 4; i
++) {
251 DPRINTF(IdeDisk
, "(%d) base:%#x mask:%#x\n",
254 windowBase
= wsba
[i
];
255 windowMask
= ~wsm
[i
] & (ULL(0xfff) << 20);
257 if ((busAddr
& windowMask
) == (windowBase
& windowMask
)) {
258 DPRINTF(IdeDisk
, "Would have matched %d (wb:%#x wm:%#x --> ba&wm:%#x wb&wm:%#x)\n",
259 i
, windowBase
, windowMask
, (busAddr
& windowMask
),
260 (windowBase
& windowMask
));
265 for (int i
= 0; i
< 4; i
++) {
267 windowBase
= wsba
[i
];
268 windowMask
= ~wsm
[i
] & (ULL(0xfff) << 20);
270 if ((busAddr
& windowMask
) == (windowBase
& windowMask
)) {
272 if (wsba
[i
] & 0x1) { // see if enabled
273 if (wsba
[i
] & 0x2) { // see if SG bit is set
275 This currently is faked by just doing a direct
276 read from memory, however, to be realistic, this
277 needs to actually do a bus transaction. The process
278 is explained in the tsunami documentation on page
279 10-12 and basically munges the address to look up a
280 PTE from a table in memory and then uses that mapping
281 to create an address for the SG page
284 tbaMask
= ~(((wsm
[i
] & (ULL(0xfff) << 20)) >> 10) | ULL(0x3ff));
285 baMask
= (wsm
[i
] & (ULL(0xfff) << 20)) | (ULL(0x7f) << 13);
286 pteAddr
= (tba
[i
] & tbaMask
) | ((busAddr
& baMask
) >> 10);
288 pioPort
->readBlob(pteAddr
, (uint8_t*)&pteEntry
, sizeof(uint64_t));
290 dmaAddr
= ((pteEntry
& ~ULL(0x1)) << 12) | (busAddr
& ULL(0x1fff));
293 baMask
= (wsm
[i
] & (ULL(0xfff) << 20)) | ULL(0xfffff);
295 dmaAddr
= (tba
[i
] & tbaMask
) | (busAddr
& baMask
);
298 return (dmaAddr
& DMA_ADDR_MASK
);
303 // if no match was found, then return the original address
308 TsunamiPChip::serialize(std::ostream
&os
)
310 SERIALIZE_SCALAR(pctl
);
311 SERIALIZE_ARRAY(wsba
, 4);
312 SERIALIZE_ARRAY(wsm
, 4);
313 SERIALIZE_ARRAY(tba
, 4);
317 TsunamiPChip::unserialize(Checkpoint
*cp
, const std::string
§ion
)
319 UNSERIALIZE_SCALAR(pctl
);
320 UNSERIALIZE_ARRAY(wsba
, 4);
321 UNSERIALIZE_ARRAY(wsm
, 4);
322 UNSERIALIZE_ARRAY(tba
, 4);
326 BEGIN_DECLARE_SIM_OBJECT_PARAMS(TsunamiPChip
)
328 Param
<Addr
> pio_addr
;
329 Param
<Tick
> pio_latency
;
330 SimObjectParam
<Platform
*> platform
;
331 SimObjectParam
<System
*> system
;
332 SimObjectParam
<Tsunami
*> tsunami
;
334 END_DECLARE_SIM_OBJECT_PARAMS(TsunamiPChip
)
336 BEGIN_INIT_SIM_OBJECT_PARAMS(TsunamiPChip
)
338 INIT_PARAM(pio_addr
, "Device Address"),
339 INIT_PARAM(pio_latency
, "Programmed IO latency"),
340 INIT_PARAM(platform
, "platform"),
341 INIT_PARAM(system
, "system object"),
342 INIT_PARAM(tsunami
, "Tsunami")
344 END_INIT_SIM_OBJECT_PARAMS(TsunamiPChip
)
346 CREATE_SIM_OBJECT(TsunamiPChip
)
348 TsunamiPChip::Params
*p
= new TsunamiPChip::Params
;
349 p
->name
= getInstanceName();
350 p
->pio_addr
= pio_addr
;
351 p
->pio_delay
= pio_latency
;
352 p
->platform
= platform
;
354 p
->tsunami
= tsunami
;
355 return new TsunamiPChip(p
);
358 REGISTER_SIM_OBJECT("TsunamiPChip", TsunamiPChip
)