[coreboot] r3698 - trunk/util/superiotool

svn at coreboot.org svn at coreboot.org
Tue Oct 28 23:13:38 CET 2008


Author: uwe
Date: 2008-10-28 23:13:38 +0100 (Tue, 28 Oct 2008)
New Revision: 3698

Modified:
   trunk/util/superiotool/ali.c
   trunk/util/superiotool/ite.c
   trunk/util/superiotool/nsc.c
   trunk/util/superiotool/smsc.c
   trunk/util/superiotool/superiotool.c
   trunk/util/superiotool/superiotool.h
   trunk/util/superiotool/winbond.c
Log:
Allow superiotool to compile and work on FreeBSD. Tested on FreeBSD 7.

Signed-off-by: Andriy Gapon <avg at icyb.net.ua>
Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006 at gmx.net>
Acked-by: Uwe Hermann <uwe at hermann-uwe.de>



Modified: trunk/util/superiotool/ali.c
===================================================================
--- trunk/util/superiotool/ali.c	2008-10-28 12:00:59 UTC (rev 3697)
+++ trunk/util/superiotool/ali.c	2008-10-28 22:13:38 UTC (rev 3698)
@@ -60,13 +60,13 @@
 
 static void enter_conf_mode_ali(uint16_t port)
 {
-	outb(0x51, port);
-	outb(0x23, port);
+	OUTB(0x51, port);
+	OUTB(0x23, port);
 }
 
 static void exit_conf_mode_ali(uint16_t port)
 {
-	outb(0xbb, port);
+	OUTB(0xbb, port);
 }
 
 void probe_idregs_ali(uint16_t port)

Modified: trunk/util/superiotool/ite.c
===================================================================
--- trunk/util/superiotool/ite.c	2008-10-28 12:00:59 UTC (rev 3697)
+++ trunk/util/superiotool/ite.c	2008-10-28 22:13:38 UTC (rev 3698)
@@ -468,11 +468,11 @@
 	/* Determine Super I/O config port. */
 	idx = (port == 0x3f0) ? 0 : ((port == 0x3bd) ? 1 : 2);
 	for (i = 0; i < 4; i++)
-		outb(init[idx][i], ISA_PNP_ADDR);
+		OUTB(init[idx][i], ISA_PNP_ADDR);
 
 	/* Sequentially write the 32 MB PnP init values. */
 	for (i = 0; i < 32; i++)
-		outb(initkey_mbpnp[i], port);
+		OUTB(initkey_mbpnp[i], port);
 }
 
 /**
@@ -482,10 +482,10 @@
  */
 static void enter_conf_mode_ite(uint16_t port)
 {
-	outb(0x87, port);
-	outb(0x01, port);
-	outb(0x55, port);
-	outb((port == 0x2e) ? 0x55 : 0xaa, port);
+	OUTB(0x87, port);
+	OUTB(0x01, port);
+	OUTB(0x55, port);
+	OUTB((port == 0x2e) ? 0x55 : 0xaa, port);
 }
 
 static void exit_conf_mode_ite(uint16_t port)

Modified: trunk/util/superiotool/nsc.c
===================================================================
--- trunk/util/superiotool/nsc.c	2008-10-28 12:00:59 UTC (rev 3697)
+++ trunk/util/superiotool/nsc.c	2008-10-28 22:13:38 UTC (rev 3698)
@@ -479,21 +479,21 @@
 
 	probing_for("NSC", "", port);
 
-	outb(CHIP_ID_REG, port);
-	if (inb(port) != CHIP_ID_REG) {
+	OUTB(CHIP_ID_REG, port);
+	if (INB(port) != CHIP_ID_REG) {
 		if (verbose)
 			printf(NOTFOUND "port=0x%02x, port+1=0x%02x\n",
-			       inb(port), inb(port + 1));
+			       INB(port), INB(port + 1));
 		return;
 	}
-	id = inb(port + 1);
+	id = INB(port + 1);
 
