Browse Source

Bugfix: Move serial_detect* and open_bitstream to DevAPI code so CPU/OpenCL can build properly without fpgautils

Luke Dashjr 12 years ago
parent
commit
37201d79c6
8 changed files with 136 additions and 124 deletions
  1. 2 1
      configure.ac
  2. 107 0
      deviceapi.c
  3. 21 0
      deviceapi.h
  4. 1 1
      driver-cpu.c
  5. 1 1
      driver-opencl.c
  6. 0 101
      fpgautils.c
  7. 3 19
      fpgautils.h
  8. 1 1
      ocl.c

+ 2 - 1
configure.ac

@@ -432,8 +432,9 @@ fi
 
 
 need_fpgautils=no
-if test x$avalon$icarus$bitforce$modminer$opencl$x6500$ztex != xnonononononono; then
+if test x$avalon$icarus$bitforce$modminer$x6500$ztex != xnononononono; then
 	need_fpgautils=yes
+	AC_DEFINE([HAVE_FPGAUTILS], [1], [Defined to 1 if fpgautils is being used])
 	
 	if $have_win32; then
 		echo '#include <iospeeds.h>' >iospeeds_local.h

+ 107 - 0
deviceapi.c

@@ -617,9 +617,11 @@ bool add_cgpu(struct cgpu_info *cgpu)
 	strcpy(cgpu->proc_repr, cgpu->dev_repr);
 	sprintf(cgpu->proc_repr_ns, "%s%u", cgpu->drv->name, cgpu->device_id);
 	
+#ifdef HAVE_FPGAUTILS
 	maybe_strdup_if_null(&cgpu->dev_manufacturer, detectone_meta_info.manufacturer);
 	maybe_strdup_if_null(&cgpu->dev_product,      detectone_meta_info.product);
 	maybe_strdup_if_null(&cgpu->dev_serial,       detectone_meta_info.serial);
+#endif
 	
 	devices_new = realloc(devices_new, sizeof(struct cgpu_info *) * (total_devices_new + lpcount + 1));
 	devices_new[total_devices_new++] = cgpu;
@@ -669,3 +671,108 @@ bool add_cgpu(struct cgpu_info *cgpu)
 	
 	return true;
 }
+
+int _serial_detect(struct device_drv *api, detectone_func_t detectone, autoscan_func_t autoscan, int flags)
+{
+	struct string_elist *iter, *tmp;
+	const char *dev, *colon;
+	bool inhibitauto = flags & 4;
+	char found = 0;
+	bool forceauto = flags & 1;
+	bool hasname;
+	size_t namel = strlen(api->name);
+	size_t dnamel = strlen(api->dname);
+
+#ifdef HAVE_FPGAUTILS
+	clear_detectone_meta_info();
+#endif
+	DL_FOREACH_SAFE(scan_devices, iter, tmp) {
+		dev = iter->string;
+		if ((colon = strchr(dev, ':')) && colon[1] != '\0') {
+			size_t idlen = colon - dev;
+
+			// allow either name:device or dname:device
+			if ((idlen != namel || strncasecmp(dev, api->name, idlen))
+			&&  (idlen != dnamel || strncasecmp(dev, api->dname, idlen)))
+				continue;
+
+			dev = colon + 1;
+			hasname = true;
+		}
+		else
+			hasname = false;
+		if (!strcmp(dev, "auto"))
+			forceauto = true;
+		else if (!strcmp(dev, "noauto"))
+			inhibitauto = true;
+		else
+		if ((flags & 2) && !hasname)
+			continue;
+		else
+		if (!detectone)
+		{}  // do nothing
+#ifdef HAVE_FPGAUTILS
+		else
+		if (serial_claim(dev, NULL))
+		{
+			applog(LOG_DEBUG, "%s is already claimed... skipping probes", dev);
+			string_elist_del(&scan_devices, iter);
+		}
+#endif
+		else if (detectone(dev)) {
+			string_elist_del(&scan_devices, iter);
+			inhibitauto = true;
+			++found;
+		}
+	}
+
+	if ((forceauto || !inhibitauto) && autoscan)
+		found += autoscan();
+
+	return found;
+}
+
+static
+FILE *_open_bitstream(const char *path, const char *subdir, const char *sub2, const char *filename)
+{
+	char fullpath[PATH_MAX];
+	strcpy(fullpath, path);
+	strcat(fullpath, "/");
+	if (subdir) {
+		strcat(fullpath, subdir);
+		strcat(fullpath, "/");
+	}
+	if (sub2) {
+		strcat(fullpath, sub2);
+		strcat(fullpath, "/");
+	}
+	strcat(fullpath, filename);
+	return fopen(fullpath, "rb");
+}
+#define _open_bitstream(path, subdir, sub2)  do {  \
+	f = _open_bitstream(path, subdir, sub2, filename);  \
+	if (f)  \
+		return f;  \
+} while(0)
+
+#define _open_bitstream2(path, path3)  do {  \
+	_open_bitstream(path, NULL, path3);  \
+	_open_bitstream(path, "../share/" PACKAGE, path3);  \
+} while(0)
+
+#define _open_bitstream3(path)  do {  \
+	_open_bitstream2(path, dname);  \
+	_open_bitstream2(path, "bitstreams");  \
+	_open_bitstream2(path, NULL);  \
+} while(0)
+
+FILE *open_bitstream(const char *dname, const char *filename)
+{
+	FILE *f;
+
+	_open_bitstream3(opt_kernel_path);
+	_open_bitstream3(cgminer_path);
+	_open_bitstream3(".");
+
+	return NULL;
+}

