src/include: Move storage class to beginning of declaration
[coreboot.git] / src / include / thread.h
blob586fb3afd0e447189cee51e2172a2aeee4cc54d8
1 /*
2 * This file is part of the coreboot project.
4 * Copyright (C) 2013 Google, Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 #ifndef THREAD_H_
16 #define THREAD_H_
18 #include <stddef.h>
19 #include <stdint.h>
20 #include <bootstate.h>
21 #include <timer.h>
22 #include <arch/cpu.h>
24 #if CONFIG_COOP_MULTITASKING && !defined(__SMM__) && !defined(__PRE_RAM__)
26 struct thread {
27 int id;
28 uintptr_t stack_current;
29 uintptr_t stack_orig;
30 struct thread *next;
31 void (*entry)(void *);
32 void *entry_arg;
33 int can_yield;
36 void threads_initialize(void);
37 /* Get the base of the thread stacks.
38 * Returns pointer to CONFIG_NUM_THREADS*CONFIG_STACK_SIZE contiguous bytes
39 * aligned to CONFIG_STACK_SIZE, or NULL.
41 void *arch_get_thread_stackbase(void);
42 /* Run func(arrg) on a new thread. Return 0 on successful start of thread, < 0
43 * when thread could not be started. Note that the thread will block the
44 * current state in the boot state machine until it is complete. */
45 int thread_run(void (*func)(void *), void *arg);
46 /* thread_run_until is the same as thread_run() except that it blocks state
47 * transitions from occurring in the (state, seq) pair of the boot state
48 * machine. */
49 int thread_run_until(void (*func)(void *), void *arg,
50 boot_state_t state, boot_state_sequence_t seq);
51 /* Return 0 on successful yield for the given amount of time, < 0 when thread
52 * did not yield. */
53 int thread_yield_microseconds(unsigned int microsecs);
55 /* Allow and prevent thread cooperation on current running thread. By default
56 * all threads are marked to be cooperative. That means a thread can yield
57 * to another thread at a pre-determined switch point. Current there is
58 * only a single place where switching may occur: a call to udelay(). */
59 void thread_cooperate(void);
60 void thread_prevent_coop(void);
62 static inline void thread_init_cpu_info_non_bsp(struct cpu_info *ci)
64 ci->thread = NULL;
67 /* Architecture specific thread functions. */
68 asmlinkage void switch_to_thread(uintptr_t new_stack, uintptr_t *saved_stack);
69 /* Set up the stack frame for a new thread so that a switch_to_thread() call
70 * will enter the thread_entry() function with arg as a parameter. The
71 * saved_stack field in the struct thread needs to be updated accordingly. */
72 void arch_prepare_thread(struct thread *t,
73 asmlinkage void (*thread_entry)(void *), void *arg);
74 #else
75 static inline void threads_initialize(void) {}
76 static inline int thread_run(void (*func)(void *), void *arg) { return -1; }
77 static inline int thread_yield_microseconds(unsigned int microsecs)
79 return -1;
81 static inline void thread_cooperate(void) {}
82 static inline void thread_prevent_coop(void) {}
83 struct cpu_info;
84 static inline void thread_init_cpu_info_non_bsp(struct cpu_info *ci) { }
85 #endif
87 #endif /* THREAD_H_ */