Browse Source

bitforce: Support for Monarch devices on Windows using new "mswin" lowlevel interface to scan for KMDF driver

Luke Dashjr 12 years ago
parent
commit
8ce4d76d54
7 changed files with 139 additions and 0 deletions
  1. 4 0
      Makefile.am
  2. 12 0
      configure.ac
  3. 11 0
      driver-bitforce.c
  4. 92 0
      lowl-mswin.c
  5. 12 0
      lowl-mswin.h
  6. 5 0
      lowlevel.c
  7. 3 0
      lowlevel.h

+ 4 - 0
Makefile.am

@@ -354,6 +354,10 @@ bfgminer_SOURCES += lowl-hid.c lowl-hid.h
 bfgminer_CPPFLAGS += $(hidapi_CFLAGS)
 bfgminer_CPPFLAGS += $(hidapi_CFLAGS)
 endif
 endif
 
 
+if NEED_BFG_LOWL_MSWIN
+bfgminer_SOURCES += lowl-mswin.c lowl-mswin.h
+endif
+
 if NEED_BFG_LOWL_PCI
 if NEED_BFG_LOWL_PCI
 bfgminer_SOURCES += lowl-pci.c lowl-pci.h
 bfgminer_SOURCES += lowl-pci.c lowl-pci.h
 
 

+ 12 - 0
configure.ac

@@ -128,6 +128,7 @@ need_lowl_vcom=no
 need_lowlevel=no
 need_lowlevel=no
 need_lowl_ftdi=no
 need_lowl_ftdi=no
 need_lowl_hid=no
 need_lowl_hid=no
+need_lowl_mswin=no
 need_lowl_pci=no
 need_lowl_pci=no
 need_lowl_spi=no
 need_lowl_spi=no
 need_lowl_usb=no
 need_lowl_usb=no
@@ -438,6 +439,10 @@ if test "x$bitforce" = xyes; then
 		need_lowl_pci=yes
 		need_lowl_pci=yes
 	fi
 	fi
 	need_lowl_vcom=yes
 	need_lowl_vcom=yes
+	driverlist="$driverlist bitforce:mswin/need_lowl_mswin"
+	if test x$have_win32 = xtrue; then
+		need_lowl_mswin=yes
+	fi
 	has_fpga=yes
 	has_fpga=yes
 	has_asic=yes
 	has_asic=yes
 	have_udevrules=true
 	have_udevrules=true
@@ -1175,6 +1180,12 @@ if test x$need_lowl_hid = xyes; then
 	need_lowlevel=yes
 	need_lowlevel=yes
 fi
 fi
 
 
+lowllist="$lowllist mswin/need_lowl_mswin"
+if test x$need_lowl_mswin = xyes; then
+	AC_DEFINE([NEED_BFG_LOWL_MSWIN], [1], [Defined to 1 if lowlevel mswin drivers are being used])
+	need_lowlevel=yes
+fi
+
 lowllist="$lowllist pci/need_lowl_pci"
 lowllist="$lowllist pci/need_lowl_pci"
 if test x$need_lowl_pci = xyes; then
 if test x$need_lowl_pci = xyes; then
 	AC_DEFINE([NEED_BFG_LOWL_PCI], [1], [Defined to 1 if lowlevel PCI drivers are being used])
 	AC_DEFINE([NEED_BFG_LOWL_PCI], [1], [Defined to 1 if lowlevel PCI drivers are being used])
@@ -1382,6 +1393,7 @@ AM_CONDITIONAL([USE_GC3355], [test x$need_gc3355 = xyes])
 AM_CONDITIONAL([NEED_BFG_LOWL_VCOM], [test x$need_lowl_vcom = xyes])
 AM_CONDITIONAL([NEED_BFG_LOWL_VCOM], [test x$need_lowl_vcom = xyes])
 AM_CONDITIONAL([NEED_BFG_LOWL_FTDI], [test x$need_lowl_ftdi = xyes])
 AM_CONDITIONAL([NEED_BFG_LOWL_FTDI], [test x$need_lowl_ftdi = xyes])
 AM_CONDITIONAL([NEED_BFG_LOWL_HID], [test x$need_lowl_hid = xyes])
 AM_CONDITIONAL([NEED_BFG_LOWL_HID], [test x$need_lowl_hid = xyes])
