gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
device.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Copyright (c) 2004-2005 The Regents of The University of Michigan
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions are
19  * met: redistributions of source code must retain the above copyright
20  * notice, this list of conditions and the following disclaimer;
21  * redistributions in binary form must reproduce the above copyright
22  * notice, this list of conditions and the following disclaimer in the
23  * documentation and/or other materials provided with the distribution;
24  * neither the name of the copyright holders nor the names of its
25  * contributors may be used to endorse or promote products derived from
26  * this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  *
40  * Authors: Ali Saidi
41  * Andrew Schultz
42  * Nathan Binkert
43  */
44 
45 /* @file
46  * Interface for devices using PCI configuration
47  */
48 
49 #ifndef __DEV_PCI_DEVICE_HH__
50 #define __DEV_PCI_DEVICE_HH__
51 
52 #include <cstring>
53 #include <vector>
54 
55 #include "dev/dma_device.hh"
56 #include "dev/pci/host.hh"
57 #include "dev/pci/pcireg.h"
58 #include "params/PciDevice.hh"
59 #include "sim/byteswap.hh"
60 
61 #define BAR_IO_MASK 0x3
62 #define BAR_MEM_MASK 0xF
63 #define BAR_IO_SPACE_BIT 0x1
64 #define BAR_IO_SPACE(x) ((x) & BAR_IO_SPACE_BIT)
65 #define BAR_NUMBER(x) (((x) - PCI0_BASE_ADDR0) >> 0x2);
66 
70 class PciDevice : public DmaDevice
71 {
72  protected:
74 
77 
81  const int PMCAP_BASE;
82  const int PMCAP_ID_OFFSET;
83  const int PMCAP_PC_OFFSET;
84  const int PMCAP_PMCS_OFFSET;
86 
87  const int MSICAP_BASE;
89 
90  const int MSIXCAP_BASE;
91  const int MSIXCAP_ID_OFFSET;
92  const int MSIXCAP_MXC_OFFSET;
100 
101  const int PXCAP_BASE;
108 
110  uint32_t BARSize[6];
111 
114 
116  bool legacyIO[6];
117 
121  bool
122  isLargeBAR(int bar) const
123  {
124  return bits(config.baseAddr[bar], 2, 1) == 0x2;
125  }
126 
131  bool
132  isBAR(Addr addr, int bar) const
133  {
134  assert(bar >= 0 && bar < 6);
135  return BARAddrs[bar] <= addr && addr < BARAddrs[bar] + BARSize[bar];
136  }
137 
142  int
144  {
145  for (int i = 0; i <= 5; ++i)
146  if (isBAR(addr, i))
147  return i;
148 
149  return -1;
150  }
151 
161  bool
162  getBAR(Addr addr, int &bar, Addr &offs)
163  {
164  int b = getBAR(addr);
165  if (b < 0)
166  return false;
167 
168  offs = addr - BARAddrs[b];
169  bar = b;
170  return true;
171  }
172 
173  public: // Host configuration interface
180  virtual Tick writeConfig(PacketPtr pkt);
181 
182 
189  virtual Tick readConfig(PacketPtr pkt);
190 
191  protected:
193 
196 
197  public:
198  Addr pciToDma(Addr pci_addr) const {
199  return hostInterface.dmaAddr(pci_addr);
200  }
201 
202  void intrPost() { hostInterface.postInt(); }
203  void intrClear() { hostInterface.clearInt(); }
204 
205  uint8_t interruptLine() const { return letoh(config.interruptLine); }
206 
212  AddrRangeList getAddrRanges() const override;
213 
219  PciDevice(const PciDeviceParams *params);
220 
225  void serialize(CheckpointOut &cp) const override;
226 
232  void unserialize(CheckpointIn &cp) override;
233 
234  const PciBusAddr &busAddr() const { return _busAddr; }
235 };
236 #endif // __DEV_PCI_DEVICE_HH__
MSICAP msicap
Definition: device.hh:88
void unserialize(CheckpointIn &cp) override
Reconstruct the state of this object from a checkpoint.
Definition: device.cc:511
Addr pciToDma(Addr pci_addr) const
Definition: device.hh:198
Defines the PCI Express capability register and its associated bitfields for a PCIe device...
Definition: pcireg.h:307
Bitfield< 7 > i
PCI device, base implementation is only config space.
Definition: device.hh:70
const int MSIXCAP_MXC_OFFSET
Definition: device.hh:92
const PciBusAddr _busAddr
Definition: device.hh:73
const int MSICAP_BASE
Definition: device.hh:87
ip6_addr_t addr
Definition: inet.hh:335
MSIXCAP msixcap
Definition: device.hh:99
Defines the MSI Capability register and its associated bitfields for the a PCI/PCIe device...
Definition: pcireg.h:241
const int PMCAP_PC_OFFSET
Definition: device.hh:83
uint8_t interruptLine
Definition: pcireg.h:82
PMCAP pmcap
Definition: device.hh:85
T letoh(T value)
Definition: byteswap.hh:145
Definition: cprintf.cc:42
const int MSIXCAP_MPBA_OFFSET
Definition: device.hh:94
PciDevice(const PciDeviceParams *params)
Constructor for PCI Dev.
Definition: device.cc:66
PXCAP pxcap
Definition: device.hh:102
bool isLargeBAR(int bar) const
Does the given BAR represent 32 lower bits of a 64-bit address?
Definition: device.hh:122
const PciBusAddr & busAddr() const
Definition: device.hh:234
bool isBAR(Addr addr, int bar) const
Does the given address lie within the space mapped by the given base address register?
Definition: device.hh:132
Bitfield< 7 > b
int MSIX_TABLE_END
Definition: device.hh:96
const int MSIXCAP_ID_OFFSET
Definition: device.hh:91
Defines the Power Management capability register and all its associated bitfields for a PCIe device...
Definition: pcireg.h:208
bool legacyIO[6]
Whether the BARs are really hardwired legacy IO locations.
Definition: device.hh:116
void clearInt()
Clear a posted PCI interrupt.
Definition: host.cc:112
uint64_t Tick
Tick count type.
Definition: types.hh:63
virtual Tick writeConfig(PacketPtr pkt)
Write to the PCI config space data that is stored locally.
Definition: device.cc:288
uint8_t interruptLine() const
Definition: device.hh:205
int MSIX_PBA_END
Definition: device.hh:98
Addr dmaAddr(Addr addr) const
Calculate the physical address of a prefetchable memory location in the PCI address space...
Definition: host.hh:148
virtual Tick readConfig(PacketPtr pkt)
Read from the PCI config space data that is stored locally.
Definition: device.cc:220
int getBAR(Addr addr)
Which base address register (if any) maps the given address?
Definition: device.hh:143
Tick pioDelay
Definition: device.hh:194
int MSIX_TABLE_OFFSET
Definition: device.hh:95
Tick configDelay
Definition: device.hh:195
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
bool getBAR(Addr addr, int &bar, Addr &offs)
Which base address register (if any) maps the given address?
Definition: device.hh:162
std::vector< MSIXTable > msix_table
MSIX Table and PBA Structures.
Definition: device.hh:106
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:255
Addr BARAddrs[6]
The current address mapping of the BARs.
Definition: device.hh:113
const Params * params() const
Definition: io_device.hh:139
AddrRangeList getAddrRanges() const override
Determine the address ranges that this device responds to.
Definition: device.cc:277
int MSIX_PBA_OFFSET
Definition: device.hh:97
std::ostream CheckpointOut
Definition: serialize.hh:68
Callback interface from PCI devices to the host.
Definition: host.hh:93
const int PMCAP_ID_OFFSET
Definition: device.hh:82
std::vector< MSIXPbaEntry > msix_pba
Definition: device.hh:107
const int PMCAP_BASE
The capability list structures and base addresses.
Definition: device.hh:81
const int PXCAP_BASE
Definition: device.hh:101
const int PMCAP_PMCS_OFFSET
Definition: device.hh:84
PciHost::DeviceInterface hostInterface
Definition: device.hh:192
T bits(T val, int first, int last)
Extract the bitfield from position &#39;first&#39; to &#39;last&#39; (inclusive) from &#39;val&#39; and right justify it...
Definition: bitfield.hh:72
void postInt()
Post a PCI interrupt to the CPU.
Definition: host.cc:104
void intrPost()
Definition: device.hh:202
PCIConfig config
The current config space.
Definition: device.hh:76
uint32_t baseAddr[6]
Definition: pcireg.h:72
const int MSIXCAP_BASE
Definition: device.hh:90
void intrClear()
Definition: device.hh:203
void serialize(CheckpointOut &cp) const override
Serialize this object to the given output stream.
Definition: device.cc:446
uint32_t BARSize[6]
The size of the BARs.
Definition: device.hh:110
const int MSIXCAP_MTAB_OFFSET
Definition: device.hh:93

Generated on Fri Feb 28 2020 16:26:59 for gem5 by doxygen 1.8.13