gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
tsunami_pchip.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2004-2005 The Regents of The University of Michigan
3  * All rights reserved.
4  *
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.
15  *
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.
27  *
28  * Authors: Ali Saidi
29  * Andrew Schultz
30  */
31 
36 
37 #include <deque>
38 #include <string>
39 #include <vector>
40 
41 #include "base/trace.hh"
42 #include "debug/Tsunami.hh"
43 #include "dev/alpha/tsunami.hh"
45 #include "dev/alpha/tsunamireg.h"
46 #include "dev/pci/device.hh"
47 #include "mem/packet.hh"
48 #include "mem/packet_access.hh"
49 #include "sim/system.hh"
50 
51 using namespace std;
52 
54  : GenericPciHost(p),
55  pioRange(RangeSize(p->pio_addr, 0x1000)),
56  pioDelay(p->pio_latency)
57 {
58  for (int i = 0; i < 4; i++) {
59  wsba[i] = 0;
60  wsm[i] = 0;
61  tba[i] = 0;
62  }
63 
64  // initialize pchip control register
65  pctl = (ULL(0x1) << 20) | (ULL(0x1) << 32) | (ULL(0x2) << 36);
66 
67  //Set back pointer in tsunami
68  p->tsunami->pchip = this;
69 }
70 
71 Tick
73 {
74  // We only need to handle our own configuration registers, pass
75  // unknown addresses to the generic code.
76  if (!pioRange.contains(pkt->getAddr()))
77  return GenericPciHost::read(pkt);
78 
79  Addr daddr = (pkt->getAddr() - pioRange.start()) >> 6;;
80  assert(pkt->getSize() == sizeof(uint64_t));
81 
82 
83  DPRINTF(Tsunami, "read va=%#x size=%d\n", pkt->getAddr(), pkt->getSize());
84 
85  switch(daddr) {
86  case TSDEV_PC_WSBA0:
87  pkt->setLE(wsba[0]);
88  break;
89  case TSDEV_PC_WSBA1:
90  pkt->setLE(wsba[1]);
91  break;
92  case TSDEV_PC_WSBA2:
93  pkt->setLE(wsba[2]);
94  break;
95  case TSDEV_PC_WSBA3:
96  pkt->setLE(wsba[3]);
97  break;
98  case TSDEV_PC_WSM0:
99  pkt->setLE(wsm[0]);
100  break;
101  case TSDEV_PC_WSM1:
102  pkt->setLE(wsm[1]);
103  break;
104  case TSDEV_PC_WSM2:
105  pkt->setLE(wsm[2]);
106  break;
107  case TSDEV_PC_WSM3:
108  pkt->setLE(wsm[3]);
109  break;
110  case TSDEV_PC_TBA0:
111  pkt->setLE(tba[0]);
112  break;
113  case TSDEV_PC_TBA1:
114  pkt->setLE(tba[1]);
115  break;
116  case TSDEV_PC_TBA2:
117  pkt->setLE(tba[2]);
118  break;
119  case TSDEV_PC_TBA3:
120  pkt->setLE(tba[3]);
121  break;
122  case TSDEV_PC_PCTL:
123  pkt->setLE(pctl);
124  break;
125  case TSDEV_PC_PLAT:
126  panic("PC_PLAT not implemented\n");
127  case TSDEV_PC_RES:
128  panic("PC_RES not implemented\n");
129  case TSDEV_PC_PERROR:
130  pkt->setLE((uint64_t)0x00);
131  break;
132  case TSDEV_PC_PERRMASK:
133  pkt->setLE((uint64_t)0x00);
134  break;
135  case TSDEV_PC_PERRSET:
136  panic("PC_PERRSET not implemented\n");
137  case TSDEV_PC_TLBIV:
138  panic("PC_TLBIV not implemented\n");
139  case TSDEV_PC_TLBIA:
140  pkt->setLE((uint64_t)0x00); // shouldn't be readable, but linux
141  break;
142  case TSDEV_PC_PMONCTL:
143  panic("PC_PMONCTL not implemented\n");
144  case TSDEV_PC_PMONCNT:
145  panic("PC_PMONCTN not implemented\n");
146  default:
147  panic("Default in PChip Read reached reading 0x%x\n", daddr);
148  }
149 
150  pkt->makeAtomicResponse();
151  return pioDelay;
152 
153 }
154 
155 Tick
157 {
158  // We only need to handle our own configuration registers, pass
159  // unknown addresses to the generic code.
160  if (!pioRange.contains(pkt->getAddr()))
161  return GenericPciHost::write(pkt);
162 
163  Addr daddr = (pkt->getAddr() - pioRange.start()) >> 6;
164 
165  assert(pkt->getSize() == sizeof(uint64_t));
166 
167  DPRINTF(Tsunami, "write - va=%#x size=%d \n", pkt->getAddr(), pkt->getSize());
168 
169  switch(daddr) {
170  case TSDEV_PC_WSBA0:
171  wsba[0] = pkt->getLE<uint64_t>();
172  break;
173  case TSDEV_PC_WSBA1:
174  wsba[1] = pkt->getLE<uint64_t>();
175  break;
176  case TSDEV_PC_WSBA2:
177  wsba[2] = pkt->getLE<uint64_t>();
178  break;
179  case TSDEV_PC_WSBA3:
180  wsba[3] = pkt->getLE<uint64_t>();
181  break;
182  case TSDEV_PC_WSM0:
183  wsm[0] = pkt->getLE<uint64_t>();
184  break;
185  case TSDEV_PC_WSM1:
186  wsm[1] = pkt->getLE<uint64_t>();
187  break;
188  case TSDEV_PC_WSM2:
189  wsm[2] = pkt->getLE<uint64_t>();
190  break;
191  case TSDEV_PC_WSM3:
192  wsm[3] = pkt->getLE<uint64_t>();
193  break;
194  case TSDEV_PC_TBA0:
195  tba[0] = pkt->getLE<uint64_t>();
196  break;
197  case TSDEV_PC_TBA1:
198  tba[1] = pkt->getLE<uint64_t>();
199  break;
200  case TSDEV_PC_TBA2:
201  tba[2] = pkt->getLE<uint64_t>();
202  break;
203  case TSDEV_PC_TBA3:
204  tba[3] = pkt->getLE<uint64_t>();
205  break;
206  case TSDEV_PC_PCTL:
207  pctl = pkt->getLE<uint64_t>();
208  break;
209  case TSDEV_PC_PLAT:
210  panic("PC_PLAT not implemented\n");
211  case TSDEV_PC_RES:
212  panic("PC_RES not implemented\n");
213  case TSDEV_PC_PERROR:
214  break;
215  case TSDEV_PC_PERRMASK:
216  panic("PC_PERRMASK not implemented\n");
217  case TSDEV_PC_PERRSET:
218  panic("PC_PERRSET not implemented\n");
219  case TSDEV_PC_TLBIV:
220  panic("PC_TLBIV not implemented\n");
221  case TSDEV_PC_TLBIA:
222  break; // value ignored, supposted to invalidate SG TLB
223  case TSDEV_PC_PMONCTL:
224  panic("PC_PMONCTL not implemented\n");
225  case TSDEV_PC_PMONCNT:
226  panic("PC_PMONCTN not implemented\n");
227  default:
228  panic("Default in PChip write reached reading 0x%x\n", daddr);
229 
230  } // uint64_t
231 
232  pkt->makeAtomicResponse();
233  return pioDelay;
234 }
235 
236 
239 {
240  return AddrRangeList({
242  pioRange
243  });
244 }
245 
246 
247 #define DMA_ADDR_MASK ULL(0x3ffffffff)
248 
249 Addr
250 TsunamiPChip::dmaAddr(const PciBusAddr &dev, Addr busAddr) const
251 {
252  // compare the address to the window base registers
253  uint64_t tbaMask = 0;
254  uint64_t baMask = 0;
255 
256  uint64_t windowMask = 0;
257  uint64_t windowBase = 0;
258 
259  uint64_t pteEntry = 0;
260 
261  Addr pteAddr;
262  Addr dmaAddr;
263 
264  for (int i = 0; i < 4; i++) {
265 
266  windowBase = wsba[i];
267  windowMask = ~wsm[i] & (ULL(0xfff) << 20);
268 
269  if ((busAddr & windowMask) == (windowBase & windowMask)) {
270 
271  if (wsba[i] & 0x1) { // see if enabled
272  if (wsba[i] & 0x2) { // see if SG bit is set
283  tbaMask = ~(((wsm[i] & (ULL(0xfff) << 20)) >> 10) |
284  ULL(0x3ff));
285  baMask = (wsm[i] & (ULL(0xfff) << 20)) | (ULL(0x7f) << 13);
286  pteAddr = (tba[i] & tbaMask) | ((busAddr & baMask) >> 10);
287 
288  sys->physProxy.readBlob(pteAddr, &pteEntry,
289  sizeof(uint64_t));
290 
291  dmaAddr = ((pteEntry & ~ULL(0x1)) << 12) |
292  (busAddr & ULL(0x1fff));
293 
294  } else {
295  baMask = (wsm[i] & (ULL(0xfff) << 20)) | ULL(0xfffff);
296  tbaMask = ~baMask;
297  dmaAddr = (tba[i] & tbaMask) | (busAddr & baMask);
298  }
299 
300  return (dmaAddr & DMA_ADDR_MASK);
301  }
302  }
303  }
304 
305  // if no match was found, then return the original address
306  return busAddr;
307 }
308 
309 void
311 {
313  SERIALIZE_ARRAY(wsba, 4);
314  SERIALIZE_ARRAY(wsm, 4);
315  SERIALIZE_ARRAY(tba, 4);
316 }
317 
318 void
320 {
325 }
326 
327 
328 TsunamiPChip *
329 TsunamiPChipParams::create()
330 {
331  return new TsunamiPChip(this);
332 }
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:167
#define DPRINTF(x,...)
Definition: trace.hh:229
AddrRange RangeSize(Addr start, Addr size)
Definition: addr_range.hh:584
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
uint64_t tba[4]
Translated Base Addresses.
uint64_t wsba[4]
Window Base addresses.
Emulation of the Tsunami CChip CSRs.
#define TSDEV_PC_PCTL
Definition: tsunamireg.h:90
Configurable generic PCI host interface.
Definition: host.hh:275
#define TSDEV_PC_TLBIV
Definition: tsunamireg.h:96
Bitfield< 7 > i
Tsunami PCI interface CSRs.
AddrRangeList getAddrRanges() const override
Every PIO device is obliged to provide an implementation that returns the address ranges the device r...
std::list< AddrRange > AddrRangeList
Convenience typedef for a collection of address ranges.
Definition: addr_range.hh:573
#define TSDEV_PC_WSM3
Definition: tsunamireg.h:85
#define TSDEV_PC_TLBIA
Definition: tsunamireg.h:97
Top level class for Tsunami Chipset emulation.
Definition: tsunami.hh:56
bool contains(const Addr &a) const
Determine if the range contains an address.
Definition: addr_range.hh:406
#define TSDEV_PC_WSM1
Definition: tsunamireg.h:83
const Tick pioDelay
#define TSDEV_PC_TBA0
Definition: tsunamireg.h:86
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: host.cc:160
#define TSDEV_PC_PLAT
Definition: tsunamireg.h:91
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:586
#define TSDEV_PC_PERROR
Definition: tsunamireg.h:93
#define TSDEV_PC_TBA2
Definition: tsunamireg.h:88
Definition: cprintf.cc:42
TsunamiPChipParams Params
#define DMA_ADDR_MASK
const AddrRange pioRange
void setLE(T v)
Set the value in the data pointer to v as little endian.
uint64_t wsm[4]
Window masks.
unsigned getSize() const
Definition: packet.hh:736
const Addr confBase
Definition: host.hh:321
#define TSDEV_PC_WSBA0
Definition: tsunamireg.h:78
PortProxy physProxy
Port to physical memory used for writing object files into ram at boot.
Definition: system.hh:218
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:645
TsunamiPChip(const Params *p)
Register the PChip with the mmu and init all wsba, wsm, and tba to 0.
#define TSDEV_PC_PERRMASK
Definition: tsunamireg.h:94
void makeAtomicResponse()
Definition: packet.hh:949
uint64_t Tick
Tick count type.
Definition: types.hh:63
#define TSDEV_PC_PERRSET
Definition: tsunamireg.h:95
A very simple implementation of the Tsunami PCI interface chips.
Declaration of top level class for the Tsunami chipset.
#define TSDEV_PC_PMONCNT
Definition: tsunamireg.h:99
#define SERIALIZE_ARRAY(member, size)
Definition: serialize.hh:658
#define TSDEV_PC_WSM0
Definition: tsunamireg.h:82
Addr getAddr() const
Definition: packet.hh:726
const Addr confSize
Definition: host.hh:322
#define TSDEV_PC_WSBA3
Definition: tsunamireg.h:81
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
#define ULL(N)
uint64_t constant
Definition: types.hh:50
System * sys
Definition: io_device.hh:105
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:255
Addr dmaAddr(const PciBusAddr &addr, Addr pci_addr) const override
Translate a PCI bus address to a memory address for DMA.
#define TSDEV_PC_TBA1
Definition: tsunamireg.h:87
void readBlob(Addr addr, void *p, int size) const
Higher level interfaces based on the above.
Definition: port_proxy.hh:179
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:643
uint64_t pctl
Pchip control register.
#define UNSERIALIZE_ARRAY(member, size)
Definition: serialize.hh:661
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
#define TSDEV_PC_WSBA1
Definition: tsunamireg.h:79
Declaration of the Packet class.
std::ostream CheckpointOut
Definition: serialize.hh:68
#define TSDEV_PC_WSM2
Definition: tsunamireg.h:84
List of Tsunami CSRs.
#define TSDEV_PC_WSBA2
Definition: tsunamireg.h:80
#define TSDEV_PC_PMONCTL
Definition: tsunamireg.h:98
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: host.cc:136
T getLE() const
Get the data in the packet byte swapped from little endian to host endian.
Addr start() const
Get the start address of the range.
Definition: addr_range.hh:297
void unserialize(CheckpointIn &cp) override
Unserialize an object.
#define TSDEV_PC_TBA3
Definition: tsunamireg.h:89
Bitfield< 0 > p
void serialize(CheckpointOut &cp) const override
Serialize an object.
#define TSDEV_PC_RES
Definition: tsunamireg.h:92

Generated on Fri Feb 28 2020 16:27:00 for gem5 by doxygen 1.8.13