Skip to content

Commit

Permalink
Modified strcture data element from fixed size to flexible array. (#8669
Browse files Browse the repository at this point in the history
)

Signed-off-by: Manoj Takasi <mtakasi@amd.com>
Co-authored-by: Manoj Takasi <mtakasi@amd.com>
  • Loading branch information
ManojTakasi and Manoj Takasi authored Dec 24, 2024
1 parent 1b54c8a commit 7f72660
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/runtime_src/core/common/drv/cu_hls.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ static void cu_hls_xgq_start(struct xrt_cu_hls *cu_hls, u32 *data)
u32 i = 0;

num_reg = (cmd->hdr.count - (sizeof(struct xgq_cmd_start_cuidx)
- sizeof(cmd->hdr) - sizeof(cmd->data)))/sizeof(u32);
- sizeof(cmd->hdr)))/sizeof(u32);
for (i = 0; i < num_reg; ++i) {
cu_write32(cu_hls, ARGS + i * 4, cmd->data[i]);
}
Expand All @@ -123,7 +123,7 @@ static void cu_hls_xgq_start_kv(struct xrt_cu_hls *cu_hls, u32 *data)
u32 i = 0;

num_reg = (cmd->hdr.count - (sizeof(struct xgq_cmd_start_cuidx_kv)
- sizeof(cmd->hdr) - sizeof(cmd->data)))/sizeof(u32);
- sizeof(cmd->hdr)))/sizeof(u32);
/* data is a {offset : value} pairs list
* cmd->data[i] -> offset
* cmd->data[i+1] -> value
Expand Down
2 changes: 1 addition & 1 deletion src/runtime_src/core/edge/drm/zocl/include/zocl_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
({ \
size_t ret; \
size_t data_size; \
data_size = sect->m_count * sizeof(typeof(sect->data)); \
data_size = sect->m_count * sizeof(*(sect->data)); \
ret = (sect) ? offsetof(typeof(*sect), data) + data_size : 0; \
(ret); \
})
Expand Down
2 changes: 1 addition & 1 deletion src/runtime_src/core/edge/drm/zocl/zert/cu_scu.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ static void scu_xgq_start(struct xrt_cu_scu *scu, u32 *data)
u32 *cu_regfile = scu->vaddr;

scu->num_reg = (cmd->hdr.count - (sizeof(struct xgq_cmd_start_cuidx)
- sizeof(cmd->hdr) - sizeof(cmd->data)))/sizeof(u32);
- sizeof(cmd->hdr)))/sizeof(u32);
for (i = 0; i < scu->num_reg; ++i) {
cu_regfile[i+1] = cmd->data[i];
}
Expand Down
4 changes: 4 additions & 0 deletions src/runtime_src/core/include/xgq_cmd_ert.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@
*/
struct xgq_cmd_start_cuidx {
struct xgq_cmd_sq_hdr hdr;
#if defined(__linux__) && defined(__KERNEL__)
uint32_t data[]; // NOLINT
#else
uint32_t data[1]; // NOLINT
#endif
};

/**
Expand Down
19 changes: 17 additions & 2 deletions src/runtime_src/core/include/xrt/detail/ert.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ struct ert_packet {
};
uint32_t header;
};
#if defined(__linux__) && defined(__KERNEL__)
uint32_t data[]; /* count number of words */
#else
uint32_t data[1]; /* count number of words */
#endif
};

/**
Expand Down Expand Up @@ -144,10 +148,13 @@ struct ert_start_kernel_cmd {
};
uint32_t header;
};

/* payload */
uint32_t cu_mask; /* mandatory cu mask */
uint32_t data[1]; /* count-1 number of words */
#if defined(__linux__) && defined(__KERNEL__)
uint32_t data[]; /* flexible array member*/
#else
uint32_t data[1]; /* count -1 number of words */
#endif
};

/**
Expand Down Expand Up @@ -327,7 +334,11 @@ struct ert_init_kernel_cmd {

/* payload */
uint32_t cu_mask; /* mandatory cu mask */
#if defined(__linux__) && defined(__KERNEL__)
uint32_t data[]; /* Flexible array member */
#else
uint32_t data[1]; /* count-9 number of words */
#endif
};

