gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
host.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 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  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions are
16  * met: redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer;
18  * redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution;
21  * neither the name of the copyright holders nor the names of its
22  * contributors may be used to endorse or promote products derived from
23  * this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  *
37  * Authors: Andreas Sandberg
38  */
39 
40 #include "dev/pci/host.hh"
41 
42 #include <utility>
43 
44 #include "debug/PciHost.hh"
45 #include "dev/pci/device.hh"
46 #include "dev/platform.hh"
47 #include "params/GenericPciHost.hh"
48 #include "params/PciHost.hh"
49 
50 PciHost::PciHost(const PciHostParams *p)
51  : PioDevice(p)
52 {
53 }
54 
56 {
57 }
58 
61 {
62  auto map_entry = devices.emplace(bus_addr, device);
63 
64  DPRINTF(PciHost, "%02x:%02x.%i: Registering device\n",
65  bus_addr.bus, bus_addr.dev, bus_addr.func);
66 
67  fatal_if(!map_entry.second,
68  "%02x:%02x.%i: PCI bus ID collision\n",
69  bus_addr.bus, bus_addr.dev, bus_addr.func);
70 
71  return DeviceInterface(*this, bus_addr, pin);
72 }
73 
74 PciDevice *
76 {
77  auto device = devices.find(addr);
78  return device != devices.end() ? device->second : nullptr;
79 }
80 
81 const PciDevice *
83 {
84  auto device = devices.find(addr);
85  return device != devices.end() ? device->second : nullptr;
86 }
87 
89  PciHost &_host,
90  PciBusAddr &bus_addr, PciIntPin interrupt_pin)
91  : host(_host),
92  busAddr(bus_addr), interruptPin(interrupt_pin)
93 {
94 }
95 
96 const std::string
98 {
99  return csprintf("%s.interface[%02x:%02x.%i]",
100  host.name(), busAddr.bus, busAddr.dev, busAddr.func);
101 }
102 
103 void
105 {
106  DPRINTF(PciHost, "postInt\n");
107 
108  host.postInt(busAddr, interruptPin);
109 }
110 
111 void
113 {
114  DPRINTF(PciHost, "clearInt\n");
115 
116  host.clearInt(busAddr, interruptPin);
117 }
118 
119 
120 GenericPciHost::GenericPciHost(const GenericPciHostParams *p)
121  : PciHost(p),
122  platform(*p->platform),
123  confBase(p->conf_base), confSize(p->conf_size),
124  confDeviceBits(p->conf_device_bits),
125  pciPioBase(p->pci_pio_base), pciMemBase(p->pci_mem_base),
126  pciDmaBase(p->pci_dma_base)
127 {
128 }
129 
131 {
132 }
133 
134 
135 Tick
137 {
138  const auto dev_addr(decodeAddress(pkt->getAddr() - confBase));
139  const Addr size(pkt->getSize());
140 
141  DPRINTF(PciHost, "%02x:%02x.%i: read: offset=0x%x, size=0x%x\n",
142  dev_addr.first.bus, dev_addr.first.dev, dev_addr.first.func,
143  dev_addr.second,
144  size);
145 
146  PciDevice *const pci_dev(getDevice(dev_addr.first));
147  if (pci_dev) {
148  // @todo Remove this after testing
149  pkt->headerDelay = pkt->payloadDelay = 0;
150  return pci_dev->readConfig(pkt);
151  } else {
152  uint8_t *pkt_data(pkt->getPtr<uint8_t>());
153  std::fill(pkt_data, pkt_data + size, 0xFF);
154  pkt->makeAtomicResponse();
155  return 0;
156  }
157 }
158 
159 Tick
161 {
162  const auto dev_addr(decodeAddress(pkt->getAddr() - confBase));
163 
164  DPRINTF(PciHost, "%02x:%02x.%i: write: offset=0x%x, size=0x%x\n",
165  dev_addr.first.bus, dev_addr.first.dev, dev_addr.first.func,
166  dev_addr.second,
167  pkt->getSize());
168 
169  PciDevice *const pci_dev(getDevice(dev_addr.first));
170  panic_if(!pci_dev,
171  "%02x:%02x.%i: Write to config space on non-existent PCI device\n",
172  dev_addr.first.bus, dev_addr.first.dev, dev_addr.first.func);
173 
174  // @todo Remove this after testing
175  pkt->headerDelay = pkt->payloadDelay = 0;
176 
177  return pci_dev->writeConfig(pkt);
178 }
179 
182 {
184 }
185 
188 {
189  const Addr offset(addr & mask(confDeviceBits));
190  const Addr bus_addr(addr >> confDeviceBits);
191 
192  return std::make_pair(
193  PciBusAddr(bits(bus_addr, 15, 8),
194  bits(bus_addr, 7, 3),
195  bits(bus_addr, 2, 0)),
196  offset);
197 }
198 
199 
200 void
202 {
203  platform.postPciInt(mapPciInterrupt(addr, pin));
204 }
205 
206 void
208 {
210 }
211 
212 
213 uint32_t
215 {
216  const PciDevice *dev(getDevice(addr));
217  assert(dev);
218 
219  return dev->interruptLine();
220 }
221 
222 
224 GenericPciHostParams::create()
225 {
226  return new GenericPciHost(this);
227 }
#define DPRINTF(x,...)
Definition: trace.hh:212
AddrRange RangeSize(Addr start, Addr size)
Definition: addr_range.hh:398
void postInt(const PciBusAddr &addr, PciIntPin pin) override
Post an interrupt to the CPU.
Definition: host.cc:201
uint8_t bus
Definition: types.hh:55
virtual ~PciHost()
Definition: host.cc:55
Configurable generic PCI host interface.
Definition: host.hh:275
uint8_t dev
Definition: types.hh:56
STL pair class.
Definition: stl.hh:61
std::list< AddrRange > AddrRangeList
Convenience typedef for a collection of address ranges.
Definition: addr_range.hh:387
PCI device, base implementation is only config space.
Definition: device.hh:70
PciDevice * getDevice(const PciBusAddr &addr)
Retrieve a PCI device from its bus address.
Definition: host.cc:75
virtual DeviceInterface registerDevice(PciDevice *device, PciBusAddr bus_addr, PciIntPin pin)
Register a PCI device with the host.
Definition: host.cc:60
ip6_addr_t addr
Definition: inet.hh:335
panic_if(!root,"Invalid expression\n")
virtual uint32_t mapPciInterrupt(const PciBusAddr &bus_addr, PciIntPin pin) const
Definition: host.cc:214
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: host.cc:160
const std::string name() const
Definition: host.cc:97
Bitfield< 23, 0 > offset
Definition: types.hh:149
virtual void postPciInt(int line)
Cause the chipset to post a cpi interrupt to the CPU.
Definition: platform.cc:50
virtual void clearPciInt(int line)
Clear a posted PCI->CPU interrupt.
Definition: platform.cc:56
T * getPtr()
get a pointer to the data ptr.
Definition: packet.hh:959
AddrRangeList getAddrRanges() const override
Every PIO device is obliged to provide an implementation that returns the address ranges the device r...
Definition: host.cc:181
void clearInt(const PciBusAddr &addr, PciIntPin pin) override
Post an interrupt to the CPU.
Definition: host.cc:207
const Addr confBase
Definition: host.hh:321
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:161
uint32_t headerDelay
The extra delay from seeing the packet until the header is transmitted.
Definition: packet.hh:340
void clearInt()
Clear a posted PCI interrupt.
Definition: host.cc:112
void makeAtomicResponse()
Definition: packet.hh:857
uint64_t Tick
Tick count type.
Definition: types.hh:63
virtual Tick readConfig(PacketPtr pkt)
Read from the PCI config space data that is stored locally.
Definition: device.cc:220
const Addr confSize
Definition: host.hh:322
This device is the base class which all devices senstive to an address range inherit from...
Definition: io_device.hh:84
PciHost(const PciHostParams *p)
Definition: host.cc:50
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
uint32_t payloadDelay
The extra pipelining delay from seeing the packet until the end of payload is transmitted by the comp...
Definition: packet.hh:358
The PCI host describes the interface between PCI devices and a simulated system.
Definition: host.hh:74
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:245
uint8_t interruptLine() const
Definition: device.hh:196
Generic interface for platforms.
int size()
Definition: pagetable.hh:146
Platform & platform
Definition: host.hh:319
uint8_t func
Definition: types.hh:57
virtual std::pair< PciBusAddr, Addr > decodeAddress(Addr address)
Decode a configuration space address.
Definition: host.cc:187
Callback interface from PCI devices to the host.
Definition: host.hh:93
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: host.cc:136
GenericPciHost(const GenericPciHostParams *p)
Definition: host.cc:120
Bitfield< 3, 0 > mask
Definition: types.hh:64
PciIntPin
Definition: types.hh:65
unsigned getSize() const
Definition: packet.hh:649
const uint8_t confDeviceBits
Definition: host.hh:323
fatal_if(p->js_features.size() > 16,"Too many job slot feature registers specified (%i)\n", p->js_features.size())
T bits(T val, int first, int last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it...
Definition: bitfield.hh:67
std::map< PciBusAddr, PciDevice * > devices
Currently registered PCI devices.
Definition: host.hh:244
void postInt()
Post a PCI interrupt to the CPU.
Definition: host.cc:104
Bitfield< 0 > p
Addr getAddr() const
Definition: packet.hh:639
virtual ~GenericPciHost()
Definition: host.cc:130

Generated on Fri Jun 9 2017 13:03:46 for gem5 by doxygen 1.8.6