1 #ifndef _GPXE_API_H 2 #define _GPXE_API_H 3 4 /** @file 5 * 6 * gPXE internal APIs 7 * 8 * There are various formally-defined APIs internal to gPXE, with 9 * several differing implementations specific to particular execution 10 * environments (e.g. PC BIOS, EFI, LinuxBIOS). 11 * 12 */ 13 14 FILE_LICENCE ( GPL2_OR_LATER ); 15 16 /** @defgroup Single-implementation APIs 17 * 18 * These are APIs for which only a single implementation may be 19 * compiled in at any given time. 20 * 21 * @{ 22 */ 23 24 /** 25 * Calculate function implementation name 26 * 27 * @v _prefix Subsystem prefix 28 * @v _api_func API function 29 * @ret _subsys_func Subsystem API function 30 * 31 * The subsystem prefix should be an empty string for the currently 32 * selected subsystem, and should be a subsystem-unique string for all 33 * other subsystems. 34 */ 35 #define SINGLE_API_NAME( _prefix, _api_func ) _prefix ## _api_func 36 37 /** 38 * Calculate static inline function name 39 * 40 * @v _prefix Subsystem prefix 41 * @v _api_func API function 42 * @ret _subsys_func Subsystem API function 43 */ 44 #define SINGLE_API_INLINE( _prefix, _api_func ) \ 45 SINGLE_API_NAME ( _prefix, _api_func ) 46 47 /** 48 * Provide an API implementation 49 * 50 * @v _prefix Subsystem prefix 51 * @v _api_func API function 52 * @v _func Implementing function 53 */ 54 #define PROVIDE_SINGLE_API( _prefix, _api_func, _func ) \ 55 /* Ensure that _api_func exists */ \ 56 typeof ( _api_func ) _api_func; \ 57 /* Ensure that _func exists */ \ 58 typeof ( _func ) _func; \ 59 /* Ensure that _func is type-compatible with _api_func */ \ 60 typeof ( _api_func ) _func; \ 61 /* Ensure that _subsys_func is non-static */ \ 62 extern typeof ( _api_func ) SINGLE_API_NAME ( _prefix, _api_func ); \ 63 /* Provide symbol alias from _subsys_func to _func */ \ 64 typeof ( _api_func ) SINGLE_API_NAME ( _prefix, _api_func ) \ 65 __attribute__ (( alias ( #_func ) )); 66 67 /** 68 * Provide a static inline API implementation 69 * 70 * @v _prefix Subsystem prefix 71 * @v _api_func API function 72 */ 73 #define PROVIDE_SINGLE_API_INLINE( _prefix, _api_func ) \ 74 /* Ensure that _api_func exists */ \ 75 typeof ( _api_func ) _api_func; \ 76 /* Ensure that _subsys_func exists and is static */ \ 77 static typeof ( SINGLE_API_INLINE ( _prefix, _api_func ) ) \ 78 SINGLE_API_INLINE ( _prefix, _api_func ); \ 79 /* Ensure that _subsys_func is type-compatible with _api_func */ \ 80 typeof ( _api_func ) SINGLE_API_INLINE ( _prefix, _api_func ); 81 82 /** @} */ 83 84 #endif /* _GPXE_API_H */ 85