Browse Source

drv_detect_all: Use priority-sorted list of registered drivers

Luke Dashjr 12 years ago
parent
commit
b59ac5192f
9 changed files with 35 additions and 129 deletions
  1. 7 0
      deviceapi.c
  2. 5 0
      deviceapi.h
  3. 1 0
      driver-cairnsmore.c
  4. 1 0
      driver-cpu.c
  5. 1 0
      driver-erupter.c
  6. 1 0
      driver-icarus.c
  7. 1 0
      driver-opencl.c
  8. 10 129
      miner.c
  9. 8 0
      miner.h

+ 7 - 0
deviceapi.c

@@ -67,10 +67,17 @@ int sort_drv_by_dname(struct driver_registration * const a, struct driver_regist
 	return strcmp(a->drv->dname, b->drv->dname);
 };
 
+static
+int sort_drv_by_priority(struct driver_registration * const a, struct driver_registration * const b)
+{
+	return a->drv->probe_priority - b->drv->probe_priority;
+};
+
 void bfg_devapi_init()
 {
 	_bfg_register_driver(NULL);
 	HASH_SRT(hh , _bfg_drvreg1, sort_drv_by_dname   );
+	HASH_SRT(hh2, _bfg_drvreg2, sort_drv_by_priority);
 }
 
 

+ 5 - 0
deviceapi.h

@@ -20,6 +20,11 @@ extern struct driver_registration *_bfg_drvreg1;
 extern struct driver_registration *_bfg_drvreg2;
 extern void bfg_devapi_init();
 
+#define BFG_FOREACH_DRIVER_BY_DNAME(reg, tmp)  \
+	HASH_ITER(hh , _bfg_drvreg1, reg, tmp)
+#define BFG_FOREACH_DRIVER_BY_PRIORITY(reg, tmp)  \
+	HASH_ITER(hh2, _bfg_drvreg2, reg, tmp)
+
 extern void _bfg_register_driver(const struct device_drv *);
 #define BFG_REGISTER_DRIVER(drv)                \
 	struct device_drv drv;                      \

+ 1 - 0
driver-cairnsmore.c

@@ -208,6 +208,7 @@ static void cairnsmore_drv_init()
 	cairnsmore_drv.thread_init = cairnsmore_init;
 	cairnsmore_drv.identify_device = cairnsmore_identify;
 	cairnsmore_drv.get_api_extra_device_status = cairnsmore_drv_extra_device_status;
