2 * Copyright (c) 2004 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 "cpu/exec_context.hh"
39 #include "dev/console.hh"
40 #include "dev/etherdev.hh"
41 #include "dev/scsi_ctrl.hh"
42 #include "dev/tlaser_clock.hh"
43 #include "dev/tsunami_pchip.hh"
44 #include "dev/tsunamireg.h"
45 #include "dev/tsunami.hh"
46 #include "mem/functional_mem/memory_control.hh"
47 #include "mem/functional_mem/physical_memory.hh"
48 #include "sim/builder.hh"
49 #include "sim/system.hh"
53 TsunamiPChip::TsunamiPChip(const string
&name
, Tsunami
*t
, Addr a
,
54 MemoryController
*mmu
)
55 : FunctionalMemory(name
), addr(a
), tsunami(t
)
57 mmu
->add_child(this, Range
<Addr
>(addr
, addr
+ size
));
59 for (int i
= 0; i
< 4; i
++) {
65 // initialize pchip control register
66 pctl
= (ULL(0x1) << 20) | (ULL(0x1) << 32) | (ULL(0x2) << 36);
68 //Set back pointer in tsunami
69 tsunami
->pchip
= this;
73 TsunamiPChip::read(MemReqPtr
&req
, uint8_t *data
)
75 DPRINTF(Tsunami
, "read va=%#x size=%d\n",
76 req
->vaddr
, req
->size
);
78 Addr daddr
= (req
->paddr
- (addr
& PA_IMPL_MASK
)) >> 6;
82 case sizeof(uint64_t):
85 *(uint64_t*)data
= wsba
[0];
88 *(uint64_t*)data
= wsba
[1];
91 *(uint64_t*)data
= wsba
[2];
94 *(uint64_t*)data
= wsba
[3];
97 *(uint64_t*)data
= wsm
[0];
100 *(uint64_t*)data
= wsm
[1];
103 *(uint64_t*)data
= wsm
[2];
106 *(uint64_t*)data
= wsm
[3];
109 *(uint64_t*)data
= tba
[0];
112 *(uint64_t*)data
= tba
[1];
115 *(uint64_t*)data
= tba
[2];
118 *(uint64_t*)data
= tba
[3];
121 *(uint64_t*)data
= pctl
;
124 panic("PC_PLAT not implemented\n");
126 panic("PC_RES not implemented\n");
127 case TSDEV_PC_PERROR
:
128 *(uint64_t*)data
= 0x00;
130 case TSDEV_PC_PERRMASK
:
131 *(uint64_t*)data
= 0x00;
133 case TSDEV_PC_PERRSET
:
134 panic("PC_PERRSET not implemented\n");
136 panic("PC_TLBIV not implemented\n");
138 *(uint64_t*)data
= 0x00; // shouldn't be readable, but linux
140 case TSDEV_PC_PMONCTL
:
141 panic("PC_PMONCTL not implemented\n");
142 case TSDEV_PC_PMONCNT
:
143 panic("PC_PMONCTN not implemented\n");
145 panic("Default in PChip Read reached reading 0x%x\n", daddr
);
150 case sizeof(uint32_t):
151 case sizeof(uint16_t):
152 case sizeof(uint8_t):
154 panic("invalid access size(?) for tsunami register!\n\n");
156 DPRINTFN("Tsunami PChip ERROR: read daddr=%#x size=%d\n", daddr
, req
->size
);
162 TsunamiPChip::write(MemReqPtr
&req
, const uint8_t *data
)
164 DPRINTF(Tsunami
, "write - va=%#x size=%d \n",
165 req
->vaddr
, req
->size
);
167 Addr daddr
= (req
->paddr
- (addr
& PA_IMPL_MASK
)) >> 6;
171 case sizeof(uint64_t):
174 wsba
[0] = *(uint64_t*)data
;
177 wsba
[1] = *(uint64_t*)data
;
180 wsba
[2] = *(uint64_t*)data
;
183 wsba
[3] = *(uint64_t*)data
;
186 wsm
[0] = *(uint64_t*)data
;
189 wsm
[1] = *(uint64_t*)data
;
192 wsm
[2] = *(uint64_t*)data
;
195 wsm
[3] = *(uint64_t*)data
;
198 tba
[0] = *(uint64_t*)data
;
201 tba
[1] = *(uint64_t*)data
;
204 tba
[2] = *(uint64_t*)data
;
207 tba
[3] = *(uint64_t*)data
;
210 pctl
= *(uint64_t*)data
;
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 return No_Fault
; // 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 Read reached reading 0x%x\n", daddr
);
236 case sizeof(uint32_t):
237 case sizeof(uint16_t):
238 case sizeof(uint8_t):
240 panic("invalid access size(?) for tsunami register!\n\n");
243 DPRINTFN("Tsunami ERROR: write daddr=%#x size=%d\n", daddr
, req
->size
);
248 #define DMA_ADDR_MASK ULL(0x3ffffffff)
251 TsunamiPChip::translatePciToDma(Addr busAddr
)
253 // compare the address to the window base registers
254 uint64_t tbaMask
= 0;
257 uint64_t windowMask
= 0;
258 uint64_t windowBase
= 0;
260 uint64_t pteEntry
= 0;
266 DPRINTF(IdeDisk
, "Translation for bus address: %#x\n", busAddr
);
267 for (int i
= 0; i
< 4; i
++) {
268 DPRINTF(IdeDisk
, "(%d) base:%#x mask:%#x\n",
271 windowBase
= wsba
[i
];
272 windowMask
= ~wsm
[i
] & (ULL(0xfff) << 20);
274 if ((busAddr
& windowMask
) == (windowBase
& windowMask
)) {
275 DPRINTF(IdeDisk
, "Would have matched %d (wb:%#x wm:%#x --> ba&wm:%#x wb&wm:%#x)\n",
276 i
, windowBase
, windowMask
, (busAddr
& windowMask
),
277 (windowBase
& windowMask
));
282 for (int i
= 0; i
< 4; i
++) {
284 windowBase
= wsba
[i
];
285 windowMask
= ~wsm
[i
] & (ULL(0xfff) << 20);
287 if ((busAddr
& windowMask
) == (windowBase
& windowMask
)) {
289 if (wsba
[i
] & 0x1) { // see if enabled
290 if (wsba
[i
] & 0x2) { // see if SG bit is set
292 This currently is faked by just doing a direct
293 read from memory, however, to be realistic, this
294 needs to actually do a bus transaction. The process
295 is explained in the tsunami documentation on page
296 10-12 and basically munges the address to look up a
297 PTE from a table in memory and then uses that mapping
298 to create an address for the SG page
301 tbaMask
= ~(((wsm
[i
] & (ULL(0xfff) << 20)) >> 10) | ULL(0x3ff));
302 baMask
= (wsm
[i
] & (ULL(0xfff) << 20)) | (ULL(0x7f) << 13);
303 pteAddr
= (tba
[i
] & tbaMask
) | ((busAddr
& baMask
) >> 10);
305 memcpy((void *)&pteEntry
,
307 physmem
->dma_addr(pteAddr
, sizeof(uint64_t)),
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(std::ostream
&os
)
330 SERIALIZE_SCALAR(pctl
);
331 SERIALIZE_ARRAY(wsba
, 4);
332 SERIALIZE_ARRAY(wsm
, 4);
333 SERIALIZE_ARRAY(tba
, 4);
337 TsunamiPChip::unserialize(Checkpoint
*cp
, const std::string
§ion
)
339 UNSERIALIZE_SCALAR(pctl
);
340 UNSERIALIZE_ARRAY(wsba
, 4);
341 UNSERIALIZE_ARRAY(wsm
, 4);
342 UNSERIALIZE_ARRAY(tba
, 4);
345 BEGIN_DECLARE_SIM_OBJECT_PARAMS(TsunamiPChip
)
347 SimObjectParam
<Tsunami
*> tsunami
;
348 SimObjectParam
<MemoryController
*> mmu
;
351 END_DECLARE_SIM_OBJECT_PARAMS(TsunamiPChip
)
353 BEGIN_INIT_SIM_OBJECT_PARAMS(TsunamiPChip
)
355 INIT_PARAM(tsunami
, "Tsunami"),
356 INIT_PARAM(mmu
, "Memory Controller"),
357 INIT_PARAM(addr
, "Device Address")
359 END_INIT_SIM_OBJECT_PARAMS(TsunamiPChip
)
361 CREATE_SIM_OBJECT(TsunamiPChip
)
363 return new TsunamiPChip(getInstanceName(), tsunami
, addr
, mmu
);
366 REGISTER_SIM_OBJECT("TsunamiPChip", TsunamiPChip
)