+AM_CONDITIONAL([NEED_BFG_LOWL_MSWIN], [test x$need_lowl_mswin = xyes])
 AM_CONDITIONAL([NEED_BFG_LOWL_PCI], [test x$need_lowl_pci = xyes])
 AM_CONDITIONAL([NEED_BFG_LOWL_PCI], [test x$need_lowl_pci = xyes])
 AM_CONDITIONAL([NEED_BFG_LOWL_SPI], [test x$need_lowl_spi = xyes])
 AM_CONDITIONAL([NEED_BFG_LOWL_SPI], [test x$need_lowl_spi = xyes])
 AM_CONDITIONAL([NEED_BFG_LOWLEVEL], [test x$need_lowlevel = xyes])
 AM_CONDITIONAL([NEED_BFG_LOWLEVEL], [test x$need_lowlevel = xyes])

+ 11 - 0
driver-bitforce.c

@@ -25,6 +25,9 @@
 #include "deviceapi.h"
 #include "deviceapi.h"
 #include "miner.h"
 #include "miner.h"
 #include "lowlevel.h"
 #include "lowlevel.h"
+#ifdef NEED_BFG_LOWL_MSWIN
+#include "lowl-mswin.h"
+#endif
 #include "lowl-pci.h"
 #include "lowl-pci.h"
 #include "lowl-vcom.h"
 #include "lowl-vcom.h"
 #include "util.h"
 #include "util.h"
@@ -521,6 +524,10 @@ bool bitforce_lowl_match(const struct lowlevel_device_info * const info)
 #ifdef NEED_BFG_LOWL_PCI
 #ifdef NEED_BFG_LOWL_PCI
 	if (info->lowl == &lowl_pci)
 	if (info->lowl == &lowl_pci)
 		return info->vid == BFL_PCI_VENDOR_ID;
 		return info->vid == BFL_PCI_VENDOR_ID;
+#endif
+#ifdef NEED_BFG_LOWL_MSWIN
+	if (lowl_mswin_match_guid(info, &WIN_GUID_DEVINTERFACE_MonarchKMDF))
+		return true;
 #endif
 #endif
 	return lowlevel_match_product(info, "BitFORCE", "SHA256");
 	return lowlevel_match_product(info, "BitFORCE", "SHA256");
 }
 }
@@ -743,6 +750,10 @@ bool bitforce_lowl_probe(const struct lowlevel_device_info * const info)
 #ifdef NEED_BFG_LOWL_PCI
 #ifdef NEED_BFG_LOWL_PCI
 	if (info->lowl == &lowl_pci)
 	if (info->lowl == &lowl_pci)
 		return bitforce_detect_oneof(info->path, &bfllif_pci);
 		return bitforce_detect_oneof(info->path, &bfllif_pci);
+#endif
+#ifdef NEED_BFG_LOWL_MSWIN
+	if (lowl_mswin_match_guid(info, &WIN_GUID_DEVINTERFACE_MonarchKMDF))
+		return bitforce_detect_oneof(info->path, &bfllif_vcom);
 #endif
 #endif
 	return vcom_lowl_probe_wrapper(info, bitforce_detect_one);
 	return vcom_lowl_probe_wrapper(info, bitforce_detect_one);
 }
 }

+ 92 - 0
lowl-mswin.c

