deviceapi.h 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 "miner.h"
  7. struct driver_registration;
  8. struct driver_registration {
  9. const struct device_drv *drv;
  10. UT_hash_handle hh; // hash & order by dname
  11. UT_hash_handle hh2; // hash by name, order by priority
  12. struct driver_registration *next; // DO NOT USE
  13. };
  14. extern struct driver_registration *_bfg_drvreg1;
  15. extern struct driver_registration *_bfg_drvreg2;
  16. extern void bfg_devapi_init();
  17. #define BFG_FOREACH_DRIVER_BY_DNAME(reg, tmp) \
  18. HASH_ITER(hh , _bfg_drvreg1, reg, tmp)
  19. #define BFG_FOREACH_DRIVER_BY_PRIORITY(reg, tmp) \
  20. HASH_ITER(hh2, _bfg_drvreg2, reg, tmp)
  21. extern void _bfg_register_driver(const struct device_drv *);
  22. #define BFG_REGISTER_DRIVER(drv) \
  23. struct device_drv drv; \
  24. __attribute__((constructor)) \
  25. static void __bfg_register_drv_ ## drv() { \
  26. _bfg_register_driver(&drv); \
  27. } \
  28. // END BFG_REGISTER_DRIVER
  29. extern bool bfg_need_detect_rescan;
  30. extern void request_work(struct thr_info *);
  31. extern struct work *get_work(struct thr_info *);
  32. extern bool hashes_done(struct thr_info *, int64_t hashes, struct timeval *tvp_hashes, uint32_t *max_nonce);
  33. extern bool hashes_done2(struct thr_info *, int64_t hashes, uint32_t *max_nonce);
  34. extern void mt_disable_start(struct thr_info *);
  35. extern void mt_disable_finish(struct thr_info *);
  36. extern void mt_disable(struct thr_info *); // blocks until reenabled
  37. extern int restart_wait(struct thr_info *, unsigned int ms);
  38. extern void minerloop_scanhash(struct thr_info *);
  39. extern bool do_job_prepare(struct thr_info *, struct timeval *tvp_now);
  40. extern void job_prepare_complete(struct thr_info *);
  41. extern void do_get_results(struct thr_info *, bool proceed_with_new_job);
  42. extern void job_results_fetched(struct thr_info *);
  43. extern void do_job_start(struct thr_info *);
  44. extern void mt_job_transition(struct thr_info *);
  45. extern void job_start_complete(struct thr_info *);
  46. extern void job_start_abort(struct thr_info *, bool failure);
  47. extern bool do_process_results(struct thr_info *, struct timeval *tvp_now, struct work *, bool stopping);
  48. extern void minerloop_async(struct thr_info *);
  49. extern void minerloop_queue(struct thr_info *);
  50. extern void *miner_thread(void *);
  51. extern void add_cgpu_live(void*);
  52. extern bool add_cgpu_slave(struct cgpu_info *, struct cgpu_info *master);
  53. typedef bool(*detectone_func_t)(const char*);
  54. typedef int(*autoscan_func_t)();
  55. enum generic_detect_flags {
  56. GDF_FORCE_AUTO = 1,
  57. GDF_REQUIRE_DNAME = 2,
  58. GDF_DEFAULT_NOAUTO = 4,
  59. };
  60. extern int _serial_detect(struct device_drv *api, detectone_func_t, autoscan_func_t, int flags);
  61. #define serial_detect_fauto(api, detectone, autoscan) \
  62. _serial_detect(api, detectone, autoscan, 1)
  63. #define serial_detect_auto(api, detectone, autoscan) \
  64. _serial_detect(api, detectone, autoscan, 0)
  65. #define serial_detect_auto_byname(api, detectone, autoscan) \
  66. _serial_detect(api, detectone, autoscan, 2)
  67. #define serial_detect(api, detectone) \
  68. _serial_detect(api, detectone, NULL, 0)
  69. #define serial_detect_byname(api, detectone) \
  70. _serial_detect(api, detectone, NULL, 2)
  71. #define noserial_detect(api, autoscan) \
  72. _serial_detect(api, NULL , autoscan, 0)
  73. #define noserial_detect_manual(api, autoscan) \
  74. _serial_detect(api, NULL , autoscan, 4)
  75. #define generic_detect(drv, detectone, autoscan, flags) _serial_detect(drv, detectone, autoscan, flags)
  76. extern FILE *open_bitstream(const char *dname, const char *filename);
  77. extern void close_device_fd(struct thr_info *);
  78. #endif