Skip to content

Commit

Permalink
Feature: add fpgaBindSVA() support to C++ bindings (#3016)
Browse files Browse the repository at this point in the history
### Description
Adds C++ member function handle::bind_sva() which calls fpgaBindSVA() to perform the magic and retrieve the pasid.


### Collateral (docs, reports, design examples, case IDs):
N/A


- [X] Document Update Required? (Specify FIM/AFU/Scripts)
C Programming Guide

### Tests added:
handle_cxx_core.bind_sva

### Tests run:
CI

Signed-off-by: Tim Whisonant <[email protected]>
  • Loading branch information
Tim Whisonant authored Sep 26, 2023
1 parent 039a7a0 commit 7043cb7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
10 changes: 9 additions & 1 deletion include/opae/cxx/core/handle.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright(c) 2018-2021, Intel Corporation
// Copyright(c) 2018-2023, Intel Corporation
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -186,11 +186,19 @@ class handle {
*/
token::ptr_t get_token() const;

/** Bind IOMMU shared virtual addressing
*
* @return the non-zero process address space ID on success
* or zero on failure.
*/
uint32_t bind_sva();

private:
handle(fpga_handle h);

fpga_handle handle_;
fpga_token token_;
uint32_t pasid_;
};

} // end of namespace types
Expand Down
10 changes: 8 additions & 2 deletions libraries/libopaecxx/src/handle.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright(c) 2018-2021, Intel Corporation
// Copyright(c) 2018-2023, Intel Corporation
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
Expand All @@ -23,6 +23,7 @@
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#include <opae/buffer.h>
#include <opae/cxx/core/except.h>
#include <opae/cxx/core/handle.h>
#include <opae/cxx/core/properties.h>
Expand All @@ -35,7 +36,7 @@ namespace opae {
namespace fpga {
namespace types {

handle::handle(fpga_handle h) : handle_(h), token_(nullptr) {}
handle::handle(fpga_handle h) : handle_(h), token_(nullptr), pasid_(0) {}

handle::~handle() {
close();
Expand Down Expand Up @@ -129,6 +130,11 @@ token::ptr_t handle::get_token() const {
return p;
}

uint32_t handle::bind_sva() {
if (!pasid_) ASSERT_FPGA_OK(fpgaBindSVA(handle_, &pasid_));
return pasid_;
}

} // end of namespace types
} // end of namespace fpga
} // end of namespace opae
25 changes: 24 additions & 1 deletion tests/opae-cxx/test_handle_cxx_core.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright(c) 2018-2022, Intel Corporation
// Copyright(c) 2018-2023, Intel Corporation
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -171,6 +171,29 @@ TEST_P(handle_cxx_core, get_token) {
ASSERT_NO_THROW(p = tok->get_parent());
}

/**
* @test bind_sva
* Verify that handle::bind_sva can retrieve the pasid
* when supported.
*/
TEST_P(handle_cxx_core, bind_sva) {
handle_ = handle::open(tokens_[0], 0);
ASSERT_NE(nullptr, handle_.get());

uint32_t pasid = 0;
bool check_it = true; // only check if bind_sva is supported

try {
pasid = handle_->bind_sva();
} catch(opae::fpga::types::not_supported &ex) {
check_it = false;
}

if (check_it) {
ASSERT_NE(0, pasid);
}
}

GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(handle_cxx_core);
INSTANTIATE_TEST_SUITE_P(handle, handle_cxx_core,
::testing::ValuesIn(test_platform::platforms({
Expand Down

0 comments on commit 7043cb7

Please sign in to comment.