+	++cairnsmore_drv.probe_priority;
 }
 
 struct device_drv cairnsmore_drv = {

+ 1 - 0
driver-cpu.c

@@ -879,6 +879,7 @@ CPUSearch:
 struct device_drv cpu_drv = {
 	.dname = "cpu",
 	.name = "CPU",
+	.supported_algos = POW_SHA256D | POW_SCRYPT,
 	.drv_detect = cpu_detect,
 	.thread_prepare = cpu_thread_prepare,
 	.can_limit_work = cpu_can_limit_work,

+ 1 - 0
driver-erupter.c

@@ -90,6 +90,7 @@ static void erupter_drv_init()
 	erupter_drv.name = "BES";
 	erupter_drv.drv_detect = erupter_detect;
 	erupter_drv.identify_device = erupter_identify;
+	++erupter_drv.probe_priority;
 	
 	erupter_drv_emerald = erupter_drv;
 	erupter_drv_emerald.name = "BEE";

+ 1 - 0
driver-icarus.c

@@ -1309,6 +1309,7 @@ static void icarus_shutdown(struct thr_info *thr)
 struct device_drv icarus_drv = {
 	.dname = "icarus",
 	.name = "ICA",
+	.probe_priority = -120,
 	.drv_detect = icarus_detect,
 	.get_api_stats = icarus_drv_stats,
 	.thread_prepare = icarus_prepare,

+ 1 - 0
driver-opencl.c

@@ -1769,6 +1769,7 @@ static void opencl_thread_shutdown(struct thr_info *thr)
 struct device_drv opencl_api = {
 	.dname = "opencl",
 	.name = "OCL",
+	.supported_algos = POW_SHA256D | POW_SCRYPT,
 	.drv_detect = opencl_detect,
 	.reinit_device = reinit_opencl_device,
 	.override_statline_temp2 = override_opencl_statline_temp,

+ 10 - 129
miner.c

@@ -10105,60 +10105,6 @@ struct device_drv cpu_drv = {
 };
 #endif
 
-#ifdef USE_BITFORCE
-extern struct device_drv bitforce_drv;
-#endif
-
-#ifdef USE_BIGPIC
-extern struct device_drv bigpic_drv;
-#endif
-
-#ifdef USE_ICARUS
-extern struct device_drv cairnsmore_drv;
-extern struct device_drv erupter_drv;
-extern struct device_drv icarus_drv;
-#endif
-
-#ifdef USE_AVALON
-extern struct device_drv avalon_drv;
-#endif
-
-#ifdef USE_KNC
-extern struct device_drv knc_drv;
-#endif
-
-#ifdef USE_LITTLEFURY
-extern struct device_drv littlefury_drv;
-#endif
-
-#ifdef USE_MODMINER
-extern struct device_drv modminer_drv;
-#endif
-
-#ifdef USE_NANOFURY
-extern struct device_drv nanofury_drv;
-#endif
-
-#ifdef USE_X6500
-extern struct device_drv x6500_api;
-#endif
-
-#ifdef USE_ZTEX
-extern struct device_drv ztex_drv;
-#endif
-
-#ifdef USE_BITFURY
-extern struct device_drv bitfury_drv;
-#endif
-
-#ifdef USE_METABANK
-extern struct device_drv metabank_drv;
-#endif
-
-#ifdef USE_BFSB
-extern struct device_drv bfsb_drv;
-#endif
-
 static int cgminer_id_count = 0;
 static int device_line_id_count;
 
@@ -10220,87 +10166,22 @@ void drv_detect_all()
 #ifdef HAVE_BFG_LOWLEVEL
 	lowlevel_scan();
 #endif
-
-#ifdef USE_ICARUS
-	if (!opt_scrypt)
-	{
-		cairnsmore_drv.drv_detect();
-		erupter_drv.drv_detect();
-		icarus_drv.drv_detect();
-	}
-#endif
-
-#ifdef USE_BITFORCE
-	if (!opt_scrypt)
-		bitforce_drv.drv_detect();
-#endif
-
-#ifdef USE_BIGPIC
-	if (!opt_scrypt)
-		bigpic_drv.drv_detect();
-#endif
-
-#ifdef USE_KNC
-	if (!opt_scrypt)
-		knc_drv.drv_detect();
-#endif
-
-#ifdef USE_MODMINER
-	if (!opt_scrypt)
-		modminer_drv.drv_detect();
-#endif
-
-#ifdef USE_NANOFURY
-	if (!opt_scrypt)
-		nanofury_drv.drv_detect();
-#endif
-
-#ifdef USE_X6500
-	if (!opt_scrypt)
-		x6500_api.drv_detect();
-#endif
-
-#ifdef USE_ZTEX
-	if (!opt_scrypt)
-		ztex_drv.drv_detect();
-#endif
-
-#ifdef USE_BITFURY
-	if (!opt_scrypt)
+	
+	struct driver_registration *reg, *tmp;
+	const int algomatch = opt_scrypt ? POW_SCRYPT : POW_SHA256D;
+	BFG_FOREACH_DRIVER_BY_PRIORITY(reg, tmp)
 	{
-		bitfury_drv.drv_detect();
-#ifdef USE_METABANK
-		metabank_drv.drv_detect();
-#endif
-#ifdef USE_BFSB
-		bfsb_drv.drv_detect();
-#endif
+		const struct device_drv * const drv = reg->drv;
+		const supported_algos_t algos = drv->supported_algos ?: POW_SHA256D;
+		if (0 == (algos & algomatch) || !drv->drv_detect)
+			continue;
+		
+		drv->drv_detect();
 	}
-#endif
-
-#ifdef USE_LITTLEFURY
-	if (!opt_scrypt)
-		littlefury_drv.drv_detect();
-#endif
-
-	/* Detect avalon last since it will try to claim the device regardless
-	 * as detection is unreliable. */
-#ifdef USE_AVALON
-	if (!opt_scrypt)
-		avalon_drv.drv_detect();
-#endif
-
-#ifdef WANT_CPUMINE
-	cpu_drv.drv_detect();
-#endif
 
 #ifdef HAVE_BFG_LOWLEVEL
 	lowlevel_scan_free();
 #endif
-
-#ifdef HAVE_OPENCL
-	opencl_api.drv_detect();
-#endif
 }
 
 static

+ 8 - 0
miner.h

@@ -283,6 +283,12 @@ struct gpu_adl {
 };
 #endif
 
+enum pow_algorithm {
+	POW_SHA256D = 1,
+	POW_SCRYPT  = 2,
+};
+typedef uint8_t supported_algos_t;
+
 struct api_data;
 struct thr_info;
 struct work;
@@ -290,6 +296,8 @@ struct work;
 struct device_drv {
 	const char *dname;
 	const char *name;
+	int8_t probe_priority;
+	supported_algos_t supported_algos;
 
 	// DRV-global functions
 	void (*drv_init)();