Skip to content

Commit e7c9a66

Browse files
committed
Move kernel_if and pll address maps to acl_hal_mmd.h
1 parent fb094d5 commit e7c9a66

File tree

7 files changed

+125
-139
lines changed

7 files changed

+125
-139
lines changed

include/acl_hal_mmd.h

Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,112 @@
1010

1111
//////////////////////////////////////////////////////////////////////////
1212
// //
13-
// Implementation of HAL that builds on top of aocl_mmd (board vendor //
13+
// Versioning constants, address maps, and bit/byte positionings used //
14+
// in acl_kernel_if and acl_pll //
15+
// //
16+
//////////////////////////////////////////////////////////////////////////
17+
18+
//// acl_kernel_if
19+
// Versioning: This value must be read from addr 0
20+
// For unit tests to work, this defines must match the one in the unit test
21+
// header file
22+
#define KERNEL_VERSION_ID (0xa0c00001)
23+
#define KERNEL_ROM_VERSION_ID (0xa0c00002)
24+
// Version number in the top 16-bits of the 32-bit status register. Used
25+
// to verify that the hardware and HAL have an identical view of the CSR
26+
// address map.
27+
#define CSR_VERSION_ID_18_1 (3)
28+
#define CSR_VERSION_ID_19_1 (4)
29+
#define CSR_VERSION_ID_23_1 (5)
30+
#define CSR_VERSION_ID CSR_VERSION_ID_23_1
31+
32+
// Address map
33+
// For unit tests to work, these defines must match those in the unit test
34+
// header file
35+
#define OFFSET_KERNEL_VERSION_ID ((dev_addr_t)0x0000)
36+
#define OFFSET_KERNEL_CRA_SEGMENT ((dev_addr_t)0x0020)
37+
#define OFFSET_SW_RESET ((dev_addr_t)0x0030)
38+
#define OFFSET_KERNEL_CRA ((dev_addr_t)0x1000)
39+
#define OFFSET_CONFIGURATION_ROM ((dev_addr_t)0x2000)
40+
41+
// Addressses for Kernel System ROM
42+
#define OFFSET_KERNEL_ROM_LOCATION_MSB (0x3ffffff8)
43+
#define OFFSET_KERNEL_ROM_LOCATION_LSB (0x3ffffffc)
44+
#define OFFSET_KERNEL_MAX_ADDRESS (0x3fffffff)
45+
46+
#define KERNEL_CRA_SEGMENT_SIZE (0x1000)
47+
#define KERNEL_ROM_SIZE_BYTES_READ 4
48+
#define KERNEL_ROM_SIZE_BYTES 8
49+
50+
// Byte offsets into the CRA:
51+
// For CSR version >= 5 byte offsets are pushed back with the proper
52+
// value except for the CSR later on in the runtime execution
53+
#define KERNEL_OFFSET_CSR 0
54+
#define KERNEL_OFFSET_PRINTF_BUFFER_SIZE 0x4
55+
#define KERNEL_OFFSET_CSR_PROFILE_CTRL 0xC
56+
#define KERNEL_OFFSET_CSR_PROFILE_DATA 0x10
57+
#define KERNEL_OFFSET_CSR_PROFILE_START_CYCLE 0x18
58+
#define KERNEL_OFFSET_CSR_PROFILE_STOP_CYCLE 0x20
59+
#define KERNEL_OFFSET_FINISH_COUNTER 0x28
60+
#define KERNEL_OFFSET_INVOCATION_IMAGE 0x30
61+
62+
// CSR version >= 5 byte offsets
63+
#define KERNEL_OFFSET_START_REG 0x8
64+
65+
// Backwards compatibility with CSR_VERSION_ID 3
66+
#define KERNEL_OFFSET_INVOCATION_IMAGE_181 0x28
67+
68+
// Bit positions
69+
#define KERNEL_CSR_START 0
70+
#define KERNEL_CSR_DONE 1
71+
#define KERNEL_CSR_STALLED 3
72+
#define KERNEL_CSR_UNSTALL 4
73+
#define KERNEL_CSR_PROFILE_TEMPORAL_STATUS 5
74+
#define KERNEL_CSR_PROFILE_TEMPORAL_RESET 6
75+
#define KERNEL_CSR_LAST_STATUS_BIT KERNEL_CSR_PROFILE_TEMPORAL_RESET
76+
#define KERNEL_CSR_STATUS_BITS_MASK \
77+
((unsigned)((1 << (KERNEL_CSR_LAST_STATUS_BIT + 1)) - 1))
78+
#define KERNEL_CSR_LMEM_INVALID_BANK 11
79+
#define KERNEL_CSR_LSU_ACTIVE 12
80+
#define KERNEL_CSR_WR_ACTIVE 13
81+
#define KERNEL_CSR_BUSY 14
82+
#define KERNEL_CSR_RUNNING 15
83+
#define KERNEL_CSR_FIRST_VERSION_BIT 16
84+
#define KERNEL_CSR_LAST_VERSION_BIT 31
85+
86+
#define KERNEL_CSR_PROFILE_SHIFT64_BIT 0
87+
#define KERNEL_CSR_PROFILE_RESET_BIT 1
88+
#define KERNEL_CSR_PROFILE_ALLOW_PROFILING_BIT 2
89+
#define KERNEL_CSR_PROFILE_LOAD_BUFFER_BIT 3
90+
#define KERNEL_CSR_PROFILE_SHARED_CONTROL_BIT1 4
91+
#define KERNEL_CSR_PROFILE_SHARED_CONTROL_BIT2 5
92+
93+
#define CONFIGURATION_ROM_BYTES 4096
94+
95+
#define RESET_TIMEOUT (2 * 1000 * 1000 * 1000)
96+
97+
// acl_pll
98+
// Address map
99+
// For unit tests to work, these defines must match those in the unit test
100+
// header file
101+
#define OFFSET_PLL_VERSION_ID ((dev_addr_t)0x000)
102+
#define OFFSET_ROM ((dev_addr_t)0x400)
103+
#define OFFSET_RECONFIG_CTRL ((dev_addr_t)0x200)
104+
#define OFFSET_RECONFIG_CTRL_20NM ((dev_addr_t)0x800)
105+
#define OFFSET_COUNTER ((dev_addr_t)0x100)
106+
#define OFFSET_RESET ((dev_addr_t)0x110)
107+
#define OFFSET_LOCK ((dev_addr_t)0x120)
108+
109+
// Constants
110+
#define MAX_KNOWN_SETTINGS 100
111+
#define MAX_POSSIBLE_FMAX 2000000
112+
#define MAX_RECONFIG_RETRIES 3
113+
#define RECONFIG_TIMEOUT (1000000000ll)
114+
#define CLK_MEASUREMENT_PERIOD (16 * 1024 * 1024)
115+
116+
//////////////////////////////////////////////////////////////////////////
117+
// //
118+
// Implementation of HAL that builds on top of aocl_mmd (board vendor //
14119
// visible), acl_pll, and acl_kernel_if. //
15120
// //
16121
//////////////////////////////////////////////////////////////////////////
@@ -24,6 +129,8 @@
24129

