Browse Source

Make iopl and ioperm work

Eric Andersen 23 years ago
parent
commit
88a880c205
1 changed files with 22 additions and 37 deletions
  1. 22 37
      libc/sysdeps/linux/arm/ioperm.c

+ 22 - 37
libc/sysdeps/linux/arm/ioperm.c

@@ -41,8 +41,8 @@
 #include <string.h>
 #include <unistd.h>
 #include <sys/types.h>
-//#include <sys/mman.h>
-//#include <asm/page.h>
+#include <sys/types.h>
+#include <sys/mman.h>
 
 
 #define IO_BASE			0x7c000000
@@ -50,62 +50,47 @@
 #define IO_ADDR(port)	(IO_BASE + ((port) << IO_SHIFT))
 
 
-#if 0
-static struct {
-  unsigned long int	base;
-  unsigned long int	io_base;
-  unsigned int		shift;
-  unsigned int		initdone;	/* since all the above could be 0 */
-} io;
-
-
 #define MAX_PORT	0x10000
 int ioperm(unsigned long int from, unsigned long int num, int turn_on)
 {
-  /* this test isn't as silly as it may look like; consider overflows! */
-  if (from >= MAX_PORT || from + num > MAX_PORT)
-    {
-      __set_errno (EINVAL);
-      return -1;
+    /* this test isn't as silly as it may look like; consider overflows! */
+    if (from >= MAX_PORT || from + num > MAX_PORT) {
+	__set_errno (EINVAL);
+	return -1;
     }
 
-  if (turn_on)
+    if (turn_on)
     {
-      if (! io.base)
-	{
-	  int fd;
+	int fd;
+	unsigned long int base;
 
-	  fd = open ("/dev/mem", O_RDWR);
-	  if (fd < 0)
+	fd = open ("/dev/mem", O_RDWR);
+	if (fd < 0)
 	    return -1;
 
-	  io.base = (unsigned long int) mmap (0, MAX_PORT << io.shift, 
-					PROT_READ | PROT_WRITE, 
-					MAP_SHARED, fd, io.io_base);
-	  close (fd);
-	  if ((long) io.base == -1)
+	base = (unsigned long int) mmap (0, MAX_PORT << IO_SHIFT, 
+		PROT_READ | PROT_WRITE, 
+		MAP_SHARED, fd, IO_BASE);
+	close (fd);
+	if ((long) base == -1)
 	    return -1;
-	}
     }
 
-  return 0;
+    return 0;
 }
 
 
 int iopl (unsigned int level)
 {
-    if (level > 3)
-      {
+    if (level > 3) {
 	__set_errno (EINVAL);
 	return -1;
-      }
-    if (level)
-      {
-	return _ioperm (0, MAX_PORT, 1);
-      }
+    }
+    if (level) {
+	return ioperm (0, MAX_PORT, 1);
+    }
     return 0;
 }
-#endif
 
 void outb (unsigned char b, unsigned long int port)
 {