device/azalia_device.c: Add option to lock down GCAP
[coreboot.git] / src / include / thread.h
bloba2c7ed208512b21c56b21e6ac876e86f8f893ffd
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 #ifndef THREAD_H_
3 #define THREAD_H_
5 #include <stdint.h>
6 #include <bootstate.h>
7 #include <arch/cpu.h>
9 #if ENV_RAMSTAGE && CONFIG(COOP_MULTITASKING)
11 struct thread {
12 int id;
13 uintptr_t stack_current;
14 uintptr_t stack_orig;
15 struct thread *next;
16 void (*entry)(void *);
17 void *entry_arg;
18 int can_yield;
21 void threads_initialize(void);
22 /* Get the base of the thread stacks.
23 * Returns pointer to CONFIG_NUM_THREADS*CONFIG_STACK_SIZE contiguous bytes
24 * aligned to CONFIG_STACK_SIZE, or NULL.
26 void *arch_get_thread_stackbase(void);
27 /* Run func(arrg) on a new thread. Return 0 on successful start of thread, < 0
28 * when thread could not be started. Note that the thread will block the
29 * current state in the boot state machine until it is complete. */
30 int thread_run(void (*func)(void *), void *arg);
31 /* thread_run_until is the same as thread_run() except that it blocks state
32 * transitions from occurring in the (state, seq) pair of the boot state
33 * machine. */
34 int thread_run_until(void (*func)(void *), void *arg,
35 boot_state_t state, boot_state_sequence_t seq);
36 /* Return 0 on successful yield for the given amount of time, < 0 when thread
37 * did not yield. */
38 int thread_yield_microseconds(unsigned int microsecs);
40 /* Allow and prevent thread cooperation on current running thread. By default
41 * all threads are marked to be cooperative. That means a thread can yield
42 * to another thread at a pre-determined switch point. Current there is
43 * only a single place where switching may occur: a call to udelay(). */
44 void thread_cooperate(void);
45 void thread_prevent_coop(void);
47 static inline void thread_init_cpu_info_non_bsp(struct cpu_info *ci)
49 ci->thread = NULL;
52 /* Architecture specific thread functions. */
53 asmlinkage void switch_to_thread(uintptr_t new_stack, uintptr_t *saved_stack);
54 /* Set up the stack frame for a new thread so that a switch_to_thread() call
55 * will enter the thread_entry() function with arg as a parameter. The
56 * saved_stack field in the struct thread needs to be updated accordingly. */
57 void arch_prepare_thread(struct thread *t,
58 asmlinkage void (*thread_entry)(void *), void *arg);
59 #else
60 static inline void threads_initialize(void) {}
61 static inline int thread_run(void (*func)(void *), void *arg) { return -1; }
62 static inline int thread_yield_microseconds(unsigned int microsecs)
64 return -1;
66 static inline void thread_cooperate(void) {}
67 static inline void thread_prevent_coop(void) {}
68 struct cpu_info;
69 static inline void thread_init_cpu_info_non_bsp(struct cpu_info *ci) { }
70 #endif
72 #endif /* THREAD_H_ */