Skip to content

Commit 377a24e

Browse files
committed
Add direct write for new start bit register
Enbaled backwards compatibility with the new CSR change
1 parent 334bdb7 commit 377a24e

File tree

2 files changed

+54
-22
lines changed

2 files changed

+54
-22
lines changed

include/acl_kernel_if.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ typedef struct {
6060

6161
// Track debug printf activity
6262
time_ns last_printf_dump = 0;
63+
64+
// CRA address offset for backwards compatibility
65+
unsigned int cra_address_offset = 8;
6366
} acl_kernel_if;
6467

6568
// *********************** Public functions **************************

src/acl_kernel_if.cpp

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ acl_process_autorun_profiler_scan_chain(unsigned int physical_device_id,
4545
// address map.
4646
#define CSR_VERSION_ID_18_1 (3)
4747
#define CSR_VERSION_ID_19_1 (4)
48-
#define CSR_VERSION_ID CSR_VERSION_ID_19_1
48+
#define CSR_VERSION_ID_23_1 (5)
49+
#define CSR_VERSION_ID CSR_VERSION_ID_23_1
4950

5051
// Address map
5152
// For unit tests to work, these defines must match those in the unit test
@@ -66,6 +67,8 @@ acl_process_autorun_profiler_scan_chain(unsigned int physical_device_id,
6667
#define KERNEL_ROM_SIZE_BYTES 8
6768

6869
// Byte offsets into the CRA:
70+
// For CSR version 5+ byte offsets are pushed back with the proper value except
71+
// for the CSR later on in the runtime execution
6972
#define KERNEL_OFFSET_CSR 0
7073
#define KERNEL_OFFSET_PRINTF_BUFFER_SIZE 0x4
7174
#define KERNEL_OFFSET_CSR_PROFILE_CTRL 0xC
@@ -75,11 +78,14 @@ acl_process_autorun_profiler_scan_chain(unsigned int physical_device_id,
7578
#define KERNEL_OFFSET_FINISH_COUNTER 0x28
7679
#define KERNEL_OFFSET_INVOCATION_IMAGE 0x30
7780

81+
// CSR version 5+ byte offsets
82+
#define KERNEL_OFFSET_START_REG 0x8
83+
7884
// Backwards compatibility with CSR_VERSION_ID 3
7985
#define KERNEL_OFFSET_INVOCATION_IMAGE_181 0x28
8086

8187
// Bit positions
82-
#define KERNEL_CSR_GO 0
88+
#define KERNEL_CSR_START 0
8389
#define KERNEL_CSR_DONE 1
8490
#define KERNEL_CSR_STALLED 3
8591
#define KERNEL_CSR_UNSTALL 4
@@ -593,8 +599,9 @@ static int acl_kernel_if_issue_profile_hw_command(acl_kernel_if *kern,
593599
int status;
594600
acl_assert_locked_or_sig();
595601
assert(acl_kernel_if_is_valid(kern));
596-
status = acl_kernel_cra_read(kern, accel_id, KERNEL_OFFSET_CSR_PROFILE_CTRL,
597-
&profile_ctrl_val);
602+
status = acl_kernel_cra_read(
603+
kern, accel_id, KERNEL_OFFSET_CSR_PROFILE_CTRL + kern->cra_address_offset,
604+
&profile_ctrl_val);
598605
if (status)
599606
return status;
600607
ACL_KERNEL_IF_DEBUG_MSG(
@@ -609,8 +616,9 @@ static int acl_kernel_if_issue_profile_hw_command(acl_kernel_if *kern,
609616
ACL_KERNEL_IF_DEBUG_MSG(
610617
kern, ":: Issue profile HW command:: Accelerator %d new csr is %x.\n",
611618
accel_id, profile_ctrl_val);
612-
status = acl_kernel_cra_write(kern, accel_id, KERNEL_OFFSET_CSR_PROFILE_CTRL,
613-
profile_ctrl_val);
619+
status = acl_kernel_cra_write(
620+
kern, accel_id, KERNEL_OFFSET_CSR_PROFILE_CTRL + kern->cra_address_offset,
621+
profile_ctrl_val);
614622
if (status)
615623
return status;
616624
return 0;
@@ -1040,6 +1048,12 @@ int acl_kernel_if_post_pll_config_init(acl_kernel_if *kern) {
10401048
ACL_KERNEL_IF_DEBUG_MSG(kern,
10411049
"Read CSR version from kernel 0: Version = %u\n",
10421050
kern->csr_version);
1051+
if (kern->csr_version < 5) {
1052+
// Set the offset to 0 for csr versions prioior to version 5
1053+
// Register addresses are pushed back since previous versions doesn't have
1054+
// the start register
1055+
kern->cra_address_offset = 0;
1056+
}
10431057
} else {
10441058
kern->csr_version = 0;
10451059
}
@@ -1220,7 +1234,8 @@ void acl_kernel_if_launch_kernel_on_custom_sof(
12201234
}
12211235

12221236
} else {
1223-
offset = (unsigned int)KERNEL_OFFSET_INVOCATION_IMAGE;
1237+
offset = (unsigned int)(KERNEL_OFFSET_INVOCATION_IMAGE +
1238+
kern->cra_address_offset);
12241239
image_p = (uintptr_t) & (image->work_dim);
12251240
image_size_static =
12261241
(size_t)((uintptr_t) & (image->arg_value) - (uintptr_t) &
@@ -1279,11 +1294,15 @@ void acl_kernel_if_launch_kernel_on_custom_sof(
12791294
return;
12801295
}
12811296

1282-
unsigned int new_csr = 0;
1283-
acl_kernel_cra_read(kern, accel_id, KERNEL_OFFSET_CSR, &new_csr);
1284-
ACL_KERNEL_SET_BIT(new_csr, KERNEL_CSR_GO);
1285-
acl_kernel_cra_write(kern, accel_id, KERNEL_OFFSET_CSR, new_csr);
1286-
1297+
// backwards compatibility for version prior to 2023.1
1298+
if (kern->csr_version < CSR_VERSION_ID) {
1299+
unsigned int new_csr = 0;
1300+
acl_kernel_cra_read(kern, accel_id, KERNEL_OFFSET_CSR, &new_csr);
1301+
ACL_KERNEL_SET_BIT(new_csr, KERNEL_CSR_START);
1302+
acl_kernel_cra_write(kern, accel_id, KERNEL_OFFSET_CSR, new_csr);
1303+
} else {
1304+
acl_kernel_cra_write(kern, accel_id, KERNEL_OFFSET_START_REG, 1);
1305+
}
12871306
// IRQ handler takes care of the completion event through
12881307
// acl_kernel_if_update_status()
12891308
}
@@ -1362,7 +1381,9 @@ static void acl_kernel_if_update_status_query(acl_kernel_if *kern,
13621381
// kernel arguments
13631382
printf_size = 0;
13641383
if (kern->accel_num_printfs[accel_id] > 0) {
1365-
acl_kernel_cra_read(kern, accel_id, KERNEL_OFFSET_PRINTF_BUFFER_SIZE,
1384+
acl_kernel_cra_read(kern, accel_id,
1385+
KERNEL_OFFSET_PRINTF_BUFFER_SIZE +
1386+
kern->cra_address_offset,
13661387
&printf_size);
13671388
assert(printf_size <= ACL_PRINTF_BUFFER_TOTAL_SIZE);
13681389
ACL_KERNEL_IF_DEBUG_MSG(kern,
@@ -1427,7 +1448,8 @@ static void acl_kernel_if_update_status_query(acl_kernel_if *kern,
14271448
// Only expect single completion for older csr version
14281449
finish_counter = 1;
14291450
} else {
1430-
acl_kernel_cra_read(kern, accel_id, KERNEL_OFFSET_FINISH_COUNTER,
1451+
acl_kernel_cra_read(kern, accel_id,
1452+
KERNEL_OFFSET_FINISH_COUNTER + kern->cra_address_offset,
14311453
&finish_counter);
14321454
ACL_KERNEL_IF_DEBUG_MSG(kern, ":: Accelerator %d has %d finishes.\n",
14331455
accel_id, finish_counter);
@@ -1586,8 +1608,9 @@ void acl_kernel_if_debug_dump_printf(acl_kernel_if *kern, unsigned k) {
15861608
next_queue_back = kern->accel_queue_back[k] + 1;
15871609

15881610
if (kern->accel_num_printfs[k] > 0) {
1589-
acl_kernel_cra_read(kern, k, KERNEL_OFFSET_PRINTF_BUFFER_SIZE,
1590-
&printf_size);
1611+
acl_kernel_cra_read(
1612+
kern, k, KERNEL_OFFSET_PRINTF_BUFFER_SIZE + kern->cra_address_offset,
1613+
&printf_size);
15911614
assert(printf_size <= ACL_PRINTF_BUFFER_TOTAL_SIZE);
15921615
ACL_KERNEL_IF_DEBUG_MSG(
15931616
kern, ":: Accelerator %d printf buffer size is %d.\n", k, printf_size);
@@ -1785,16 +1808,19 @@ static uint64_t acl_kernel_if_get_profile_data_word(acl_kernel_if *kern,
17851808
#ifdef _WIN32
17861809
// Use 32-bit reads on Windows.
17871810
unsigned int low_word, high_word;
1788-
status = acl_kernel_cra_read(kern, accel_id, KERNEL_OFFSET_CSR_PROFILE_DATA,
1789-
&low_word);
1811+
status = acl_kernel_cra_read(
1812+
kern, accel_id, KERNEL_OFFSET_CSR_PROFILE_DATA + kern->cra_address_offset,
1813+
&low_word);
17901814
if (status)
17911815
return (uint64_t)status;
17921816
ACL_KERNEL_IF_DEBUG_MSG(kern,
17931817
":: Read profile hardware:: Accelerator %d "
17941818
"profile_data low_word is %x.\n",
17951819
accel_id, low_word);
17961820
status = acl_kernel_cra_read(kern, accel_id,
1797-
KERNEL_OFFSET_CSR_PROFILE_DATA + 4, &high_word);
1821+
KERNEL_OFFSET_CSR_PROFILE_DATA + 4 +
1822+
kern->cra_address_offset,
1823+
&high_word);
17981824
if (status)
17991825
return (uint64_t)status;
18001826
ACL_KERNEL_IF_DEBUG_MSG(kern,
@@ -1805,7 +1831,8 @@ static uint64_t acl_kernel_if_get_profile_data_word(acl_kernel_if *kern,
18051831
((((uint64_t)high_word) & 0xFFFFFFFF) << 32) | (low_word & 0xFFFFFFFF);
18061832
#else
18071833
status = acl_kernel_cra_read_64b(
1808-
kern, accel_id, KERNEL_OFFSET_CSR_PROFILE_DATA, &read_result);
1834+
kern, accel_id, KERNEL_OFFSET_CSR_PROFILE_DATA + kern->cra_address_offset,
1835+
&read_result);
18091836
if (status)
18101837
return (uint64_t)status;
18111838
ACL_KERNEL_IF_DEBUG_MSG(kern,
@@ -1905,7 +1932,8 @@ int acl_kernel_if_set_profile_start_cycle(acl_kernel_if *kern, cl_uint accel_id,
19051932
assert(acl_kernel_if_is_valid(kern));
19061933
assert(accel_id < kern->num_accel);
19071934
status = acl_kernel_cra_write_64b(
1908-
kern, accel_id, KERNEL_OFFSET_CSR_PROFILE_START_CYCLE, value);
1935+
kern, accel_id,
1936+
KERNEL_OFFSET_CSR_PROFILE_START_CYCLE + kern->cra_address_offset, value);
19091937

19101938
return status;
19111939
}
@@ -1919,6 +1947,7 @@ int acl_kernel_if_set_profile_stop_cycle(acl_kernel_if *kern, cl_uint accel_id,
19191947
assert(acl_kernel_if_is_valid(kern));
19201948
assert(accel_id < kern->num_accel);
19211949
status = acl_kernel_cra_write_64b(
1922-
kern, accel_id, KERNEL_OFFSET_CSR_PROFILE_STOP_CYCLE, value);
1950+
kern, accel_id,
1951+
KERNEL_OFFSET_CSR_PROFILE_STOP_CYCLE + kern->cra_address_offset, value);
19231952
return status;
19241953
}

0 commit comments

Comments
 (0)