Skip to content

Commit c07ba31

Browse files
authored
Merge pull request #65 from tlauda/topic/free_core_structs
arch: free core specific structs
2 parents 6eb484a + ce53ba1 commit c07ba31

4 files changed

Lines changed: 96 additions & 5 deletions

File tree

src/arch/xtensa/include/arch/task.h

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,26 +171,67 @@ static inline void arch_allocate_tasks(void)
171171
{
172172
/* irq low */
173173
struct irq_task **low = task_irq_low_get();
174-
*low = rzalloc(RZONE_SYS, SOF_MEM_CAPS_RAM, sizeof(**low));
174+
*low = rzalloc(RZONE_RUNTIME, SOF_MEM_CAPS_RAM, sizeof(**low));
175175
list_init(&((*low)->list));
176176
spinlock_init(&((*low)->lock));
177177
(*low)->irq = PLATFORM_IRQ_TASK_LOW;
178178

179179
/* irq medium */
180180
struct irq_task **med = task_irq_med_get();
181-
*med = rzalloc(RZONE_SYS, SOF_MEM_CAPS_RAM, sizeof(**med));
181+
*med = rzalloc(RZONE_RUNTIME, SOF_MEM_CAPS_RAM, sizeof(**med));
182182
list_init(&((*med)->list));
183183
spinlock_init(&((*med)->lock));
184184
(*med)->irq = PLATFORM_IRQ_TASK_MED;
185185

186186
/* irq high */
187187
struct irq_task **high = task_irq_high_get();
188-
*high = rzalloc(RZONE_SYS, SOF_MEM_CAPS_RAM, sizeof(**high));
188+
*high = rzalloc(RZONE_RUNTIME, SOF_MEM_CAPS_RAM, sizeof(**high));
189189
list_init(&((*high)->list));
190190
spinlock_init(&((*high)->lock));
191191
(*high)->irq = PLATFORM_IRQ_TASK_HIGH;
192192
}
193193

194+
/**
195+
* \brief Frees IRQ tasks.
196+
*/
197+
static inline void arch_free_tasks(void)
198+
{
199+
uint32_t flags;
200+
201+
/* free IRQ low task */
202+
struct irq_task **low = task_irq_low_get();
203+
204+
spin_lock_irq(&(*low)->lock, flags);
205+
interrupt_disable(PLATFORM_IRQ_TASK_LOW);
206+
interrupt_unregister(PLATFORM_IRQ_TASK_LOW);
207+
list_item_del(&(*low)->list);
208+
spin_unlock_irq(&(*low)->lock, flags);
209+
210+
rfree(*low);
211+
212+
/* free IRQ medium task */
213+
struct irq_task **med = task_irq_med_get();
214+
215+
spin_lock_irq(&(*med)->lock, flags);
216+
interrupt_disable(PLATFORM_IRQ_TASK_MED);
217+
interrupt_unregister(PLATFORM_IRQ_TASK_MED);
218+
list_item_del(&(*med)->list);
219+
spin_unlock_irq(&(*med)->lock, flags);
220+
221+
rfree(*med);
222+
223+
/* free IRQ high task */
224+
struct irq_task **high = task_irq_high_get();
225+
226+
spin_lock_irq(&(*high)->lock, flags);
227+
interrupt_disable(PLATFORM_IRQ_TASK_HIGH);
228+
interrupt_unregister(PLATFORM_IRQ_TASK_HIGH);
229+
list_item_del(&(*high)->list);
230+
spin_unlock_irq(&(*high)->lock, flags);
231+
232+
rfree(*high);
233+
}
234+
194235
/**
195236
* \brief Assigns IRQ tasks to interrupts.
196237
*/

src/arch/xtensa/smp/include/arch/idc.h

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ static inline void arch_idc_init(void)
259259

260260
/* initialize idc data */
261261
struct idc **idc = idc_get();
262-
*idc = rzalloc(RZONE_SYS, SOF_MEM_CAPS_RAM, sizeof(**idc));
262+
*idc = rzalloc(RZONE_RUNTIME, SOF_MEM_CAPS_RAM, sizeof(**idc));
263263
spinlock_init(&((*idc)->lock));
264264
(*idc)->busy_bit_mask = idc_get_busy_bit_mask(core);
265265
(*idc)->done_bit_mask = idc_get_done_bit_mask(core);
@@ -274,4 +274,29 @@ static inline void arch_idc_init(void)
274274
(*idc)->busy_bit_mask | (*idc)->done_bit_mask);
275275
}
276276

277+
/**
278+
* \brief Frees IDC data and unregisters interrupt.
279+
*/
280+
static inline void idc_free(void)
281+
{
282+
int core = arch_cpu_get_id();
283+
int i = 0;
284+
uint32_t idctfc;
285+
286+
trace_idc("IDF");
287+
288+
/* disable and unregister interrupt */
289+
interrupt_disable(PLATFORM_IDC_INTERRUPT(core));
290+
interrupt_unregister(PLATFORM_IDC_INTERRUPT(core));
291+
292+
/* clear BUSY bits */
293+
for (i = 0; i < PLATFORM_CORE_COUNT; i++) {
294+
idctfc = idc_read(IPC_IDCTFC(i), core);
295+
if (idctfc & IPC_IDCTFC_BUSY)
296+
idc_write(IPC_IDCTFC(i), core, idctfc);
297+
}
298+
299+
rfree(*idc_get());
300+
}
301+
277302
#endif

src/include/sof/schedule.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,6 @@ static inline void schedule_task_config(struct task *task, uint16_t priority,
110110

111111
int scheduler_init(struct sof *sof);
112112

113+
void scheduler_free(void);
114+
113115
#endif

src/lib/schedule.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ int scheduler_init(struct sof *sof)
374374
trace_pipe("ScI");
375375

376376
struct schedule_data **sch = arch_schedule_get();
377-
*sch = rzalloc(RZONE_SYS, SOF_MEM_CAPS_RAM, sizeof(**sch));
377+
*sch = rzalloc(RZONE_RUNTIME, SOF_MEM_CAPS_RAM, sizeof(**sch));
378378
list_init(&((*sch)->list));
379379
spinlock_init(&((*sch)->lock));
380380
(*sch)->clock = PLATFORM_SCHED_CLOCK;
@@ -389,3 +389,26 @@ int scheduler_init(struct sof *sof)
389389

390390
return 0;
391391
}
392+
393+
/* Frees scheduler */
394+
void scheduler_free(void)
395+
{
396+
struct schedule_data **sch = arch_schedule_get();
397+
uint32_t flags;
398+
399+
spin_lock_irq(&(*sch)->lock, flags);
400+
401+
/* disable and unregister scheduler interrupt */
402+
interrupt_disable(PLATFORM_SCHEDULE_IRQ);
403+
interrupt_unregister(PLATFORM_SCHEDULE_IRQ);
404+
405+
/* free arch tasks */
406+
arch_free_tasks();
407+
408+
work_cancel_default(&(*sch)->work);
409+
list_item_del(&(*sch)->list);
410+
411+
spin_unlock_irq(&(*sch)->lock, flags);
412+
413+
rfree(*sch);
414+
}

0 commit comments

Comments
 (0)