summaryrefslogtreecommitdiff
path: root/util/nvramtool/cmos_lowlevel.c
diff options
context:
space:
mode:
authorAndriy Gapon <avg@icyb.net.ua>2008-10-30 15:41:39 +0000
committerUwe Hermann <uwe@hermann-uwe.de>2008-10-30 15:41:39 +0000
commit6a4bf9886ac9990206ac64fd09890bca433d9bd8 (patch)
treefbb671eed32708e7d8bbe4852ef3ff624db7034c /util/nvramtool/cmos_lowlevel.c
parentb076ced581669632d03b2f768b30aec2ffcd2e23 (diff)
downloadcoreboot-6a4bf9886ac9990206ac64fd09890bca433d9bd8.tar.xz
Allow nvramtool to build and work on FreeBSD. Tested on FreeBSD 7.
Signed-off-by: Andriy Gapon <avg@icyb.net.ua> Acked-by: Uwe Hermann <uwe@hermann-uwe.de> git-svn-id: svn://svn.coreboot.org/coreboot/trunk@3709 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'util/nvramtool/cmos_lowlevel.c')
-rw-r--r--util/nvramtool/cmos_lowlevel.c46
1 files changed, 39 insertions, 7 deletions
diff --git a/util/nvramtool/cmos_lowlevel.c b/util/nvramtool/cmos_lowlevel.c
index 9ad6891d0c..b5e8dee9b2 100644
--- a/util/nvramtool/cmos_lowlevel.c
+++ b/util/nvramtool/cmos_lowlevel.c
@@ -28,7 +28,11 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\*****************************************************************************/
-#include <sys/io.h>
+#if defined(__FreeBSD__)
+#include <fcntl.h>
+#include <unistd.h>
+#endif
+
#include "common.h"
#include "cmos_lowlevel.h"
@@ -176,8 +180,8 @@ unsigned char cmos_read_byte (unsigned index)
port_1 = 0x73;
}
- outb(index, port_0);
- return inb(port_1);
+ OUTB(index, port_0);
+ return INB(port_1);
}
/****************************************************************************
@@ -204,8 +208,8 @@ void cmos_write_byte (unsigned index, unsigned char value)
port_1 = 0x73;
}
- outb(index, port_0);
- outb(value, port_1);
+ OUTB(index, port_0);
+ OUTB(value, port_1);
}
/****************************************************************************
@@ -248,8 +252,35 @@ void cmos_write_all (unsigned char data[])
* level is therefore somewhat dangerous.
****************************************************************************/
void set_iopl (int level)
- { assert((level >= 0) && (level <= 3));
-
+ {
+#if defined(__FreeBSD__)
+ static int io_fd = -1;
+#endif
+
+ assert((level >= 0) && (level <= 3));
+
+#if defined(__FreeBSD__)
+ if (level == 0)
+ {
+ if (io_fd != -1)
+ {
+ close(io_fd);
+ io_fd = -1;
+ }
+ }
+ else
+ {
+ if (io_fd == -1)
+ {
+ io_fd = open("/dev/io", O_RDWR);
+ if (io_fd < 0)
+ {
+ perror("/dev/io");
+ exit(1);
+ }
+ }
+ }
+#else
if (iopl(level))
{ fprintf(stderr,
"%s: iopl() system call failed. You must be root to do "
@@ -257,6 +288,7 @@ void set_iopl (int level)
prog_name);
exit(1);
}
+#endif
}
/****************************************************************************