+ 21 - 0
deviceapi.h

@@ -32,4 +32,25 @@ extern void minerloop_queue(struct thr_info *);
 
 extern void *miner_thread(void *);
 
+typedef bool(*detectone_func_t)(const char*);
+typedef int(*autoscan_func_t)();
+
+extern int _serial_detect(struct device_drv *api, detectone_func_t, autoscan_func_t, int flags);
+#define serial_detect_fauto(api, detectone, autoscan)  \
+	_serial_detect(api, detectone, autoscan, 1)
+#define serial_detect_auto(api, detectone, autoscan)  \
+	_serial_detect(api, detectone, autoscan, 0)
+#define serial_detect_auto_byname(api, detectone, autoscan)  \
+	_serial_detect(api, detectone, autoscan, 2)
+#define serial_detect(api, detectone)  \
+	_serial_detect(api, detectone,     NULL, 0)
+#define serial_detect_byname(api, detectone)  \
+	_serial_detect(api, detectone,     NULL, 2)
+#define noserial_detect(api, autoscan)  \
+	_serial_detect(api, NULL     , autoscan, 0)
+#define noserial_detect_manual(api, autoscan)  \
+	_serial_detect(api, NULL     , autoscan, 4)
+
+extern FILE *open_bitstream(const char *dname, const char *filename);
+
 #endif

+ 1 - 1
driver-cpu.c

@@ -30,7 +30,7 @@
 #include <libgen.h>
 
 #include "compat.h"
-#include "fpgautils.h"
+#include "deviceapi.h"
 #include "miner.h"
 #include "bench_block.h"
 #include "util.h"

+ 1 - 1
driver-opencl.c

@@ -39,8 +39,8 @@
 #define OMIT_OPENCL_API
 
 #include "compat.h"
-#include "fpgautils.h"
 #include "miner.h"
+#include "deviceapi.h"
 #include "driver-opencl.h"
 #include "findnonce.h"
 #include "ocl.h"

+ 0 - 101
fpgautils.c

