Skip to content

Commit 4203376

Browse files
author
Siyuan Cheng
committed
DSP: add DSP support for ARC processor
add DSP reg in context switch add AGU reg in context switch to support XY mem add thread option and API to dis/enable DSP switch Signed-off-by: Siyuan Cheng <[email protected]>
1 parent 83e4f5d commit 4203376

File tree

11 files changed

+663
-10
lines changed

11 files changed

+663
-10
lines changed

arch/Kconfig

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,11 @@ config CPU_HAS_DCLS
564564
This option is enabled when the processor hardware is configured in
565565
Dual-redundant Core Lock-step (DCLS) topology.
566566

567+
config CPU_HAS_DSP
568+
bool
569+
help
570+
This option is enabled when the CPU has hardware DSP unit.
571+
567572
config CPU_HAS_FPU
568573
bool
569574
help
@@ -742,6 +747,24 @@ config FPU_SHARING
742747

743748
endmenu
744749

750+
menu "Digital Signal Processing Options"
751+
752+
config DSP
753+
bool "This option enables digital signal processing (DSP)"
754+
depends on CPU_HAS_DSP
755+
help
756+
This option enables DSP and DSP instructions.
757+
758+
config DSP_SHARING
759+
bool "DSP register sharing"
760+
depends on DSP && MULTITHREADING
761+
help
762+
This option enables preservation of the hardware DSP registers
763+
across context switches to allow multiple threads to perform concurrent
764+
DSP operations.
765+
766+
endmenu
767+
745768
menu "Cache Options"
746769

747770
config DCACHE

arch/arc/Kconfig

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,50 @@ config ARC_NORMAL_FIRMWARE
327327
resources of the ARC processors, and, therefore, it shall avoid
328328
accessing them.
329329

330+
config ARC_DSP_BFLY_SHARING
331+
bool "ARC complex DSP operation"
332+
depends on DSP && CPU_ARCEM
333+
default n
334+
help
335+
This option is to enable Zephyr to store and restore DSP_BFLY0
336+
and FFT_CTRL registers during context switch. This option is
337+
only required when butterfly instructions are used in
338+
multi-thread.
339+
340+
config ARC_HAS_AGU_REGS
341+
bool "ARC address generation unit registers"
342+
default n
343+
help
344+
Processors with XY memory and AGU registers can configure this
345+
option to accelerate DSP instrctions.
346+
347+
config AGU_SHARING
348+
bool "ARC address generation unit register sharing"
349+
depends on ARC_HAS_AGU_REGS && MULTITHREADING
350+
help
351+
This option enables preservation of the hardware AGU registers
352+
across context switches to allow multiple threads to perform concurrent
353+
operations on XY memory. Save and restore small size AGU registers is
354+
set as default, including 4 address pointers regs, 2 address offset regs
355+
and 4 modifiers regs.
356+
357+
config ARC_AGU_MEDIUM
358+
bool "ARC AGU medium size register"
359+
depends on AGU_SHARING
360+
default n
361+
help
362+
Save and restore medium AGU registers, including 8 address pointers regs,
363+
4 address offset regs and 12 modifiers regs.
364+
365+
config ARC_AGU_LARGE
366+
bool "ARC AGU large size register"
367+
depends on AGU_SHARING
368+
default n
369+
select ARC_AGU_MEDIUM
370+
help
371+
Save and restore large AGU registers, including 12 address pointers regs,
372+
8 address offset regs and 24 modifiers regs.
373+
330374
menu "ARC MPU Options"
331375
depends on CPU_HAS_MPU
332376

arch/arc/core/offsets/offsets.c

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,69 @@ GEN_OFFSET_SYM(_callee_saved_stack_t, dpfp2l);
115115
GEN_OFFSET_SYM(_callee_saved_stack_t, dpfp1h);
116116
GEN_OFFSET_SYM(_callee_saved_stack_t, dpfp1l);
117117
#endif
118-
119118
#endif
119+
#ifdef CONFIG_DSP_SHARING
120+
GEN_OFFSET_SYM(_callee_saved_stack_t, dsp_ctrl);
121+
GEN_OFFSET_SYM(_callee_saved_stack_t, acc0_lo);
122+
GEN_OFFSET_SYM(_callee_saved_stack_t, acc0_glo);
123+
GEN_OFFSET_SYM(_callee_saved_stack_t, acc0_hi);
124+
GEN_OFFSET_SYM(_callee_saved_stack_t, acc0_ghi);
125+
#ifdef CONFIG_ARC_DSP_BFLY_SHARING
126+
GEN_OFFSET_SYM(_callee_saved_stack_t, dsp_bfly0);
127+
GEN_OFFSET_SYM(_callee_saved_stack_t, dsp_fft_ctrl);
128+
#endif
129+
#endif
130+
#ifdef CONFIG_AGU_SHARING
131+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_ap0);
132+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_ap1);
133+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_ap2);
134+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_ap3);
135+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_os0);
136+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_os1);
137+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_mod0);
138+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_mod1);
139+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_mod2);
140+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_mod3);
141+
#ifdef CONFIG_ARC_AGU_MEDIUM
142+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_ap4);
143+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_ap5);
144+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_ap6);
145+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_ap7);
146+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_os2);
147+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_os3);
148+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_mod4);
149+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_mod5);
150+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_mod6);
151+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_mod7);
152+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_mod8);
153+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_mod9);
154+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_mod10);
155+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_mod11);
156+
#endif
157+
#ifdef CONFIG_ARC_AGU_LARGE
158+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_ap8);
159+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_ap9);
160+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_ap10);
161+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_ap11);
162+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_os4);
163+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_os5);
164+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_os6);
165+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_os7);
166+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_mod12);
167+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_mod13);
168+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_mod14);
169+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_mod15);
170+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_mod16);
171+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_mod17);
172+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_mod18);
173+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_mod19);
174+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_mod20);
175+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_mod21);
176+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_mod22);
177+
GEN_OFFSET_SYM(_callee_saved_stack_t, agu_mod23);
178+
#endif
179+
#endif
180+
120181
GEN_ABSOLUTE_SYM(___callee_saved_stack_t_SIZEOF, sizeof(_callee_saved_stack_t));
121182

