deviceapi.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #ifndef __DEVICEAPI_H__
  2. #define __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 void request_work(struct thr_info *);
  30. extern struct work *get_work(struct thr_info *);
  31. extern bool hashes_done(struct thr_info *, int64_t hashes, struct timeval *tvp_hashes, uint32_t *max_nonce);
  32. extern bool hashes_done2(struct thr_info *, int64_t hashes, uint32_t *max_nonce);
  33. extern void mt_disable_start(struct thr_info *);
  34. extern void mt_disable_finish(struct thr_info *);
  35. extern void mt_disable(struct thr_info *); // blocks until reenabled
  36. extern int restart_wait(struct thr_info *, unsigned int ms);
  37. extern void minerloop_scanhash(struct thr_info *);
  38. extern bool do_job_prepare(struct thr_info *, struct timeval *tvp_now);
  39. extern void job_prepare_complete(struct thr_info *);
  40. extern void do_get_results(struct thr_info *, bool proceed_with_new_job);
  41. extern void job_results_fetched(struct thr_info *);
  42. extern void do_job_start(struct thr_info *);
  43. extern void mt_job_transition(struct thr_info *);
  44. extern void job_start_complete(struct thr_info *);
  45. extern void job_start_abort(struct thr_info *, bool failure);
  46. extern bool do_process_results(struct thr_info *, struct timeval *tvp_now, struct work *, bool stopping);
  47. extern void minerloop_async(struct thr_info *);
  48. extern void minerloop_queue(struct thr_info *);
  49. extern void *miner_thread(void *);
  50. extern void add_cgpu_live(void*);
  51. extern bool add_cgpu_slave(struct cgpu_info *, struct cgpu_info *master);
  52. typedef bool(*detectone_func_t)(const char*);
  53. typedef int(*autoscan_func_t)();
  54. enum generic_detect_flags {
  55. GDF_FORCE_AUTO = 1,
  56. GDF_REQUIRE_DNAME = 2,
  57. GDF_DEFAULT_NOAUTO = 4,
  58. };
  59. extern int _serial_detect(struct device_drv *api, detectone_func_t, autoscan_func_t, int flags);
  60. #define serial_detect_fauto(api, detectone, autoscan) \
  61. _serial_detect(api, detectone, autoscan, 1)
  62. #define serial_detect_auto(api, detectone, autoscan) \
  63. _serial_detect(api, detectone, autoscan, 0)
  64. #define serial_detect_auto_byname(api, detectone, autoscan) \
  65. _serial_detect(api, detectone, autoscan, 2)
  66. #define serial_detect(api, detectone) \
  67. _serial_detect(api, detectone, NULL, 0)
  68. #define serial_detect_byname(api, detectone) \
  69. _serial_detect(api, detectone, NULL, 2)
  70. #define noserial_detect(api, autoscan) \
  71. _serial_detect(api, NULL , autoscan, 0)
  72. #define noserial_detect_manual(api, autoscan) \
  73. _serial_detect(api, NULL , autoscan, 4)
  74. #define generic_detect(drv, detectone, autoscan, flags) _serial_detect(drv, detectone, autoscan, flags)
  75. extern FILE *open_bitstream(const char *dname, const char *filename);
  76. extern void close_device_fd(struct thr_info *);
  77. #endif