#define KDMA_BLOCK_SIZE 64 /* Limited by KDMA CU */
Expand Down Expand Up @@ -411,7 +422,11 @@ struct ert_configure_cmd {
uint32_t dsa52:1;

/* cu address map size is num_cus */
#if defined(__linux__) && defined(__KERNEL__)
uint32_t data[]; /* Flexible array member */
#else
uint32_t data[1];
#endif
};

/*
Expand Down
25 changes: 18 additions & 7 deletions src/runtime_src/core/include/xrt/detail/xclbin.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,12 @@ extern "C" {
unsigned char m_keyBlock[256]; /* Signature for validation of binary */
uint64_t m_uniqueId; /* axlf's uniqueId, use it to skip redownload etc */
struct axlf_header m_header; /* Inline header */
struct axlf_section_header m_sections[1]; /* One or more section headers follow */
#if defined(__linux__) && defined(__KERNEL__)
struct axlf_section_header m_sections[]; // One or more section headers follow. Flexible array size suitable for kernel space.
#else
struct axlf_section_header m_sections[1]; /* One or more section headers follow */
#endif
};
XCLBIN_STATIC_ASSERT(sizeof(struct axlf) == 496, "axlf structure no longer is 496 bytes in size");

typedef struct axlf xclBin;

Expand Down Expand Up @@ -296,10 +299,12 @@ extern "C" {

struct mem_topology {
int32_t m_count; //Number of mem_data
#if defined(__linux__) && defined(__KERNEL__)
struct mem_data m_mem_data[]; //Should be sorted on mem_type. Flexible array size suitable for kernel space. Flexible array size suitable for kernel space.
#else
struct mem_data m_mem_data[1]; //Should be sorted on mem_type
#endif
};
XCLBIN_STATIC_ASSERT(sizeof(struct mem_topology) == 48, "mem_topology structure no longer is 48 bytes in size");


/**** CONNECTIVITY SECTION ****/
/* Connectivity of each argument of Kernel. It will be in terms of argument
Expand Down Expand Up @@ -389,9 +394,12 @@ extern "C" {

struct ip_layout {
int32_t m_count;
#if defined(__linux__) && defined(__KERNEL__)
struct ip_data m_ip_data[]; //All the ip_data needs to be sorted by m_base_address. Flexible array size suitable for kernel space.
#else
struct ip_data m_ip_data[1]; //All the ip_data needs to be sorted by m_base_address.
#endif
};
XCLBIN_STATIC_ASSERT(sizeof(struct ip_layout) == 88, "ip_layout structure no longer is 88 bytes in size");

/*** Debug IP section layout ****/
enum DEBUG_IP_TYPE {
Expand Down Expand Up @@ -450,9 +458,12 @@ extern "C" {

struct clock_freq_topology { /* Clock frequency section */
int16_t m_count; /* Number of entries */
struct clock_freq m_clock_freq[1]; /* Clock array */
#if defined(__linux__) && defined(__KERNEL__)
struct clock_freq m_clock_freq[]; // Clock array. Flexible array size suitable for kernel space.
#else
struct clock_freq m_clock_freq[1]; /* Clock array */
#endif
};
XCLBIN_STATIC_ASSERT(sizeof(struct clock_freq_topology) == 138, "clock_freq_topology structure no longer is 138 bytes in size");

enum MCS_TYPE { /* Supported MCS file types */
MCS_UNKNOWN = 0, /* Initialized value */
Expand Down
2 changes: 1 addition & 1 deletion src/runtime_src/core/pcie/driver/linux/xocl/xocl_drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ static inline void xocl_memcpy_toio(void *iomem, void *buf, u32 size)
({ \
size_t ret; \
size_t data_size; \
data_size = (sect) ? sect->m_count * sizeof(typeof(sect->data)) : 0; \
data_size = (sect) ? (sect->m_count * sizeof(*(sect->data))) : 0; \
ret = (sect) ? offsetof(typeof(*sect), data) + data_size : 0; \
(ret); \
})
Expand Down

0 comments on commit 7f72660

Please sign in to comment.