Ported functions port_deny_full and port_deny to BSDs. Also converted the C++ comments to C comments.
This commit is contained in:
+89
-37
@@ -7,27 +7,35 @@
|
|||||||
*
|
*
|
||||||
* FreeBSD support by Guillaume Filion and Philip Pokorny, copyright 05/2001
|
* FreeBSD support by Guillaume Filion and Philip Pokorny, copyright 05/2001
|
||||||
*
|
*
|
||||||
* NetBSD port by Guillaume Filion, copyright 12/2001
|
* NetBSD port by Guillaume Filion, copyright 12/2001 and 02/2002
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This file defines 4 static inline functions for port I/O:
|
This file defines 6 static inline functions for port I/O:
|
||||||
|
|
||||||
// Read a byte from port
|
Read a byte from port
|
||||||
static inline int port_in (unsigned short int port);
|
static inline int port_in (unsigned short int port);
|
||||||
// Returns the content of the byte.
|
Returns the content of the byte.
|
||||||
|
|
||||||
// Write a char(byte) 'val' to port.
|
Write a char(byte) 'val' to port.
|
||||||
static inline void port_out (unsigned short int port, unsigned char val);
|
static inline void port_out (unsigned short int port, unsigned char val);
|
||||||
// Returns nothing.
|
Returns nothing.
|
||||||
|
|
||||||
// Get access to a specific port
|
Get access to a specific port
|
||||||
static inline int port_access (unsigned short int port);
|
static inline int port_access (unsigned short int port);
|
||||||
// Returns 0 if successful, -1 if failed
|
Returns 0 if successful, -1 if failed
|
||||||
|
|
||||||
// Get access 3 to ports: port (CONTROL), port+1 (STATUS) and port+2 (DATA)
|
Close access to a specific port
|
||||||
static inline int port_access_full (unsigned short int port);
|
static inline int port_deny (unsigned short int port);
|
||||||
// Returns 0 if successful, -1 if failed
|
Returns 0 if successful, -1 if failed
|
||||||
|
|
||||||
|
Get access 3 to ports: port (CONTROL), port+1 (STATUS) and port+2 (DATA)
|
||||||
|
static inline int port_access_full (unsigned short int port);
|
||||||
|
Returns 0 if successful, -1 if failed
|
||||||
|
|
||||||
|
Close access to 3 ports: port (CONTROL), port+1 (STATUS) and port+2 (DATA)
|
||||||
|
static inline int port_deny_full (unsigned short int port);
|
||||||
|
Returns 0 if successful, -1 if failed
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef PORT_H
|
#ifndef PORT_H
|
||||||
@@ -39,48 +47,54 @@ static inline int port_access_full (unsigned short int port);
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
// -------------------------------------------------------------
|
/* ------------------------------------------------------------- */
|
||||||
// Use ioperm, inb and outb in <sys/io.h> (Linux)
|
/* Use ioperm, inb and outb in <sys/io.h> (Linux) */
|
||||||
#if defined HAVE_IOPERM && HAVE_SYS_IO_H
|
#if defined HAVE_IOPERM && HAVE_SYS_IO_H
|
||||||
#include <sys/io.h>
|
#include <sys/io.h>
|
||||||
|
|
||||||
// Read a byte from port
|
/* Read a byte from port */
|
||||||
static inline int port_in (unsigned short int port) {
|
static inline int port_in (unsigned short int port) {
|
||||||
return inb(port);
|
return inb(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write a byte 'val' to port
|
/* Write a byte 'val' to port */
|
||||||
static inline void port_out (unsigned short int port, unsigned char val) {
|
static inline void port_out (unsigned short int port, unsigned char val) {
|
||||||
outb(val, port);
|
outb(val, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get access to a specific port
|
/* Get access to a specific port */
|
||||||
static inline int port_access (unsigned short int port) {
|
static inline int port_access (unsigned short int port) {
|
||||||
return ioperm(port, 1, 255);
|
return ioperm(port, 1, 255);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get access to 3 ports: port (CONTROL), port+1 (STATUS) and port+2 (DATA)
|
/* Close access to a specific port */
|
||||||
|
static inline int port_deny (unsigned short int port) {
|
||||||
|
return ioperm(port, 1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get access to 3 ports: port (CONTROL), port+1 (STATUS) and port+2 (DATA) */
|
||||||
static inline int port_access_full (unsigned short int port) {
|
static inline int port_access_full (unsigned short int port) {
|
||||||
return ioperm(port, 3, 255);
|
return ioperm(port, 3, 255);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Close access to 3 ports: port (CONTROL), port+1 (STATUS) and port+2 (DATA) */
|
||||||
static inline int port_deny_full (unsigned short int port) {
|
static inline int port_deny_full (unsigned short int port) {
|
||||||
return ioperm(port, 3, 0);
|
return ioperm(port, 3, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------
|
/* ------------------------------------------------------------- */
|
||||||
// Use i386_get_ioperm, i386_set_ioperm, inb and outb from <machine/pio.h> (NetBSD)
|
/* Use i386_get_ioperm, i386_set_ioperm, inb and outb from <machine/pio.h> (NetBSD) */
|
||||||
#elif defined HAVE_LIBI386 && defined HAVE_MACHINE_PIO_H && defined HAVE_MACHINE_SYSARCH_H
|
#elif defined HAVE_LIBI386 && defined HAVE_MACHINE_PIO_H && defined HAVE_MACHINE_SYSARCH_H
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <machine/pio.h>
|
#include <machine/pio.h>
|
||||||
#include <machine/sysarch.h>
|
#include <machine/sysarch.h>
|
||||||
|
|
||||||
// Read a byte from port
|
/* Read a byte from port */
|
||||||
static inline int port_in (unsigned short int port) {
|
static inline int port_in (unsigned short int port) {
|
||||||
return inb(port);
|
return inb(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write a byte 'val' to port
|
/* Write a byte 'val' to port */
|
||||||
static inline void port_out (unsigned short int port, unsigned char val) {
|
static inline void port_out (unsigned short int port, unsigned char val) {
|
||||||
outb(port, val);
|
outb(port, val);
|
||||||
}
|
}
|
||||||
@@ -100,7 +114,7 @@ static inline void setaccess(u_long * map, u_int bit, int allow) {
|
|||||||
map[word] |= mask;
|
map[word] |= mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get access to a specific port
|
/* Get access to a specific port */
|
||||||
static inline int port_access (unsigned short int port) {
|
static inline int port_access (unsigned short int port) {
|
||||||
u_long iomap[32];
|
u_long iomap[32];
|
||||||
|
|
||||||
@@ -113,7 +127,20 @@ static inline int port_access (unsigned short int port) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get access to 3 ports: port (CONTROL), port+1 (STATUS) and port+2 (DATA)
|
/* Close access to a specific port */
|
||||||
|
static inline int port_deny (unsigned short int port) {
|
||||||
|
u_long iomap[32];
|
||||||
|
|
||||||
|
if (i386_get_ioperm(iomap) == -1) return -1;
|
||||||
|
|
||||||
|
setaccess(iomap, port, 0);
|
||||||
|
|
||||||
|
if (i386_set_ioperm(iomap) == -1) return -1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get access to 3 ports: port (CONTROL), port+1 (STATUS) and port+2 (DATA) */
|
||||||
static inline int port_access_full (unsigned short int port) {
|
static inline int port_access_full (unsigned short int port) {
|
||||||
u_long iomap[32];
|
u_long iomap[32];
|
||||||
|
|
||||||
@@ -128,13 +155,28 @@ static inline int port_access_full (unsigned short int port) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//#endif // defined HAVE_LIBI386 && defined HAVE_SYS_TYPES_H && defined HAVE_MACHINE_PIO_H
|
/* Close access to 3 ports: port (CONTROL), port+1 (STATUS) and port+2 (DATA) */
|
||||||
|
static inline int port_deny_full (unsigned short int port) {
|
||||||
|
u_long iomap[32];
|
||||||
|
|
||||||
// -------------------------------------------------------------
|
if (i386_get_ioperm(iomap) == -1) return -1;
|
||||||
// Last chance! Use /dev/io and i386 ASM code (BSD4.3 ?)
|
|
||||||
|
setaccess(iomap, port , 0);
|
||||||
|
setaccess(iomap, port+1, 0);
|
||||||
|
setaccess(iomap, port+2, 0);
|
||||||
|
|
||||||
|
if (i386_set_ioperm(iomap) == -1) return -1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* #endif // defined HAVE_LIBI386 && defined HAVE_SYS_TYPES_H && defined HAVE_MACHINE_PIO_H */
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------- */
|
||||||
|
/* Last chance! Use /dev/io and i386 ASM code (BSD4.3 ?) */
|
||||||
#else
|
#else
|
||||||
|
|
||||||
// Read a byte from port
|
/* Read a byte from port */
|
||||||
static inline int port_in (unsigned short int port) {
|
static inline int port_in (unsigned short int port) {
|
||||||
unsigned char value;
|
unsigned char value;
|
||||||
__asm__ volatile ("inb %1,%0":"=a" (value)
|
__asm__ volatile ("inb %1,%0":"=a" (value)
|
||||||
@@ -142,29 +184,39 @@ static inline int port_in (unsigned short int port) {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write a byte 'val' to port
|
/* Write a byte 'val' to port */
|
||||||
static inline void port_out (unsigned short int port, unsigned char val) {
|
static inline void port_out (unsigned short int port, unsigned char val) {
|
||||||
__asm__ volatile ("outb %0,%1\n"::"a" (val), "d" (port)
|
__asm__ volatile ("outb %0,%1\n"::"a" (val), "d" (port)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get access to 3 ports: port (CONTROL), port+1 (STATUS) and port+2 (DATA)
|
/* Get access to 3 ports: port (CONTROL), port+1 (STATUS) and port+2 (DATA) */
|
||||||
static inline int port_access_full (unsigned short int port) {
|
static inline int port_access_full (unsigned short int port) {
|
||||||
static FILE * port_access_handle = NULL ;
|
static FILE * port_access_handle = NULL ;
|
||||||
|
|
||||||
if( port_access_handle
|
if( port_access_handle
|
||||||
|| (port_access_handle = fopen("/dev/io", "rw")) != NULL ) {
|
|| (port_access_handle = fopen("/dev/io", "rw")) != NULL ) {
|
||||||
return( 0 ); // Success
|
return( 0 ); /* Success */
|
||||||
} else {
|
} else {
|
||||||
return( -1 ); // Failure
|
return( -1 ); /* Failure */
|
||||||
};
|
};
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get access to a specific port
|
/* Get access to a specific port */
|
||||||
static inline int port_access (unsigned short int port) {
|
static inline int port_access (unsigned short int port) {
|
||||||
return port_access_full(port); // /dev/io gives you access to all ports.
|
return port_access_full(port); /* /dev/io gives you access to all ports. */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Close access to 3 ports: port (CONTROL), port+1 (STATUS) and port+2 (DATA) */
|
||||||
|
static inline int port_deny_full (unsigned short int port) {
|
||||||
|
/* Can't close /dev/io... */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Close access to a specific port */
|
||||||
|
static inline int port_deny (unsigned short int port) {
|
||||||
|
/* Can't close /dev/io... */
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -189,4 +241,4 @@ port_out (unsigned int port, unsigned char val)
|
|||||||
#endif
|
#endif
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#endif // PORT_H
|
#endif /* PORT_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user