deviceapi.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. UT_hash_handle hh; // hash & order by dname
  12. UT_hash_handle hh2; // hash by name, order by priority
  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_FIND_DRV_BY_DNAME(reg, name, namelen) \
  19. HASH_FIND(hh , _bfg_drvreg1, name, namelen, reg)
  20. #define BFG_FIND_DRV_BY_NAME(reg, name, namelen) \
  21. HASH_FIND(hh2, _bfg_drvreg2, name, namelen, reg)
  22. #define BFG_FOREACH_DRIVER_BY_DNAME(reg, tmp) \
  23. HASH_ITER(hh , _bfg_drvreg1, reg, tmp)
  24. #define BFG_FOREACH_DRIVER_BY_PRIORITY(reg, tmp) \
  25. HASH_ITER(hh2, _bfg_drvreg2, reg, tmp)
  26. extern void _bfg_register_driver(const struct device_drv *);
  27. #define BFG_REGISTER_DRIVER(drv) \
  28. struct device_drv drv; \
  29. __attribute__((constructor)) \
  30. static void __bfg_register_drv_ ## drv() { \
  31. _bfg_register_driver(&drv); \
  32. } \
  33. // END BFG_REGISTER_DRIVER
  34. extern bool bfg_need_detect_rescan;
  35. extern void request_work(struct thr_info *);
  36. extern struct work *get_work(struct thr_info *);
  37. extern bool hashes_done(struct thr_info *, int64_t hashes, struct timeval *tvp_hashes, uint32_t *max_nonce);
  38. extern bool hashes_done2(struct thr_info *, int64_t hashes, uint32_t *max_nonce);
  39. extern void mt_disable_start(struct thr_info *);
  40. extern void mt_disable_finish(struct thr_info *);
  41. extern void mt_disable(struct thr_info *); // blocks until reenabled
  42. extern int restart_wait(struct thr_info *, unsigned int ms);
  43. extern void minerloop_scanhash(struct thr_info *);
  44. extern void mt_disable_start__async(struct thr_info *);
  45. extern bool do_job_prepare(struct thr_info *, struct timeval *tvp_now);
  46. extern void job_prepare_complete(struct thr_info *);
  47. extern void do_get_results(struct thr_info *, bool proceed_with_new_job);
  48. extern void job_results_fetched(struct thr_info *);
  49. extern void do_job_start(struct thr_info *);
  50. extern void mt_job_transition(struct thr_info *);
  51. extern void job_start_complete(struct thr_info *);
  52. extern void job_start_abort(struct thr_info *, bool failure);
  53. extern bool do_process_results(struct thr_info *, struct timeval *tvp_now, struct work *, bool stopping);
  54. extern void minerloop_async(struct thr_info *);
  55. extern void minerloop_queue(struct thr_info *);
  56. // Establishes a simple way for external threads to directly communicate with device
  57. extern void cgpu_setup_control_requests(struct cgpu_info *);
  58. extern void cgpu_request_control(struct cgpu_info *);
  59. extern void cgpu_release_control(struct cgpu_info *);
  60. extern void *miner_thread(void *);
  61. extern void add_cgpu_live(void*);
  62. extern bool add_cgpu_slave(struct cgpu_info *, struct cgpu_info *master);
  63. enum bfg_set_device_replytype {
  64. SDR_AUTO,
  65. SDR_OK,
  66. SDR_ERR,
  67. SDR_HELP,
  68. SDR_UNKNOWN,
  69. SDR_NOSUPP,
  70. };
  71. 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);
  72. struct bfg_set_device_definition {
  73. const char *optname;
  74. bfg_set_device_func_t func;
  75. const char *description;
  76. };
  77. extern const char *proc_set_device(struct cgpu_info *proc, char *optname, char *newvalue, char *replybuf, enum bfg_set_device_replytype *out_success);
  78. typedef bool(*detectone_func_t)(const char*);
  79. typedef int(*autoscan_func_t)();
  80. enum generic_detect_flags {
  81. GDF_REQUIRE_DNAME = 2,
  82. GDF_DEFAULT_NOAUTO = 4,
  83. };
  84. extern int _serial_detect(struct device_drv *api, detectone_func_t, autoscan_func_t, int flags);
  85. #define noserial_detect_manual(api, autoscan) \
  86. _serial_detect(api, NULL , autoscan, 4)
  87. #define generic_detect(drv, detectone, autoscan, flags) _serial_detect(drv, detectone, autoscan, flags)
  88. extern FILE *open_bitstream(const char *dname, const char *filename);
  89. extern void close_device_fd(struct thr_info *);
  90. #define for_each_managed_proc(procvar, dev) \
  91. for (struct cgpu_info *procvar = dev; procvar; procvar = procvar->next_proc)
  92. #define for_each_logical_proc(procvar, dev) \
  93. for (struct cgpu_info *procvar = dev; procvar && procvar->device == (dev); procvar = procvar->next_proc)
  94. extern struct cgpu_info *device_proc_by_id(struct cgpu_info *dev, int procid);
  95. #endif