Skip to content

Commit b7b266b

Browse files
duda-patrykCommit Bot
authored andcommitted
Provide 'is_interrupt_enabled' function for all cores
Add a function that will provide information if interrupts are enabled. This information will be used to fix shortcomings in common code for UART buffering and usleep(). BUG=b:190597666 BRANCH=none TEST=make -j buildall TEST=make runhosttests TEST=Note for running tests: this patch only adds function implementation so, to test this it is necessary to add some code which uses the function eg. console command which prints information if interrupt is enabled. Minute-ia core: It is necessary to compile firmware for ISH (Intel Sensor Hub) which is available on drallion board (eg. chromeos6-row1-rack9-host19). Firmware must be placed in /lib/firmware/intel/drallion_ish.bin (partition must be writeable, if not use /usr/share/vboot/bin/make_dev_ssd.sh on DUT tu unlock it, don't forget about reboot). After copying firmware to /lib/firmware/intel/ it is necessary to reboot DUT. After reboot use `ectool --name=cros_ish version` to check if correct version is running. NDS32 core. This core is used in it8320dx chip which is present in ampton (octopus family). EC can be compiled using 'make BOARD=ampton' and flashed using 'chromeos-firmwareupdate -e ec.bin', but EC software sync needs to be disabled using 'set_gbb_flags.sh 0x200' Riscv-rv32i core, hayato (asurada family) uses it81202 as EC which is based on risc-v. EC can be compiled using 'make BOARD=hayato' and flashed using 'chromeos-firmwareupdate -e ec.bin', but EC software sync needs to be disabled using 'set_gbb_flags.sh 0x200' Cortex-M, this is the most common core. Just compile EC for platform which contains Cortex-M core (eg. bloonchipper) and test if it works. Signed-off-by: Patryk Duda <[email protected]> Change-Id: I502553cd57e6ce897d5845a3aad01a44a9058405 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2953227 Commit-Queue: Marcin Wojtas <[email protected]> Tested-by: Patryk Duda <[email protected]> Reviewed-by: Aseda Aboagye <[email protected]>
1 parent a6431b4 commit b7b266b

File tree

7 files changed

+62
-0
lines changed

7 files changed

+62
-0
lines changed

core/cortex-m/task.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,16 @@ void interrupt_enable(void)
227227
asm("cpsie i");
228228
}
229229

230+
inline int is_interrupt_enabled(void)
231+
{
232+
int primask;
233+
234+
/* Interrupts are enabled when PRIMASK bit is 0 */
235+
asm("mrs %0, primask":"=r"(primask));
236+
237+
return !(primask & 0x1);
238+
}
239+
230240
inline int in_interrupt_context(void)
231241
{
232242
int ret;

core/cortex-m0/task.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,16 @@ void interrupt_enable(void)
161161
asm("cpsie i");
162162
}
163163

164+
inline int is_interrupt_enabled(void)
165+
{
166+
int primask;
167+
168+
/* Interrupts are enabled when PRIMASK bit is 0 */
169+
asm("mrs %0, primask":"=r"(primask));
170+
171+
return !(primask & 0x1);
172+
}
173+
164174
inline int in_interrupt_context(void)
165175
{
166176
int ret;

core/host/task.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ test_mockable void interrupt_enable(void)
138138
pthread_mutex_unlock(&interrupt_lock);
139139
}
140140

141+
inline int is_interrupt_enabled(void)
142+
{
143+
return !interrupt_disabled;
144+
}
145+
141146
static void _task_execute_isr(int sig)
142147
{
143148
in_interrupt = 1;

core/minute-ia/task.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,18 @@ void interrupt_enable(void)
173173
__asm__ __volatile__ ("sti");
174174
}
175175

176+
inline int is_interrupt_enabled(void)
177+
{
178+
uint32_t eflags = 0;
179+
180+
__asm__ __volatile__ ("pushfl\n"
181+
"popl %0\n"
182+
: "=r"(eflags));
183+
184+
/* Check Interrupt Enable flag */
185+
return !!(eflags & 0x200);
186+
}
187+
176188
inline int in_interrupt_context(void)
177189
{
178190
return !!__in_isr;

core/nds32/task.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,16 @@ void __ram_code interrupt_enable(void)
224224
asm volatile ("mtsr %0, $INT_MASK" : : "r"(val));
225225
}
226226

227+
inline int is_interrupt_enabled(void)
228+
{
229+
uint32_t val = 0;
230+
231+
asm volatile ("mfsr %0, $INT_MASK" : "=r"(val));
232+
233+
/* Interrupts are enabled if any of HW2 ~ HW15 is enabled */
234+
return !!(val & 0xFFFC);
235+
}
236+
227237
inline int in_interrupt_context(void)
228238
{
229239
/* check INTL (Interrupt Stack Level) bits */

core/riscv-rv32i/task.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,16 @@ void __ram_code interrupt_enable(void)
199199
asm volatile ("csrs mie, t0");
200200
}
201201

202+
inline int is_interrupt_enabled(void)
203+
{
204+
int mie = 0;
205+
206+
asm volatile ("csrr %0, mie" : "=r"(mie));
207+
208+
/* Check if MEIE bit is set in MIE register */
209+
return !!(mie & 0x800);
210+
}
211+
202212
inline int in_interrupt_context(void)
203213
{
204214
return in_interrupt;

include/task.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ void interrupt_disable(void);
7979
*/
8080
void interrupt_enable(void);
8181

82+
/**
83+
* Check if interrupts are enabled
84+
*/
85+
int is_interrupt_enabled(void);
86+
8287
/*
8388
* Define irq_lock and irq_unlock that match the function signatures to Zephyr's
8489
* functions. In reality, these simply call the current implementation of

0 commit comments

Comments
 (0)