From 3f36a8a7d7e3d839c33db2447bc1a87f74a5085c Mon Sep 17 00:00:00 2001 From: Jeff Lin Date: Tue, 6 Jun 2023 13:00:26 -0700 Subject: [PATCH 1/4] CR-1161216 - Always enable GCQ's interrupt to allow compatibility between GCQ v1 and v2 (#7566) (#7576) * Updated xgq_impl.h to always write 1 to GCQ's interrupt enable bit to address CR-1161216. This is due to default GCQ v2 interrupt enable is set to 0. Signed-off-by: Jeff Lin * Only write to interrupt enable bit of GCQ for the writable register. Signed-off-by: Jeff Lin --------- Signed-off-by: Jeff Lin Co-authored-by: Jeff Lin (cherry picked from commit aaf0c1d8073ae82fc8b853b4cadc60e5852756c2) --- src/runtime_src/core/include/xgq_impl.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/runtime_src/core/include/xgq_impl.h b/src/runtime_src/core/include/xgq_impl.h index d9847f39cdf..7b2529cb367 100644 --- a/src/runtime_src/core/include/xgq_impl.h +++ b/src/runtime_src/core/include/xgq_impl.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2021, Xilinx Inc + * Copyright (C) 2023, Advanced Micro Devices, Inc * * This file is dual licensed. It may be redistributed and/or modified * under the terms of the Apache 2.0 License OR version 2 of the GNU @@ -198,6 +199,7 @@ struct xgq { #define XGQ_NEED_DOUBLE_READ(xgq) (((xgq)->xq_flags & XGQ_DOUBLE_READ) != 0) #define XGQ_IS_IN_MEM_PROD(xgq) (((xgq)->xq_flags & XGQ_IN_MEM_PROD) != 0) +#define XGQ_INTR_ENABLE_OFFSET 12 /* * XGQ implementation details and helper routines. @@ -379,6 +381,8 @@ xgq_init(struct xgq *xgq, uint64_t flags, uint64_t io_hdl, uint64_t ring_addr, } else { sqprod = sq_produced; cqprod = cq_produced; + // Write 1 to GCQ interrupt enable register to always enable interrupt + xgq_reg_write32(xgq->xq_io_hdl, cqprod + XGQ_INTR_ENABLE_OFFSET, 1); } xgq_init_ring(xgq, &xgq->xq_sq, sqprod, ring_addr + offsetof(struct xgq_header, xh_sq_consumed), @@ -526,6 +530,8 @@ static inline int xgq_attach(struct xgq *xgq, uint64_t flags, uint64_t io_hdl, u } else { sqprod = sq_produced; cqprod = cq_produced; + // Write 1 to GCQ interrupt enable register to always enable interrupt + xgq_reg_write32(xgq->xq_io_hdl, sqprod + XGQ_INTR_ENABLE_OFFSET, 1); } xgq_init_ring(xgq, &xgq->xq_sq, sqprod, ring_addr + offsetof(struct xgq_header, xh_sq_consumed), From 3e96913ac467132269cc6595d95cde2ff320328e Mon Sep 17 00:00:00 2001 From: Ch Vamshi Krishna <40261882+chvamshi-xilinx@users.noreply.github.com> Date: Thu, 15 Jun 2023 16:04:45 +0530 Subject: [PATCH 2/4] moving to latest petalinux and removed vdu recipes (#7592) (#7593) (cherry picked from commit 2827c0fe27c5caecbe36802bdd4a09ba532b7721) --- build/build_edge.sh | 31 +------------ build/petalinux.build | 2 +- .../scripts/apu_recipes/kernel-module-vdu.bb | 31 ------------- .../scripts/apu_recipes/libvdu-ctrlsw.bb | 44 ------------------- .../tools/scripts/apu_recipes/vdu-firmware.bb | 42 ------------------ 5 files changed, 3 insertions(+), 147 deletions(-) delete mode 100755 src/runtime_src/tools/scripts/apu_recipes/kernel-module-vdu.bb delete mode 100755 src/runtime_src/tools/scripts/apu_recipes/libvdu-ctrlsw.bb delete mode 100755 src/runtime_src/tools/scripts/apu_recipes/vdu-firmware.bb diff --git a/build/build_edge.sh b/build/build_edge.sh index 8c1ea547464..a411d2ff5b0 100755 --- a/build/build_edge.sh +++ b/build/build_edge.sh @@ -67,7 +67,7 @@ install_recipes() eval "$SAVED_OPTIONS_LOCAL" } -enable_vdu() +enable_vdu_init() { VERSAL_PROJECT_DIR=$1 APU_RECIPES_DIR=$XRT_REPO_DIR/src/runtime_src/tools/scripts/apu_recipes @@ -88,35 +88,8 @@ enable_vdu() cp $INIT_SCRIPT $VERSAL_PROJECT_DIR/project-spec/meta-user/recipes-apps/vdu-init/files # Generate vdu modules and add them to apu package - - # Enable VDU kernel module - VDU_MOD_BB_FILE=$APU_RECIPES_DIR/kernel-module-vdu.bb - if [ ! -d $VERSAL_PROJECT_DIR/project-spec/meta-user/recipes-apps/kernel-module-vdu ]; then - $PETA_BIN/petalinux-config --silentconfig - $PETA_BIN/petalinux-create -t apps --template install -n kernel-module-vdu --enable - fi - cp -rf $VDU_MOD_BB_FILE $VERSAL_PROJECT_DIR/project-spec/meta-user/recipes-apps/kernel-module-vdu/ - - # Enable VDU firmware - VDU_FIRMWARE_BB_FILE=$APU_RECIPES_DIR/vdu-firmware.bb - if [ ! -d $VERSAL_PROJECT_DIR/project-spec/meta-user/recipes-apps/vdu-firmware ]; then - $PETA_BIN/petalinux-config --silentconfig - $PETA_BIN/petalinux-create -t apps --template install -n vdu-firmware --enable - fi - cp -rf $VDU_FIRMWARE_BB_FILE $VERSAL_PROJECT_DIR/project-spec/meta-user/recipes-apps/vdu-firmware/ - - # Enable VDU control software library - # This is not required as PS Kernels statically linking with control software, Enabling this to debug standalone control software - VDU_LIBRARY_BB_FILE=$APU_RECIPES_DIR/libvdu-ctrlsw.bb - if [ ! -d $VERSAL_PROJECT_DIR/project-spec/meta-user/recipes-apps/libvdu-ctrlsw ]; then - $PETA_BIN/petalinux-config --silentconfig - $PETA_BIN/petalinux-create -t apps --template install -n libvdu-ctrlsw --enable - fi - cp -rf $VDU_LIBRARY_BB_FILE $VERSAL_PROJECT_DIR/project-spec/meta-user/recipes-apps/libvdu-ctrlsw/ - echo "IMAGE_INSTALL:append = \" libvdu-ctrlsw kernel-module-vdu vdu-firmware\"" >> build/conf/local.conf echo "MACHINE_FEATURES = \"vdu\"" >> build/conf/local.conf - #sed -i '1iMACHINE = \" versal-ai-core-generic \"' build/conf/local.conf } @@ -384,7 +357,7 @@ if [[ $apu_package == 1 ]]; then if [[ $AARCH = $versal_dir ]]; then # configure the project with appropriate options config_versal_project . - enable_vdu . + enable_vdu_init . fi echo "[CMD]: petalinux-config -c kernel --silentconfig" diff --git a/build/petalinux.build b/build/petalinux.build index 22ed9a2f323..74041446792 100644 --- a/build/petalinux.build +++ b/build/petalinux.build @@ -1,3 +1,3 @@ # When updating Petalinux build please file a SH ticket to retain the build # https://jira.xilinx.com/secure/CreateIssue!default.jspa -PETALINUX="/proj/petalinux/2023.1/petalinux-v2023.1_03292225//tool/petalinux-v2023.1-final" +PETALINUX="/proj/petalinux/2023.1/petalinux-v2023.1_05012318/tool/petalinux-v2023.1-final" diff --git a/src/runtime_src/tools/scripts/apu_recipes/kernel-module-vdu.bb b/src/runtime_src/tools/scripts/apu_recipes/kernel-module-vdu.bb deleted file mode 100755 index e80a44c8a7b..00000000000 --- a/src/runtime_src/tools/scripts/apu_recipes/kernel-module-vdu.bb +++ /dev/null @@ -1,31 +0,0 @@ -SUMMARY = "Linux kernel module for Video Decode Unit" -DESCRIPTION = "Out-of-tree VDU decoder common kernel modules" -SECTION = "kernel/modules" -LICENSE = "GPLv2" -LIC_FILES_CHKSUM = "file://LICENSE.md;md5=eb723b61539feef013de476e68b5c50a" - -XILINX_VDU_VERSION = "1.0.0" -PV = "${XILINX_VDU_VERSION}-xilinx-${XILINX_RELEASE_VERSION}+git${SRCPV}" - -S = "${WORKDIR}/git" - -BRANCH ?= "master" -REPO ?= "git://gitenterprise.xilinx.com/xilinx-vcu/vdu-modules.git;protocol=https" -SRCREV ?= "974797e5eb83519df5690a5ff7d59b8630bbb281" - -BRANCHARG = "${@['nobranch=1', 'branch=${BRANCH}'][d.getVar('BRANCH', True) != '']}" -SRC_URI = "${REPO};${BRANCHARG}" - -inherit module features_check - -REQUIRED_MACHINE_FEATURES = "vdu" - -EXTRA_OEMAKE += "O=${STAGING_KERNEL_BUILDDIR}" - -RDEPENDS:${PN} = "vdu-firmware" - -COMPATIBLE_MACHINE = "^$" -COMPATIBLE_MACHINE:versal-ai-core = "versal-ai-core" -COMPATIBLE_MACHINE:versal-ai-edge = "versal-ai-edge" - -PACKAGE_ARCH = "${SOC_FAMILY_ARCH}" diff --git a/src/runtime_src/tools/scripts/apu_recipes/libvdu-ctrlsw.bb b/src/runtime_src/tools/scripts/apu_recipes/libvdu-ctrlsw.bb deleted file mode 100755 index 384865d33ea..00000000000 --- a/src/runtime_src/tools/scripts/apu_recipes/libvdu-ctrlsw.bb +++ /dev/null @@ -1,44 +0,0 @@ -SUMMARY = "Control Software for VDU" -DESCRIPTION = "Control software libraries, test applications and headers provider for VDU" -LICENSE = "MIT" -LIC_FILES_CHKSUM = "file://LICENSE.md;md5=c15ae83ba15c4ab3fa4eb2c22975258f" - -XILINX_VDU_VERSION = "1.0.0" -PV = "${XILINX_VDU_VERSION}-xilinx-${XILINX_RELEASE_VERSION}+git${SRCPV}" - -inherit autotools features_check - -REQUIRED_MACHINE_FEATURES = "vdu" - -BRANCH ?= "master" -REPO ?= "git://gitenterprise.xilinx.com/xilinx-vcu/vdu-ctrl-sw.git;protocol=https" -SRCREV ?= "89a186d39c77d3625ee43b722e9220639fa24bde" - -BRANCHARG = "${@['nobranch=1', 'branch=${BRANCH}'][d.getVar('BRANCH', True) != '']}" -SRC_URI = "${REPO};${BRANCHARG}" - -S = "${WORKDIR}/git" - -COMPATIBLE_MACHINE = "^$" -COMPATIBLE_MACHINE:versal-ai-core = "versal-ai-core" -COMPATIBLE_MACHINE:versal-ai-edge = "versal-ai-edge" - -PACKAGE_ARCH = "${SOC_FAMILY_ARCH}" - -RDEPENDS:${PN} = "kernel-module-vdu" - -do_compile[dirs] = "${S}" -do_install[dirs] = "${S}" - -EXTRA_OEMAKE = "CC='${CC}' CXX='${CXX} ${CXXFLAGS}'" -EXTRA_OEMAKE +=" INSTALL_HDR_PATH=${D}${includedir}/vdu-ctrl-sw/include INSTALL_PATH=${D}${bindir}" - -do_install:append() { - - oe_libinstall -C ${S}/bin/ -so liballegro_decode ${D}/${libdir}/ -} - -# These libraries shouldn't get installed in world builds unless something -# explicitly depends upon them. - -EXCLUDE_FROM_WORLD = "1" diff --git a/src/runtime_src/tools/scripts/apu_recipes/vdu-firmware.bb b/src/runtime_src/tools/scripts/apu_recipes/vdu-firmware.bb deleted file mode 100755 index 99235a14009..00000000000 --- a/src/runtime_src/tools/scripts/apu_recipes/vdu-firmware.bb +++ /dev/null @@ -1,42 +0,0 @@ -SUMMARY = "Firmware for VDU" -DESCRIPTION = "Firmware binaries provider for VDU" -LICENSE = "Proprietary" -LIC_FILES_CHKSUM = "file://LICENSE.md;md5=9a0e309e0fae4f23561b63b72f69e77f" - -XILINX_VDU_VERSION = "1.0.0" -PV = "${XILINX_VDU_VERSION}-xilinx-${XILINX_RELEASE_VERSION}+git${SRCPV}" - -S = "${WORKDIR}/git" - -inherit autotools features_check - -REQUIRED_MACHINE_FEATURES = "vdu" - -BRANCH ?= "master" -REPO ?= "git://gitenterprise.xilinx.com/xilinx-vcu/vdu-firmware.git;protocol=https" -SRCREV ?= "baf73ff6e31fec2aea457e401fc46504c4bdbe5e" - -BRANCHARG = "${@['nobranch=1', 'branch=${BRANCH}'][d.getVar('BRANCH', True) != '']}" -SRC_URI = "${REPO};${BRANCHARG}" - -COMPATIBLE_MACHINE = "^$" -COMPATIBLE_MACHINE:versal-ai-core = "versal-ai-core" -COMPATIBLE_MACHINE:versal-ai-edge = "versal-ai-edge" - -PACKAGE_ARCH = "${SOC_FAMILY_ARCH}" -EXTRA_OEMAKE +="INSTALL_PATH=${D}/lib/firmware" - -do_compile[noexec] = "1" -do_install[dirs] = "${S}" - -# Inhibit warnings about files being stripped -INHIBIT_PACKAGE_DEBUG_SPLIT = "1" -INHIBIT_PACKAGE_STRIP = "1" -FILES:${PN} = "/lib/firmware/*" - - -# These libraries shouldn't get installed in world builds unless something -# explicitly depends upon them. -EXCLUDE_FROM_WORLD = "1" - -INSANE_SKIP:${PN} = "ldflags" From c3e77d33f541fd28cf392a423c3f0b781e0a14bc Mon Sep 17 00:00:00 2001 From: mtakasi01 <133196374+mtakasi01@users.noreply.github.com> Date: Mon, 19 Jun 2023 12:35:54 +0530 Subject: [PATCH 3/4] Get Memory info from ZOCL using xgq for Built in ps kernel (#7564) (#7596) * Fixed xgq assignment issue for multislot Signed-off-by: Saif * Fixed allignment issues Signed-off-by: Saifuddin * Cleanup memory manager for built in ps kernel support Signed-off-by: Saifuddin * Get the ps kernel mem info from zocl through xgq * Fix issue to Get the ps kernel mem info from zocl through xgq Signed-off-by: Saifuddin * Not to fail the driver is PS kernel memory is not configured * Fixed review comments Signed-off-by: Saifuddin * Added memory management changes to this branch Signed-off-by: Saifuddin * Delete unused variable Signed-off-by: Saifuddin * Fixed one issue Signed-off-by: Saifuddin * Remove the multislot fix from PS memory fix branch Signed-off-by: Saifuddin --------- Signed-off-by: Saif Signed-off-by: Saifuddin Co-authored-by: Saif (cherry picked from commit 47b38eaaea13415ad45b519f40e4ff8c62671e26) Co-authored-by: Saifuddin Kaijar <54270703+saifuddin-xilinx@users.noreply.github.com> --- .../core/edge/drm/zocl/zocl_ctrl_ert.c | 30 +- src/runtime_src/core/include/xgq_cmd_common.h | 1 + src/runtime_src/core/include/xgq_cmd_ert.h | 35 +++ .../pcie/driver/linux/xocl/userpf/common.h | 1 + .../pcie/driver/linux/xocl/userpf/xocl_drm.c | 258 +++--------------- .../pcie/driver/linux/xocl/userpf/xocl_kds.c | 81 +++++- .../core/pcie/driver/linux/xocl/xocl_drm.h | 9 +- 7 files changed, 190 insertions(+), 225 deletions(-) diff --git a/src/runtime_src/core/edge/drm/zocl/zocl_ctrl_ert.c b/src/runtime_src/core/edge/drm/zocl/zocl_ctrl_ert.c index 0be25a04bca..dded40efa63 100644 --- a/src/runtime_src/core/edge/drm/zocl/zocl_ctrl_ert.c +++ b/src/runtime_src/core/edge/drm/zocl/zocl_ctrl_ert.c @@ -62,6 +62,7 @@ #define ERT_CQ_IRQ 0 #define ERT_CU_IRQ 1 +#define ZOCL_HOSTMEM_MASK 0xFFFFffff00000000LL /* * CQ format version 1.0: * First word on CQ is version number, followed by ctrl XGQ, which may go up to 1.5k. @@ -899,7 +900,6 @@ static void zert_cmd_uncfg_cu(struct zocl_ctrl_ert *zert, struct xgq_cmd_sq_hdr init_resp(resp, cmd->cid, rc); } - static void zert_cmd_query_cu(struct zocl_ctrl_ert *zert, struct xgq_cmd_sq_hdr *cmd, struct xgq_com_queue_entry *resp) { @@ -957,6 +957,33 @@ static void zert_cmd_query_cu(struct zocl_ctrl_ert *zert, struct xgq_cmd_sq_hdr } } +static void zert_cmd_query_mem(struct zocl_ctrl_ert *zert, struct xgq_cmd_sq_hdr *cmd, + struct xgq_com_queue_entry *resp) +{ + struct xgq_cmd_query_mem *c = (struct xgq_cmd_query_mem *)cmd; + struct xgq_cmd_resp_query_mem *r = (struct xgq_cmd_resp_query_mem *)resp; + struct drm_zocl_dev *zdev = zocl_get_zdev(); + + init_resp(resp, cmd->cid, 0); + + switch (c->type) { + case XGQ_CMD_QUERY_MEM_ADDR: + r->l_mem_info = (u32)zdev->host_mem; + r->h_mem_info = (u32)((zdev->host_mem & ZOCL_HOSTMEM_MASK) >> 32); + break; + + case XGQ_CMD_QUERY_MEM_SIZE: + r->l_mem_info = (u32)zdev->host_mem_len; + r->h_mem_info = (u32)((zdev->host_mem_len & ZOCL_HOSTMEM_MASK) >> 32); + break; + + default: + zert_err(zert, "Unknown query mem type: %d", c->type); + init_resp(resp, cmd->cid, -EINVAL); + break; + } +} + struct zert_ops { u32 op; char *name; @@ -967,6 +994,7 @@ struct zert_ops { { XGQ_CMD_OP_CFG_CU, "XGQ_CMD_OP_CFG_CU", zert_cmd_cfg_cu }, { XGQ_CMD_OP_UNCFG_CU, "XGQ_CMD_OP_UNCFG_CU", zert_cmd_uncfg_cu }, { XGQ_CMD_OP_QUERY_CU, "XGQ_CMD_OP_QUERY_CU", zert_cmd_query_cu }, + { XGQ_CMD_OP_QUERY_MEM, "XGQ_CMD_OP_QUERY_MEM", zert_cmd_query_mem }, { XGQ_CMD_OP_IDENTIFY, "XGQ_CMD_OP_IDENTIFY", zert_cmd_identify }, { XGQ_CMD_OP_TIMESET, "XGQ_CMD_OP_TIMESET", zert_cmd_timeset } }; diff --git a/src/runtime_src/core/include/xgq_cmd_common.h b/src/runtime_src/core/include/xgq_cmd_common.h index 129cd5286aa..709faa97507 100644 --- a/src/runtime_src/core/include/xgq_cmd_common.h +++ b/src/runtime_src/core/include/xgq_cmd_common.h @@ -112,6 +112,7 @@ enum xgq_cmd_opcode { XGQ_CMD_OP_DATA_INTEGRITY = 0x10e, XGQ_CMD_OP_EXIT = 0x10f, XGQ_CMD_OP_UNCFG_CU = 0x110, + XGQ_CMD_OP_QUERY_MEM = 0x111, /* Common command type */ XGQ_CMD_OP_BARRIER = 0x200, diff --git a/src/runtime_src/core/include/xgq_cmd_ert.h b/src/runtime_src/core/include/xgq_cmd_ert.h index fab9e94672f..218f4225a1b 100644 --- a/src/runtime_src/core/include/xgq_cmd_ert.h +++ b/src/runtime_src/core/include/xgq_cmd_ert.h @@ -281,6 +281,22 @@ struct xgq_cmd_query_cu { uint32_t rsvd2:8; }; +/** + * struct xgq_cmd_query_mem: query MEM command + */ +enum xgq_cmd_query_mem_type { + XGQ_CMD_QUERY_MEM_ADDR = 0x0, + XGQ_CMD_QUERY_MEM_SIZE = 0x1, +}; + +struct xgq_cmd_query_mem { + struct xgq_cmd_sq_hdr hdr; + + /* word 2 */ + uint32_t type:1; + uint32_t rsvd1:31; +}; + /** * struct xgq_cmd_resp_query_cu: query CU command response * @@ -316,6 +332,25 @@ struct xgq_cmd_resp_query_cu { uint32_t rcode; }; +/** + * struct xgq_cmd_resp_query_mem: query Memory command response + * + * @status: status of the MEM + * + * @mem_start_addr: Start address of the memory + * @mem_size: memory size + * + */ +struct xgq_cmd_resp_query_mem { + struct xgq_cmd_cq_hdr hdr; + + struct { + uint32_t l_mem_info; + uint32_t h_mem_info; + }; + uint32_t rcode; +}; + /** * struct xgq_cmd_resp_clock_calib: query clock counter response * diff --git a/src/runtime_src/core/pcie/driver/linux/xocl/userpf/common.h b/src/runtime_src/core/pcie/driver/linux/xocl/userpf/common.h index 3638eb0ad47..7080af89660 100644 --- a/src/runtime_src/core/pcie/driver/linux/xocl/userpf/common.h +++ b/src/runtime_src/core/pcie/driver/linux/xocl/userpf/common.h @@ -259,6 +259,7 @@ int xocl_kds_register_cus(struct xocl_dev *xdev, int slot_hd, xuid_t *uuid, struct ip_layout *ip_layout, struct ps_kernel_node *ps_kernel); int xocl_kds_unregister_cus(struct xocl_dev *xdev, int slot_hd); +int xocl_kds_xgq_query_mem(struct xocl_dev *xdev, struct mem_data *mem_data); int xocl_kds_set_cu_read_range(struct xocl_dev *xdev, u32 cu_idx, u32 start, u32 size); 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 1769fe66f44..4a5d643672c 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 @@ -629,13 +629,6 @@ void *xocl_drm_init(xdev_handle_t xdev_hdl) goto failed; } - drm_p->cma_bank_idx = -1; - /* Memory manager initialization is done in two phase. - * Phase 1 is done based on platform and Phase 2 is done - * based on XCLBIN. We have done phase 1 here. - */ - drm_p->xocl_drm_mm_done = true; - return drm_p; failed: @@ -698,6 +691,7 @@ static int xocl_mm_insert_node_range_all(struct xocl_drm *drm_p, uint32_t *mem_i struct mem_topology *grp_topology, struct drm_mm_node *dnode, u64 size) { struct mem_data *mem_data = NULL; + struct mem_data *ps_mem_data = &drm_p->ps_mem_data; struct xocl_mm *xocl_mm = drm_p->xocl_mm; uint64_t start_addr = 0; uint64_t end_addr = 0; @@ -713,9 +707,21 @@ static int xocl_mm_insert_node_range_all(struct xocl_drm *drm_p, uint32_t *mem_i XOCL_IS_PS_KERNEL_MEM(grp_topology, i)) continue; + if (ps_mem_data->m_used) { + /* Check whether PS memory falls on this Bank or not */ + if ((ps_mem_data->m_base_address >= mem_data->m_base_address) && + (ps_mem_data->m_size <= mem_data->m_size * 1024)) { + start_addr = ps_mem_data->m_base_address; + end_addr = start_addr + ps_mem_data->m_size * 1024; + } + else + continue; + } + else { + start_addr = mem_data->m_base_address; + end_addr = start_addr + mem_data->m_size * 1024; + } phy_bank_exists = true; - start_addr = mem_data->m_base_address; - 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, @@ -734,9 +740,9 @@ static int xocl_mm_insert_node_range_all(struct xocl_drm *drm_p, uint32_t *mem_i /* If no physical memory BANKs exists till now then * allocate memory from the base address of the memory manager. */ - if (!phy_bank_exists) { - start_addr = xocl_mm->start_addr; - end_addr = xocl_mm->end_addr; + if (!phy_bank_exists && ps_mem_data->m_used) { + start_addr = ps_mem_data->m_base_address; + end_addr = start_addr + ps_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, @@ -755,8 +761,8 @@ static int xocl_mm_insert_node_range_all(struct xocl_drm *drm_p, uint32_t *mem_i return ret; } -static int xocl_mm_insert_node_range(struct xocl_drm *drm_p, u32 mem_id, - struct mem_topology *grp_topology, struct drm_mm_node *node, u64 size) +static int xocl_mm_insert_node_range(struct xocl_drm *drm_p, + struct mem_data *mem_data, struct drm_mm_node *node, u64 size) { struct xocl_mm *xocl_mm = drm_p->xocl_mm; uint64_t start_addr = 0; @@ -764,8 +770,8 @@ static int xocl_mm_insert_node_range(struct xocl_drm *drm_p, u32 mem_id, int ret = 0; BUG_ON(!xocl_mm && !xocl_mm->mm); - start_addr = grp_topology->m_mem_data[mem_id].m_base_address; - end_addr = start_addr + grp_topology->m_mem_data[mem_id].m_size * 1024; + start_addr = mem_data->m_base_address; + 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, node, size, PAGE_SIZE, 0, @@ -803,8 +809,8 @@ int xocl_mm_insert_node(struct xocl_drm *drm_p, unsigned memidx, grp_topology, node, size); } else { - ret = xocl_mm_insert_node_range(drm_p, memidx, - grp_topology, node, size); + ret = xocl_mm_insert_node_range(drm_p, + &grp_topology->m_mem_data[memidx], node, size); } XOCL_PUT_GROUP_TOPOLOGY(drm_p->xdev, slotidx); @@ -938,14 +944,14 @@ int xocl_cleanup_mem_all(struct xocl_drm *drm_p) uint32_t slot_id = 0; mutex_lock(&drm_p->mm_lock); - - for (slot_id = 0; slot_id < MAX_SLOT_SUPPORT; slot_id++) { + + for (slot_id = 0; slot_id < MAX_SLOT_SUPPORT; slot_id++) { ret = xocl_cleanup_mem_nolock(drm_p, slot_id); if (ret) break; } - - mutex_unlock(&drm_p->mm_lock); + + mutex_unlock(&drm_p->mm_lock); return ret; } @@ -967,8 +973,7 @@ static int xocl_cleanup_drm_memory_manager(struct xocl_mm *xocl_mm) return 0; } -static int xocl_init_drm_mm(struct xocl_drm *drm_p, struct xocl_mm *xocl_mm, - uint64_t mm_start_addr, uint64_t mm_end_addr, uint32_t m_count) +static int xocl_init_drm_mm(struct xocl_drm *drm_p, struct xocl_mm *xocl_mm) { int err = 0; int i = 0; @@ -996,13 +1001,9 @@ static int xocl_init_drm_mm(struct xocl_drm *drm_p, struct xocl_mm *xocl_mm, goto error; } - drm_mm_init(xocl_mm->mm, mm_start_addr, (mm_end_addr - mm_start_addr)); - xocl_mm->start_addr = mm_start_addr; - xocl_mm->end_addr = mm_end_addr; - xocl_mm->m_count = m_count; - - xocl_info(drm_p->ddev->dev, "drm_mm_init called for the available memory range" - " <%llx - %llx>", mm_start_addr, mm_end_addr); + /* Initialize with max and min possible value */ + drm_mm_init(xocl_mm->mm, 0, U64_MAX); + xocl_info(drm_p->ddev->dev, "drm_mm_init called for the maximum memory range possible"); return 0; @@ -1013,21 +1014,9 @@ static int xocl_init_drm_mm(struct xocl_drm *drm_p, struct xocl_mm *xocl_mm, static int xocl_init_drm_memory_manager(struct xocl_drm *drm_p) { - struct xocl_dev *xdev = drm_p->xdev; struct xocl_mm *xocl_mm = NULL; - void *blob = NULL; - int offset = 0; - const u64 *prop; - uint64_t mem_start, mem_end; - const char *ipname; - uint64_t mm_start_addr = 0; - uint64_t mm_end_addr = 0; int err = 0; - blob = XDEV(xdev)->fdt_blob; - if (!blob) - return 0; - mutex_lock(&drm_p->mm_lock); xocl_mm = vzalloc(sizeof(struct xocl_mm)); if (!xocl_mm) { @@ -1035,47 +1024,19 @@ static int xocl_init_drm_memory_manager(struct xocl_drm *drm_p) return -ENOMEM; } - /* Initialize with max and min possible value */ - mm_start_addr = 0xffffFFFFffffFFFF; - mm_end_addr = 0; - - for (offset = fdt_next_node(blob, -1, NULL); - offset >= 0; - offset = fdt_next_node(blob, offset, NULL)) { - ipname = fdt_get_name(blob, offset, NULL); - if (ipname && strncmp(ipname, NODE_RESERVED_PSMEM, - strlen(NODE_RESERVED_PSMEM))) - continue; - - prop = fdt_getprop(blob, offset, PROP_IO_OFFSET, NULL); - if (!prop) - continue; - - mem_start = be64_to_cpu(prop[0]); - mem_end = mem_start + be64_to_cpu(prop[1]); - /* Update the start and end address for the memory manager */ - if (mem_start < mm_start_addr) - mm_start_addr = mem_start; - if (mem_end > mm_end_addr) - mm_end_addr = mem_end; - - ++xocl_mm->m_count; - } - - if (!xocl_mm->m_count) { - mutex_unlock(&drm_p->mm_lock); - vfree(xocl_mm); - return 0; - } - - err = xocl_init_drm_mm(drm_p, xocl_mm, mm_start_addr, mm_end_addr, - xocl_mm->m_count); + err = xocl_init_drm_mm(drm_p, xocl_mm); if (err) goto error; - + drm_p->xocl_mm = xocl_mm; + + err = xocl_p2p_mem_init(drm_p->xdev); + if (err && err != -ENODEV) + xocl_err(drm_p->ddev->dev, + "init p2p mem failed, err %d", err); + error: - if (err) + if (err && err != -ENODEV) xocl_cleanup_drm_memory_manager(xocl_mm); mutex_unlock(&drm_p->mm_lock); @@ -1107,126 +1068,6 @@ static int xocl_cleanup_memory_manager(struct xocl_drm *drm_p) return 0; } -static int xocl_init_memory_manager(struct xocl_drm *drm_p) -{ - struct mem_topology *topo = NULL; - struct mem_data *mem_data = NULL; - uint64_t mm_start_addr = 0; - uint64_t mm_end_addr = 0; - size_t ddr_bank_size = 0; - int err = 0; - int i = 0; - uint32_t legacy_slot_id = DEFAULT_PL_SLOT; - - mutex_lock(&drm_p->mm_lock); - err = XOCL_GET_MEM_TOPOLOGY(drm_p->xdev, topo, legacy_slot_id); - if (err) { - mutex_unlock(&drm_p->mm_lock); - return err; - } - - if (!topo) { - XOCL_PUT_MEM_TOPOLOGY(drm_p->xdev, legacy_slot_id); - mutex_unlock(&drm_p->mm_lock); - /* Before return check if drm memory manager is initialized already. - * This is done from platform metadata. - */ - if (drm_p->xocl_drm_mm_done) - return 0; - else - return -EINVAL; - } - - /* Initialize with max and min possible value */ - mm_start_addr = 0xffffFFFFffffFFFF; - mm_end_addr = 0; - - /* Initialize all the banks and their sizes */ - /* Currently only fixed sizes are supported */ - for (i = 0; i < topo->m_count; i++) { - mem_data = &topo->m_mem_data[i]; - ddr_bank_size = mem_data->m_size * 1024; - - if (!ddr_bank_size) - continue; - - if (XOCL_IS_STREAM(topo, i)) - continue; - - if (XOCL_IS_PS_KERNEL_MEM(topo, i)) - continue; - - if (!is_mem_region_valid(drm_p, mem_data)) - continue; - - /* Update the start and end address for the memory manager */ - if (mem_data->m_base_address < mm_start_addr) - mm_start_addr = mem_data->m_base_address; - if ((mem_data->m_base_address + ddr_bank_size) > mm_end_addr) - mm_end_addr = mem_data->m_base_address + ddr_bank_size; - } - - if (drm_p->xocl_mm) { - /* Validate the new memory topology with existing memory manager */ - if ((drm_p->xocl_mm->start_addr != mm_start_addr) || - (drm_p->xocl_mm->end_addr != mm_end_addr) || - (drm_p->xocl_mm->m_count != topo->m_count)) { - /* If there is some memory already in use then we can't - * reinitialize the memory manager. But if no memory is - * in use then we will be able to reintialize the memory - * manager again with updated topology. - */ - if(xocl_check_topology(drm_p)) - err = -EINVAL; - else - err = -EAGAIN; - - goto error; - } - else { - /* Memory manager initialization is done and consistent */ - XOCL_PUT_MEM_TOPOLOGY(drm_p->xdev, legacy_slot_id); - mutex_unlock(&drm_p->mm_lock); - return 0; - } - } - - if (!drm_p->xocl_mm) { - drm_p->xocl_mm = vzalloc(sizeof(struct xocl_mm)); - if (!drm_p->xocl_mm) { - err = -ENOMEM; - goto error; - } - - err = xocl_init_drm_mm(drm_p, drm_p->xocl_mm, mm_start_addr, mm_end_addr, - topo->m_count); - if (err) - goto error; - } - - XOCL_PUT_MEM_TOPOLOGY(drm_p->xdev, legacy_slot_id); - - err = xocl_p2p_mem_init(drm_p->xdev); - if (err && err != -ENODEV) { - xocl_err(drm_p->ddev->dev, - "init p2p mem failed, err %d", err); - goto error; - } - - mutex_unlock(&drm_p->mm_lock); - - return 0; - -error: - XOCL_PUT_MEM_TOPOLOGY(drm_p->xdev, legacy_slot_id); - if (err) - xocl_cleanup_memory_manager(drm_p); - - mutex_unlock(&drm_p->mm_lock); - - return err; -} - int xocl_init_mem(struct xocl_drm *drm_p, uint32_t slot_id) { size_t ddr_bank_size; @@ -1246,22 +1087,6 @@ int xocl_init_mem(struct xocl_drm *drm_p, uint32_t slot_id) reserved2 = 0x1000000; } - /* Initialize the memory manager */ - err = xocl_init_memory_manager(drm_p); - if (err) { - - /* If mem topology is not consistent then reintialize it - * again with the updated memory topology. - */ - if (err == -EAGAIN) - err = xocl_init_memory_manager(drm_p); - - if (err) { - xocl_xdev_err(drm_p->ddev->dev, "Memory Initialize failed 0x%x", err); - return err; - } - } - mutex_lock(&drm_p->mm_lock); drm_p->cma_bank_idx = -1; @@ -1341,6 +1166,7 @@ int xocl_init_mem(struct xocl_drm *drm_p, uint32_t slot_id) done: XOCL_PUT_GROUP_TOPOLOGY(drm_p->xdev, slot_id); + if (err) xocl_cleanup_mem_nolock(drm_p, slot_id); diff --git a/src/runtime_src/core/pcie/driver/linux/xocl/userpf/xocl_kds.c b/src/runtime_src/core/pcie/driver/linux/xocl/userpf/xocl_kds.c index 64cde84944a..4eb2a9e09c6 100644 --- a/src/runtime_src/core/pcie/driver/linux/xocl/userpf/xocl_kds.c +++ b/src/runtime_src/core/pcie/driver/linux/xocl/userpf/xocl_kds.c @@ -1941,6 +1941,11 @@ xocl_kds_xgq_cfg_cus(struct xocl_dev *xdev, xuid_t *xclbin_id, struct xrt_cu_inf if (cu_info[i].num_args) max_off_arg_size = cu_info[i].args[max_off_idx].size; cfg_cu->payload_size = max_off + max_off_arg_size + sizeof(struct xgq_cmd_sq_hdr); + if(cfg_cu->payload_size > MAX_CQ_SLOT_SIZE) { + userpf_err(xdev, "CU Argument Size %x > MAX_CQ_SLOT_SIZE!", cfg_cu->payload_size); + kfree(xcmd); + return -ENOMEM; + } /* * Times 2 to make sure XGQ slot size is bigger than the size of * key-value pair commands, eg. ERT_START_KEY_VAL. @@ -2143,6 +2148,75 @@ static int xocl_kds_xgq_query_cu(struct xocl_dev *xdev, u32 cu_idx, u32 cu_domai return 0; } +static int __xocl_kds_xgq_query_mem(struct xocl_dev *xdev, + enum xgq_cmd_query_mem_type type, + struct xgq_cmd_resp_query_mem *resp) +{ + struct xgq_cmd_query_mem *query_mem = NULL; + struct kds_sched *kds = &XDEV(xdev)->kds; + struct kds_client *client = NULL; + struct kds_command *xcmd = NULL; + int ret = 0; + + client = kds->anon_client; + xcmd = kds_alloc_command(client, sizeof(struct xgq_cmd_query_mem)); + if (!xcmd) + return -ENOMEM; + + query_mem = xcmd->info; + + query_mem->hdr.opcode = XGQ_CMD_OP_QUERY_MEM; + query_mem->hdr.count = sizeof(*query_mem) - sizeof(query_mem->hdr); + query_mem->hdr.state = 1; + query_mem->type = type; + + xcmd->cb.notify_host = xocl_kds_xgq_notify; + xcmd->cb.free = kds_free_command; + xcmd->priv = kds; + xcmd->type = KDS_ERT; + xcmd->opcode = OP_CONFIG; + xcmd->response = resp; + xcmd->response_size = sizeof(*resp); + + ret = kds_submit_cmd_and_wait(kds, xcmd); + if (ret) + return ret; + + if (resp->hdr.cstate != XGQ_CMD_STATE_COMPLETED) { + userpf_err(xdev, "Query MEM type %d failed cstate(%d) rcode(%d)", + type, resp->hdr.cstate, resp->rcode); + return -EINVAL; + } + + return 0; +} + +int xocl_kds_xgq_query_mem(struct xocl_dev *xdev, struct mem_data *mem_data) +{ + struct xgq_cmd_resp_query_mem resp; + int ret = 0; + + ret = __xocl_kds_xgq_query_mem(xdev, XGQ_CMD_QUERY_MEM_ADDR, &resp); + if (ret) + return ret; + + mem_data->m_base_address = (uint64_t) resp.h_mem_info << 32 | resp.l_mem_info; + + memset(&resp, 0, sizeof(struct xgq_cmd_resp_query_mem)); + ret = __xocl_kds_xgq_query_mem(xdev, XGQ_CMD_QUERY_MEM_SIZE, &resp); + if (ret) + return ret; + + mem_data->m_size = (uint64_t) resp.h_mem_info << 32 | resp.l_mem_info; + mem_data->m_used = true; + + userpf_info(xdev, "Query MEM completed\n"); + userpf_info(xdev, "Memory Start address %llx\n", mem_data->m_base_address); + userpf_info(xdev, "Memory size %llx\n", mem_data->m_size); + + return 0; +} + static int xocl_kds_update_xgq(struct xocl_dev *xdev, int slot_hdl, xuid_t *uuid, struct drm_xocl_kds cfg, struct ip_layout *ip_layout, @@ -2384,6 +2458,7 @@ int xocl_kds_unregister_cus(struct xocl_dev *xdev, int slot_hdl) int i = 0; struct xrt_cu *xcu = NULL; struct kds_cu_mgmt *cu_mgmt = NULL; + struct xgq_cmd_resp_query_cu resp = {}; XDEV(xdev)->kds.xgq_enable = false; ret = xocl_ert_ctrl_connect(xdev); @@ -2418,7 +2493,11 @@ int xocl_kds_unregister_cus(struct xocl_dev *xdev, int slot_hdl) ret = xocl_kds_xgq_uncfg_cu(xdev, 0, DOMAIN_PL, true); if (ret) goto out; - + + ret = xocl_kds_xgq_query_mem(xdev, &XOCL_DRM(xdev)->ps_mem_data); + if (ret) + userpf_info(xdev, "WARN ! Device doesn't configure for PS Kernel memory\n"); + xdev->reset_ert_cus = false; } } diff --git a/src/runtime_src/core/pcie/driver/linux/xocl/xocl_drm.h b/src/runtime_src/core/pcie/driver/linux/xocl/xocl_drm.h index 19a3c6892e8..f506e7aaa01 100644 --- a/src/runtime_src/core/pcie/driver/linux/xocl/xocl_drm.h +++ b/src/runtime_src/core/pcie/driver/linux/xocl/xocl_drm.h @@ -59,12 +59,8 @@ struct xocl_cma_bank { struct xocl_mm { /* Memory manager */ struct drm_mm *mm; - uint64_t start_addr; - uint64_t end_addr; - uint32_t m_count; - /* Array of bo stats - * for whole device memory manager */ + /* Array of bo stats for whole device memory manager */ struct drm_xocl_mm_stat *bo_usage_stat; }; @@ -84,12 +80,11 @@ struct xocl_drm { /* Memory manager */ struct xocl_mm *xocl_mm; - bool xocl_drm_mm_done; struct drm_xocl_mm_stat mm_usage_stat[MAX_MEM_BANK_COUNT]; /* Xocl driver memory list head */ struct list_head mem_list_head; - + struct mem_data ps_mem_data; int cma_bank_idx; }; From 211e224430d446345fc84d6cc8efd04d8911dc03 Mon Sep 17 00:00:00 2001 From: Jeff Lin Date: Mon, 19 Jun 2023 10:39:50 -0700 Subject: [PATCH 4/4] CR-1165917 Adding v70pq2 PCIe device ID to xocl driver (#7590) (#7595) * CR-1165917 Added v70pq2 PCIe device ID to xocl driver Signed-off-by: Jeff Lin * Add v70pq2 idcode for APU package creation Signed-off-by: Jeff Lin --------- Signed-off-by: Jeff Lin Co-authored-by: Jeff Lin (cherry picked from commit 1fe3b95ac7f636456c504666369e5a5cbc8af79a) --- build/build_edge.sh | 1 + src/runtime_src/core/pcie/driver/linux/xocl/devices.h | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/build/build_edge.sh b/build/build_edge.sh index a411d2ff5b0..c3bfc2f4542 100755 --- a/build/build_edge.sh +++ b/build/build_edge.sh @@ -376,6 +376,7 @@ if [[ $apu_package == 1 ]]; then export PATH=$PETALINUX/../../tool/petalinux-v$PETALINUX_VER-final/components/yocto/buildtools/sysroots/x86_64-petalinux-linux/usr/bin:$PATH $XRT_REPO_DIR/src/runtime_src/tools/scripts/pkgapu.sh -output $ORIGINAL_DIR/$PETALINUX_NAME/apu_packages -images $ORIGINAL_DIR/$PETALINUX_NAME/images/linux/ -idcode "0x14ca8093" -package-name xrt-apu-vck5000 $XRT_REPO_DIR/src/runtime_src/tools/scripts/pkgapu.sh -output $ORIGINAL_DIR/$PETALINUX_NAME/apu_packages -images $ORIGINAL_DIR/$PETALINUX_NAME/images/linux/ -idcode "0x04cd7093" -package-name xrt-apu + $XRT_REPO_DIR/src/runtime_src/tools/scripts/pkgapu.sh -output $ORIGINAL_DIR/$PETALINUX_NAME/apu_packages -images $ORIGINAL_DIR/$PETALINUX_NAME/images/linux/ -idcode "0x14cd7093" -package-name xrt-apu-v70pq2 # Generate archiver for petalinux project if [[ $archiver == 1 ]]; then diff --git a/src/runtime_src/core/pcie/driver/linux/xocl/devices.h b/src/runtime_src/core/pcie/driver/linux/xocl/devices.h index 624233fcdea..2e230d66980 100644 --- a/src/runtime_src/core/pcie/driver/linux/xocl/devices.h +++ b/src/runtime_src/core/pcie/driver/linux/xocl/devices.h @@ -3447,6 +3447,7 @@ struct xocl_subdev_map { { XOCL_PCI_DEVID(0x10EE, 0x5044, PCI_ANY_ID, MGMT_VERSAL) }, \ { XOCL_PCI_DEVID(0x10EE, 0x5048, PCI_ANY_ID, VERSAL_MGMT_RAPTOR2) }, \ { XOCL_PCI_DEVID(0x10EE, 0x5094, PCI_ANY_ID, V70_MGMT_RAPTOR2) }, \ + { XOCL_PCI_DEVID(0x10EE, 0x50B0, PCI_ANY_ID, V70_MGMT_RAPTOR2) }, \ { XOCL_PCI_DEVID(0x10EE, 0x6098, PCI_ANY_ID, VCK190_MGMT_RAPTOR2) }, \ { XOCL_PCI_DEVID(0x10EE, 0xE098, PCI_ANY_ID, XBB_MFG_VCK190) }, \ { XOCL_PCI_DEVID(0x10EE, 0x5078, PCI_ANY_ID, VERSAL_MGMT_RAPTOR2) }, \ @@ -3525,6 +3526,7 @@ struct xocl_subdev_map { { XOCL_PCI_DEVID(0x10EE, 0x5045, PCI_ANY_ID, USER_XDMA_VERSAL) },\ { XOCL_PCI_DEVID(0x10EE, 0x5049, PCI_ANY_ID, VERSAL_USER_RAPTOR2) }, \ { XOCL_PCI_DEVID(0x10EE, 0x5095, PCI_ANY_ID, V70_USER_RAPTOR2_ES3) }, \ + { XOCL_PCI_DEVID(0x10EE, 0x50B1, PCI_ANY_ID, V70_USER_RAPTOR2_ES3) }, \ { XOCL_PCI_DEVID(0x10EE, 0x6099, PCI_ANY_ID, VCK190_USER_RAPTOR2) }, \ { XOCL_PCI_DEVID(0x10EE, 0x5079, PCI_ANY_ID, VERSAL_USER_RAPTOR2) }, \ { XOCL_PCI_DEVID(0x10EE, 0x5099, PCI_ANY_ID, AVALON_USER_RAPTOR2) } @@ -3608,6 +3610,14 @@ struct xocl_subdev_map { .vbnv = "xilinx_v70", \ .priv_data = &XOCL_BOARD_V70_USER_RAPTOR2_ES3, \ .type = XOCL_DSAMAP_RAPTOR2 }, \ + { 0x10EE, 0x50B0, PCI_ANY_ID, \ + .vbnv = "xilinx_v70pq2", \ + .priv_data = &XOCL_BOARD_V70_MGMT_RAPTOR2, \ + .type = XOCL_DSAMAP_RAPTOR2 }, \ + { 0x10EE, 0x50B1, PCI_ANY_ID, \ + .vbnv = "xilinx_v70pq2", \ + .priv_data = &XOCL_BOARD_V70_USER_RAPTOR2_ES3, \ + .type = XOCL_DSAMAP_RAPTOR2 }, \ { 0x10EE, 0x6098, PCI_ANY_ID, \ .vbnv = "xilinx_vck190", \ .priv_data = &XOCL_BOARD_VCK190_MGMT_RAPTOR2, \