Browse Source

lowl-pci: New lowlevel driver for raw PCI devices

Luke Dashjr 12 years ago
parent
commit
03e8c90324
5 changed files with 88 additions and 0 deletions
  1. 4 0
      Makefile.am
  2. 7 0
      configure.ac
  3. 69 0
      lowl-pci.c
  4. 5 0
      lowlevel.c
  5. 3 0
      lowlevel.h

+ 4 - 0
Makefile.am

@@ -299,6 +299,10 @@ bfgminer_SOURCES += lowl-hid.c lowl-hid.h
 bfgminer_CPPFLAGS += $(hidapi_CFLAGS)
 endif
 
+if NEED_BFG_LOWL_PCI
+bfgminer_SOURCES += lowl-pci.c
+endif
+
 bin_PROGRAMS += bfgminer-rpc
 bfgminer_rpc_SOURCES = api-example.c
 bfgminer_rpc_LDADD = @WS2_LIBS@

+ 7 - 0
configure.ac

@@ -125,6 +125,7 @@ need_dynclock=no
 need_lowl_vcom=no
 need_lowlevel=no
 need_lowl_hid=no
+need_lowl_pci=no
 need_lowl_usb=no
 have_cygwin=false
 have_win32=false
@@ -981,6 +982,11 @@ if test x$need_lowl_hid = xyes; then
 	need_lowlevel=yes
 fi
 
+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])
+	need_lowlevel=yes
+fi
+
 if test x$need_lowl_usb = xyes; then
 	need_lowlevel=yes
 fi
@@ -1169,6 +1175,7 @@ AM_CONDITIONAL([NEED_BFG_BINLOADER], [test x$need_binloader = xyes])
 AM_CONDITIONAL([NEED_DYNCLOCK], [test x$need_dynclock = xyes])
 AM_CONDITIONAL([NEED_BFG_LOWL_VCOM], [test x$need_lowl_vcom = xyes])
 AM_CONDITIONAL([NEED_BFG_LOWL_HID], [test x$need_lowl_hid = xyes])
+AM_CONDITIONAL([NEED_BFG_LOWL_PCI], [test x$need_lowl_pci = xyes])
 AM_CONDITIONAL([NEED_BFG_LOWLEVEL], [test x$need_lowlevel = xyes])
 AM_CONDITIONAL([HAS_SCRYPT], [test x$scrypt = xyes])
 AM_CONDITIONAL([HAVE_CURSES], [test x$curses = xyes])

+ 69 - 0
lowl-pci.c

@@ -0,0 +1,69 @@
+/*
+ * 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 <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <dirent.h>
+
+#include <utlist.h>
+
+#include "lowlevel.h"
+#include "util.h"
+
+static
+struct lowlevel_device_info *pci_devinfo_scan()
+{
+	struct lowlevel_device_info *devinfo_list = NULL, *info;
+	struct dirent *de;
+	char filename[0x100] = "/sys/bus/pci/devices", buf[0x10];
+	DIR * const D = opendir(filename);
+	if (!D)
+		return 0;
+	char * const p = &filename[strlen(filename)], *devid;
+	const size_t psz = sizeof(filename) - (p - filename);
+	uint32_t vid, pid;
+	size_t d_name_len;
+	while ( (de = readdir(D)) )
+	{
+		d_name_len = strlen(de->d_name);
+		snprintf(p, psz, "/%s/vendor", de->d_name);
+		if (!bfg_slurp_file(buf, sizeof(buf), filename))
+			continue;
+		vid = strtoll(buf, NULL, 0);
+		snprintf(p, psz, "/%s/device", de->d_name);
+		if (!bfg_slurp_file(buf, sizeof(buf), filename))
+			continue;
+		pid = strtoll(buf, NULL, 0);
+		devid = malloc(4 + d_name_len + 1);
+		sprintf(devid, "pci:%s", de->d_name);
+		
+		info = malloc(sizeof(struct lowlevel_device_info));
+		*info = (struct lowlevel_device_info){
+			.lowl = &lowl_pci,
+			.devid = devid,
+			.path = strdup(de->d_name),
+			.vid = vid,
+			.pid = pid,
+		};
+		
+		LL_PREPEND(devinfo_list, info);
+	}
+	closedir(D);
+	return devinfo_list;
+}
+
+struct lowlevel_driver lowl_pci = {
+	.dname = "pci",
+	.devinfo_scan = pci_devinfo_scan,
+};

+ 5 - 0
lowlevel.c

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

+ 3 - 0
lowlevel.h

@@ -66,6 +66,9 @@ extern struct lowlevel_driver lowl_hid;
 #ifdef USE_NANOFURY
 extern struct lowlevel_driver lowl_mcp2210;
 #endif
+#ifdef NEED_BFG_LOWL_PCI
+extern struct lowlevel_driver lowl_pci;
+#endif
 #ifdef HAVE_LIBUSB
 extern struct lowlevel_driver lowl_usb;
 #else