Skip to content

Commit

Permalink
Fix bug in patching args in multiple runs (#8660)
Browse files Browse the repository at this point in the history
* Fix bug in patching args multiple times

Signed-off-by: rbramand <[email protected]>

* Address comments on PR

Signed-off-by: rbramand <[email protected]>

---------

Signed-off-by: rbramand <[email protected]>
Co-authored-by: rbramand <[email protected]>
  • Loading branch information
rbramand-xilinx and rbramand authored Dec 17, 2024
1 parent 0492ce9 commit 4042c06
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/runtime_src/core/common/api/xrt_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<patch_info> m_ctrlcode_patchinfo;
Expand All @@ -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
{
Expand Down Expand Up @@ -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<uint32_t*>(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
Expand Down

0 comments on commit 4042c06

Please sign in to comment.