00001 /******************************************************************* 00002 * Lots of files in emcmot need the functions inb/outb 00003 * the normal way thes are defined is by including either asm/io.h or 00004 * sys/io.h. 00005 * However lots of things can go wrong in trying to include these 00006 * depending on compiler/kernel/libc version etc so instead of including 00007 * them directly include this LOCal SYS/IO.H file that tries to fix 00008 * some of these problems. 00009 *******************************************************************/ 00010 00011 #ifndef LOCSYSIO_H 00012 #define LOCSYSIO_H 00013 00014 /* 00015 Compiling this for LINUX (not RTLINUX) means linking this into a Linux 00016 process, running non-real-time in user space. This is useful for debugging. 00017 If this is done, then the following stuff needs to be done to access the 00018 IO space. 00019 */ 00020 00021 #ifdef DEFINE_EXTERN_BEFORE_IO 00022 /* 00023 Because of a limitation in gcc (present at least in 2.7.2.1 and below), you 00024 _have to_ compile any source code that uses these routines with optimisation 00025 turned on (gcc -O1 or higher), or alternatively #define extern to be 00026 empty before #including <asm/io.h>. 00027 00028 Otherwise, you'll get errors at link time like: 00029 00030 stg.c:475: undefined reference to `__inbc' 00031 */ 00032 #define extern 00033 #endif 00034 00035 /* 00036 Need to access ports in range 0x200-0x21F and 0x600-0x61F, for default 00037 STG base address. ioperm() only enables up to 0x3FF, so we need to use 00038 iopl() to grant full access to IO space. 00039 */ 00040 #include <sys/types.h> 00041 #include <unistd.h> /* iopl() */ 00042 00043 00044 #if defined(__KERNEL__) && defined(linux) 00045 #include <linux/kernel.h> 00046 #if !defined(rtai) 00047 /* P.C. These two headers cause a bunch of compiler errors on 00048 a RH7.1 system using 2.4.9-rtai 00049 */ 00050 #include <linux/types.h> 00051 #include <linux/fs.h> 00052 #endif 00053 #endif 00054 00055 #if defined(linux) || defined(rtlinux) || defined(rtai) 00056 #include <sys/io.h> /* ioperm() */ 00057 #endif 00058 00059 00060 /* Linux or RT-Linux use io ports */ 00061 #ifndef LINUX_VERSION_CODE 00062 #include <linux/version.h> 00063 #endif 00064 00065 #ifndef __GLIBC__ 00066 #include <features.h> /* __GLIBC__ */ 00067 #endif 00068 00069 // Pre 2.2 kernels don't seem to have the KERNEL_VERSION macro. 00070 #ifndef KERNEL_VERSION 00071 #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c)) 00072 #endif 00073 00074 /* Only include this for systems with an old version of glibc or an 00075 old version of the linux kernel. Othewise it is not needed and results 00076 in a bunch of redefined symbol warnings/errors. 00077 */ 00078 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,2,0) || !defined(__GLIBC__) || __GLIBC__ < 2 00079 #include <asm/io.h> /* outw, inw */ 00080 #endif 00081 00082 #endif 00083 // LOCSYSIO_H