Browse Source

lowlevel: Add a userpointer to lowl_found_devinfo_func_t and use it for serial_autodetect

Luke Dashjr 12 years ago
parent
commit
ebf66582ac
5 changed files with 12 additions and 15 deletions
  1. 1 1
      driver-nanofury.c
  2. 1 1
      driver-x6500.c
  3. 4 7
      fpgautils.c
  4. 2 2
      lowlevel.c
  5. 4 4
      lowlevel.h

+ 1 - 1
driver-nanofury.c

@@ -161,7 +161,7 @@ fail:
 }
 
 static
-bool nanofury_foundlowl(struct lowlevel_device_info * const info)
+bool nanofury_foundlowl(struct lowlevel_device_info * const info, __maybe_unused void *userp)
 {
 	const char * const product = info->product;
 	const char * const serial = info->serial;

+ 1 - 1
driver-x6500.c

@@ -127,7 +127,7 @@ uint32_t x6500_get_register(struct jtag_port *jp, uint8_t addr)
 	return bits2int(buf, 32);
 }
 
-static bool x6500_foundlowl(struct lowlevel_device_info * const info)
+static bool x6500_foundlowl(struct lowlevel_device_info * const info, __maybe_unused void *userp)
 {
 	const char * const product = info->product;
 	const char * const serial = info->serial;

+ 4 - 7
fpgautils.c

@@ -647,10 +647,9 @@ extern void _vcom_devinfo_scan_querydosdevice(struct lowlevel_device_info **);
 extern void _vcom_devinfo_scan_lsdev(struct lowlevel_device_info **);
 #endif
 
-static detectone_func_t _serial_autodetect_current_detectone;
-
-bool _serial_autodetect_found_cb(struct lowlevel_device_info * const devinfo)
+bool _serial_autodetect_found_cb(struct lowlevel_device_info * const devinfo, void *userp)
 {
+	detectone_func_t detectone = userp;
 	if (bfg_claim_any(NULL, devinfo->path, devinfo->devid))
 	{
 		applog(LOG_DEBUG, "%s (%s) is already claimed, skipping probe", devinfo->path, devinfo->devid);
@@ -666,7 +665,7 @@ bool _serial_autodetect_found_cb(struct lowlevel_device_info * const devinfo)
 		.product = devinfo->product,
 		.serial = devinfo->serial,
 	};
-	const bool rv = _serial_autodetect_current_detectone(devinfo->path);
+	const bool rv = detectone(devinfo->path);
 	clear_detectone_meta_info();
 	return rv;
 }
@@ -677,14 +676,12 @@ int _serial_autodetect(detectone_func_t detectone, ...)
 	char *needles_array[0x10];
 	int needlecount = 0;
 	
-	_serial_autodetect_current_detectone = detectone;
-	
 	va_start(needles, detectone);
 	while ( (needles_array[needlecount++] = va_arg(needles, void *)) )
 	{}
 	va_end(needles);
 	
-	return _lowlevel_detect(_serial_autodetect_found_cb, NULL, (const char **)needles_array);
+	return _lowlevel_detect(_serial_autodetect_found_cb, NULL, (const char **)needles_array, detectone);
 }
 
 static

+ 2 - 2
lowlevel.c

@@ -76,7 +76,7 @@ void lowlevel_scan()
 	}
 }
 
-int _lowlevel_detect(lowl_found_devinfo_func_t cb, const char *serial, const char **product_needles)
+int _lowlevel_detect(lowl_found_devinfo_func_t cb, const char *serial, const char **product_needles, void *userp)
 {
 	struct lowlevel_device_info *info, *tmp;
 	int found = 0, i;
@@ -88,7 +88,7 @@ int _lowlevel_detect(lowl_found_devinfo_func_t cb, const char *serial, const cha
 		for (i = 0; product_needles[i]; ++i)
 			if (!strstr(info->product, product_needles[i]))
 				goto next;
-		if (!cb(info))
+		if (!cb(info, userp))
 			continue;
 		LL_DELETE(devinfo_list, info);
 		++found;

+ 4 - 4
lowlevel.h

@@ -7,7 +7,7 @@
 
 struct lowlevel_device_info;
 
-typedef bool (*lowl_found_devinfo_func_t)(struct lowlevel_device_info *);
+typedef bool (*lowl_found_devinfo_func_t)(struct lowlevel_device_info *, void *);
 
 struct lowlevel_driver {
 	struct lowlevel_device_info *(*devinfo_scan)();
@@ -29,9 +29,9 @@ struct lowlevel_device_info {
 };
 
 extern void lowlevel_scan();
-extern int _lowlevel_detect(lowl_found_devinfo_func_t, const char *serial, const char **product_needles);
-#define lowlevel_detect(func, ...)  _lowlevel_detect(func, NULL, (const char *[]){__VA_ARGS__, NULL})
-#define lowlevel_detect_serial(func, serial)  _lowlevel_detect(func, serial, (const char *[]){NULL})
+extern int _lowlevel_detect(lowl_found_devinfo_func_t, const char *serial, const char **product_needles, void *);
+#define lowlevel_detect(func, ...)  _lowlevel_detect(func, NULL, (const char *[]){__VA_ARGS__, NULL}, NULL)
+#define lowlevel_detect_serial(func, serial)  _lowlevel_detect(func, serial, (const char *[]){NULL}, NULL)
 extern void lowlevel_scan_free();
 extern void lowlevel_devinfo_free(struct lowlevel_device_info *);