25130
#include <MMD/aocl_mmd.h>
26131

132+
133+
27134
extern acl_kernel_update_callback acl_kernel_update_fn;
28135
extern acl_process_printf_buffer_callback acl_process_printf_buffer_fn;
29136

src/acl_kernel_if.cpp

Lines changed: 8 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <cassert>
66
#include <cinttypes>
77
#include <cstdint>
8+
#include <cmath>
89
#include <stdio.h>
910
#include <stdlib.h>
1011
#include <string>
@@ -36,84 +37,6 @@ extern int
3637
acl_process_autorun_profiler_scan_chain(unsigned int physical_device_id,
3738
unsigned int accel_id);
3839

39-
// Versioning: This value must be read from addr 0
40-
// For unit tests to work, this defines must match the one in the unit test
41-
// header file
42-
#define KERNEL_VERSION_ID (0xa0c00001)
43-
#define KERNEL_ROM_VERSION_ID (0xa0c00002)
44-
// Version number in the top 16-bits of the 32-bit status register. Used
45-
// to verify that the hardware and HAL have an identical view of the CSR
46-
// address map.
47-
#define CSR_VERSION_ID_18_1 (3)
48-
#define CSR_VERSION_ID_19_1 (4)
49-
#define CSR_VERSION_ID_23_1 (5)
50-
#define CSR_VERSION_ID CSR_VERSION_ID_23_1
51-
52-
// Address map
53-
// For unit tests to work, these defines must match those in the unit test
54-
// header file
55-
#define OFFSET_VERSION_ID ((dev_addr_t)0x0000)
56-
#define OFFSET_KERNEL_CRA_SEGMENT ((dev_addr_t)0x0020)
57-
#define OFFSET_SW_RESET ((dev_addr_t)0x0030)
58-
#define OFFSET_KERNEL_CRA ((dev_addr_t)0x1000)
59-
#define OFFSET_CONFIGURATION_ROM ((dev_addr_t)0x2000)
60-
61-
// Addressses for Kernel System ROM
62-
#define OFFSET_KERNEL_ROM_LOCATION_MSB (0x3ffffff8)
63-
#define OFFSET_KERNEL_ROM_LOCATION_LSB (0x3ffffffc)
64-
#define OFFSET_KERNEL_MAX_ADDRESS (0x3fffffff)
65-
66-
#define KERNEL_CRA_SEGMENT_SIZE (0x1000)
67-
#define KERNEL_ROM_SIZE_BYTES_READ 4
68-
#define KERNEL_ROM_SIZE_BYTES 8
69-
70-
// Byte offsets into the CRA:
71-
// For CSR version >= 5 byte offsets are pushed back with the proper
72-
// value except for the CSR later on in the runtime execution
73-
#define KERNEL_OFFSET_CSR 0
74-
#define KERNEL_OFFSET_PRINTF_BUFFER_SIZE 0x4
75-
#define KERNEL_OFFSET_CSR_PROFILE_CTRL 0xC
76-
#define KERNEL_OFFSET_CSR_PROFILE_DATA 0x10
77-
#define KERNEL_OFFSET_CSR_PROFILE_START_CYCLE 0x18
78-
#define KERNEL_OFFSET_CSR_PROFILE_STOP_CYCLE 0x20
79-
#define KERNEL_OFFSET_FINISH_COUNTER 0x28
80-
#define KERNEL_OFFSET_INVOCATION_IMAGE 0x30
81-
82-
// CSR version >= 5 byte offsets
83-
#define KERNEL_OFFSET_START_REG 0x8
84-
85-
// Backwards compatibility with CSR_VERSION_ID 3
86-
#define KERNEL_OFFSET_INVOCATION_IMAGE_181 0x28
87-
88-
// Bit positions
89-
#define KERNEL_CSR_START 0
90-
#define KERNEL_CSR_DONE 1
91-
#define KERNEL_CSR_STALLED 3
92-
#define KERNEL_CSR_UNSTALL 4
93-
#define KERNEL_CSR_PROFILE_TEMPORAL_STATUS 5
94-
#define KERNEL_CSR_PROFILE_TEMPORAL_RESET 6
95-
#define KERNEL_CSR_LAST_STATUS_BIT KERNEL_CSR_PROFILE_TEMPORAL_RESET
96-
#define KERNEL_CSR_STATUS_BITS_MASK \
97-
((unsigned)((1 << (KERNEL_CSR_LAST_STATUS_BIT + 1)) - 1))
98-
#define KERNEL_CSR_LMEM_INVALID_BANK 11
99-
#define KERNEL_CSR_LSU_ACTIVE 12
100-
#define KERNEL_CSR_WR_ACTIVE 13
101-
#define KERNEL_CSR_BUSY 14
102-
#define KERNEL_CSR_RUNNING 15
103-
#define KERNEL_CSR_FIRST_VERSION_BIT 16
104-
#define KERNEL_CSR_LAST_VERSION_BIT 31
105-
106-
#define KERNEL_CSR_PROFILE_SHIFT64_BIT 0
107-
#define KERNEL_CSR_PROFILE_RESET_BIT 1
108-
#define KERNEL_CSR_PROFILE_ALLOW_PROFILING_BIT 2
109-
#define KERNEL_CSR_PROFILE_LOAD_BUFFER_BIT 3
110-
#define KERNEL_CSR_PROFILE_SHARED_CONTROL_BIT1 4
111-
#define KERNEL_CSR_PROFILE_SHARED_CONTROL_BIT2 5
112-
113-
#define CONFIGURATION_ROM_BYTES 4096
114-
115-
#define RESET_TIMEOUT (2 * 1000 * 1000 * 1000)
116-
11740
#define ACL_KERNEL_READ_BIT(w, b) (((w) >> (b)) & 1)
11841
#define ACL_KERNEL_READ_BIT_RANGE(w, h, l) \
11942
(((w) >> (l)) & ((1 << ((h) - (l) + 1)) - 1))
@@ -178,7 +101,7 @@ static int check_version_id(acl_kernel_if *kern) {
178101
int r;
179102
acl_assert_locked();
180103

181-
r = acl_kernel_if_read_32b(kern, OFFSET_VERSION_ID, &version);
104+
r = acl_kernel_if_read_32b(kern, OFFSET_KERNEL_VERSION_ID, &version);
182105
ACL_KERNEL_IF_DEBUG_MSG(kern, "Version ID check, read: %08x\n", version);
183106
if (r != 0 ||
184107
(version != KERNEL_VERSION_ID && version != KERNEL_ROM_VERSION_ID)) {
@@ -196,15 +119,15 @@ static int get_auto_discovery_string(acl_kernel_if *kern, char *config_str) {
196119
char description_size_msb[KERNEL_ROM_SIZE_BYTES_READ + 1];
197120
char description_size_lsb[KERNEL_ROM_SIZE_BYTES_READ + 1];
198121
unsigned int size_location;
199-
unsigned int size, temp_size, rom_size;
122+
unsigned int size, rom_size;
200123
size_t r;
201124
int result;
202125
acl_assert_locked();
203126

204127
kern->cur_segment = 0xffffffff;
205128

206129
version = 0;
207-
acl_kernel_if_read_32b(kern, OFFSET_VERSION_ID, &version);
130+
acl_kernel_if_read_32b(kern, OFFSET_KERNEL_VERSION_ID, &version);
208131
if (version == KERNEL_ROM_VERSION_ID) {
209132
// Read autodiscovery size
210133
size_location = OFFSET_KERNEL_ROM_LOCATION_MSB;
@@ -221,12 +144,7 @@ static int get_auto_discovery_string(acl_kernel_if *kern, char *config_str) {
221144
size += (unsigned int)strtol(description_size_lsb, NULL, 16);
222145

223146
// Find beginning address of ROM
224-
temp_size = size + KERNEL_ROM_SIZE_BYTES;
225-
rom_size = 1;
226-
while (temp_size > 0) {
227-
temp_size = temp_size >> 1;
228-
rom_size = rom_size << 1;
229-
}
147+
rom_size = 1 << ((unsigned)log2(size + KERNEL_ROM_SIZE_BYTES) + 1);
230148
rom_address = OFFSET_KERNEL_MAX_ADDRESS - rom_size + 1;
231149
config_str[0] = '\0';
232150
result = acl_kernel_rom_cra_read_block(kern, rom_address, config_str,
@@ -728,7 +646,7 @@ int acl_kernel_if_init(acl_kernel_if *kern, acl_bsp_io bsp_io,
728646
}
729647

730648
version = 0;
731-
acl_kernel_if_read_32b(kern, OFFSET_VERSION_ID, &version);
649+
acl_kernel_if_read_32b(kern, OFFSET_KERNEL_VERSION_ID, &version);
732650
ACL_KERNEL_IF_DEBUG_MSG_VERBOSE(kern, 2, ":: Kernel version 0x%x\n",
733651
version);
734652
size_t config_str_len = 0;
@@ -1226,8 +1144,8 @@ void acl_kernel_if_launch_kernel_on_custom_sof(
12261144
offset = (unsigned int)(KERNEL_OFFSET_INVOCATION_IMAGE +
12271145
kern->cra_address_offset);
12281146
image_p = (uintptr_t) & (image->work_dim);
1229-
image_size_static =
1230-
(size_t)((uintptr_t) & (image->arg_value) - (uintptr_t) &
1147+
image_size_static =
1148+
(size_t)((uintptr_t) & (image->arg_value) - (uintptr_t) &
12311149
(image->work_dim));
12321150
}
12331151

src/acl_pll.cpp

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,6 @@
1111
#define PLL_VERSION_ID (0xa0c00001)
1212
#define PLL_VERSION_ID_20NM (0xa0c00002)
1313

14-
// Address map
15-
// For unit tests to work, these defines must match those in the unit test
16-
// header file
17-
#define OFFSET_VERSION_ID ((dev_addr_t)0x000)
18-
#define OFFSET_ROM ((dev_addr_t)0x400)
19-
#define OFFSET_RECONFIG_CTRL ((dev_addr_t)0x200)
20-
#define OFFSET_RECONFIG_CTRL_20NM ((dev_addr_t)0x800)
21-
#define OFFSET_COUNTER ((dev_addr_t)0x100)
22-
#define OFFSET_RESET ((dev_addr_t)0x110)
23-
#define OFFSET_LOCK ((dev_addr_t)0x120)
24-
25-
// Constants
26-
#define MAX_KNOWN_SETTINGS 100
27-
#define MAX_POSSIBLE_FMAX 2000000
28-
#define MAX_RECONFIG_RETRIES 3
29-
#define RECONFIG_TIMEOUT (1000000000ll)
30-
#define CLK_MEASUREMENT_PERIOD (16 * 1024 * 1024)
31-
3214
#define ACL_PLL_DEBUG_MSG_VERBOSE(p, verbosity, m, ...) \
3315
if (p->io.printf && (p->io.debug_verbosity) >= verbosity) \
3416
do { \
@@ -113,7 +95,7 @@ static int get_version_id(acl_pll *pll) {
11395
int r;
11496

11597
ACL_PLL_DEBUG_MSG_VERBOSE(pll, 1, "PLL: Reading PLL version ID\n");
116-
r = _acl_pll_read(pll, OFFSET_VERSION_ID, &version);
98+
r = _acl_pll_read(pll, OFFSET_PLL_VERSION_ID, &version);
11799
if (r != 0 || (version != PLL_VERSION_ID && version != PLL_VERSION_ID_20NM)) {
118100
pll->io.printf(
119101
" PLL: Version mismatch! Expected 0x%x or 0x%x but read 0x%x\n",

test/acl_mem_device_global_test.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ MT_TEST(acl_mem_device_global, read_device_global) {
224224
ACL_LOCKED(acl_print_debug_msg("begin read_device_global\n"));
225225
char str[100];
226226
const size_t strsize = sizeof(str) / sizeof(char); // includes NUL (!)
227-
char resultbuf[strsize];
228227
cl_int status;
229228
cl_event read_event = 0;
230229

@@ -261,7 +260,6 @@ MT_TEST(acl_mem_device_global, write_device_global) {
261260
ACL_LOCKED(acl_print_debug_msg("begin write_device_global\n"));
262261
char str[100];
263262
const size_t strsize = sizeof(str) / sizeof(char); // includes NUL (!)
264-
char resultbuf[strsize];
265263
cl_int status;
266264
cl_event write_event = 0;
267265

test/acl_test.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -86,29 +86,10 @@ typedef struct {
8686
void *status_user_data;
8787
} acl_hal_device_test;
8888

89-
// This must match the define in acl_kernel_if.c
90-
#define KERNEL_VERSION_ID (0xa0c00001)
91-
92-
// These must match the defines in acl_kernel_if.c
93-
#define OFFSET_VERSION_ID ((dev_addr_t)0x0000)
94-
#define OFFSET_KERNEL_CRA_SEGMENT ((dev_addr_t)0x0020)
95-
#define OFFSET_SW_RESET ((dev_addr_t)0x0030)
9689
// Default mem_org address.
9790
// Runtime is now using one loaded from autodiscovery,
9891
// rather than hard coded value.
9992
// For tests, autodiscovery will still have the default value.
10093
#define OFFSET_MEM_ORG ((dev_addr_t)0x0018)
101-
#define OFFSET_KERNEL_CRA ((dev_addr_t)0x1000)
102-
#define OFFSET_CONFIGURATION_ROM ((dev_addr_t)0x2000)
103-
104-
// These must match the defines in acl_pll.c
105-
#define OFFSET_ROM ((dev_addr_t)0x400)
106-
#define OFFSET_RECONFIG_CTRL ((dev_addr_t)0x200)
107-
#define OFFSET_COUNTER ((dev_addr_t)0x100)
108-
#define OFFSET_RESET ((dev_addr_t)0x110)
109-
#define OFFSET_LOCK ((dev_addr_t)0x120)
110-
111-
// This must match the define in acl_pll.c
112-
#define MAX_KNOWN_SETTINGS 100
11394

11495
#endif

test/fake_bsp/fakegoodbsp.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ AOCL_MMD_CALL int aocl_mmd_read(int handle, aocl_mmd_op_t op, size_t len,
247247
"14 s5_net 0 0 2 1024 0 4294967296 4294967296 8589934592 0 0 ";
248248
UNREFERENCED_PARAMETER(op);
249249
switch (offset) {
250-
case OFFSET_VERSION_ID:
250+
case OFFSET_KERNEL_VERSION_ID:
251251
if (len == sizeof(unsigned int)) {
252252
unsigned int version_id = KERNEL_VERSION_ID;
253253
memcpy(dst, &version_id, len);
@@ -385,7 +385,7 @@ AOCL_MMD_CALL int aocl_mmd_write(int handle, aocl_mmd_op_t op, size_t len,
385385
size_t new_offset;
386386
UNREFERENCED_PARAMETER(op);
387387
switch (offset) {
388-
case OFFSET_VERSION_ID:
388+
case OFFSET_KERNEL_VERSION_ID:
389389
fprintf(stderr, "Error: Not handling write of 0x%x in unit test\n",
390390
(unsigned int)offset);
391391
return -1;
@@ -498,7 +498,7 @@ AOCL_MMD_CALL int aocl_mmd_copy(int handle, aocl_mmd_op_t op, size_t len,
498498
size_t new_dst_offset;
499499
UNREFERENCED_PARAMETER(op);
500500
switch (src_offset) {
501-
case OFFSET_VERSION_ID:
501+
case OFFSET_KERNEL_VERSION_ID:
502502
fprintf(stderr, "Error: Not handling copy from 0x%x in unit test\n",
503503
(unsigned int)src_offset);
504504
return -1;
@@ -544,7 +544,7 @@ AOCL_MMD_CALL int aocl_mmd_copy(int handle, aocl_mmd_op_t op, size_t len,
544544
return -1;
545545
}
546546
switch (dst_offset) {
547-
case OFFSET_VERSION_ID:
547+
case OFFSET_KERNEL_VERSION_ID:
548548
fprintf(stderr, "Error: Not handling copy to 0x%x in unit test\n",
549549
(unsigned int)dst_offset);
550550
return -1;

0 commit comments

Comments
 (0)