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/bus/bus.hh"
42 #include "mem/bus/pio_interface.hh"
43 #include "mem/bus/pio_interface_impl.hh"
44 #include "mem/functional/memory_control.hh"
45 #include "mem/functional/physical.hh"
46 #include "sim/builder.hh"
47 #include "sim/system.hh"
50 //Should this be AlphaISA?
51 using namespace TheISA
;
53 TsunamiPChip::TsunamiPChip(const string
&name
, Tsunami
*t
, Addr a
,
54 MemoryController
*mmu
, HierParams
*hier
,
55 Bus
*pio_bus
, Tick pio_latency
)
56 : PioDevice(name
, t
), addr(a
), tsunami(t
)
58 mmu
->add_child(this, RangeSize(addr
, size
));
60 for (int i
= 0; i
< 4; i
++) {
67 pioInterface
= newPioInterface(name
+ ".pio", hier
, pio_bus
, this,
68 &TsunamiPChip::cacheAccess
);
69 pioInterface
->addAddrRange(RangeSize(addr
, size
));
70 pioLatency
= pio_latency
* pio_bus
->clockRate
;
74 // initialize pchip control register
75 pctl
= (ULL(0x1) << 20) | (ULL(0x1) << 32) | (ULL(0x2) << 36);
77 //Set back pointer in tsunami
78 tsunami
->pchip
= this;
82 TsunamiPChip::read(MemReqPtr
&req
, uint8_t *data
)
84 DPRINTF(Tsunami
, "read va=%#x size=%d\n",
85 req
->vaddr
, req
->size
);
87 Addr daddr
= (req
->paddr
- (addr
& EV5::PAddrImplMask
)) >> 6;
91 case sizeof(uint64_t):
94 *(uint64_t*)data
= wsba
[0];
97 *(uint64_t*)data
= wsba
[1];
100 *(uint64_t*)data
= wsba
[2];
103 *(uint64_t*)data
= wsba
[3];
106 *(uint64_t*)data
= wsm
[0];
109 *(uint64_t*)data
= wsm
[1];
112 *(uint64_t*)data
= wsm
[2];
115 *(uint64_t*)data
= wsm
[3];
118 *(uint64_t*)data
= tba
[0];
121 *(uint64_t*)data
= tba
[1];
124 *(uint64_t*)data
= tba
[2];
127 *(uint64_t*)data
= tba
[3];
130 *(uint64_t*)data
= pctl
;
133 panic("PC_PLAT not implemented\n");
135 panic("PC_RES not implemented\n");
136 case TSDEV_PC_PERROR
:
137 *(uint64_t*)data
= 0x00;
139 case TSDEV_PC_PERRMASK
:
140 *(uint64_t*)data
= 0x00;
142 case TSDEV_PC_PERRSET
:
143 panic("PC_PERRSET not implemented\n");
145 panic("PC_TLBIV not implemented\n");
147 *(uint64_t*)data
= 0x00; // shouldn't be readable, but linux
149 case TSDEV_PC_PMONCTL
:
150 panic("PC_PMONCTL not implemented\n");
151 case TSDEV_PC_PMONCNT
:
152 panic("PC_PMONCTN not implemented\n");
154 panic("Default in PChip Read reached reading 0x%x\n", daddr
);
159 case sizeof(uint32_t):
160 case sizeof(uint16_t):
161 case sizeof(uint8_t):
163 panic("invalid access size(?) for tsunami register!\n\n");
165 DPRINTFN("Tsunami PChip ERROR: read daddr=%#x size=%d\n", daddr
, req
->size
);
171 TsunamiPChip::write(MemReqPtr
&req
, const uint8_t *data
)
173 DPRINTF(Tsunami
, "write - va=%#x size=%d \n",
174 req
->vaddr
, req
->size
);
176 Addr daddr
= (req
->paddr
- (addr
& EV5::PAddrImplMask
)) >> 6;
180 case sizeof(uint64_t):
183 wsba
[0] = *(uint64_t*)data
;
186 wsba
[1] = *(uint64_t*)data
;
189 wsba
[2] = *(uint64_t*)data
;
192 wsba
[3] = *(uint64_t*)data
;
195 wsm
[0] = *(uint64_t*)data
;
198 wsm
[1] = *(uint64_t*)data
;
201 wsm
[2] = *(uint64_t*)data
;
204 wsm
[3] = *(uint64_t*)data
;
207 tba
[0] = *(uint64_t*)data
;
210 tba
[1] = *(uint64_t*)data
;
213 tba
[2] = *(uint64_t*)data
;
216 tba
[3] = *(uint64_t*)data
;
219 pctl
= *(uint64_t*)data
;
222 panic("PC_PLAT not implemented\n");
224 panic("PC_RES not implemented\n");
225 case TSDEV_PC_PERROR
:
227 case TSDEV_PC_PERRMASK
:
228 panic("PC_PERRMASK not implemented\n");
229 case TSDEV_PC_PERRSET
:
230 panic("PC_PERRSET not implemented\n");
232 panic("PC_TLBIV not implemented\n");
234 return NoFault
; // value ignored, supposted to invalidate SG TLB
235 case TSDEV_PC_PMONCTL
:
236 panic("PC_PMONCTL not implemented\n");
237 case TSDEV_PC_PMONCNT
:
238 panic("PC_PMONCTN not implemented\n");
240 panic("Default in PChip Read reached reading 0x%x\n", daddr
);
245 case sizeof(uint32_t):
246 case sizeof(uint16_t):
247 case sizeof(uint8_t):
249 panic("invalid access size(?) for tsunami register!\n\n");
252 DPRINTFN("Tsunami ERROR: write daddr=%#x size=%d\n", daddr
, req
->size
);
257 #define DMA_ADDR_MASK ULL(0x3ffffffff)
260 TsunamiPChip::translatePciToDma(Addr busAddr
)
262 // compare the address to the window base registers
263 uint64_t tbaMask
= 0;
266 uint64_t windowMask
= 0;
267 uint64_t windowBase
= 0;
269 uint64_t pteEntry
= 0;
275 DPRINTF(IdeDisk
, "Translation for bus address: %#x\n", busAddr
);
276 for (int i
= 0; i
< 4; i
++) {
277 DPRINTF(IdeDisk
, "(%d) base:%#x mask:%#x\n",
280 windowBase
= wsba
[i
];
281 windowMask
= ~wsm
[i
] & (ULL(0xfff) << 20);
283 if ((busAddr
& windowMask
) == (windowBase
& windowMask
)) {
284 DPRINTF(IdeDisk
, "Would have matched %d (wb:%#x wm:%#x --> ba&wm:%#x wb&wm:%#x)\n",
285 i
, windowBase
, windowMask
, (busAddr
& windowMask
),
286 (windowBase
& windowMask
));
291 for (int i
= 0; i
< 4; i
++) {
293 windowBase
= wsba
[i
];
294 windowMask
= ~wsm
[i
] & (ULL(0xfff) << 20);
296 if ((busAddr
& windowMask
) == (windowBase
& windowMask
)) {
298 if (wsba
[i
] & 0x1) { // see if enabled
299 if (wsba
[i
] & 0x2) { // see if SG bit is set
301 This currently is faked by just doing a direct
302 read from memory, however, to be realistic, this
303 needs to actually do a bus transaction. The process
304 is explained in the tsunami documentation on page
305 10-12 and basically munges the address to look up a
306 PTE from a table in memory and then uses that mapping
307 to create an address for the SG page
310 tbaMask
= ~(((wsm
[i
] & (ULL(0xfff) << 20)) >> 10) | ULL(0x3ff));
311 baMask
= (wsm
[i
] & (ULL(0xfff) << 20)) | (ULL(0x7f) << 13);
312 pteAddr
= (tba
[i
] & tbaMask
) | ((busAddr
& baMask
) >> 10);
314 memcpy((void *)&pteEntry
,
316 physmem
->dma_addr(pteAddr
, sizeof(uint64_t)),
319 dmaAddr
= ((pteEntry
& ~ULL(0x1)) << 12) | (busAddr
& ULL(0x1fff));
322 baMask
= (wsm
[i
] & (ULL(0xfff) << 20)) | ULL(0xfffff);
324 dmaAddr
= (tba
[i
] & tbaMask
) | (busAddr
& baMask
);
327 return (dmaAddr
& DMA_ADDR_MASK
);
332 // if no match was found, then return the original address
337 TsunamiPChip::serialize(std::ostream
&os
)
339 SERIALIZE_SCALAR(pctl
);
340 SERIALIZE_ARRAY(wsba
, 4);
341 SERIALIZE_ARRAY(wsm
, 4);
342 SERIALIZE_ARRAY(tba
, 4);
346 TsunamiPChip::unserialize(Checkpoint
*cp
, const std::string
§ion
)
348 UNSERIALIZE_SCALAR(pctl
);
349 UNSERIALIZE_ARRAY(wsba
, 4);
350 UNSERIALIZE_ARRAY(wsm
, 4);
351 UNSERIALIZE_ARRAY(tba
, 4);
355 TsunamiPChip::cacheAccess(MemReqPtr
&req
)
357 return curTick
+ pioLatency
;
360 BEGIN_DECLARE_SIM_OBJECT_PARAMS(TsunamiPChip
)
362 SimObjectParam
<Tsunami
*> tsunami
;
363 SimObjectParam
<MemoryController
*> mmu
;
365 SimObjectParam
<Bus
*> pio_bus
;
366 Param
<Tick
> pio_latency
;
367 SimObjectParam
<HierParams
*> hier
;
369 END_DECLARE_SIM_OBJECT_PARAMS(TsunamiPChip
)
371 BEGIN_INIT_SIM_OBJECT_PARAMS(TsunamiPChip
)
373 INIT_PARAM(tsunami
, "Tsunami"),
374 INIT_PARAM(mmu
, "Memory Controller"),
375 INIT_PARAM(addr
, "Device Address"),
376 INIT_PARAM_DFLT(pio_bus
, "The IO Bus to attach to", NULL
),
377 INIT_PARAM_DFLT(pio_latency
, "Programmed IO latency in bus cycles", 1),
378 INIT_PARAM_DFLT(hier
, "Hierarchy global variables", &defaultHierParams
)
380 END_INIT_SIM_OBJECT_PARAMS(TsunamiPChip
)
382 CREATE_SIM_OBJECT(TsunamiPChip
)
384 return new TsunamiPChip(getInstanceName(), tsunami
, addr
, mmu
, hier
,
385 pio_bus
, pio_latency
);
388 REGISTER_SIM_OBJECT("TsunamiPChip", TsunamiPChip
)