122183
GEN_ABSOLUTE_SYM(_K_THREAD_NO_FLOAT_SIZEOF, sizeof(struct k_thread));

arch/arc/core/thread.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
#include <zephyr/arch/arc/v2/mpu/arc_core_mpu.h>
2121
#endif
2222

23+
#if defined(CONFIG_DSP) && defined(CONFIG_DSP_SHARING)
24+
static struct k_spinlock lock;
25+
#endif
2326
/* initial stack frame */
2427
struct init_stack_frame {
2528
uintptr_t pc;
@@ -253,3 +256,33 @@ int arch_float_enable(struct k_thread *thread, unsigned int options)
253256
return 0;
254257
}
255258
#endif /* CONFIG_FPU && CONFIG_FPU_SHARING */
259+
260+
#if defined(CONFIG_DSP) && defined(CONFIG_DSP_SHARING)
261+
int arch_dsp_disable(struct k_thread *thread, unsigned int options)
262+
{
263+
/* Ensure a preemptive context switch does not occur */
264+
265+
k_spinlock_key_t key = k_spin_lock(&lock);
266+
267+
/* Disable DSP or AGU capabilities for the thread */
268+
thread->base.user_options &= ~(uint8_t)options;
269+
270+
k_spin_unlock(&lock, key);
271+
272+
return 0;
273+
}
274+
275+
int arch_dsp_enable(struct k_thread *thread, unsigned int options)
276+
{
277+
/* Ensure a preemptive context switch does not occur */
278+
279+
k_spinlock_key_t key = k_spin_lock(&lock);
280+
281+
/* Enable dsp or agu capabilities for the thread */
282+
thread->base.user_options |= (uint8_t)options;
283+
284+
k_spin_unlock(&lock, key);
285+
286+
return 0;
287+
}
288+
#endif /* CONFIG_DSP && CONFIG_DSP_SHARING */

arch/arc/include/kernel_arch_data.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,69 @@ struct _callee_saved_stack {
156156
uintptr_t dpfp1h;
157157
uintptr_t dpfp1l;
158158
#endif
159+
#endif
160+
161+
#ifdef CONFIG_DSP_SHARING
162+
#ifdef CONFIG_ARC_DSP_BFLY_SHARING
163+
uintptr_t dsp_fft_ctrl;
164+
uintptr_t dsp_bfly0;
165+
#endif
166+
uintptr_t acc0_ghi;
167+
uintptr_t acc0_hi;
168+
uintptr_t acc0_glo;
169+
uintptr_t acc0_lo;
170+
uintptr_t dsp_ctrl;
171+
#endif
159172

173+
#ifdef CONFIG_AGU_SHARING
174+
uintptr_t agu_ap0;
175+
uintptr_t agu_ap1;
176+
uintptr_t agu_ap2;
177+
uintptr_t agu_ap3;
178+
uintptr_t agu_os0;
179+
uintptr_t agu_os1;
180+
uintptr_t agu_mod0;
181+
uintptr_t agu_mod1;
182+
uintptr_t agu_mod2;
183+
uintptr_t agu_mod3;
184+
#ifdef CONFIG_ARC_AGU_MEDIUM
185+
uintptr_t agu_ap4;
186+
uintptr_t agu_ap5;
187+
uintptr_t agu_ap6;
188+
uintptr_t agu_ap7;
189+
uintptr_t agu_os2;
190+
uintptr_t agu_os3;
191+
uintptr_t agu_mod4;
192+
uintptr_t agu_mod5;
193+
uintptr_t agu_mod6;
194+
uintptr_t agu_mod7;
195+
uintptr_t agu_mod8;
196+
uintptr_t agu_mod9;
197+
uintptr_t agu_mod10;
198+
uintptr_t agu_mod11;
199+
#endif
200+
#ifdef CONFIG_ARC_AGU_LARGE
201+
uintptr_t agu_ap8;
202+
uintptr_t agu_ap9;
203+
uintptr_t agu_ap10;
204+
uintptr_t agu_ap11;
205+
uintptr_t agu_os4;
206+
uintptr_t agu_os5;
207+
uintptr_t agu_os6;
208+
uintptr_t agu_os7;
209+
uintptr_t agu_mod12;
210+
uintptr_t agu_mod13;
211+
uintptr_t agu_mod14;
212+
uintptr_t agu_mod15;
213+
uintptr_t agu_mod16;
214+
uintptr_t agu_mod17;
215+
uintptr_t agu_mod18;
216+
uintptr_t agu_mod19;
217+
uintptr_t agu_mod20;
218+
uintptr_t agu_mod21;
219+
uintptr_t agu_mod22;
220+
uintptr_t agu_mod23;
221+
#endif
160222
#endif
161223
/*
162224
* No need to save r31 (blink), it's either already pushed as the pc or

0 commit comments

Comments
 (0)