From adf27adb3cfadc6e4c41d6db814159f1329b24f3 Mon Sep 17 00:00:00 2001 From: Saifuddin Kaijar <54270703+saifuddin-xilinx@users.noreply.github.com> Date: Wed, 3 May 2023 21:03:12 +0530 Subject: [PATCH] Cherry picks #7519 & #7527 for 2023.1 branch (#7534) * CR-1160935 : Fixed a issue for xbtest invalid card BDF (#7519) * Fixed a issue for xbtest invalid card BDF * Fixed a issue for xbtest invalid card BDF Signed-off-by: Saifuddin * incorporate review comments Signed-off-by: Saifuddin --------- Signed-off-by: Saifuddin (cherry picked from commit e5ba80c289d6ccad94203170c68f40e3cbe77b3b) * Fixed xocl driver issues (#7527) Signed-off-by: Saifuddin (cherry picked from commit 5cc736133e1de14968ecf091b6885471671b4dcf) --- .../pcie/driver/linux/xocl/userpf/xocl_bo.c | 22 +++++++++++-------- .../pcie/driver/linux/xocl/userpf/xocl_drm.c | 2 +- .../driver/linux/xocl/userpf/xocl_ioctl.c | 4 ++-- .../core/pcie/linux/system_linux.cpp | 22 ++++++++++++------- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/runtime_src/core/pcie/driver/linux/xocl/userpf/xocl_bo.c b/src/runtime_src/core/pcie/driver/linux/xocl/userpf/xocl_bo.c index e089169aa02..e62eb08f466 100644 --- a/src/runtime_src/core/pcie/driver/linux/xocl/userpf/xocl_bo.c +++ b/src/runtime_src/core/pcie/driver/linux/xocl/userpf/xocl_bo.c @@ -559,16 +559,20 @@ __xocl_create_bo_ioctl(struct drm_device *dev, struct drm_file *filp, uint32_t slot_id = 0; int ret; - /* Currently userspace will provide the corresponding hw context id. - * Driver has to map that hw context to the corresponding slot id. - */ - hw_ctx_id = xocl_bo_slot_idx(args->flags); - ret = xocl_get_slot_id_by_hw_ctx_id(xdev, filp, hw_ctx_id); - if (ret < 0) - return ERR_PTR(ret); + if (bo_type != XOCL_BO_EXECBUF) { + /* Currently userspace will provide the corresponding hw context id. + * Driver has to map that hw context to the corresponding slot id. + * This is not valid for Host memory. + */ + hw_ctx_id = xocl_bo_slot_idx(args->flags); + ret = xocl_get_slot_id_by_hw_ctx_id(xdev, filp, hw_ctx_id); + if (ret < 0) + return ERR_PTR(ret); + + slot_id = ret; + args->flags = xocl_bo_set_slot_idx(args->flags, slot_id); + } - slot_id = ret; - args->flags = xocl_bo_set_slot_idx(args->flags, slot_id); xobj = xocl_create_bo(dev, args->size, args->flags, bo_type); if (IS_ERR(xobj)) { DRM_ERROR("object creation failed idx %d, size 0x%llx\n", diff --git a/src/runtime_src/core/pcie/driver/linux/xocl/userpf/xocl_drm.c b/src/runtime_src/core/pcie/driver/linux/xocl/userpf/xocl_drm.c index 92de3baa3ed..1769fe66f44 100644 --- a/src/runtime_src/core/pcie/driver/linux/xocl/userpf/xocl_drm.c +++ b/src/runtime_src/core/pcie/driver/linux/xocl/userpf/xocl_drm.c @@ -715,7 +715,7 @@ static int xocl_mm_insert_node_range_all(struct xocl_drm *drm_p, uint32_t *mem_i phy_bank_exists = true; start_addr = mem_data->m_base_address; - end_addr = start_addr + mem_data->m_size; + end_addr = start_addr + mem_data->m_size * 1024; #if defined(XOCL_DRM_FREE_MALLOC) ret = drm_mm_insert_node_in_range(xocl_mm->mm, dnode, size, PAGE_SIZE, 0, diff --git a/src/runtime_src/core/pcie/driver/linux/xocl/userpf/xocl_ioctl.c b/src/runtime_src/core/pcie/driver/linux/xocl/userpf/xocl_ioctl.c index 06e08213a32..a1d7d3781a3 100644 --- a/src/runtime_src/core/pcie/driver/linux/xocl/userpf/xocl_ioctl.c +++ b/src/runtime_src/core/pcie/driver/linux/xocl/userpf/xocl_ioctl.c @@ -744,8 +744,6 @@ xocl_read_axlf_helper(struct xocl_drm *drm_p, struct drm_xocl_axlf *axlf_ptr, } done: - /* Update the slot */ - *slot = slot_id; if (size < 0) err = size; if (err) { @@ -766,6 +764,8 @@ xocl_read_axlf_helper(struct xocl_drm *drm_p, struct drm_xocl_axlf *axlf_ptr, userpf_info(xdev, "Loaded xclbin %pUb", &bin_obj.m_header.uuid); out_done: + /* Update the slot */ + *slot = slot_id; vfree(axlf); return err; } diff --git a/src/runtime_src/core/pcie/linux/system_linux.cpp b/src/runtime_src/core/pcie/linux/system_linux.cpp index 2cdcf423ee7..e8a09ccbdbe 100644 --- a/src/runtime_src/core/pcie/linux/system_linux.cpp +++ b/src/runtime_src/core/pcie/linux/system_linux.cpp @@ -127,17 +127,23 @@ std::shared_ptr system_linux:: get_pcidev(unsigned index, bool is_user) const { - if (is_user) { - if (index < user_ready_list.size()) - return user_ready_list[index]; + try { + if (is_user) { + if (index < user_ready_list.size()) + return user_ready_list[index]; - return user_nonready_list[index - user_ready_list.size()]; - } + if ((index - user_ready_list.size()) < user_nonready_list.size()) + return user_nonready_list.at(index - user_ready_list.size()); + } - if (index < mgmt_ready_list.size()) - return mgmt_ready_list[index]; + if (index < mgmt_ready_list.size()) + return mgmt_ready_list[index]; - return mgmt_nonready_list[index - mgmt_ready_list.size()]; + return mgmt_nonready_list.at(index - mgmt_ready_list.size()); + } + catch (const std::exception&) { + return nullptr; + } } size_t