deviceapi.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #ifndef BFG_DEVICEAPI_H
  2. #define BFG_DEVICEAPI_H
  3. #include <stdbool.h>
  4. #include <stdint.h>
  5. #include <sys/time.h>
  6. #include <uthash.h>
  7. #include "miner.h"
  8. struct driver_registration;
  9. struct driver_registration {
  10. const struct device_drv *drv;
  11. struct driver_registration *next_dname;
  12. struct driver_registration *next_prio;
  13. struct driver_registration *next; // DO NOT USE
  14. };
  15. extern struct driver_registration *_bfg_drvreg1;
  16. extern struct driver_registration *_bfg_drvreg2;
  17. extern void bfg_devapi_init();
  18. #define BFG_FOREACH_DRIVER_BY_DNAME(reg, tmp) \
  19. LL_FOREACH_SAFE2(_bfg_drvreg1, reg, tmp, next_dname)
  20. #define BFG_FOREACH_DRIVER_BY_PRIORITY(reg, tmp) \
  21. LL_FOREACH_SAFE2(_bfg_drvreg2, reg, tmp, next_prio)
  22. extern void _bfg_register_driver(const struct device_drv *);
  23. #define BFG_REGISTER_DRIVER(drv) \
  24. struct device_drv drv; \
  25. __attribute__((constructor)) \
  26. static void __bfg_register_drv_ ## drv() { \
  27. _bfg_register_driver(&drv); \
  28. } \
  29. // END BFG_REGISTER_DRIVER
  30. extern bool bfg_need_detect_rescan;
  31. extern void request_work(struct thr_info *);
  32. extern struct work *get_work(struct thr_info *);
  33. extern bool hashes_done(struct thr_info *, int64_t hashes, struct timeval *tvp_hashes, uint32_t *max_nonce);
  34. extern bool hashes_done2(struct thr_info *, int64_t hashes, uint32_t *max_nonce);
  35. extern void mt_disable_start(struct thr_info *);
  36. extern void mt_disable_finish(struct thr_info *);
  37. extern void mt_disable(struct thr_info *); // blocks until reenabled
  38. extern int restart_wait(struct thr_info *, unsigned int ms);
  39. extern void minerloop_scanhash(struct thr_info *);
  40. extern void mt_disable_start__async(struct thr_info *);
  41. extern bool do_job_prepare(struct thr_info *, struct timeval *tvp_now);
  42. extern void job_prepare_complete(struct thr_info *);
  43. extern void do_get_results(struct thr_info *, bool proceed_with_new_job);
  44. extern void job_results_fetched(struct thr_info *);
  45. extern void do_job_start(struct thr_info *);
  46. extern void mt_job_transition(struct thr_info *);
  47. extern void job_start_complete(struct thr_info *);
  48. extern void job_start_abort(struct thr_info *, bool failure);
  49. extern bool do_process_results(struct thr_info *, struct timeval *tvp_now, struct work *, bool stopping);
  50. extern void minerloop_async(struct thr_info *);
  51. extern void minerloop_queue(struct thr_info *);
  52. // Establishes a simple way for external threads to directly communicate with device
  53. extern void cgpu_setup_control_requests(struct cgpu_info *);
  54. extern void cgpu_request_control(struct cgpu_info *);
  55. extern void cgpu_release_control(struct cgpu_info *);
  56. extern void *miner_thread(void *);
  57. extern void add_cgpu_live(void*);
  58. extern bool add_cgpu_slave(struct cgpu_info *, struct cgpu_info *master);
  59. enum bfg_set_device_replytype {
  60. SDR_AUTO,
  61. SDR_OK,
  62. SDR_ERR,
  63. SDR_HELP,
  64. SDR_UNKNOWN,
  65. SDR_NOSUPP,
  66. };
  67. typedef const char *(*bfg_set_device_func_t)(struct cgpu_info *proc, const char *optname, const char *newvalue, char *replybuf, enum bfg_set_device_replytype *out_success);
  68. struct bfg_set_device_definition {
  69. const char *optname;
  70. bfg_set_device_func_t func;
  71. const char *description;
  72. };
  73. extern const char *proc_set_device(struct cgpu_info *proc, char *optname, char *newvalue, char *replybuf, enum bfg_set_device_replytype *out_success);
  74. typedef bool(*detectone_func_t)(const char*);
  75. typedef int(*autoscan_func_t)();
  76. enum generic_detect_flags {
  77. GDF_REQUIRE_DNAME = 2,
  78. GDF_DEFAULT_NOAUTO = 4,
  79. };
  80. extern int _serial_detect(struct device_drv *api, detectone_func_t, autoscan_func_t, int flags);
  81. #define noserial_detect_manual(api, autoscan) \
  82. _serial_detect(api, NULL , autoscan, 4)
  83. #define generic_detect(drv, detectone, autoscan, flags) _serial_detect(drv, detectone, autoscan, flags)
  84. extern FILE *open_bitstream(const char *dname, const char *filename);
  85. extern void close_device_fd(struct thr_info *);
  86. #define for_each_managed_proc(procvar, dev) \
  87. for (struct cgpu_info *procvar = dev; procvar; procvar = procvar->next_proc)
  88. #define for_each_logical_proc(procvar, dev) \
  89. for (struct cgpu_info *procvar = dev; procvar && procvar->device == (dev); procvar = procvar->next_proc)
  90. extern struct cgpu_info *device_proc_by_id(struct cgpu_info *dev, int procid);
  91. #endif