[coreboot-gerrit] New patch to review for coreboot: viatool: add NetBSD support

Andrey Korolyov (andrey@xdel.ru) gerrit at coreboot.org
Tue Jan 5 18:15:09 CET 2016


Andrey Korolyov (andrey at xdel.ru) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/12836

-gerrit

commit 72271eb59c0af6eff8fe5669b4bf1707bac4ba0c
Author: Andrey Korolyov <andrey at xdel.ru>
Date:   Tue Jan 5 20:09:02 2016 +0300

    viatool: add NetBSD support
    
    Change-Id: I033044e4b781475d6d60a49a61313a720103ce38
    Signed-off-by: Andrey Korolyov <andrey at xdel.ru>
---
 util/viatool/Makefile  | 13 +++++++++++--
 util/viatool/viatool.c | 12 ++++++++++++
 util/viatool/viatool.h | 28 ++++++++++++++++++++++++++++
 3 files changed, 51 insertions(+), 2 deletions(-)

diff --git a/util/viatool/Makefile b/util/viatool/Makefile
index de3bfdd..37e74bf 100644
--- a/util/viatool/Makefile
+++ b/util/viatool/Makefile
@@ -40,11 +40,16 @@ CFLAGS += -I/usr/local/include
 LDFLAGS += -L/usr/local/lib
 LIBS = -lz
 endif
+ifeq ($(OS_ARCH), NetBSD)
+CFLAGS += -I/usr/pkg/include
+LDFLAGS += -L/usr/pkg/lib -Wl,-rpath-link,/usr/pkg/lib
+LIBS = -lz -lpciutils -lpci -l$(shell uname -p)
+endif
 
 all: pciutils dep $(PROGRAM)
 
 $(PROGRAM): $(OBJS)
-	$(CC) $(CFLAGS) -o $(PROGRAM) $(OBJS) $(LDFLAGS)
+	$(CC) $(CFLAGS) -o $(PROGRAM) $(OBJS) $(LDFLAGS) $(LIBS)
 
 clean:
 	# Remove build results
@@ -62,7 +67,11 @@ dep:
 define LIBPCI_TEST
 /* Avoid a failing test due to libpci header symbol shadowing breakage */
 #define index shadow_workaround_index
+#ifdef __NetBSD__
+#include <pciutils/pci.h>
+#else
 #include <pci/pci.h>
+#endif
 struct pci_access *pacc;
 int main(int argc, char **argv)
 {
@@ -77,7 +86,7 @@ export LIBPCI_TEST
 pciutils:
 	@printf "\nChecking for pciutils and zlib... "
 	@echo "$$LIBPCI_TEST" > .test.c
-	@$(CC) $(CFLAGS) .test.c -o .test $(LDFLAGS) >/dev/null 2>&1 &&	  \
+	@echo $(CC) $(CFLAGS) .test.c -o .test $(LDFLAGS) $(LIBS) >/dev/null 2>&1 &&	  \
 		printf "found.\n" || ( printf "not found.\n\n"; 	  \
 		printf "Please install pciutils-devel and zlib-devel.\n"; \
 		printf "See README for more information.\n\n";		  \
diff --git a/util/viatool/viatool.c b/util/viatool/viatool.c
index 0fde455..c19647f 100644
--- a/util/viatool/viatool.c
+++ b/util/viatool/viatool.c
@@ -25,6 +25,10 @@
 #include <unistd.h>
 #include "viatool.h"
 
+#ifdef __NetBSD__
+#include <machine/sysarch.h>
+#endif
+
 /*
  * http://pci-ids.ucw.cz/read/PC/8086
  * http://en.wikipedia.org/wiki/Intel_Tick-Tock
@@ -146,6 +150,14 @@ int main(int argc, char *argv[])
 #if defined(__FreeBSD__)
 	if (open("/dev/io", O_RDWR) < 0) {
 		perror("/dev/io");
+#elif defined(__NetBSD__)
+# ifdef __i386__
+	if (i386_iopl(3)) {
+		perror("iopl");
+# else
+	if (x86_64_iopl(3)) {
+		perror("iopl");
+# endif
 #else
 	if (iopl(3)) {
 		perror("iopl");
diff --git a/util/viatool/viatool.h b/util/viatool/viatool.h
index a0a5d79..338d7a5 100644
--- a/util/viatool/viatool.h
+++ b/util/viatool/viatool.h
@@ -28,13 +28,41 @@
 #define __DARWIN__
 #include <DirectHW/DirectHW.h>
 #endif
+#ifdef __NetBSD__
+#include <pciutils/pci.h>
+#else
 #include <pci/pci.h>
+#endif
 
 /* This #include is needed for freebsd_{rd,wr}msr. */
 #if defined(__FreeBSD__)
 #include <machine/cpufunc.h>
 #endif
 
+#ifdef __NetBSD__
+static uint8_t __attribute__ ((unused))
+inb(unsigned port)
+{
+	uint8_t data;
+	__asm volatile("inb %w1,%0" : "=a" (data) : "d" (port));
+	return data;
+}
+static uint16_t __attribute__ ((unused))
+inw(unsigned port)
+{
+uint16_t data;
+	__asm volatile("inw %w1,%0": "=a" (data) : "d" (port));
+	return data;
+}
+static uint32_t __attribute__ ((unused))
+inl(unsigned port)
+{
+	uint32_t data;
+	__asm volatile("inl %w1,%0": "=a" (data) : "d" (port));
+	return data;
+}
+#endif
+
 #include <stdlib.h>
 
 #define VIATOOL_VERSION "1.0"



More information about the coreboot-gerrit mailing list