Skip to content

Commit 4a875d8

Browse files
committed
[silicon_creator,ibex] Move code away from header
The code conditionally compiles from inline version of the code on the RV platform, and otherwise just declares some external symbol. This makes the code very difficult to test and mock because the OT_PLATFORM_RV32 define is only true when compiling for RISC-V but we do want to test some of this code on the host in a unittest. Since the initial motivation for this was probably just to make it inline, and we have since then enabled LTO, there is no realy reason to do this anymore. This commit moves the device implementation to ibex.c so that the header always just defines the prototypes. Signed-off-by: Amaury Pouly <[email protected]>
1 parent e9cecaf commit 4a875d8

File tree

2 files changed

+29
-35
lines changed

2 files changed

+29
-35
lines changed

sw/device/silicon_creator/lib/drivers/ibex.c

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,31 @@
1414

1515
static const dt_rv_core_ibex_t kRvCoreIbexDt = kDtRvCoreIbex;
1616

17+
void ibex_mcycle_zero(void) {
18+
CSR_WRITE(CSR_REG_MCYCLE, 0);
19+
CSR_WRITE(CSR_REG_MCYCLEH, 0);
20+
}
21+
22+
uint32_t ibex_mcycle32(void) {
23+
uint32_t val;
24+
CSR_READ(CSR_REG_MCYCLE, &val);
25+
return val;
26+
}
27+
28+
uint64_t ibex_mcycle(void) {
29+
uint32_t lo, hi, hi2;
30+
do {
31+
CSR_READ(CSR_REG_MCYCLEH, &hi);
32+
CSR_READ(CSR_REG_MCYCLE, &lo);
33+
CSR_READ(CSR_REG_MCYCLEH, &hi2);
34+
} while (hi != hi2);
35+
return ((uint64_t)hi << 32) | lo;
36+
}
37+
38+
uint64_t ibex_time_to_cycles(uint64_t time_us) {
39+
return to_cpu_cycles(time_us);
40+
}
41+
1742
/**
1843
* Base address of the rv_core_ibex registers.
1944
*
@@ -181,10 +206,3 @@ void ibex_clear_nmi(ibex_nmi_source_t nmi_src) {
181206
abs_mmio_write32(rv_core_ibex_base() + RV_CORE_IBEX_NMI_STATE_REG_OFFSET,
182207
nmi_src);
183208
}
184-
185-
// `extern` declarations to give the inline functions in the corresponding
186-
// header a link location.
187-
extern void ibex_mcycle_zero(void);
188-
extern uint32_t ibex_mcycle32(void);
189-
extern uint64_t ibex_mcycle(void);
190-
extern uint64_t ibex_time_to_cycles(uint64_t time_us);

sw/device/silicon_creator/lib/drivers/ibex.h

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,51 +32,27 @@ uint32_t ibex_fpga_version(void);
3232
OT_WARN_UNUSED_RESULT
3333
size_t ibex_addr_remap_slots(void);
3434

35-
#ifdef OT_PLATFORM_RV32
3635
/**
3736
* Set the MCYCLE counter register to zero.
3837
*/
39-
inline void ibex_mcycle_zero(void) {
40-
CSR_WRITE(CSR_REG_MCYCLE, 0);
41-
CSR_WRITE(CSR_REG_MCYCLEH, 0);
42-
}
38+
void ibex_mcycle_zero(void);
4339

4440
/**
4541
* Read the low 32 bits of the MCYCLE counter.
4642
*/
4743
OT_WARN_UNUSED_RESULT
48-
inline uint32_t ibex_mcycle32(void) {
49-
uint32_t val;
50-
CSR_READ(CSR_REG_MCYCLE, &val);
51-
return val;
52-
}
44+
uint32_t ibex_mcycle32(void);
5345

5446
/**
5547
* Read the 64-bit MCYCLE counter.
5648
*/
5749
OT_WARN_UNUSED_RESULT
58-
inline uint64_t ibex_mcycle(void) {
59-
uint32_t lo, hi, hi2;
60-
do {
61-
CSR_READ(CSR_REG_MCYCLEH, &hi);
62-
CSR_READ(CSR_REG_MCYCLE, &lo);
63-
CSR_READ(CSR_REG_MCYCLEH, &hi2);
64-
} while (hi != hi2);
65-
return ((uint64_t)hi << 32) | lo;
66-
}
50+
uint64_t ibex_mcycle(void);
6751

6852
/**
6953
* Convert from microseconds to CPU cycles.
7054
*/
71-
inline uint64_t ibex_time_to_cycles(uint64_t time_us) {
72-
return to_cpu_cycles(time_us);
73-
}
74-
#else
75-
extern void ibex_mcycle_zero(void);
76-
extern uint32_t ibex_mcycle32(void);
77-
extern uint64_t ibex_mcycle(void);
78-
extern uint64_t ibex_time_to_cycles(uint64_t time_us);
79-
#endif
55+
uint64_t ibex_time_to_cycles(uint64_t time_us);
8056

8157
/**
8258
* Get random data from the EDN0 interface.

0 commit comments

Comments
 (0)