-	outb(CHIP_REV_REG, port);
-	if (inb(port) != CHIP_REV_REG) {
+	OUTB(CHIP_REV_REG, port);
+	if (INB(port) != CHIP_REV_REG) {
 		printf("Warning: Can't get chip revision. Setting to 0xff.\n");
 		rev = 0xff;
 	} else {
-		rev = inb(port + 1);
+		rev = INB(port + 1);
 	}
 
 	if (superio_unknown(reg_table, id)) {

Modified: trunk/util/superiotool/smsc.c
===================================================================
--- trunk/util/superiotool/smsc.c	2008-10-28 12:00:59 UTC (rev 3697)
+++ trunk/util/superiotool/smsc.c	2008-10-28 22:13:38 UTC (rev 3698)
@@ -608,13 +608,13 @@
 	 * in the assumption that the extra 0x55 won't hurt the other
 	 * Super I/Os. This is verified to be true on (at least) the FDC37N769.
 	 */
-	outb(0x55, port);
-	outb(0x55, port);
+	OUTB(0x55, port);
+	OUTB(0x55, port);
 }
 
 static void exit_conf_mode_smsc(uint16_t port)
 {
-	outb(0xaa, port);
+	OUTB(0xaa, port);
 }
 
 static void probe_idregs_smsc_helper(uint16_t port, uint8_t idreg,

Modified: trunk/util/superiotool/superiotool.c
===================================================================
--- trunk/util/superiotool/superiotool.c	2008-10-28 12:00:59 UTC (rev 3697)
+++ trunk/util/superiotool/superiotool.c	2008-10-28 22:13:38 UTC (rev 3698)
@@ -23,6 +23,11 @@
 
 #include "superiotool.h"
 
+#if defined(__FreeBSD__)
+#include <fcntl.h>
+#include <unistd.h>
+#endif
+
 /* Command line options. */
 int dump = 0, verbose = 0, extra_dump = 0;
 
@@ -31,25 +36,25 @@
 
 uint8_t regval(uint16_t port, uint8_t reg)
 {
-	outb(reg, port);
-	return inb(port + ((port == 0x3bd) ? 2 : 1)); /* 0x3bd is special. */
+	OUTB(reg, port);
+	return INB(port + ((port == 0x3bd) ? 2 : 1)); /* 0x3bd is special. */
 }
 
 void regwrite(uint16_t port, uint8_t reg, uint8_t val)
 {
-	outb(reg, port);
-	outb(val, port + 1);
+	OUTB(reg, port);
+	OUTB(val, port + 1);
 }
 
 void enter_conf_mode_winbond_fintek_ite_8787(uint16_t port)
 {
-	outb(0x87, port);
-	outb(0x87, port);
+	OUTB(0x87, port);
+	OUTB(0x87, port);
 }
 
 void exit_conf_mode_winbond_fintek_ite_8787(uint16_t port)
 {
-	outb(0xaa, port);		/* Fintek, Winbond */
+	OUTB(0xaa, port);		/* Fintek, Winbond */
 	regwrite(port, 0x02, 0x02);	/* ITE */
 }
 
@@ -204,6 +209,9 @@
 int main(int argc, char *argv[])
 {
 	int i, j, opt, option_index;
+#if defined(__FreeBSD__)
+	int io_fd;
+#endif
 
 	static const struct option long_options[] = {
 		{"dump",		no_argument, NULL, 'd'},
@@ -247,8 +255,13 @@
 		}
 	}
 
+#if defined(__FreeBSD__)
+	if ((io_fd = open("/dev/io", O_RDWR)) < 0) {
+		perror("/dev/io");
+#else
 	if (iopl(3) < 0) {
 		perror("iopl");
+#endif
 		printf("Superiotool must be run as root.\n");
 		exit(1);
 	}
@@ -264,5 +277,8 @@
 	if (!chip_found)
 		printf("No Super I/O found\n");
 
+#if defined(__FreeBSD__)
+	close(io_fd);
+#endif
 	return 0;
 }

Modified: trunk/util/superiotool/superiotool.h
===================================================================
--- trunk/util/superiotool/superiotool.h	2008-10-28 12:00:59 UTC (rev 3697)
+++ trunk/util/superiotool/superiotool.h	2008-10-28 22:13:38 UTC (rev 3698)
@@ -28,8 +28,28 @@
 #include <stdint.h>
 #include <string.h>
 #include <getopt.h>
+#if defined(__GLIBC__)
 #include <sys/io.h>
+#endif
 
+#if defined(__FreeBSD__)
+#include <sys/types.h>
+#include <machine/cpufunc.h>
+#define OUTB(x, y) do { u_int tmp = (y); outb(tmp, (x)); } while (0)
+#define OUTW(x, y) do { u_int tmp = (y); outw(tmp, (x)); } while (0)
+#define OUTL(x, y) do { u_int tmp = (y); outl(tmp, (x)); } while (0)
+#define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })
+#define INW(x) __extension__ ({ u_int tmp = (x); inw(tmp); })
+#define INL(x) __extension__ ({ u_int tmp = (x); inl(tmp); })
+#else
+#define OUTB outb
+#define OUTW outw
+#define OUTL outl
+#define INB  inb
+#define INW  inw
+#define INL  inl
+#endif
+
 #define USAGE "Usage: superiotool [-d] [-e] [-l] [-V] [-v] [-h]\n\n\
   -d | --dump            Dump Super I/O register contents\n\
   -e | --extra-dump      Dump secondary registers too (e.g. EC registers)\n\

Modified: trunk/util/superiotool/winbond.c
===================================================================
--- trunk/util/superiotool/winbond.c	2008-10-28 12:00:59 UTC (rev 3697)
+++ trunk/util/superiotool/winbond.c	2008-10-28 22:13:38 UTC (rev 3698)
@@ -470,18 +470,18 @@
 
 static void enter_conf_mode_winbond_88(uint16_t port)
 {
-	outb(0x88, port);
+	OUTB(0x88, port);
 }
 
 static void enter_conf_mode_winbond_89(uint16_t port)
 {
-	outb(0x89, port);
+	OUTB(0x89, port);
 }
 
 static void enter_conf_mode_winbond_86(uint16_t port)
 {
-	outb(0x86, port);
-	outb(0x86, port);
+	OUTB(0x86, port);
+	OUTB(0x86, port);
 }
 
 static void probe_idregs_winbond_helper(const char *init, uint16_t port)





More information about the coreboot mailing list