Add inteltool support for FreeBSD.
authorIdwer Vollering <vidwer@gmail.com>
Sun, 24 Oct 2010 13:50:13 +0000 (13:50 +0000)
committerUwe Hermann <uwe@hermann-uwe.de>
Sun, 24 Oct 2010 13:50:13 +0000 (13:50 +0000)
Signed-off-by: Idwer Vollering <vidwer@gmail.com>
Acked-by Stefan Reinauer <stepan@coreboot.org>
Acked-by: Uwe Hermann <uwe@hermann-uwe.de>
git-svn-id: svn://svn.coreboot.org/coreboot/trunk@5981 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1

util/inteltool/Makefile
util/inteltool/inteltool.c
util/inteltool/inteltool.h

index 3850682e5f2e7832493a2e15d0ee3510d25047de..c6894c0afd036fa7d34ea6d12a82876b694cfd9c 100644 (file)
@@ -33,6 +33,11 @@ OS_ARCH      = $(shell uname)
 ifeq ($(OS_ARCH), Darwin)
 LDFLAGS = -framework DirectIO -lpci -lz
 endif
+ifeq ($(OS_ARCH), FreeBSD)
+CFLAGS += -I/usr/local/include
+LDFLAGS += -L/usr/local/lib
+LIBS = -lz
+endif
 
 all: pciutils dep $(PROGRAM)
 
index c6a835fd7e9a856ce75b6f050ca171d4d683269c..bf5efc9924c94c026a1020d8a5249aaad0702698 100644 (file)
@@ -3,6 +3,7 @@
  *
  * Copyright (C) 2008-2010 by coresystems GmbH
  *  written by Stefan Reinauer <stepan@coresystems.de>
+ * Copyright (C) 2009 Carl-Daniel Hailfinger
  *
  * 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
@@ -24,6 +25,9 @@
 #include <fcntl.h>
 #include <sys/mman.h>
 #include "inteltool.h"
+#if defined(__FreeBSD__)
+#include <unistd.h>
+#endif
 
 static const struct {
        uint16_t vendor_id, device_id;
@@ -213,7 +217,17 @@ int main(int argc, char *argv[])
                }
        }
 
+#if defined(__FreeBSD__)
+       int io_fd;
+#endif
+
+#if defined(__FreeBSD__)
+       if ((io_fd = open("/dev/io", O_RDWR)) < 0) {
+               perror("/dev/io");
+#else
        if (iopl(3)) {
+               perror("iopl");
+#endif
                printf("You need to be root.\n");
                exit(1);
        }
index 8eb70895058114cae2454e5a81803884fd4d1452..bc18a69c655e22965da859719413bad2b564cca8 100644 (file)
@@ -2,6 +2,7 @@
  * inteltool - dump all registers on an Intel CPU + chipset based system.
  *
  * Copyright (C) 2008-2010 by coresystems GmbH
+ * Copyright (C) 2009 Carl-Daniel Hailfinger
  *
  * 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
 #endif
 #include <pci/pci.h>
 
+/* This #include is needed for freebsd_{rd,wr}msr. */
+#if defined(__FreeBSD__)
+#include <machine/cpufunc.h>
+#endif
+
 #define INTELTOOL_VERSION "1.0"
 
 /* Tested chipsets: */
 
 #define ARRAY_SIZE(a) ((int)(sizeof(a) / sizeof((a)[0])))
 
-#ifndef __DARWIN__
+#if !defined(__DARWIN__) && !defined(__FreeBSD__)
 typedef struct { uint32_t hi, lo; } msr_t;
 #endif
+#if defined (__FreeBSD__)
+/* FreeBSD already has conflicting definitions for wrmsr/rdmsr. */
+#undef rdmsr
+#undef wrmsr
+#define rdmsr freebsd_rdmsr
+#define wrmsr freebsd_wrmsr
+typedef struct { uint32_t hi, lo; } msr_t;
+msr_t freebsd_rdmsr(int addr);
+int freebsd_wrmsr(int addr, msr_t msr);
+#endif
 typedef struct { uint16_t addr; int size; char *name; } io_register_t;
 
 void *map_physical(unsigned long phys_addr, size_t len);
@@ -105,4 +121,3 @@ int print_gpios(struct pci_dev *sb);
 int print_epbar(struct pci_dev *nb);
 int print_dmibar(struct pci_dev *nb);
 int print_pciexbar(struct pci_dev *nb);
-