SystemC Library API Reference Manual
Reference documentation for the Simics SystemC Library.
 
Loading...
Searching...
No Matches
pci_mapping_interconnect.h
Go to the documentation of this file.
1/*
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_MAPPING_INTERCONNECT_H
16#define SIMICS_SYSTEMC_COMPOSITE_PCI_MAPPING_INTERCONNECT_H
17
18#if defined SIMICS_6_API || defined SHOW_OBSOLETE_API
19
20#include <systemc>
21#include <tlm>
22#include <tlm_utils/multi_passthrough_target_socket.h>
23#include <tlm_utils/simple_target_socket.h>
24#include <tlm_utils/simple_initiator_socket.h>
25
32
37
38#include <vector>
39
40namespace { // NOLINT(build/namespaces_headers)
41const char *const PCI_MAPPING_INTERCONNECT_TAG = "intel/PciMappingInterconnect";
42} // namespace
43
44namespace simics {
45namespace systemc {
46namespace composite {
47
50template<typename TSocket>
51class PciMappingInterconnectExtensionSender
52 : public iface::ExtensionSender<TSocket> {
53 public:
54 virtual ~PciMappingInterconnectExtensionSender() {}
55 void send_extension(iface::Transaction *transaction) override {
56 failed_transaction_ = iface::Transaction(NULL);
57 iface::ExtensionSender<TSocket>::send_extension(transaction);
58 }
59 void send_failed(iface::Transaction *transaction) override {
60 failed_transaction_ = *transaction;
61 iface::ExtensionSender<TSocket>::send_failed(transaction);
62 }
63 iface::Transaction failed_transaction_;
64};
65
84template <unsigned int BUSWIDTH, typename TYPES>
85class PciMappingInterconnect : public sc_core::sc_module {
86 private:
87 // Socket types used by the interconnect
88 typedef tlm_utils::simple_target_socket<
89 PciMappingInterconnect, BUSWIDTH, TYPES> target_socket_t;
90 typedef tlm_utils::multi_passthrough_target_socket<
91 PciMappingInterconnect, BUSWIDTH, TYPES> multi_target_socket_t;
92 typedef tlm_utils::simple_initiator_socket<
93 PciMappingInterconnect, BUSWIDTH, TYPES> initiator_socket_t;
94 typedef struct {
95 tlm::tlm_target_socket<BUSWIDTH, TYPES> *tlm;
96 tlm_utils::multi_target_base<BUSWIDTH, TYPES> *multi;
97 } supported_target_socket_t;
98
99 public:
100#ifndef SYSTEMC_3_0_0
101 SC_HAS_PROCESS(PciMappingInterconnect);
102#endif
103 explicit PciMappingInterconnect(
104 sc_core::sc_module_name = "PciMappingInterconnect")
105 : target_socket("target_socket"),
106 simics_target_socket("simics_target_socket"),
107 pci_bus_initiator_socket("pci_bus_initiator_socket"),
108 initiator_sockets_("initiator_socket"),
109 pci_target_socket_(),
110 pci_device_target_socket_(),
111 pci_bus_target_socket_("pci_bus_target_socket"),
112 number_of_functions_(1),
113 mapping_id_offset_(0x10100) { // 255 + 64k (max VFs) + 1 (round up)
114 target_socket.register_b_transport(
115 this, &PciMappingInterconnect::b_transport);
116 target_socket.register_transport_dbg(
117 this, &PciMappingInterconnect::transport_dbg);
118 simics_target_socket.register_b_transport(
119 this, &PciMappingInterconnect::simics_b_transport);
120 pci_bus_target_socket_.register_b_transport(
121 this, &PciMappingInterconnect::pci_bus_b_transport);
122 pci_bus_target_socket_.register_transport_dbg(
123 this, &PciMappingInterconnect::pci_bus_transport_dbg);
124 pci_bus_target_socket_.register_get_direct_mem_ptr(
125 this, &PciMappingInterconnect::pci_bus_get_direct_mem_ptr);
126 pci_bus_initiator_socket.register_invalidate_direct_mem_ptr(
127 this, &PciMappingInterconnect::pci_bus_invalidate_direct_mem_ptr);
128 sender_.init(&pci_bus_initiator_socket);
129 extension_.init(&sender_);
130 }
131
132 virtual void before_end_of_elaboration();
133
134 void retrieveFunctionData(int id, int bar);
135
136 void connect(iface::PciDeviceQueryInterface *pci, ConfObjectRef o);
137
138 void connectConfig(iface::BaseAddressRegisterQueryInterface *bar,
139 simics2tlm::IoMemory *gasket,
140 ConfObjectRef o);
141
142 void connectMmio(iface::BaseAddressRegisterQueryInterface *bar,
143 simics2tlm::IoMemory *gasket,
144 ConfObjectRef o);
145
146 void busReset();
147
148 // Sockets bound by external logic (see also private scope):
150 multi_target_socket_t target_socket;
151 multi_target_socket_t simics_target_socket;
153 initiator_socket_t pci_bus_initiator_socket;
154
155 private:
156 // TLM2 methods
157 void b_transport(int id, tlm::tlm_generic_payload &trans, // NOLINT: SystemC API
158 sc_core::sc_time &t); // NOLINT: SystemC API
159 unsigned int transport_dbg(int id, tlm::tlm_generic_payload &trans); // NOLINT: SystemC API
160 void simics_b_transport(int id, tlm::tlm_generic_payload &trans, // NOLINT: SystemC API
161 sc_core::sc_time &t); // NOLINT: SystemC API
162 void pci_bus_b_transport(tlm::tlm_generic_payload &trans, // NOLINT: SystemC API
163 sc_core::sc_time &t); // NOLINT: SystemC API
164 unsigned int pci_bus_transport_dbg(tlm::tlm_generic_payload &trans); // NOLINT: SystemC API
165 bool pci_bus_get_direct_mem_ptr(tlm::tlm_generic_payload &trans, // NOLINT: SystemC API
166 tlm::tlm_dmi &dmi_data); // NOLINT: SystemC API
167 void pci_bus_invalidate_direct_mem_ptr(sc_dt::uint64 start_range,
168 sc_dt::uint64 end_range);
169
170 // Helper methods
171 void castToTarget(sc_core::sc_object *object,
172 supported_target_socket_t *target);
173 template <typename TGasket>
174 void bindToGasket(supported_target_socket_t target,
175 TGasket *gasket, ConfObjectRef o, int id);
176 void updateCommand(int id, uint16_t old_command);
177 void updateBaseAddress(int id, int bar);
178 void updateMemoryMapping(bool enable, types::addr_space_t space,
179 uint64_t base_address, int bar_size_bits,
180 int mapping_id);
181 void interceptBarAccess(int id, tlm::tlm_generic_payload &trans, // NOLINT
182 sc_core::sc_time &t); // NOLINT: SystemC API
183
184 // Sockets created and bound by internal logic (see also public scope):
185 // IC -> Device, forwards the incoming PCI transactions
186 sc_core::sc_vector<initiator_socket_t> initiator_sockets_;
187 supported_target_socket_t pci_target_socket_;
188 initiator_socket_t pci_device_initiator_socket_;
189 supported_target_socket_t pci_device_target_socket_;
190 // Device -> IC, intercept upstream pci-bus transactions
191 target_socket_t pci_bus_target_socket_;
192
193 struct function_data_t {
194 int function;
195 uint16_t command;
196 uint32_t base_address[6];
197 };
198 std::vector<function_data_t> function_data_;
199 int number_of_functions_;
200 int mapping_id_offset_;
201 iface::BaseAddressRegisterQueryInterface::BarInfo bar_info_;
202
203 PciMappingInterconnectExtensionSender<
204 initiator_socket_t> sender_;
205 iface::PciBusExtension extension_;
206};
207
208template <unsigned int BUSWIDTH, typename TYPES>
209void PciMappingInterconnect<BUSWIDTH, TYPES>::before_end_of_elaboration() {
210 // Because of the way SystemC has been designed, we cannot create new
211 // sockets dynamically ouside of the CTOR except for in the
212 // before_end_of_elaboration() method.
213
214 // Create initiator sockets equal to the number of PCI functions
215 initiator_sockets_.init(number_of_functions_);
216 for (std::size_t i = 0; i < initiator_sockets_.size(); ++i) {
217 if (pci_target_socket_.tlm) {
218 initiator_sockets_[i].bind(*pci_target_socket_.tlm);
219 } else {
220 initiator_sockets_[i].bind(*pci_target_socket_.multi);
221 }
222 }
223
224 // Allocate and initialize function data based on device configuration
225 function_data_ = std::vector<function_data_t>(number_of_functions_);
226 int prev_function = -1;
227 int id = -1;
228 for (iface::BaseAddressRegisterQueryInterface::BarInfo::const_iterator it
229 = bar_info_.begin(); it != bar_info_.end(); ++it) {
230 int current_function = (*it).function;
231 if (current_function != prev_function) {
232 function_data_[++id].function = current_function;
233 prev_function = current_function;
234 }
235 }
236
237 if (pci_device_target_socket_.tlm) {
238 pci_device_initiator_socket_.bind(*pci_device_target_socket_.tlm);
239 } else if (pci_device_target_socket_.multi) {
240 pci_device_initiator_socket_.bind(*pci_device_target_socket_.multi);
241 }
242}
243
244// Get up-to-date BAR/CMD information whenever we need it. It cannot be cached
245// in the interconnect module as it might change over time by the model,
246// reverse execution, checkpoint restore, ...
247// @id is the function ID (socket ID) currently accessed
248// @bar is the BAR number currently access, or -1 for config register access in
249// which case all BARs must be retrieved
250template <unsigned int BUSWIDTH, typename TYPES>
251void PciMappingInterconnect<BUSWIDTH, TYPES>::retrieveFunctionData(
252 int id, int bar) {
253 tlm::tlm_generic_payload trans;
254 trans.set_command(tlm::TLM_READ_COMMAND);
255 trans.set_data_length(4);
256 trans.set_streaming_width(4);
257
258 uint32_t value = 0;
259 trans.set_data_ptr(reinterpret_cast<unsigned char *>(&value));
260 trans.set_address(0x4);
261
262 auto ret = initiator_sockets_[id]->transport_dbg(trans);
263 if (ret == 0) {
264 // The target is not able to perform the transport_dbg.
265 // The PCI interconnector is unable to get the up-to-date
266 // BAR/CMD information which may cause unexpected behavior
267 return;
268 }
269
270 function_data_[id].command = value;
271
272 // -1 means config register access => read all bars
273 bool all_bars = (bar == -1) ? true : false;
274
275 // NOTE: the IO, Mem32, Mem64 bits are ignored by updateMemoryMapping, no
276 // need to filter them out here
277 int function = function_data_[id].function;
278 for (iface::BaseAddressRegisterQueryInterface::BarInfo::const_iterator
279 it = bar_info_.begin(); it != bar_info_.end(); ++it) {
280 // BarInfo holds _all_ BARs for _all_ functions. This can probably
281 // be done in a much more clever way that avoids iterating over the
282 // entire BarInfo for each function in the outer loop.
283 if ((*it).function != function) {
284 continue;
285 }
286 if (all_bars) {
287 bar = ((*it).offset - 0x10) / 4;
288 } else if (bar != ((*it).offset - 0x10) / 4) {
289 continue;
290 }
291 uint32_t base_address = 0;
292 trans.set_address((*it).offset);
293 trans.set_data_ptr(
294 reinterpret_cast<unsigned char *>(&base_address));
295 trans.set_data_length(sizeof base_address);
296 trans.set_streaming_width(trans.get_data_length());
297 initiator_sockets_[id]->transport_dbg(trans);
298 function_data_[id].base_address[bar] = base_address;
299 if ((*it).is_64bit) {
300 // Read higher 32 bits in next BAR
301 trans.set_address((*it).offset + 4);
302 trans.set_data_ptr(
303 reinterpret_cast<unsigned char *>(&base_address));
304 trans.set_data_length(sizeof base_address);
305 trans.set_streaming_width(trans.get_data_length());
306 initiator_sockets_[id]->transport_dbg(trans);
307 function_data_[id].base_address[bar + 1] = base_address;
308 }
309 }
310}
311
320template <unsigned int BUSWIDTH, typename TYPES>
321void PciMappingInterconnect<BUSWIDTH, TYPES>::connect(
322 iface::PciDeviceQueryInterface *pci, ConfObjectRef o) {
323 castToTarget(pci->getPciDeviceTargetSocket(),
324 &pci_device_target_socket_);
325 castToTarget(pci->getConfigTargetSocket(), &pci_target_socket_);
326 tlm::tlm_initiator_socket<BUSWIDTH, TYPES> *initiator
327 = dynamic_cast<tlm::tlm_initiator_socket<BUSWIDTH, TYPES> *>(
328 pci->getPciBusInitiatorSocket());
329 if (initiator) {
330 pci_bus_target_socket_.bind(*initiator);
331 } else {
332 SIM_LOG_ERROR(o, Log_Configuration,
333 "object returned by getPciBusInitiatorSocket was not"
334 " a tlm::tlm_initiator_socket.");
335 }
336}
337
344template <unsigned int BUSWIDTH, typename TYPES>
345void PciMappingInterconnect<BUSWIDTH, TYPES>::connectConfig(
346 iface::BaseAddressRegisterQueryInterface *bar,
347 simics2tlm::IoMemory *gasket, ConfObjectRef o) {
348 // F0 must always exist
349 // NOTE: by Simics convention, F0 always get mapping ID = 255
350 gasket->addGasket(
351 255, simics2tlm::createGasket(&target_socket, o));
352
353 // How many more functions are there?
354 bar_info_ = bar->getBarInfo();
355 int prev_function = 0;
356 for (iface::BaseAddressRegisterQueryInterface::BarInfo::const_iterator it
357 = bar_info_.begin(); it != bar_info_.end(); ++it) {
358 int current_function = (*it).function;
359 if (current_function != prev_function) {
360 ++number_of_functions_;
361 prev_function = current_function;
362 gasket->addGasket(255 + current_function,
363 simics2tlm::createGasket(&target_socket, o));
364 }
365 FATAL_ERROR_IF(current_function < prev_function,
366 "BarInfo must be sorted on function number"
367 " in ascending order");
368 }
369}
370
376template <unsigned int BUSWIDTH, typename TYPES>
377void PciMappingInterconnect<BUSWIDTH, TYPES>::connectMmio(
378 iface::BaseAddressRegisterQueryInterface *bar,
379 simics2tlm::IoMemory *gasket, ConfObjectRef o) {
381 = bar->getBarTargetSockets();
382 for (iface::BaseAddressRegisterQueryInterface::BarSockets::const_iterator it
383 = bar_sockets.begin(); it != bar_sockets.end(); ++it) {
384 supported_target_socket_t target = {};
385 castToTarget((*it).second, &target);
386 bindToGasket(target, gasket, o,
387 (*it).first.mapping_id + mapping_id_offset_);
388 }
389}
390
392template <unsigned int BUSWIDTH, typename TYPES>
393void PciMappingInterconnect<BUSWIDTH, TYPES>::busReset() {
394 for (iface::BaseAddressRegisterQueryInterface::BarInfo::const_iterator it
395 = bar_info_.begin(); it != bar_info_.end(); ++it) {
396 int mapping_id = (*it).mapping_id + mapping_id_offset_;
398 if ((*it).is_memory) {
400 }
401 extension_.remove_map(space, mapping_id);
402 if (sender_.failed_transaction_.payload()) {
403 SC_REPORT_INFO(PCI_MAPPING_INTERCONNECT_TAG,
404 "Failure to unmap device on bus_reset");
405 }
406 }
407}
408
410
411/*
412 * Intercept the BAR and Command regs, always forward transaction to target to
413 * handle all errors there
414 */
415template <unsigned int BUSWIDTH, typename TYPES>
416void PciMappingInterconnect<BUSWIDTH, TYPES>::b_transport(
417 int id,
418 tlm::tlm_generic_payload &trans, // NOLINT
419 sc_core::sc_time &t) { // NOLINT
420 interceptBarAccess(id, trans, t);
421 initiator_sockets_[id]->b_transport(trans, t);
422}
423
424/*
425 * transport_dbg is side-effect free = forwarded without inspection
426 */
427template <unsigned int BUSWIDTH, typename TYPES>
428unsigned int PciMappingInterconnect<BUSWIDTH, TYPES>::transport_dbg(
429 int id,
430 tlm::tlm_generic_payload &trans) { // NOLINT
431 return initiator_sockets_[id]->transport_dbg(trans);
432}
433
434/*
435 * For pci-device, just relay the incoming transaction to outgoing socket
436 */
437template <unsigned int BUSWIDTH, typename TYPES>
438void PciMappingInterconnect<BUSWIDTH, TYPES>::simics_b_transport(
439 int id, tlm::tlm_generic_payload &trans, // NOLINT
440 sc_core::sc_time &t) { // NOLINT
441 pci_device_initiator_socket_->b_transport(trans, t);
442}
443
444/*
445 * For pci-bus, just relay the incoming transaction to outgoing socket
446 */
447template <unsigned int BUSWIDTH, typename TYPES>
448void PciMappingInterconnect<BUSWIDTH, TYPES>::pci_bus_b_transport(
449 tlm::tlm_generic_payload &trans, // NOLINT
450 sc_core::sc_time &t) { // NOLINT
451 pci_bus_initiator_socket->b_transport(trans, t);
452}
453
454/*
455 * For pci-bus, just relay the incoming transaction to outgoing socket
456 */
457template <unsigned int BUSWIDTH, typename TYPES>
458unsigned int PciMappingInterconnect<BUSWIDTH, TYPES>::pci_bus_transport_dbg(
459 tlm::tlm_generic_payload &trans) { // NOLINT
460 return pci_bus_initiator_socket->transport_dbg(trans);
461}
462
463/*
464 * For pci-bus, just relay the incoming transaction to outgoing socket
465 */
466template <unsigned int BUSWIDTH, typename TYPES>
467bool PciMappingInterconnect<BUSWIDTH, TYPES>::pci_bus_get_direct_mem_ptr(
468 tlm::tlm_generic_payload &trans, // NOLINT
469 tlm::tlm_dmi &dmi_data) { // NOLINT
470 return pci_bus_initiator_socket->get_direct_mem_ptr(trans, dmi_data);
471}
472
473/*
474 * For pci-bus, just relay the incoming BW transaction to target socket
475 */
476template <unsigned int BUSWIDTH, typename TYPES>
477void PciMappingInterconnect<BUSWIDTH, TYPES>::pci_bus_invalidate_direct_mem_ptr(
478 sc_dt::uint64 start_range,
479 sc_dt::uint64 end_range) {
480 pci_bus_target_socket_->invalidate_direct_mem_ptr(start_range,
481 end_range);
482}
483
484// Cast sc_object to a supported target socket and return it.
485// TPciDevice is the type of the PCI device,
486template <unsigned int BUSWIDTH, typename TYPES>
487void PciMappingInterconnect<BUSWIDTH, TYPES>::castToTarget(
488 sc_core::sc_object *object, supported_target_socket_t *target) {
489 tlm::tlm_target_socket<BUSWIDTH, TYPES> *tlm_target
490 = dynamic_cast<tlm::tlm_target_socket<BUSWIDTH, TYPES> *>(object);
491 if (tlm_target) {
492 target->tlm = tlm_target;
493 return;
494 }
495
496 tlm_utils::multi_target_base<BUSWIDTH, TYPES> *multi_target
497 = dynamic_cast<tlm_utils::multi_target_base<BUSWIDTH, TYPES> *>(object);
498 if (multi_target) {
499 target->multi = multi_target;
500 return;
501 }
502
503 SC_REPORT_ERROR(PCI_MAPPING_INTERCONNECT_TAG,
504 "Unable to dynamic-cast PCI target socket");
505}
506
507template <unsigned int BUSWIDTH, typename TYPES>
508template <typename TGasket>
509void PciMappingInterconnect<BUSWIDTH, TYPES>::bindToGasket(
510 supported_target_socket_t target,
511 TGasket *gasket, ConfObjectRef o, int id) {
512 if (target.tlm) {
513 gasket->addGasket(id, simics2tlm::createGasket(target.tlm, o));
514 } else if (target.multi) {
515 // coverity[var_deref_model], safe cast based on castToTarget() func
516 gasket->addGasket(id, simics2tlm::createGasket(target.multi, o));
517 }
518}
519
520/*
521 * When command register is written to, the mappings need to be re-evaluated
522 * and possibly updated.
523 *
524 * There is no error handling, so if the mapping fails this will only be logged
525 * but the access will still pass (i.e. transaction forwarded to target device
526 * where registers are updated without side-effects)
527 */
528template <unsigned int BUSWIDTH, typename TYPES>
529void PciMappingInterconnect<BUSWIDTH, TYPES>::updateCommand(
530 int id, uint16_t old_command) {
531 int command = function_data_[id].command;
532 if (command == old_command) {
533 return;
534 }
535 int function = function_data_[id].function;
536 bool mem_enable = (command >> 1) & 1;
537 bool io_enable = command & 1;
538
539 for (iface::BaseAddressRegisterQueryInterface::BarInfo::const_iterator it
540 = bar_info_.begin(); it != bar_info_.end(); ++it) {
541 if ((*it).function == function) {
542 bool enable
543 = (*it).is_memory ? mem_enable : io_enable;
545 = (*it).is_memory ? types::Sim_Addr_Space_Memory
547 int bar = ((*it).offset - 0x10) / 4;
548 uint64_t base_address = function_data_[id].base_address[bar];
549 if ((*it).is_64bit) {
550 base_address |= static_cast<uint64_t>(
551 function_data_[id].base_address[bar + 1]) << 32;
552 }
553 updateMemoryMapping(enable, space, base_address,
554 (*it).size_bits,
555 (*it).mapping_id + mapping_id_offset_);
556 }
557 }
558}
559
560/*
561 * When BAR register is written to, the mapping need to be re-evaluated and
562 * possibly updated.
563 *
564 * There is no error handling, so if the mapping fails this will only be logged
565 * but the access will still pass (i.e. transaction forwarded to target device
566 * where registers are updated without side-effects)
567 */
568template <unsigned int BUSWIDTH, typename TYPES>
569void PciMappingInterconnect<BUSWIDTH, TYPES>::updateBaseAddress(int id,
570 int bar) {
571 int command = function_data_[id].command;
572 int function = function_data_[id].function;
573 bool mem_enable = (command >> 1) & 1;
574 bool io_enable = command & 1;
575 for (iface::BaseAddressRegisterQueryInterface::BarInfo::const_iterator it
576 = bar_info_.begin(); it != bar_info_.end(); ++it) {
577 if ((*it).function == function && (*it).offset == 0x10 + 4 * bar) {
578 bool enable = (*it).is_memory ? mem_enable : io_enable;
579 if (!enable) {
580 // no re-mapping will be done as encoding is not enabled
581 return;
582 }
584 = (*it).is_memory ? types::Sim_Addr_Space_Memory
586 uint64_t base_address = function_data_[id].base_address[bar];
587 if ((*it).is_64bit) {
588 base_address |= static_cast<uint64_t>(
589 function_data_[id].base_address[bar + 1]) << 32;
590 }
591 updateMemoryMapping(enable, space, base_address,
592 (*it).size_bits,
593 (*it).mapping_id + mapping_id_offset_);
594 break;
595 }
596 }
597}
598
599template <unsigned int BUSWIDTH, typename TYPES>
600void PciMappingInterconnect<BUSWIDTH, TYPES>::updateMemoryMapping(
601 bool enable,
603 uint64_t base_address,
604 int bar_size_bits,
605 int mapping_id) {
606 extension_.remove_map(space, mapping_id);
607 if (sender_.failed_transaction_.payload()) {
608 SC_REPORT_INFO(PCI_MAPPING_INTERCONNECT_TAG, "Failure to unmap device");
609 return;
610 }
611
612 if (enable) {
613 types::map_info_t info(base_address & ~((1ULL << bar_size_bits) - 1),
614 0, 1ULL << bar_size_bits,
615 mapping_id);
616 extension_.add_map(space, info);
617
618 if (sender_.failed_transaction_.payload()) {
619 SC_REPORT_INFO(PCI_MAPPING_INTERCONNECT_TAG,
620 "Failure to map device");
621 return;
622 }
623 }
624}
625
626template <unsigned int BUSWIDTH, typename TYPES>
627void PciMappingInterconnect<BUSWIDTH, TYPES>::interceptBarAccess(
628 int id,
629 tlm::tlm_generic_payload &trans, // NOLINT
630 sc_core::sc_time &t) { // NOLINT
631 // Decode the generic payload (GP) struct
632 sc_dt::uint64 offset = trans.get_address();
633 unsigned int size = trans.get_data_length();
634 uint64_t *data = reinterpret_cast<uint64_t *>(trans.get_data_ptr());
635
636 // Check assumptions (but leave it up to target device to report errors)
637 if (trans.get_byte_enable_ptr()) {
638 return;
639 }
640 if (trans.get_streaming_width() != size) {
641 return;
642 }
643 // NOTE: we should also check that address is DWORD/4-byte aligned, but
644 // our Viper/X58 platform seems to address single bytes so ...
645
646 // We are only interested in write access to BARn or Command regs
647 if (trans.is_write()) {
648 uint16_t old_command = function_data_[id].command;
649
650 switch (offset) {
651 case 0x04: { // command & status
652 retrieveFunctionData(id, -1);
653 function_data_[id].command = (*data) & 0xffff; // ignore status
654 updateCommand(id, old_command);
655 break;
656 }
657 case 0x10: // BAR0-BAR5
658 case 0x14:
659 case 0x18:
660 case 0x1c:
661 case 0x20:
662 case 0x24:
663 int bar = (offset - 0x10) / 4;
664 retrieveFunctionData(id, bar);
665 // NOTE: the IO, Mem32, Mem64 bits are ignored by
666 // updateMemoryMapping, no need to filter them out here. In
667 // addition, any bits less than the size of the BAR as defined by
668 // the BarInfo will also be ignored/truncated by
669 // updateMemoryMapping; making sure we always send a naturally
670 // aligned address to Simics
671 function_data_[id].base_address[bar] = *data & 0xffffffff;
672 if (size == 8 && !(offset % 8)) {
673 function_data_[id].base_address[bar + 1] = *data >> 32;
674 }
675 updateBaseAddress(id, bar);
676 break;
677 }
678 }
679}
680
681} // namespace composite
682} // namespace systemc
683} // namespace simics
684
685#endif
686#endif
std::vector< std::pair< BaseAddressRegister, sc_core::sc_object * > > BarSockets
IO/Memory space target socket(s).
Definition: pci_device_query_interface.h:106
@ Log_Configuration
Definition: adapter_log_groups.h:23
addr_space_t
Stand-alone, version of the Simics addr_space_t enum.
Definition: addr_space.h:21
@ Sim_Addr_Space_Memory
Definition: addr_space.h:24
@ Sim_Addr_Space_IO
Definition: addr_space.h:23
Definition: adapter.h:79