From 4042c062618947babb9dd5e45b33aac9dc2c8804 Mon Sep 17 00:00:00 2001 From: Rahul Bramandlapalli <54270708+rbramand-xilinx@users.noreply.github.com> Date: Wed, 18 Dec 2024 02:16:55 +0530 Subject: [PATCH] Fix bug in patching args in multiple runs (#8660) * Fix bug in patching args multiple times Signed-off-by: rbramand * Address comments on PR Signed-off-by: rbramand --------- Signed-off-by: rbramand Co-authored-by: rbramand --- .../core/common/api/xrt_module.cpp | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/runtime_src/core/common/api/xrt_module.cpp b/src/runtime_src/core/common/api/xrt_module.cpp index 98c73f0be5e..bcd8096e475 100644 --- a/src/runtime_src/core/common/api/xrt_module.cpp +++ b/src/runtime_src/core/common/api/xrt_module.cpp @@ -48,6 +48,10 @@ static constexpr size_t column_page_size = AIE_COLUMN_PAGE_SIZE; static constexpr uint8_t Elf_Amd_Aie2p = 69; static constexpr uint8_t Elf_Amd_Aie2ps = 64; +// In aie2p max bd data words is 8 and in aie4/aie2ps its 9 +// using max bd words as 9 to cover all cases +static constexpr size_t max_bd_words = 9; + static const char* Scratch_Pad_Mem_Symbol = "scratch-pad-mem"; static const char* Control_Packet_Symbol = "control-packet"; static const char* Control_Code_Symbol = "control-code"; @@ -141,6 +145,8 @@ struct patcher uint64_t offset_to_patch_buffer; uint32_t offset_to_base_bo_addr; uint32_t mask; // This field is valid only when patching scheme is scalar_32bit_kind + bool dirty = false; // Tells whether this entry is already patched or not + uint32_t bd_data_ptrs[max_bd_words]; // array to store bd ptrs original values }; std::vector m_ctrlcode_patchinfo; @@ -166,9 +172,10 @@ struct patcher , m_ctrlcode_patchinfo(std::move(ctrlcode_offset)) {} -// Replace certain bits of *data_to_patch with register_value. Which bits to be replaced is specified by mask -// For *data_to_patch be 0xbb11aaaa and mask be 0x00ff0000 -// To make *data_to_patch be 0xbb55aaaa, register_value must be 0x00550000 + // Replace certain bits of *data_to_patch with register_value. Which bits to be replaced is specified by mask + // For *data_to_patch be 0xbb11aaaa and mask be 0x00ff0000 + // To make *data_to_patch be 0xbb55aaaa, register_value must be 0x00550000 + void patch32(uint32_t* data_to_patch, uint64_t register_value, uint32_t mask) const { @@ -253,8 +260,18 @@ struct patcher void patch_it(uint8_t* base, uint64_t new_value) { - for (auto item : m_ctrlcode_patchinfo) { + for (auto& item : m_ctrlcode_patchinfo) { auto bd_data_ptr = reinterpret_cast(base + item.offset_to_patch_buffer); + if (!item.dirty) { + // first time patching cache bd ptr values using bd ptrs array in patch info + std::copy(bd_data_ptr, bd_data_ptr + max_bd_words, item.bd_data_ptrs); + item.dirty = true; + } + else { + // not the first time patching, restore bd ptr values from patch info bd ptrs array + std::copy(item.bd_data_ptrs, item.bd_data_ptrs + max_bd_words, bd_data_ptr); + } + switch (m_symbol_type) { case symbol_type::scalar_32bit_kind: // new_value is a register value