6 #include <boost/make_shared.hpp>
20 std::cout <<
"XDMA: opening dev: " << _devicePath << std::endl;
28 _ctrlIntf.emplace(_devicePath);
30 std::for_each(_eventFiles.begin(), _eventFiles.end(), [](
auto& eventFile) { eventFile = nullptr; });
34 for(
size_t i = 0; i < _maxDmaChannels; i++) {
36 _dmaChannels.emplace_back(_devicePath, i);
44 std::cout <<
"XDMA: opened interface with " << _dmaChannels.size() <<
" DMA channels and " << _eventFiles.size()
45 <<
" interrupt sources\n";
51 std::for_each(_eventFiles.begin(), _eventFiles.end(), [](
auto& eventFile) { eventFile = nullptr; });
62 if(bar == 0 && _ctrlIntf.has_value()) {
63 return _ctrlIntf.value();
68 const size_t dmaChIdx = bar - 13;
69 if(dmaChIdx < _dmaChannels.size()) {
70 return _dmaChannels[dmaChIdx];
78 constexpr
size_t wordsPerLine = 8;
80 for(n = 0; n < (nbytes /
sizeof(*data)) && n < 64; n++) {
81 if(!(n % wordsPerLine)) {
82 std::cout << std::hex << std::setw(4) << std::setfill(
'0') << n *
sizeof(*data) <<
":";
84 std::cout <<
" " << std::hex << std::setw(8) << std::setfill(
'0') << data[n];
85 if((n % wordsPerLine) == wordsPerLine - 1) {
89 if((n % wordsPerLine) != wordsPerLine) {
97 std::cout <<
"XDMA: read " << sizeInBytes <<
" bytes @ BAR" << bar <<
", 0x" << std::hex << address << std::endl;
99 auto& intf = _intfFromBar(bar);
100 intf.read(address, data, sizeInBytes);
102 dump(data, sizeInBytes);
108 std::cout <<
"XDMA: write " << sizeInBytes <<
" bytes @ BAR" << bar <<
", 0x" << std::hex << address << std::endl;
110 auto& intf = _intfFromBar(bar);
111 intf.write(address, data, sizeInBytes);
113 dump(data, sizeInBytes);
119 std::promise<void> subscriptionDonePromise;
120 auto subscriptionDoneFuture = subscriptionDonePromise.get_future();
121 if(interruptNumber >= _maxInterrupts) {
124 subscriptionDonePromise.set_value();
125 return subscriptionDoneFuture;
128 if(!_eventFiles[interruptNumber]) {
129 _eventFiles[interruptNumber] = std::make_unique<EventFile>(
this, _devicePath, interruptNumber, asyncDomain);
130 _eventFiles[interruptNumber]->startThread(std::move(subscriptionDonePromise));
134 subscriptionDonePromise.set_value();
136 return subscriptionDoneFuture;
140 std::string result =
"XDMA backend: Device path = " + _devicePath +
", number of DMA channels = ";
145 result +=
"unknown (device closed)";
153 std::string address, std::map<std::string, std::string> parameters) {
154 if(address.empty()) {
158 return boost::make_shared<XdmaBackend>(
"/dev/" + address, parameters[
"map"]);