SystemC Library API Reference Manual
Reference documentation for the Simics SystemC Library.
 
Loading...
Searching...
No Matches
pci_gasket.h
Go to the documentation of this file.
1/* -*- mode: C++; c-file-style: "virtutech-c++" -*-
2
3 © 2015 Intel Corporation
4
5 This software and the related documents are Intel copyrighted materials, and
6 your use of them is governed by the express license under which they were
7 provided to you ("License"). Unless the License provides otherwise, you may
8 not use, modify, copy, publish, distribute, disclose or transmit this software
9 or the related documents without Intel's prior written permission.
10
11 This software and the related documents are provided as is, with no express or
12 implied warranties, other than those that are expressly stated in the License.
13*/
14
15#ifndef SIMICS_SYSTEMC_COMPOSITE_PCI_GASKET_H
16#define SIMICS_SYSTEMC_COMPOSITE_PCI_GASKET_H
17
18#if defined SIMICS_5_API || defined SIMICS_6_API
19
20#include <systemc>
21#include <tlm>
22
25
27
33
37
41
44
45namespace simics {
46namespace systemc {
47
48namespace composite {
49
50class PciGasketBase {
51 public:
52 typedef PciGasketBase *is_composite_pci_gasket;
53 template <typename C>
54 static void initClassInternal(ConfClass *cls);
55
56 protected:
57 Connector<tlm2simics::PciBus> simics_pci_;
58};
59
60template <typename C>
61void PciGasketBase::initClassInternal(ConfClass *cls) {
62 static iface::IoMemorySimicsAdapter<C> io_memory_simics_adapter;
63 static iface::PciDeviceSimicsAdapter<C> pci_device_simics_adapter;
64 static iface::PciExpressSimicsAdapter<C> pci_express_simics_adapter;
65 cls->add(simics::Attribute(
66 "pci_bus", "o|n",
67 "The PCI-bus to connect to.",
68 ATTR_CLS_VAR(C, simics_pci_)));
69 cls->add(io_memory_simics_adapter);
70 cls->add(pci_device_simics_adapter);
71 cls->add(pci_express_simics_adapter);
72}
73
81template<unsigned int BUSWIDTH = 32,
82 typename TYPES = tlm::tlm_base_protocol_types>
83class PciGasket : public PciGasketBase,
84 public simics2tlm::IoMemoryGasketAdapter,
85 public simics2tlm::PciDeviceGasketAdapter,
86 public simics2tlm::PciExpressGasketAdapter {
87 public:
88 explicit PciGasket(iface::SimulationInterface *simulation)
89 : IoMemoryGasketAdapter(&systemc_mmio_, simulation),
90 PciDeviceGasketAdapter(&systemc_pci_, simulation),
91 PciExpressGasketAdapter(&systemc_pci_express_, simulation),
92 simulation_(simulation) {
93 }
94
95 // PciDeviceGasketAdapter
96 virtual void bus_reset() { /* override */
97 Context context(simulation_);
98 interconnect_.busReset();
99 PciDeviceGasketAdapter::bus_reset();
100 }
101
102 // NOTE: the template parameter is required for the
103 // PciMappingInterconnect::connect*<> template methods, where it is
104 // needed for the multi_passthrough_target_socket<> template class. By
105 // using the TPciDevice as method parameter, the compiler can deduce the
106 // template parameter.
107 template<typename TPciDevice>
108 void connect(TPciDevice *device) {
109 connect(dynamic_cast<iface::PciDeviceQueryInterface *>(device),
110 dynamic_cast<iface::BaseAddressRegisterQueryInterface *>(
111 device),
112 simulation_->simics_object());
113 }
114
115 void connect(iface::PciDeviceQueryInterface *pci,
116 iface::BaseAddressRegisterQueryInterface *bar,
117 ConfObjectRef gasket) {
118 ConfObjectRef o = simulation_->simics_object();
119
120 if (!pci) {
121 SIM_LOG_ERROR(gasket, Log_Configuration,
122 "The PCI device does not implement the"
123 " PciDeviceQueryInterface interface");
124 return;
125 }
126
127 if (!bar) {
128 SIM_LOG_ERROR(gasket, Log_Configuration,
129 "The PCI device does not implement the"
130 " BaseAddressRegisterQueryInterface interface");
131 return;
132 }
133
134 // Connect the device's config space target socket and pci-bus
135 // initiator socket via the interconnect to support snooping
136 interconnect_.connect(pci, o);
137
138 // Connecting the interconnect to the pci-bus
139 simics_pci_->set_device(gasket);
140 simics_pci_->set_gasket(
141 tlm2simics::createGasket(
142 &interconnect_.pci_bus_initiator_socket, o));
143
144 // Connect device's pci-device target socket
145 // The bus_reset() is intercepted by the composite class and handled
146 // by busReset() before the transaction is forwarded to the device.
147 // This allows the IC to unmap all mappings upon bus_reset.
148 systemc_pci_.set_gasket(
149 simics2tlm::createGasket(
150 &interconnect_.simics_target_socket, o));
151 systemc_pci_express_.set_gasket(
152 simics2tlm::createGasket(
153 &interconnect_.simics_target_socket, o));
154
155 // Connect IC's config space target sockets (snooping)
156 interconnect_.connectConfig(bar, &systemc_mmio_, o);
157
158 // Connect device's io/mem space target socket(s)
159 interconnect_.connectMmio(bar, &systemc_mmio_, o);
160 }
161
162 private:
163 iface::SimulationInterface *simulation_;
164
165 // Snoop PCI transactions and handle Simics mappings
166 PciMappingInterconnect<BUSWIDTH, TYPES> interconnect_;
167
168 // Gaskets required for wrapping a PCI device
169 simics2tlm::IoMemory systemc_mmio_; // incoming MMIO (conf/mem/io spaces)
170 simics2tlm::PciDevice systemc_pci_; // Simics pci-bus specific interface
171 simics2tlm::PciExpress systemc_pci_express_; // Simics PCIe interface
172};
173
174} // namespace composite
175
176template <class T>
177void SCLCompositePciInit(typename T::is_composite_pci_gasket,
178 ConfClass *cls) {
179 systemc::composite::PciGasketBase::initClassInternal<T>(cls);
180}
181
182} // namespace systemc
183} // namespace simics
184
185#else
186static_assert(false, "pci_express interface is deprecated. Use SIMICS_API:=6.");
187#endif
188#endif
void SCLCompositePciInit(...)
Definition: class_decorator.h:28
Definition: pci_bus_interface.h:24