@@ -0,0 +1,92 @@
+/*
+ * Copyright 2014 Luke Dashjr
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 3 of the License, or (at your option)
+ * any later version.  See COPYING for more details.
+ */
+
+#include "config.h"
+
+#include <malloc.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <objbase.h>
+#include <rpc.h>
+#include <setupapi.h>
+#include <utlist.h>
+
+#include "logging.h"
+#include "lowlevel.h"
+#include "lowl-mswin.h"
+#include "util.h"
+
+static
+struct lowlevel_device_info *mswin_devinfo_scan()
+{
+	struct lowlevel_device_info *devinfo_list = NULL, *info;
+	
+	HDEVINFO devinfo = SetupDiGetClassDevs(NULL, NULL, NULL, (DIGCF_ALLCLASSES | DIGCF_DEVICEINTERFACE | DIGCF_PRESENT));
+	if (INVALID_HANDLE_VALUE == devinfo)
+		applogfailinfor(NULL, LOG_DEBUG, "SetupDiGetClassDevs", "%s", bfg_strerror(GetLastError(), BST_SYSTEM));
+	
+	SP_DEVINFO_DATA devinfodata = {
+		.cbSize = sizeof(devinfodata),
+	};
+	SP_DEVICE_INTERFACE_DATA devifacedata = {
+		.cbSize = sizeof(devifacedata),
+	};
+	for (int i = 0; SetupDiEnumDeviceInfo(devinfo, i, &devinfodata); ++i)
+	{
+		// FIXME: Figure out a way to get all GUIDs here
+		if (!SetupDiEnumDeviceInterfaces(devinfo, &devinfodata, &WIN_GUID_DEVINTERFACE_MonarchKMDF, 0, &devifacedata))
+		{
+			applogfailinfo(LOG_DEBUG, "SetupDiEnumDeviceInterfaces", "%s", bfg_strerror(GetLastError(), BST_SYSTEM));
+			continue;
+		}
+		DWORD detailsz;
+		if (!(!SetupDiGetDeviceInterfaceDetail(devinfo, &devifacedata, NULL, 0, &detailsz, NULL) && GetLastError() == ERROR_INSUFFICIENT_BUFFER))
+		{
+			applogfailinfo(LOG_ERR, "SetupDiEnumDeviceInterfaceDetail (1)", "%s", bfg_strerror(GetLastError(), BST_SYSTEM));
+			continue;
+		}
+		PSP_DEVICE_INTERFACE_DETAIL_DATA detail = alloca(detailsz);
+		detail->cbSize = sizeof(*detail);
+		if (!SetupDiGetDeviceInterfaceDetail(devinfo, &devifacedata, detail, detailsz, &detailsz, NULL))
+		{
+			applogfailinfo(LOG_ERR, "SetupDiEnumDeviceInterfaceDetail (2)", "%s", bfg_strerror(GetLastError(), BST_SYSTEM));
+			continue;
+		}
+		
+		char *devid = malloc(6 + strlen(detail->DevicePath) + 1);
+		sprintf(devid, "mswin:%s", detail->DevicePath);
+		
+		info = malloc(sizeof(struct lowlevel_device_info));
+		*info = (struct lowlevel_device_info){
+			.lowl = &lowl_mswin,
+			.devid = devid,
+			.path = strdup(detail->DevicePath),
+			.lowl_data = (void *)&WIN_GUID_DEVINTERFACE_MonarchKMDF,
+		};
+		LL_PREPEND(devinfo_list, info);
+	}
+	
+	SetupDiDestroyDeviceInfoList(devinfo);
+	
+	return devinfo_list;
+}
+
+bool lowl_mswin_match_guid(const struct lowlevel_device_info * const info, const GUID * const guid)
+{
+	if (info->lowl != &lowl_mswin)
+		return false;
+	return IsEqualGUID(info->lowl_data, guid);
+}
+
+struct lowlevel_driver lowl_mswin = {
+	.dname = "mswin",
+	.devinfo_scan = mswin_devinfo_scan,
+};

+ 12 - 0
lowl-mswin.h

@@ -0,0 +1,12 @@
+#ifndef BFG_LOWL_MSWIN_H
+#define BFG_LOWL_MSWIN_H
+
+#include <stdbool.h>
+
+#include <rpc.h>
+
+static const GUID WIN_GUID_DEVINTERFACE_MonarchKMDF = { 0xdcdb8d6f, 0x98b0, 0x4d1c, {0xa2, 0x77, 0x71, 0x17, 0x69, 0x70, 0x54, 0x31} };
+
+extern bool lowl_mswin_match_guid(const struct lowlevel_device_info *, const GUID *);
+
+#endif

+ 5 - 0
lowlevel.c

@@ -109,6 +109,11 @@ struct lowlevel_device_info *lowlevel_scan()
 	LL_CONCAT(devinfo_list, devinfo_mid_list);
 	LL_CONCAT(devinfo_list, devinfo_mid_list);
 #endif
 #endif
 	
 	
+#ifdef NEED_BFG_LOWL_MSWIN
+	devinfo_mid_list = lowl_mswin.devinfo_scan();
+	LL_CONCAT(devinfo_list, devinfo_mid_list);
+#endif
+	
 #ifdef NEED_BFG_LOWL_PCI
 #ifdef NEED_BFG_LOWL_PCI
 	devinfo_mid_list = lowl_pci.devinfo_scan();
 	devinfo_mid_list = lowl_pci.devinfo_scan();
 	LL_CONCAT(devinfo_list, devinfo_mid_list);
 	LL_CONCAT(devinfo_list, devinfo_mid_list);

+ 3 - 0
lowlevel.h

@@ -70,6 +70,9 @@ extern struct lowlevel_driver lowl_hid;
 #ifdef USE_NANOFURY
 #ifdef USE_NANOFURY
 extern struct lowlevel_driver lowl_mcp2210;
 extern struct lowlevel_driver lowl_mcp2210;
 #endif
 #endif
+#ifdef NEED_BFG_LOWL_MSWIN
+extern struct lowlevel_driver lowl_mswin;
+#endif
 #ifdef NEED_BFG_LOWL_PCI
 #ifdef NEED_BFG_LOWL_PCI
 extern struct lowlevel_driver lowl_pci;
 extern struct lowlevel_driver lowl_pci;
 #endif
 #endif