Skip to content

Commit 2ccac09

Browse files
committed
Skip csr version check when cra_ring_root doesn't exist
Parse the new field from the auto-discovery string. Skip csr version check if cra_ring_root doesn't exit. Update the forward-compatibility auto-discovery string test. Note:previous test had an issue: The number of fields per device global is fixed (here to 1), not variable. I had to update that as well.
1 parent aec4d87 commit 2ccac09

File tree

6 files changed

+50
-8
lines changed

6 files changed

+50
-8
lines changed

include/acl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,8 @@ typedef struct acl_device_def_autodiscovery_t {
526526
// Device global definition.
527527
std::unordered_map<std::string, acl_device_global_mem_def_t>
528528
device_global_mem_defs;
529+
// Zibai
530+
bool cra_ring_root_exist = true; // Set the default value to true for backwards compatibility flows.
529531
} acl_device_def_autodiscovery_t;
530532

531533
typedef struct acl_device_def_t {

include/acl_kernel_if.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ int acl_kernel_if_init(acl_kernel_if *kern, acl_bsp_io bsp_io,
6969
int acl_kernel_if_update(const acl_device_def_autodiscovery_t &devdef,
7070
acl_kernel_if *kern);
7171
int acl_kernel_if_is_valid(acl_kernel_if *kern);
72-
int acl_kernel_if_post_pll_config_init(acl_kernel_if *kern);
72+
int acl_kernel_if_post_pll_config_init(const acl_device_def_autodiscovery_t &devdef, acl_kernel_if *kern);
7373

7474
void acl_kernel_if_register_callbacks(
7575
acl_kernel_update_callback kernel_update,

src/acl_auto_configure.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,26 @@ static bool read_uint_counters(const std::string &str,
9999
return true;
100100
}
101101

102+
// Reads the next word in str and converts it into a boolean.
103+
// Returns true if a valid integer was read or false if an error occurred.
104+
// pos is updated to the position immediately following the parsed word
105+
// even if an error occurs.
106+
static bool read_bool_counters(const std::string &str,
107+
std::string::size_type &pos, bool &val,
108+
std::vector<int> &counters) noexcept {
109+
std::string result;
110+
pos = read_word(str, pos, result);
111+
decrement_section_counters(counters);
112+
try {
113+
std::cout << "zibai what's the result" << result << "\n";
114+
val = static_cast<bool>(std::stoi(result));
115+
} catch (const std::exception &e) {
116+
UNREFERENCED_PARAMETER(e);
117+
return false;
118+
}
119+
return true;
120+
}
121+
102122
// Reads the next word in str and converts it into an unsigned.
103123
// Returns true if a valid integer was read or false if an error occurred.
104124
// pos is updated to the position immediately following the parsed word
@@ -1052,6 +1072,12 @@ bool acl_load_device_def_from_str(const std::string &config_str,
10521072
config_str, curr_pos, devdef.device_global_mem_defs, counters, err_str);
10531073
}
10541074

1075+
// Check whether csr_ring_root exist in the IP.
1076+
if (result && counters.back() > 0) {
1077+
result = read_bool_counters(config_str, curr_pos, devdef.cra_ring_root_exist,
1078+
counters);
1079+
}
1080+
10551081
// forward compatibility: bypassing remaining fields at the end of device
10561082
// description section
10571083
while (result && counters.size() > 0 &&

src/acl_hal_mmd.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,7 @@ static int l_try_device(unsigned int physical_device_id, const char *name,
11131113

11141114
// Post-PLL config init function - at this point, it's safe to talk to the
11151115
// kernel CSR registers.
1116-
if (acl_kernel_if_post_pll_config_init(&kern[physical_device_id]))
1116+
if (acl_kernel_if_post_pll_config_init(sys->device[physical_device_id].autodiscovery_def, &kern[physical_device_id]))
11171117
return 0;
11181118

11191119
return 1;
@@ -2150,7 +2150,8 @@ int acl_hal_mmd_program_device(unsigned int physical_device_id,
21502150
}
21512151
// Post-PLL config init function - at this point, it's safe to talk to the
21522152
// kernel CSR registers.
2153-
if (acl_kernel_if_post_pll_config_init(&kern[physical_device_id]))
2153+
// Zibai, pass devdef->autodiscovery_def into it.
2154+
if (acl_kernel_if_post_pll_config_init(devdef->autodiscovery_def, &kern[physical_device_id]))
21542155
return -1;
21552156

21562157
return 0;

src/acl_kernel_if.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ acl_process_autorun_profiler_scan_chain(unsigned int physical_device_id,
4646
#define CSR_VERSION_ID_18_1 (3)
4747
#define CSR_VERSION_ID_19_1 (4)
4848
#define CSR_VERSION_ID CSR_VERSION_ID_19_1
49+
// Starting from 2023.1 release, some IPs don't have the cra_ring_root for the Runtime to check the version. E.g, pure streaming design.
50+
#define NO_CSR_VERSION_ID (-1)
4951

5052
// Address map
5153
// For unit tests to work, these defines must match those in the unit test
@@ -471,6 +473,7 @@ static uintptr_t acl_kernel_cra_set_segment_rom(acl_kernel_if *kern,
471473

472474
static int acl_kernel_cra_read(acl_kernel_if *kern, unsigned int accel_id,
473475
unsigned int addr, unsigned int *val) {
476+
assert(kern->csr_version != NO_CSR_VERSION_ID);
474477
uintptr_t segment_offset = acl_kernel_cra_set_segment(kern, accel_id, addr);
475478
acl_assert_locked_or_sig();
476479
return acl_kernel_if_read_32b(
@@ -479,6 +482,7 @@ static int acl_kernel_cra_read(acl_kernel_if *kern, unsigned int accel_id,
479482

480483
int acl_kernel_cra_read_64b(acl_kernel_if *kern, unsigned int accel_id,
481484
unsigned int addr, uint64_t *val) {
485+
assert(kern->csr_version != NO_CSR_VERSION_ID);
482486
uintptr_t segment_offset = acl_kernel_cra_set_segment(kern, accel_id, addr);
483487
acl_assert_locked_or_sig();
484488
return acl_kernel_if_read_64b(
@@ -530,6 +534,7 @@ static int acl_kernel_rom_cra_read_block(acl_kernel_if *kern, unsigned int addr,
530534

531535
static int acl_kernel_cra_write(acl_kernel_if *kern, unsigned int accel_id,
532536
unsigned int addr, unsigned int val) {
537+
assert(kern->csr_version != NO_CSR_VERSION_ID);
533538
uintptr_t segment_offset = acl_kernel_cra_set_segment(kern, accel_id, addr);
534539
acl_assert_locked_or_sig();
535540
return acl_kernel_if_write_32b(
@@ -538,6 +543,7 @@ static int acl_kernel_cra_write(acl_kernel_if *kern, unsigned int accel_id,
538543

539544
static int acl_kernel_cra_write_64b(acl_kernel_if *kern, unsigned int accel_id,
540545
unsigned int addr, uint64_t val) {
546+
assert(kern->csr_version != NO_CSR_VERSION_ID);
541547
uintptr_t segment_offset = acl_kernel_cra_set_segment(kern, accel_id, addr);
542548
acl_assert_locked();
543549
return acl_kernel_if_write_64b(
@@ -547,6 +553,7 @@ static int acl_kernel_cra_write_64b(acl_kernel_if *kern, unsigned int accel_id,
547553
static int acl_kernel_cra_write_block(acl_kernel_if *kern,
548554
unsigned int accel_id, unsigned int addr,
549555
unsigned int *val, size_t size) {
556+
assert(kern->csr_version != NO_CSR_VERSION_ID);
550557
uintptr_t segment_offset = acl_kernel_cra_set_segment(kern, accel_id, addr);
551558
uintptr_t logical_addr =
552559
kern->accel_csr[accel_id].address + addr - OFFSET_KERNEL_CRA;
@@ -1017,7 +1024,7 @@ int acl_kernel_if_update(const acl_device_def_autodiscovery_t &devdef,
10171024
// Post-PLL config init function - at this point it's safe to talk to
10181025
// the kernel CSR registers.
10191026
// Returns 0 on success
1020-
int acl_kernel_if_post_pll_config_init(acl_kernel_if *kern) {
1027+
int acl_kernel_if_post_pll_config_init(const acl_device_def_autodiscovery_t &devdef, acl_kernel_if *kern) {
10211028
unsigned int csr, version;
10221029
unsigned k;
10231030
char *profile_start_cycle = getenv("ACL_PROFILE_START_CYCLE");
@@ -1032,14 +1039,19 @@ int acl_kernel_if_post_pll_config_init(acl_kernel_if *kern) {
10321039
kern->io.printf("HAL Kern Error: Post PLL init: Invalid kernel handle");
10331040
assert(0 && "Invalid kernel handle");
10341041
}
1035-
if (kern->num_accel > 0) {
1042+
if (kern->num_accel > 0 && devdef.cra_ring_root_exist) {
10361043
acl_kernel_cra_read(kern, 0, KERNEL_OFFSET_CSR, &csr);
10371044
version = ACL_KERNEL_READ_BIT_RANGE(csr, KERNEL_CSR_LAST_VERSION_BIT,
10381045
KERNEL_CSR_FIRST_VERSION_BIT);
10391046
kern->csr_version = version;
10401047
ACL_KERNEL_IF_DEBUG_MSG(kern,
10411048
"Read CSR version from kernel 0: Version = %u\n",
10421049
kern->csr_version);
1050+
} else if (kern->num_accel > 0 && !devdef.cra_ring_root_exist) {
1051+
kern->csr_version = NO_CSR_VERSION_ID;
1052+
ACL_KERNEL_IF_DEBUG_MSG(kern,
1053+
"CRA ring root doesn't exist, setting kern->csr_version to %u\n",
1054+
kern->csr_version);
10431055
} else {
10441056
kern->csr_version = 0;
10451057
}
@@ -1149,7 +1161,7 @@ void acl_kernel_if_launch_kernel_on_custom_sof(
11491161
// in the kern->csr_version field. The value is cached after PLL init to
11501162
// avoid reading back on every kernel launch, which would add overhead.
11511163
if (!(kern->csr_version >= CSR_VERSION_ID_18_1 &&
1152-
kern->csr_version <= CSR_VERSION_ID)) {
1164+
kern->csr_version <= CSR_VERSION_ID) && !(kern->csr_version == NO_CSR_VERSION_ID)) {
11531165
kern->io.printf("Hardware CSR version ID differs from version expected by "
11541166
"software. Either:\n");
11551167
kern->io.printf(" a) Ensure your compiled design was generated by the "
@@ -1256,6 +1268,7 @@ void acl_kernel_if_launch_kernel_on_custom_sof(
12561268
acl_kernel_cra_write_block(kern, accel_id, offset, (unsigned int *)image_p,
12571269
image_size_static);
12581270
}
1271+
12591272
if (kern->csr_version != CSR_VERSION_ID_18_1 && image->arg_value_size > 0) {
12601273
acl_kernel_cra_write_block(
12611274
kern, accel_id, offset + (unsigned int)image_size_static,

test/acl_auto_configure_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,11 +482,11 @@ TEST(auto_configure, many_ok_forward_compatibility) {
482482
// sections and subsections to check forward compatibility
483483

484484
std::string str(VERSIONIDTOSTR(
485-
ACL_AUTO_CONFIGURE_VERSIONID) " 28 "
485+
ACL_AUTO_CONFIGURE_VERSIONID) " 29 "
486486
"sample40byterandomhash000000000000000000 "
487487
"a10gx 0 1 15 DDR 2 1 6 0 2147483648 100 "
488488
"100 100 100 200 200 200 200 0 0 0 0 2 "
489-
"1 name1 1 name2 47 "
489+
"1 name1 name2 0 0 47 "
490490
"40 external_sort_stage_0 0 128 1 0 0 1 0 "
491491
"1 0 1 10 0 0 4 1 0 0 0 500 500 500 0 0 "
492492
"0 0 1 1 1 3 1 1 1 3 1 0 0 800 800 800 "

0 commit comments

Comments
 (0)