Skip to content

Commit d7de42a

Browse files
committed
refactor: use UioRegion instead of phys_addr/size
1 parent 1dc6e74 commit d7de42a

8 files changed

Lines changed: 24 additions & 35 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/pyudmaio/build*
33
/pyudmaio/pyudmaio/*.so
44
/.vscode
5+
/.cache
56
*.pyc
67
*.egg-info
78

inc/udmaio/DmaBufferAbstract.hpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,9 @@ class DmaBufferAbstract : private boost::noncopyable {
2626
virtual void copy_from_buf(uint8_t* dest, const UioRegion& buf_info) const = 0;
2727

2828
public:
29-
/// @brief Get physical address
30-
/// @return Physical address of DMA data buffer
31-
virtual uintptr_t get_phys_addr() const = 0;
32-
33-
/// @brief Get buffer size
34-
/// @return Size of DMA data buffer
35-
virtual uintptr_t get_phys_size() const = 0;
29+
/// @brief Get physical region
30+
/// @return Physical address and size of DMA data buffer
31+
virtual UioRegion get_phys_region() const = 0;
3632

3733
/// @brief Append received DMA data to vector
3834
/// @param buf_info Memory region of DMA buffer

inc/udmaio/FpgaMemBufferOverAxi.hpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@ namespace udmaio {
2525
/// DMA data buffer accessed over AXI/UIO, described w/ explicit address & size
2626
class FpgaMemBufferOverAxi : public DmaBufferAbstract, public UioIf {
2727
public:
28-
FpgaMemBufferOverAxi(UioDeviceLocation dev_loc) : UioIf("FpgaMemBufferOverAxi", hw) {}
28+
FpgaMemBufferOverAxi(UioDeviceLocation dev_loc) : UioIf("FpgaMemBufferOverAxi", dev_loc) {}
2929

30-
uintptr_t get_phys_addr() const override { return _region.addr; }
31-
32-
uintptr_t get_phys_size() const override { return _region.size; }
30+
UioRegion get_phys_region() const override { return _hw->get_phys_region(); }
3331

3432
protected:
3533
void copy_from_buf(uint8_t* dest, const UioRegion& buf_info) const override {
@@ -38,8 +36,8 @@ class FpgaMemBufferOverAxi : public DmaBufferAbstract, public UioIf {
3836
<< buf_info.addr << std::dec;
3937
BOOST_LOG_SEV(_lg, bls::trace)
4038
<< "FpgaMemBufferOverAxi: append_from_buf: buf_info.size = " << buf_info.size;
41-
uintptr_t mmap_addr = buf_info.addr - _region.addr;
42-
std::memcpy(dest, static_cast<uint8_t*>(_mem) + mmap_addr, buf_info.size);
39+
uintptr_t mmap_addr = buf_info.addr - get_phys_region().addr;
40+
std::memcpy(dest, static_cast<uint8_t*>(_hw->get_virt_mem()) + mmap_addr, buf_info.size);
4341
}
4442
};
4543

inc/udmaio/FpgaMemBufferOverXdma.hpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ namespace udmaio {
2222
/// DMA data buffer accessed over XDMA using the xdma c2h0 stream channel
2323
class FpgaMemBufferOverXdma : public DmaBufferAbstract {
2424
int _dma_fd;
25-
uintptr_t _phys_addr;
25+
UioRegion _phys_region;
2626

2727
public:
2828
/// @brief Constructs a DMA data buffer
2929
/// @param path Base path of XDMA instance in `/dev`
3030
/// @param phys_addr Physical address of DMA data buffer
3131
explicit FpgaMemBufferOverXdma(const std::string& path, uintptr_t phys_addr)
32-
: _phys_addr{phys_addr} {
32+
: _phys_region{phys_addr, 0} { // FIXME: can we get the memory size?
3333
const std::string dev_path{path + "/c2h0"};
3434
_dma_fd = open(dev_path.c_str(), O_RDWR);
3535
if (_dma_fd < 0) {
@@ -38,12 +38,7 @@ class FpgaMemBufferOverXdma : public DmaBufferAbstract {
3838
}
3939
virtual ~FpgaMemBufferOverXdma() { close(_dma_fd); }
4040

41-
uintptr_t get_phys_addr() const override { return _phys_addr; }
42-
43-
uintptr_t get_phys_size() const override {
44-
// there is no way to get the size over the Xdma, return 0 and let the user handle it
45-
return 0;
46-
}
41+
UioRegion get_phys_region() const override { return _phys_region; }
4742

4843
protected:
4944
void copy_from_buf(uint8_t* dest, const UioRegion& buf_info) const override {

inc/udmaio/HwAccessor.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ class HwAccessor : public Logger, private boost::noncopyable {
109109
virtual void arm_interrupt();
110110
virtual uint32_t wait_for_interrupt();
111111
virtual int get_fd_int() const { return -1; }
112-
virtual uintptr_t get_phys_addr() const { return 0; }
112+
virtual UioRegion get_phys_region() const { return {0, 0}; }
113+
virtual void* get_virt_mem() const { return nullptr; }
113114
};
114115

115116
// Base class for mmap'ed hardware access
@@ -216,7 +217,8 @@ class HwAccessorMmap : public HwAccessor {
216217
}
217218

218219
public:
219-
uintptr_t get_phys_addr() const final override { return _region.addr; }
220+
UioRegion get_phys_region() const final override { return _region; }
221+
void* get_virt_mem() const final override { return _mem; }
220222
};
221223

222224
// Hardware accessor for XDMA. Can support either 32 or 64 bit access

inc/udmaio/UDmaBuf.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include "DmaBufferAbstract.hpp"
1515
#include "Logging.hpp"
16+
#include "udmaio/UioConfig.hpp"
1617

1718
namespace udmaio {
1819

@@ -34,8 +35,7 @@ class UDmaBuf : public DmaBufferAbstract, public Logger {
3435

3536
virtual ~UDmaBuf();
3637

37-
uintptr_t get_phys_addr() const override;
38-
uintptr_t get_phys_size() const override;
38+
UioRegion get_phys_region() const override;
3939
};
4040

4141
} // namespace udmaio

src/UDmaBuf.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,8 @@ UDmaBuf::~UDmaBuf() {
6868
::close(_fd);
6969
}
7070

71-
uintptr_t UDmaBuf::get_phys_addr() const {
72-
return _phys.addr;
73-
}
74-
75-
uintptr_t UDmaBuf::get_phys_size() const {
76-
return _phys.size;
71+
UioRegion UDmaBuf::get_phys_region() const {
72+
return _phys;
7773
}
7874

7975
void UDmaBuf::copy_from_buf(uint8_t* dest, const UioRegion& buf_info) const {

src/UioMemSgdma.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,20 @@
1111

1212
#include "udmaio/UioMemSgdma.hpp"
1313

14-
#include <bitset>
14+
#include <cstdint>
1515

1616
namespace udmaio {
1717

1818
void UioMemSgdma::write_cyc_mode(const std::vector<UioRegion>& dst_bufs) {
1919
_nr_cyc_desc = dst_bufs.size();
2020
_next_readable_buf = 0;
2121
size_t i = 0;
22+
2223
for (auto dst_buf : dst_bufs) {
2324
BOOST_LOG_SEV(_lg, bls::trace)
2425
<< "dest buf addr = 0x" << std::hex << dst_buf.addr << std::dec;
2526

26-
uintptr_t nxtdesc = _hw->get_phys_addr() + ((i + 1) % _nr_cyc_desc) * DESC_ADDR_STEP;
27+
uintptr_t nxtdesc = get_first_desc_addr() + ((i + 1) % _nr_cyc_desc) * DESC_ADDR_STEP;
2728

2829
S2mmDesc desc{
2930
.nxtdesc = nxtdesc,
@@ -47,7 +48,7 @@ void UioMemSgdma::init_buffers(DmaBufferAbstract& mem, size_t num_buffers, size_
4748
std::vector<UioRegion> dst_bufs;
4849
for (size_t i = 0; i < num_buffers; i++) {
4950
dst_bufs.push_back({
50-
.addr = mem.get_phys_addr() + i * buf_size,
51+
.addr = mem.get_phys_region().addr + i * buf_size,
5152
.size = buf_size,
5253
});
5354
};
@@ -84,7 +85,7 @@ void UioMemSgdma::print_descs() const {
8485
}
8586
8687
uintptr_t UioMemSgdma::get_first_desc_addr() const {
87-
return _hw->get_phys_addr();
88+
return _hw->get_phys_region().addr;
8889
}
8990
9091
std::ostream& operator<<(std::ostream& os, const UioRegion& buf_info) {

0 commit comments

Comments
 (0)