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 //Set back pointer in tsunami
66 tsunami
->pchip
= this;
70 TsunamiPChip::read(MemReqPtr
&req
, uint8_t *data
)
72 DPRINTF(Tsunami
, "read va=%#x size=%d\n",
73 req
->vaddr
, req
->size
);
75 Addr daddr
= (req
->paddr
- (addr
& PA_IMPL_MASK
)) >> 6;
79 case sizeof(uint64_t):
82 *(uint64_t*)data
= wsba
[0];
85 *(uint64_t*)data
= wsba
[1];
88 *(uint64_t*)data
= wsba
[2];
91 *(uint64_t*)data
= wsba
[3];
94 *(uint64_t*)data
= wsm
[0];
97 *(uint64_t*)data
= wsm
[1];
100 *(uint64_t*)data
= wsm
[2];
103 *(uint64_t*)data
= wsm
[3];
106 *(uint64_t*)data
= tba
[0];
109 *(uint64_t*)data
= tba
[1];
112 *(uint64_t*)data
= tba
[2];
115 *(uint64_t*)data
= tba
[3];
118 // might want to change the clock??
119 *(uint64_t*)data
= 0x00; // try this
122 panic("PC_PLAT not implemented\n");
124 panic("PC_RES not implemented\n");
125 case TSDEV_PC_PERROR
:
126 *(uint64_t*)data
= 0x00;
128 case TSDEV_PC_PERRMASK
:
129 *(uint64_t*)data
= 0x00;
131 case TSDEV_PC_PERRSET
:
132 panic("PC_PERRSET not implemented\n");
134 panic("PC_TLBIV not implemented\n");
136 *(uint64_t*)data
= 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
);
148 case sizeof(uint32_t):
149 case sizeof(uint16_t):
150 case sizeof(uint8_t):
152 panic("invalid access size(?) for tsunami register!\n\n");
154 DPRINTFN("Tsunami PChip ERROR: read daddr=%#x size=%d\n", daddr
, req
->size
);
160 TsunamiPChip::write(MemReqPtr
&req
, const uint8_t *data
)
162 DPRINTF(Tsunami
, "write - va=%#x size=%d \n",
163 req
->vaddr
, req
->size
);
165 Addr daddr
= (req
->paddr
- (addr
& PA_IMPL_MASK
)) >> 6;
169 case sizeof(uint64_t):
172 wsba
[0] = *(uint64_t*)data
;
175 wsba
[1] = *(uint64_t*)data
;
178 wsba
[2] = *(uint64_t*)data
;
181 wsba
[3] = *(uint64_t*)data
;
184 wsm
[0] = *(uint64_t*)data
;
187 wsm
[1] = *(uint64_t*)data
;
190 wsm
[2] = *(uint64_t*)data
;
193 wsm
[3] = *(uint64_t*)data
;
196 tba
[0] = *(uint64_t*)data
;
199 tba
[1] = *(uint64_t*)data
;
202 tba
[2] = *(uint64_t*)data
;
205 tba
[3] = *(uint64_t*)data
;
208 // might want to change the clock??
211 panic("PC_PLAT not implemented\n");
213 panic("PC_RES not implemented\n");
214 case TSDEV_PC_PERROR
:
216 case TSDEV_PC_PERRMASK
:
217 panic("PC_PERRMASK not implemented\n");
218 case TSDEV_PC_PERRSET
:
219 panic("PC_PERRSET not implemented\n");
221 panic("PC_TLBIV not implemented\n");
223 return No_Fault
; // value ignored, supposted to invalidate SG TLB
224 case TSDEV_PC_PMONCTL
:
225 panic("PC_PMONCTL not implemented\n");
226 case TSDEV_PC_PMONCNT
:
227 panic("PC_PMONCTN not implemented\n");
229 panic("Default in PChip Read reached reading 0x%x\n", daddr
);
234 case sizeof(uint32_t):
235 case sizeof(uint16_t):
236 case sizeof(uint8_t):
238 panic("invalid access size(?) for tsunami register!\n\n");
241 DPRINTFN("Tsunami ERROR: write daddr=%#x size=%d\n", daddr
, req
->size
);
246 #define DMA_ADDR_MASK ULL(0x3ffffffff)
249 TsunamiPChip::translatePciToDma(Addr busAddr
)
251 // compare the address to the window base registers
252 uint64_t tbaMask
= 0;
255 uint64_t windowMask
= 0;
256 uint64_t windowBase
= 0;
258 uint64_t pteEntry
= 0;
263 for (int i
= 0; i
< 4; i
++) {
264 windowBase
= wsba
[i
];
265 windowMask
= ~wsm
[i
] & (0x7ff << 20);
267 if ((busAddr
& windowMask
) == (windowBase
& windowMask
)) {
270 if (wsba
[i
] & 0x1) { // see if enabled
271 if (wsba
[i
] & 0x2) { // see if SG bit is set
273 This currently is faked by just doing a direct
274 read from memory, however, to be realistic, this
275 needs to actually do a bus transaction. The process
276 is explained in the tsunami documentation on page
277 10-12 and basically munges the address to look up a
278 PTE from a table in memory and then uses that mapping
279 to create an address for the SG page
282 tbaMask
= ~(((wsm
[i
] & (0x7ff << 20)) >> 10) | 0x3ff);
283 baMask
= (wsm
[i
] & (0x7ff << 20)) | (0x7f << 13);
284 pteAddr
= (tba
[i
] & tbaMask
) | ((busAddr
& baMask
) >> 10);
286 memcpy((void *)&pteEntry
,
288 physmem
->dma_addr(pteAddr
, sizeof(uint64_t)),
291 dmaAddr
= ((pteEntry
& ~0x1) << 12) | (busAddr
& 0x1fff);
294 baMask
= (wsm
[i
] & (0x7ff << 20)) | 0xfffff;
296 dmaAddr
= (tba
[i
] & tbaMask
) | (busAddr
& baMask
);
299 return (dmaAddr
& DMA_ADDR_MASK
);
308 TsunamiPChip::serialize(std::ostream
&os
)
310 SERIALIZE_ARRAY(wsba
, 4);
311 SERIALIZE_ARRAY(wsm
, 4);
312 SERIALIZE_ARRAY(tba
, 4);
316 TsunamiPChip::unserialize(Checkpoint
*cp
, const std::string
§ion
)
318 UNSERIALIZE_ARRAY(wsba
, 4);
319 UNSERIALIZE_ARRAY(wsm
, 4);
320 UNSERIALIZE_ARRAY(tba
, 4);
323 BEGIN_DECLARE_SIM_OBJECT_PARAMS(TsunamiPChip
)
325 SimObjectParam
<Tsunami
*> tsunami
;
326 SimObjectParam
<MemoryController
*> mmu
;
329 END_DECLARE_SIM_OBJECT_PARAMS(TsunamiPChip
)
331 BEGIN_INIT_SIM_OBJECT_PARAMS(TsunamiPChip
)
333 INIT_PARAM(tsunami
, "Tsunami"),
334 INIT_PARAM(mmu
, "Memory Controller"),
335 INIT_PARAM(addr
, "Device Address")
337 END_INIT_SIM_OBJECT_PARAMS(TsunamiPChip
)
339 CREATE_SIM_OBJECT(TsunamiPChip
)
341 return new TsunamiPChip(getInstanceName(), tsunami
, addr
, mmu
);
344 REGISTER_SIM_OBJECT("TsunamiPChip", TsunamiPChip
)