1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  *  The driver for the Cirrus Logic's Sound Fusion CS46XX based soundcards
4  *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
5  *
6  * NOTE: comments are copy/paste from cwcemb80.lst
7  * provided by Tom Woller at Cirrus (my only
8  * documentation about the SP OS running inside
9  * the DSP)
10  */
11 
12 #ifndef __CS46XX_DSP_TASK_TYPES_H__
13 #define __CS46XX_DSP_TASK_TYPES_H__
14 
15 #include "cs46xx_dsp_scb_types.h"
16 
17 /*********************************************************************************************
18 Example hierarchy of stream control blocks in the SP
19 
20 hfgTree
21 Ptr____Call (c)
22        \
23  -------+------         -------------      -------------      -------------      -----
24 | SBlaster IF  |______\| Foreground  |___\| Middlegr'nd |___\| Background  |___\| Nul |
25 |              |Goto  /| tree header |g  /| tree header |g  /| tree header |g  /| SCB |r
26  -------------- (g)     -------------      -------------      -------------      -----
27        |c                     |c                 |c                 |c
28        |                      |                  |                  |
29       \/                  -------------      -------------      -------------
30                        | Foreground  |_\  | Middlegr'nd |_\  | Background  |_\
31                        |     tree    |g/  |    tree     |g/  |     tree    |g/
32                         -------------      -------------      -------------
33                               |c                 |c                 |c
34                               |                  |                  |
35                              \/                 \/                 \/
36 
37 *********************************************************************************************/
38 
39 #define		HFG_FIRST_EXECUTE_MODE			0x0001
40 #define		HFG_FIRST_EXECUTE_MODE_BIT		0
41 #define		HFG_CONTEXT_SWITCH_MODE			0x0002
42 #define		HFG_CONTEXT_SWITCH_MODE_BIT		1
43 
44 #define MAX_FG_STACK_SIZE 	32			/* THESE NEED TO BE COMPUTED PROPERLY */
45 #define MAX_MG_STACK_SIZE 	16
46 #define MAX_BG_STACK_SIZE 	9
47 #define MAX_HFG_STACK_SIZE	4
48 
49 #define SLEEP_ACTIVE_INCREMENT		0		/* Enable task tree thread to go to sleep
50 											   This should only ever be used on the Background thread */
51 #define STANDARD_ACTIVE_INCREMENT	1		/* Task tree thread normal operation */
52 #define SUSPEND_ACTIVE_INCREMENT	2		/* Cause execution to suspend in the task tree thread
53                                                This should only ever be used on the Background thread */
54 
55 #define HOSTFLAGS_DISABLE_BG_SLEEP  0       /* Host-controlled flag that determines whether we go to sleep
56                                                at the end of BG */
57 
58 /* Minimal context save area for Hyper Forground */
59 struct dsp_hf_save_area {
60 	u32	r10_save;
61 	u32	r54_save;
62 	u32	r98_save;
63 
64 	___DSP_DUAL_16BIT_ALLOC(
65 	    status_save,
66 	    ind_save
67 	)
68 
69 	___DSP_DUAL_16BIT_ALLOC(
70 	    rci1_save,
71 	    rci0_save
72 	)
73 
74 	u32	r32_save;
75 	u32	r76_save;
76 	u32	rsd2_save;
77 
78        	___DSP_DUAL_16BIT_ALLOC(
79 	      rsi2_save,	  /* See TaskTreeParameterBlock for
80 				     remainder of registers  */
81 	      rsa2Save
82 	)
83 	/* saved as part of HFG context  */
84 };
85 
86 
87 /* Task link data structure */
88 struct dsp_tree_link {
89 	___DSP_DUAL_16BIT_ALLOC(
90 	/* Pointer to sibling task control block */
91 	    next_scb,
92 	/* Pointer to child task control block */
93 	    sub_ptr
94 	)
95 
96 	___DSP_DUAL_16BIT_ALLOC(
97 	/* Pointer to code entry point */
98 	    entry_point,
99 	/* Pointer to local data */
100 	    this_spb
101 	)
102 };
103 
104 
105 struct dsp_task_tree_data {
106 	___DSP_DUAL_16BIT_ALLOC(
107 	/* Initial tock count; controls task tree execution rate */
108 	    tock_count_limit,
109 	/* Tock down counter */
110 	    tock_count
111 	)
112 
113 	/* Add to ActiveCount when TockCountLimit reached:
114 	   Subtract on task tree termination */
115 	___DSP_DUAL_16BIT_ALLOC(
116 	    active_tncrement,
117 	/* Number of pending activations for task tree */
118 	    active_count
119 	)
120 
121         ___DSP_DUAL_16BIT_ALLOC(
122 	/* BitNumber to enable modification of correct bit in ActiveTaskFlags */
123 	    active_bit,
124 	/* Pointer to OS location for indicating current activity on task level */
125 	    active_task_flags_ptr
126 	)
127 
128 	/* Data structure for controlling movement of memory blocks:-
129 	   currently unused */
130 	___DSP_DUAL_16BIT_ALLOC(
131 	    mem_upd_ptr,
132 	/* Data structure for controlling synchronous link update */
133 	    link_upd_ptr
134 	)
135 
136 	___DSP_DUAL_16BIT_ALLOC(
137 	/* Save area for remainder of full context. */
138 	    save_area,
139 	/* Address of start of local stack for data storage */
140 	    data_stack_base_ptr
141 	)
142 
143 };
144 
145 
146 struct dsp_interval_timer_data
147 {
148 	/* These data items have the same relative locations to those */
149 	___DSP_DUAL_16BIT_ALLOC(
150 	     interval_timer_period,
151 	     itd_unused
152 	)
153 
154 	/* used for this data in the SPOS control block for SPOS 1.0 */
155 	___DSP_DUAL_16BIT_ALLOC(
156 	     num_FG_ticks_this_interval,
157 	     num_intervals
158 	)
159 };
160 
161 
162 /* This structure contains extra storage for the task tree
163    Currently, this additional data is related only to a full context save */
164 struct dsp_task_tree_context_block {
165 	/* Up to 10 values are saved onto the stack.  8 for the task tree, 1 for
166 	   The access to the context switch (call or interrupt), and 1 spare that
167 	   users should never use.  This last may be required by the system */
168 	___DSP_DUAL_16BIT_ALLOC(
169 	     stack1,
170 	     stack0
171 	)
172 	___DSP_DUAL_16BIT_ALLOC(
173 	     stack3,
174 	     stack2
175 	)
176 	___DSP_DUAL_16BIT_ALLOC(
177 	     stack5,
178 	     stack4
179 	)
180 	___DSP_DUAL_16BIT_ALLOC(
181 	     stack7,
182 	     stack6
183 	)
184 	___DSP_DUAL_16BIT_ALLOC(
185 	     stack9,
186 	     stack8
187 	)
188 
189 	u32	  saverfe;
190 
191 	/* Value may be overwritten by stack save algorithm.
192 	   Retain the size of the stack data saved here if used */
193 	___DSP_DUAL_16BIT_ALLOC(
194              reserved1,
195   	     stack_size
196 	)
197 	u32		saverba;	  /* (HFG) */
198 	u32		saverdc;
199 	u32		savers_config_23; /* (HFG) */
200 	u32		savers_DMA23;	  /* (HFG) */
201 	u32		saversa0;
202 	u32		saversi0;
203 	u32		saversa1;
204 	u32		saversi1;
205 	u32		saversa3;
206 	u32		saversd0;
207 	u32		saversd1;
208 	u32		saversd3;
209 	u32		savers_config01;
210 	u32		savers_DMA01;
211 	u32		saveacc0hl;
212 	u32		saveacc1hl;
213 	u32		saveacc0xacc1x;
214 	u32		saveacc2hl;
215 	u32		saveacc3hl;
216 	u32		saveacc2xacc3x;
217 	u32		saveaux0hl;
218 	u32		saveaux1hl;
219 	u32		saveaux0xaux1x;
220 	u32		saveaux2hl;
221 	u32		saveaux3hl;
222 	u32		saveaux2xaux3x;
223 	u32		savershouthl;
224 	u32		savershoutxmacmode;
225 };
226 
227 
228 struct dsp_task_tree_control_block {
229 	struct dsp_hf_save_area			context;
230 	struct dsp_tree_link			links;
231 	struct dsp_task_tree_data		data;
232 	struct dsp_task_tree_context_block	context_blk;
233 	struct dsp_interval_timer_data		int_timer;
234 };
235 
236 
237 #endif /* __DSP_TASK_TYPES_H__ */
238