@@ -119,7 +119,6 @@ int _detectone_wrap(const detectone_func_t detectone, const char * const param,
 
 struct detectone_meta_info_t detectone_meta_info;
 
-static
 void clear_detectone_meta_info(void)
 {
 	detectone_meta_info = (struct detectone_meta_info_t){
@@ -475,62 +474,6 @@ int _serial_autodetect(detectone_func_t detectone, ...)
 	return rv;
 }
 
-int _serial_detect(struct device_drv *api, detectone_func_t detectone, autoscan_func_t autoscan, int flags)
-{
-	struct string_elist *iter, *tmp;
-	const char *dev, *colon;
-	bool inhibitauto = flags & 4;
-	char found = 0;
-	bool forceauto = flags & 1;
-	bool hasname;
-	size_t namel = strlen(api->name);
-	size_t dnamel = strlen(api->dname);
-
-	clear_detectone_meta_info();
-	DL_FOREACH_SAFE(scan_devices, iter, tmp) {
-		dev = iter->string;
-		if ((colon = strchr(dev, ':')) && colon[1] != '\0') {
-			size_t idlen = colon - dev;
-
-			// allow either name:device or dname:device
-			if ((idlen != namel || strncasecmp(dev, api->name, idlen))
-			&&  (idlen != dnamel || strncasecmp(dev, api->dname, idlen)))
-				continue;
-
-			dev = colon + 1;
-			hasname = true;
-		}
-		else
-			hasname = false;
-		if (!strcmp(dev, "auto"))
-			forceauto = true;
-		else if (!strcmp(dev, "noauto"))
-			inhibitauto = true;
-		else
-		if ((flags & 2) && !hasname)
-			continue;
-		else
-		if (!detectone)
-		{}  // do nothing
-		else
-		if (serial_claim(dev, NULL))
-		{
-			applog(LOG_DEBUG, "%s is already claimed... skipping probes", dev);
-			string_elist_del(&scan_devices, iter);
-		}
-		else if (detectone(dev)) {
-			string_elist_del(&scan_devices, iter);
-			inhibitauto = true;
-			++found;
-		}
-	}
-
-	if ((forceauto || !inhibitauto) && autoscan)
-		found += autoscan();
-
-	return found;
-}
-
 enum bfg_device_bus {
 	BDB_SERIAL,
 	BDB_USB,
@@ -933,50 +876,6 @@ ssize_t _serial_read(int fd, char *buf, size_t bufsiz, char *eol)
 	return tlen;
 }
 
-static FILE *_open_bitstream(const char *path, const char *subdir, const char *sub2, const char *filename)
-{
-	char fullpath[PATH_MAX];
-	strcpy(fullpath, path);
-	strcat(fullpath, "/");
-	if (subdir) {
-		strcat(fullpath, subdir);
-		strcat(fullpath, "/");
-	}
-	if (sub2) {
-		strcat(fullpath, sub2);
-		strcat(fullpath, "/");
-	}
-	strcat(fullpath, filename);
-	return fopen(fullpath, "rb");
-}
-#define _open_bitstream(path, subdir, sub2)  do {  \
-	f = _open_bitstream(path, subdir, sub2, filename);  \
-	if (f)  \
-		return f;  \
-} while(0)
-
-#define _open_bitstream2(path, path3)  do {  \
-	_open_bitstream(path, NULL, path3);  \
-	_open_bitstream(path, "../share/" PACKAGE, path3);  \
-} while(0)
-
-#define _open_bitstream3(path)  do {  \
-	_open_bitstream2(path, dname);  \
-	_open_bitstream2(path, "bitstreams");  \
-	_open_bitstream2(path, NULL);  \
-} while(0)
-
-FILE *open_bitstream(const char *dname, const char *filename)
-{
-	FILE *f;
-
-	_open_bitstream3(opt_kernel_path);
-	_open_bitstream3(cgminer_path);
-	_open_bitstream3(".");
-
-	return NULL;
-}
-
 #define bailout(...)  do {  \
 	applog(__VA_ARGS__);  \
 	return NULL;  \

+ 3 - 19
fpgautils.h

@@ -10,6 +10,8 @@
 #include <libusb.h>
 #endif
 
+#include "deviceapi.h"
+
 struct device_drv;
 struct cgpu_info;
 
@@ -21,25 +23,8 @@ struct detectone_meta_info_t {
 
 // NOTE: Should detectone become run multithreaded, this will become a threadsafe #define
 extern struct detectone_meta_info_t detectone_meta_info;
+extern void clear_detectone_meta_info(void);
 
-typedef bool(*detectone_func_t)(const char*);
-typedef int(*autoscan_func_t)();
-
-extern int _serial_detect(struct device_drv *api, detectone_func_t, autoscan_func_t, int flags);
-#define serial_detect_fauto(api, detectone, autoscan)  \
-	_serial_detect(api, detectone, autoscan, 1)
-#define serial_detect_auto(api, detectone, autoscan)  \
-	_serial_detect(api, detectone, autoscan, 0)
-#define serial_detect_auto_byname(api, detectone, autoscan)  \
-	_serial_detect(api, detectone, autoscan, 2)
-#define serial_detect(api, detectone)  \
-	_serial_detect(api, detectone,     NULL, 0)
-#define serial_detect_byname(api, detectone)  \
-	_serial_detect(api, detectone,     NULL, 2)
-#define noserial_detect(api, autoscan)  \
-	_serial_detect(api, NULL     , autoscan, 0)
-#define noserial_detect_manual(api, autoscan)  \
-	_serial_detect(api, NULL     , autoscan, 4)
 extern int _serial_autodetect(detectone_func_t, ...);
 #define serial_autodetect(...)  _serial_autodetect(__VA_ARGS__, NULL)
 
@@ -61,7 +46,6 @@ extern ssize_t _serial_read(int fd, char *buf, size_t buflen, char *eol);
 	_serial_read(fd, buf, bufsiz, &eol)
 #define serial_close(fd)  close(fd)
 
-extern FILE *open_bitstream(const char *dname, const char *filename);
 extern FILE *open_xilinx_bitstream(const char *dname, const char *repr, const char *fwfile, unsigned long *out_len);
 
 extern int get_serial_cts(int fd);

+ 1 - 1
ocl.c

@@ -33,8 +33,8 @@
 
 #define OMIT_OPENCL_API
 
+#include "deviceapi.h"
 #include "findnonce.h"
-#include "fpgautils.h"
 #include "ocl.h"
 
 /* Platform API */