Alternative library and kernel for add-in development on fx-9860G and fx-CG50 under Linux.
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.

126 lines
4.6KB

  1. //---
  2. // gint:drivers - General tools for drivers
  3. //---
  4. #ifndef GINT_DRIVERS
  5. #define GINT_DRIVERS
  6. #include <gint/defs/attributes.h>
  7. #include <gint/defs/types.h>
  8. //---
  9. // Driver procedure flow
  10. //
  11. // Drivers are initialized in priority order, and in linking order within
  12. // the same priority level (pretty much undefined). Make sure every
  13. // driver's priority level is higher than those of its dependencies.
  14. //
  15. // At initialization, the following functions are called:
  16. // 1. driver_sh3() [if not NULL, SH3 fx9860g only]
  17. // 2. ctx_save(sys_ctx) [if not NULL]
  18. // 3. init() [if not NULL]
  19. //
  20. // Then, if the on-screen boot log is enabled, the status() function is
  21. // called and the returned string is displayed (21 characters max).
  22. // 4. status() [if not NULL, if GINT_BOOT_LOG is defined]
  23. //
  24. // If the gint_switch() function is called to temporarily give back
  25. // control to the operating system, the state of each driver is saved to
  26. // the stack, then restored from there.
  27. // 5. ctx_save(stack) [if not NULL]
  28. // 6. ctx_restore(stack) [if not NULL]
  29. //
  30. // When finally the driver is unloaded, the system context is restored.
  31. // 7. ctx_restore(sys_ctx) [if not NULL]
  32. //---
  33. /* gint_driver_t - driver meta-information used by gint */
  34. typedef struct
  35. {
  36. /* Driver name */
  37. const char *name;
  38. /* driver_sh3() - rectify driver initialization on SH3 platforms
  39. This function is called during driver initialization on SH3. It may
  40. be NULL. */
  41. void (*driver_sh3)(void);
  42. /* init() - initialize the driver
  43. This function is called after ctx_save() and needs not save the
  44. system setting. It is typically used to initialize registers to
  45. suitable values on startup. If there is no init function, this field
  46. may be set to NULL */
  47. void (*init)(void);
  48. /* unload() - deinitialize the driver
  49. This function is called before ctx_restore() when gint is unloaded.
  50. If there is no unload function, the field may be set to NULL */
  51. void (*unload)(void);
  52. /* Size of a context object for the driver */
  53. uint ctx_size;
  54. /* System context. The driver has to allocate a buffer of size at least
  55. ctx_size, where gint stores the system's configuration. It is
  56. advised to place this buffer in the .gint_bss section using the GBSS
  57. macro of <defs/attributes.h> if it doesn't need to be initialized */
  58. void *sys_ctx;
  59. /* ctx_save() - save the driver's hardware support
  60. This function is provided by the driver to save the state of its
  61. hardware support (memory-mapped MPU registers, port state, etc).
  62. @ctx A buffer of size ctx_size */
  63. void (*ctx_save)(void *ctx);
  64. /* ctx_restore() - restore a saved context
  65. This function is provided by the driver to restore the state saved
  66. by ctx_save(). It can alter the contents of the buffer freely.
  67. @ctx A context buffer filled by ctx_save() */
  68. void (*ctx_restore)(void *ctx);
  69. /* status() - status string generation
  70. When the boot log is defined, this function is called to print
  71. information returned by the driver, for debugging purposes. This is
  72. expected to be a short (max 21 bytes) string because only a few
  73. lines are available for all drivers.
  74. Returns a pointer to a string; a static buffer is suitable. */
  75. const char * (*status)(void);
  76. } GPACKED(4) gint_driver_t;
  77. /* GINT_DECLARE_DRIVER() - make a driver visible to gint
  78. Use this macro to expose a driver by passing it the name of a gint_driver_t
  79. structure. This macro moves the structure to the .gint.drivers.* sections,
  80. which are automatically traversed at startup.
  81. The @level argument represents the priority level: lower numbers mean that
  82. drivers will be loaded sooner. This numbering allows a primitive form of
  83. dependency for drivers. You need to specify a level which is strictly
  84. higher than the level of all the drivers you depend on. */
  85. #define GINT_DECLARE_DRIVER(level, name) \
  86. GSECTION(".gint.drivers." #level) extern gint_driver_t name;
  87. /* GINT_DRIVER_SH3() - declare a function for SH3-rectification
  88. This macro makes its argument NULL on fxcg50, this way the named function
  89. can be defined under #ifdef FX9860G while keeping the structure clean. */
  90. #ifdef FXCG50
  91. #define GINT_DRIVER_SH3(name) NULL
  92. #else
  93. #define GINT_DRIVER_SH3(name) name
  94. #endif
  95. /* GINT_DRIVER_STATUS() - declare a function for status string generation
  96. This macro makes its argument NULL when GINT_BOOT_LOG is defuned, this way
  97. the named function can be defined under #ifdef GINT_BOOT_LOG while keeping
  98. the structure clean. */
  99. #ifdef GINT_BOOT_LOG
  100. #define GINT_DRIVER_STATUS(name) name
  101. #else
  102. #define GINT_DRIVER_STATUS(name) NULL
  103. #endif
  104. #endif /* GINT_DRIVERS */