mb/google/brya/uldrenite: Add WWAN RW350R-GL power on sequence
[coreboot2.git] / src / arch / x86 / include / mode_switch.h
blob54969b2e67c26d5f82bb1a644e593cd40104586e
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <stdint.h>
5 #if ENV_X86_64
6 /*
7 * Assembly code that drops into protected mode and calls the function
8 * specified as first argument, which must have been compiled for x86_32.
9 * After the function returns it enters long mode again.
10 * The function pointer destination must be below 4GiB in physical memory.
12 * The called function has 0-3 arguments and returns an int.
14 int protected_mode_call_wrapper(uint32_t func_ptr,
15 uint32_t opt_arg1,
16 uint32_t opt_arg2,
17 uint32_t opt_arg3);
20 * Drops into protected mode and calls the function, which must have been compiled for x86_32.
21 * After the function returns it enters long mode again.
22 * The function pointer destination must be below 4GiB in physical memory.
24 * The called function doesn't have arguments and returns an int.
26 static inline int protected_mode_call(void *func)
28 return protected_mode_call_wrapper((uintptr_t)func, 0, 0, 0);
32 * Drops into protected mode and calls the function, which must have been compiled for x86_32.
33 * After the function returns it enters long mode again.
34 * The function pointer destination must be below 4GiB in physical memory.
35 * Only the lower 32bits of the argument are passed to the called function.
37 * The called function have one argument and returns an int.
39 static inline int protected_mode_call_1arg(void *func, uint32_t arg1)
41 return protected_mode_call_wrapper((uintptr_t)func, arg1, 0, 0);
45 * Drops into protected mode and calls the function, which must have been compiled for x86_32.
46 * After the function returns it enters long mode again.
47 * The function pointer destination must be below 4GiB in physical memory.
48 * Only the lower 32bits of the argument are passed to the called function.
50 * The called function has two arguments and returns an int.
52 static inline int protected_mode_call_2arg(void *func, uint32_t arg1, uint32_t arg2)
54 return protected_mode_call_wrapper((uintptr_t)func, arg1, arg2, 0);
58 * Drops into protected mode and calls the function, which must have been compiled for x86_32.
59 * After the function returns it enters long mode again.
60 * The function pointer destination must be below 4GiB in physical memory.
61 * Only the lower 32bits of the argument are passed to the called function.
63 * The called function has two arguments and returns an int.
65 static inline int protected_mode_call_3arg(void *func, uint32_t arg1, uint32_t arg2,
66 uint32_t arg3)
68 return protected_mode_call_wrapper((uintptr_t)func, arg1, arg2, arg3);
70 #else
71 static inline int protected_mode_call(void *func)
73 int (*doit)(void) = func;
75 return doit();
78 static inline int protected_mode_call_1arg(void *func, uint32_t arg1)
80 int (*doit)(uint32_t arg1) = func;
82 return doit(arg1);
85 static inline int protected_mode_call_2arg(void *func, uint32_t arg1, uint32_t arg2)
87 int (*doit)(uint32_t arg1, uint32_t arg2) = func;
89 return doit(arg1, arg2);
92 static inline int protected_mode_call_3arg(void *func, uint32_t arg1, uint32_t arg2,
93 uint32_t arg3)
95 int (*doit)(uint32_t arg1, uint32_t arg2, uint32_t arg3) = func;
97 return doit(arg1, arg2, arg3);
99 #endif