You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

api.h 2.5KB

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