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_6_API || defined SHOW_OBSOLETE_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 // Bind all currently unmapped adapters (i.e. the ones just created above)
66 // to this gasket class before a subsequent device class's
67 // initClassInternal calls bindUnmappedSimicsAdapters for the device class.
69
70 cls->add(simics::Attribute(
71 "pci_bus", "o|n",
72 "The PCI-bus to connect to.",
73 ATTR_CLS_VAR(C, simics_pci_)));
74 cls->add(io_memory_simics_adapter);
75 cls->add(pci_device_simics_adapter);
76 cls->add(pci_express_simics_adapter);
77}
78
86template<unsigned int BUSWIDTH = 32,
87 typename TYPES = tlm::tlm_base_protocol_types>
88class PciGasket : public PciGasketBase,
89 public simics2tlm::IoMemoryGasketAdapter,
90 public simics2tlm::PciDeviceGasketAdapter,
91 public simics2tlm::PciExpressGasketAdapter {
92 public:
93 explicit PciGasket(iface::SimulationInterface *simulation)
94 : IoMemoryGasketAdapter(&systemc_mmio_, simulation),
95 PciDeviceGasketAdapter(&systemc_pci_, simulation),
96 PciExpressGasketAdapter(&systemc_pci_express_, simulation),
97 simulation_(simulation) {
98 }
99
100 // PciDeviceGasketAdapter
101 virtual void bus_reset() { /* override */
102 Context context(simulation_);
103 interconnect_.busReset();
104 PciDeviceGasketAdapter::bus_reset();
105 }
106
107 // NOTE: the template parameter is required for the
108 // PciMappingInterconnect::connect*<> template methods, where it is
109 // needed for the multi_passthrough_target_socket<> template class. By
110 // using the TPciDevice as method parameter, the compiler can deduce the
111 // template parameter.
112 template<typename TPciDevice>
113 void connect(TPciDevice *device) {
114 connect(dynamic_cast<iface::PciDeviceQueryInterface *>(device),
115 dynamic_cast<iface::BaseAddressRegisterQueryInterface *>(
116 device),
117 simulation_->simics_object());
118 }
119
120 void connect(iface::PciDeviceQueryInterface *pci,
121 iface::BaseAddressRegisterQueryInterface *bar,
122 ConfObjectRef gasket) {
123 ConfObjectRef o = simulation_->simics_object();
124
125 if (!pci) {
126 SIM_LOG_ERROR(gasket, Log_Configuration,
127 "The PCI device does not implement the"
128 " PciDeviceQueryInterface interface");
129 return;
130 }
131
132 if (!bar) {
133 SIM_LOG_ERROR(gasket, Log_Configuration,
134 "The PCI device does not implement the"
135 " BaseAddressRegisterQueryInterface interface");
136 return;
137 }
138
139 // Connect the device's config space target socket and pci-bus
140 // initiator socket via the interconnect to support snooping
141 interconnect_.connect(pci, o);
142
143 // Connecting the interconnect to the pci-bus
144 simics_pci_->set_device(gasket);
145 simics_pci_->set_gasket(
146 tlm2simics::createGasket(
147 &interconnect_.pci_bus_initiator_socket, o));
148
149 // Connect device's pci-device target socket
150 // The bus_reset() is intercepted by the composite class and handled
151 // by busReset() before the transaction is forwarded to the device.
152 // This allows the IC to unmap all mappings upon bus_reset.
153 systemc_pci_.set_gasket(
154 simics2tlm::createGasket(
155 &interconnect_.simics_target_socket, o));
156 systemc_pci_express_.set_gasket(
157 simics2tlm::createGasket(
158 &interconnect_.simics_target_socket, o));
159
160 // Connect IC's config space target sockets (snooping)
161 interconnect_.connectConfig(bar, &systemc_mmio_, o);
162
163 // Connect device's io/mem space target socket(s)
164 interconnect_.connectMmio(bar, &systemc_mmio_, o);
165 }
166
167 private:
168 iface::SimulationInterface *simulation_;
169
170 // Snoop PCI transactions and handle Simics mappings
171 PciMappingInterconnect<BUSWIDTH, TYPES> interconnect_;
172
173 // Gaskets required for wrapping a PCI device
174 simics2tlm::IoMemory systemc_mmio_; // incoming MMIO (conf/mem/io spaces)
175 simics2tlm::PciDevice systemc_pci_; // Simics pci-bus specific interface
176 simics2tlm::PciExpress systemc_pci_express_; // Simics PCIe interface
177};
178
179} // namespace composite
180
181template <class T>
182void SCLCompositePciInit(typename T::is_composite_pci_gasket,
183 ConfClass *cls) {
184 systemc::composite::PciGasketBase::initClassInternal<T>(cls);
185}
186
187} // namespace systemc
188} // namespace simics
189
190#else
191static_assert(false, "pci_express interface is deprecated. Use SIMICS_API:=6.");
192#endif
193#endif
void bindUnmappedSimicsAdapters(conf_class_t *conf_class)
Bind all adapters that are still pending mapping to a conf_class.
Definition: simics_adapter.h:186
void SCLCompositePciInit(...)
Definition: class_decorator.h:31
Definition: adapter.h:81