From 7043cb74b10ed3a67e1e8a3b533e9fdc9e08d113 Mon Sep 17 00:00:00 2001 From: Tim Whisonant Date: Tue, 26 Sep 2023 11:28:49 -0700 Subject: [PATCH] Feature: add fpgaBindSVA() support to C++ bindings (#3016) ### 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 --- include/opae/cxx/core/handle.h | 10 +++++++++- libraries/libopaecxx/src/handle.cpp | 10 ++++++++-- tests/opae-cxx/test_handle_cxx_core.cpp | 25 ++++++++++++++++++++++++- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/include/opae/cxx/core/handle.h b/include/opae/cxx/core/handle.h index 4c5013201aa1..e4979257c88f 100644 --- a/include/opae/cxx/core/handle.h +++ b/include/opae/cxx/core/handle.h @@ -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: @@ -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 diff --git a/libraries/libopaecxx/src/handle.cpp b/libraries/libopaecxx/src/handle.cpp index 97e6796d5942..fe27b5badb32 100644 --- a/libraries/libopaecxx/src/handle.cpp +++ b/libraries/libopaecxx/src/handle.cpp @@ -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: @@ -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 #include #include #include @@ -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(); @@ -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 diff --git a/tests/opae-cxx/test_handle_cxx_core.cpp b/tests/opae-cxx/test_handle_cxx_core.cpp index 408638157000..fe4ba38760cc 100644 --- a/tests/opae-cxx/test_handle_cxx_core.cpp +++ b/tests/opae-cxx/test_handle_cxx_core.cpp @@ -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: @@ -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({