rendered paste bodyIndex: superiotool.c
===================================================================
--- superiotool.c (revision 2975)
+++ superiotool.c (working copy)
@@ -28,6 +28,43 @@
/* Global flag which indicates whether a chip was detected at all. */
int chip_found = 0;
+#if (__arm__)
+uint8_t inb(uint16_t port)
+{
+ static uint8_t val = 0;
+ FILE *fd = fopen("/dev/port", "r"); /* "a"? */
+
+ if (fd == NULL) {
+ perror("fopen");
+ return 0xff;
+ }
+
+ if (fseek(fd, port, SEEK_SET) != port) {
+ perror("fseek");
+ return 0xff;
+ }
+
+ fread(&val, sizeof(uint8_t), 1, fd);
+ fclose(fd);
+
+ return val;
+}
+
+void outb(uint8_t val, uint16_t port)
+{
+ int fd = open("/dev/port", O_WRONLY);
+
+ if (fd < 0) {
+ perror("open");
+ return;
+ }
+
+ lseek(fd, port, SEEK_SET);
+ write(fd, &val, 1);
+ close(fd);
+}
+#endif
+
uint8_t regval(uint16_t port, uint8_t reg)
{
outb(reg, port);
@@ -202,11 +239,13 @@
}
}
+#if !(__arm__)
if (iopl(3) < 0) {
perror("iopl");
printf("Superiotool must be run as root.\n");
exit(1);
}
+#endif
print_version();
Index: superiotool.h
===================================================================
--- superiotool.h (revision 2975)
+++ superiotool.h (working copy)
@@ -27,7 +27,13 @@
#include <stdint.h>
#include <string.h>
#include <getopt.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#if !(__arm__)
#include <sys/io.h>
+#endif
#define USAGE "Usage: superiotool [-d] [-V] [-v] [-h]\n\n\
-d | --dump Dump Super I/O register contents\n\
@@ -70,6 +76,10 @@
};
/* superiotool.c */
+#if (__arm__)
+uint8_t inb(uint16_t port);
+void outb(uint8_t val, uint16_t port);
+#endif
uint8_t regval(uint16_t port, uint8_t reg);
void regwrite(uint16_t port, uint8_t reg, uint8_t val);
void enter_conf_mode_winbond_fintek_ite_8787(uint16_t port);