Support Debian/kFreeBSD

Corresponding to flashrom svn r1507.

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Tested-by: Robert Millan <rmh@debian.org>
Tested-by: Uwe Hermann <uwe@hermann-uwe.de>
Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
diff --git a/hwaccess.c b/hwaccess.c
index 51e113e..0efcb6d 100644
--- a/hwaccess.c
+++ b/hwaccess.c
@@ -40,7 +40,7 @@
 {
 }
 
-#if defined(__FreeBSD__) || defined(__DragonFly__)
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 int io_fd;
 #endif
 
@@ -52,7 +52,7 @@
 #else
 #if defined (__sun) && (defined(__i386) || defined(__amd64))
 	if (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) != 0) {
-#elif defined(__FreeBSD__) || defined (__DragonFly__)
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined (__DragonFly__)
 	if ((io_fd = open("/dev/io", O_RDWR)) < 0) {
 #else 
 	if (iopl(3) != 0) {
@@ -71,7 +71,7 @@
 
 void release_io_perms(void)
 {
-#if defined(__FreeBSD__) || defined(__DragonFly__)
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 	close(io_fd);
 #endif
 }
diff --git a/hwaccess.h b/hwaccess.h
index c10b12e..1e276ec 100644
--- a/hwaccess.h
+++ b/hwaccess.h
@@ -189,6 +189,10 @@
  */
 
 #if defined(__FreeBSD__) || defined(__DragonFly__)
+  /* Note that Debian/kFreeBSD (FreeBSD kernel with glibc) has conflicting
+   * out[bwl] definitions in machine/cpufunc.h and sys/io.h at least in some
+   * versions. Use machine/cpufunc.h only for plain FreeBSD/DragonFlyBSD.
+   */
   #include <machine/cpufunc.h>
   #define off64_t off_t
   #define lseek64 lseek
@@ -228,7 +232,7 @@
   #define INL  inportl
 
 #else
-
+  /* This is the usual glibc interface. */
   #define OUTB outb
   #define OUTW outw
   #define OUTL outl
@@ -299,12 +303,12 @@
   #endif
 #endif
 
-#if !defined(__DARWIN__) && !defined(__FreeBSD__) && !defined(__DragonFly__) && !defined(__LIBPAYLOAD__)
+#if !defined(__DARWIN__) && !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) && !defined(__DragonFly__) && !defined(__LIBPAYLOAD__)
 typedef struct { uint32_t hi, lo; } msr_t;
 msr_t rdmsr(int addr);
 int wrmsr(int addr, msr_t msr);
 #endif
-#if defined(__FreeBSD__) || defined(__DragonFly__)
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 /* FreeBSD already has conflicting definitions for wrmsr/rdmsr. */
 #undef rdmsr
 #undef wrmsr
diff --git a/os.h b/os.h
index 4ca7bb5..f1b366f 100644
--- a/os.h
+++ b/os.h
@@ -30,6 +30,9 @@
 // FreeBSD
 #elif defined(__FreeBSD__)
 #define __FLASHROM_OS__ "FreeBSD"
+// FreeBSD with glibc-based userspace (e.g. Debian/kFreeBSD)
+#elif defined(__FreeBSD_kernel__) && defined(__GLIBC__)
+#define __FLASHROM_OS__ "FreeBSD-glibc"
 // DragonFlyBSD
 #elif defined(__DragonFly__)
 #define __FLASHROM_OS__ "DragonFlyBSD"
diff --git a/physmap.c b/physmap.c
index d92015d..e54dee4 100644
--- a/physmap.c
+++ b/physmap.c
@@ -382,7 +382,7 @@
 	fd_msr = -1;
 }
 #else
-#if defined(__FreeBSD__) || defined(__DragonFly__)
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 #include <sys/ioctl.h>
 
 typedef struct {