| 1 |
|
| 2 |
#ifndef BOOTSTATE_H |
| 3 |
#define BOOTSTATE_H |
| 4 |
|
| 5 |
#include <assert.h> |
| 6 |
#include <stddef.h> |
| 7 |
|
| 8 |
#if ENV_RAMSTAGE |
| 9 |
#include <main_decl.h> |
| 10 |
#endif |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
typedef enum { |
| 77 |
BS_PRE_DEVICE, |
| 78 |
BS_DEV_INIT_CHIPS, |
| 79 |
BS_DEV_ENUMERATE, |
| 80 |
BS_DEV_RESOURCES, |
| 81 |
BS_DEV_ENABLE, |
| 82 |
BS_DEV_INIT, |
| 83 |
BS_POST_DEVICE, |
| 84 |
BS_OS_RESUME_CHECK, |
| 85 |
BS_OS_RESUME, |
| 86 |
BS_WRITE_TABLES, |
| 87 |
BS_PAYLOAD_LOAD, |
| 88 |
BS_PAYLOAD_BOOT, |
| 89 |
} boot_state_t; |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
typedef enum { |
| 94 |
BS_ON_ENTRY, |
| 95 |
BS_ON_EXIT |
| 96 |
} boot_state_sequence_t; |
| 97 |
|
| 98 |
struct boot_state_callback { |
| 99 |
void *arg; |
| 100 |
void (*callback)(void *arg); |
| 101 |
|
| 102 |
struct boot_state_callback *next; |
| 103 |
#if CONFIG(DEBUG_BOOT_STATE) |
| 104 |
const char *location; |
| 105 |
#endif |
| 106 |
}; |
| 107 |
|
| 108 |
static inline const char *bscb_location(const struct boot_state_callback *bscb) |
| 109 |
{ |
| 110 |
#if CONFIG(DEBUG_BOOT_STATE) |
| 111 |
return bscb->location; |
| 112 |
#else |
| 113 |
return dead_code_t(const char *); |
| 114 |
#endif |
| 115 |
} |
| 116 |
|
| 117 |
#if CONFIG(DEBUG_BOOT_STATE) |
| 118 |
#define BOOT_STATE_CALLBACK_LOC __FILE__ ":" STRINGIFY(__LINE__) |
| 119 |
#define BOOT_STATE_CALLBACK_INIT_DEBUG .location = BOOT_STATE_CALLBACK_LOC, |
| 120 |
#define INIT_BOOT_STATE_CALLBACK_DEBUG(bscb_) \ |
| 121 |
do { \ |
| 122 |
bscb_->location = BOOT_STATE_CALLBACK_LOC; \ |
| 123 |
} while (0) |
| 124 |
#else |
| 125 |
#define BOOT_STATE_CALLBACK_INIT_DEBUG |
| 126 |
#define INIT_BOOT_STATE_CALLBACK_DEBUG(bscb_) |
| 127 |
#endif |
| 128 |
|
| 129 |
#define BOOT_STATE_CALLBACK_INIT(func_, arg_) \ |
| 130 |
{ \ |
| 131 |
.arg = arg_, \ |
| 132 |
.callback = func_, \ |
| 133 |
.next = NULL, \ |
| 134 |
BOOT_STATE_CALLBACK_INIT_DEBUG \ |
| 135 |
} |
| 136 |
|
| 137 |
#define BOOT_STATE_CALLBACK(name_, func_, arg_) \ |
| 138 |
struct boot_state_callback name_ = BOOT_STATE_CALLBACK_INIT(func_, arg_) |
| 139 |
|
| 140 |
|
| 141 |
#define INIT_BOOT_STATE_CALLBACK(bscb_, func_, arg_) \ |
| 142 |
do { \ |
| 143 |
INIT_BOOT_STATE_CALLBACK_DEBUG(bscb_) \ |
| 144 |
bscb_->callback = func_; \ |
| 145 |
bscb_->arg = arg_ \ |
| 146 |
} while (0) |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
int boot_state_sched_on_entry(struct boot_state_callback *bscb, |
| 153 |
boot_state_t state); |
| 154 |
int boot_state_sched_on_exit(struct boot_state_callback *bscb, |
| 155 |
boot_state_t state); |
| 156 |
|
| 157 |
struct boot_state_init_entry; |
| 158 |
void boot_state_sched_entries(struct boot_state_init_entry *entries, |
| 159 |
size_t num); |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
int boot_state_block(boot_state_t state, boot_state_sequence_t seq); |
| 164 |
int boot_state_unblock(boot_state_t state, boot_state_sequence_t seq); |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
struct boot_state_init_entry { |
| 170 |
boot_state_t state; |
| 171 |
boot_state_sequence_t when; |
| 172 |
struct boot_state_callback bscb; |
| 173 |
}; |
| 174 |
|
| 175 |
#if ENV_RAMSTAGE |
| 176 |
#define BOOT_STATE_INIT_ATTR __attribute__((used, section(".bs_init"))) |
| 177 |
#else |
| 178 |
#define BOOT_STATE_INIT_ATTR __attribute__((unused)) |
| 179 |
#endif |
| 180 |
|
| 181 |
#define BOOT_STATE_INIT_ENTRY(state_, when_, func_, arg_) \ |
| 182 |
static struct boot_state_init_entry func_ ##_## state_ ##_## when_ = \ |
| 183 |
{ \ |
| 184 |
.state = state_, \ |
| 185 |
.when = when_, \ |
| 186 |
.bscb = BOOT_STATE_CALLBACK_INIT(func_, arg_), \ |
| 187 |
}; \ |
| 188 |
static struct boot_state_init_entry * \ |
| 189 |
bsie_ ## func_ ##_## state_ ##_## when_ BOOT_STATE_INIT_ATTR = \ |
| 190 |
&func_ ##_## state_ ##_## when_; \ |
| 191 |
_Static_assert(!(state_ == BS_PAYLOAD_BOOT && when_ == BS_ON_EXIT), \ |
| 192 |
"Invalid bootstate hook"); \ |
| 193 |
_Static_assert(!(state_ == BS_OS_RESUME && when_ == BS_ON_EXIT), \ |
| 194 |
"Invalid bootstate hook"); |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
void arch_bootstate_coreboot_exit(void); |
| 199 |
|
| 200 |
#endif |