Back to index

glibc  2.9
Defines | Functions | Variables
ioperm.c File Reference
#include <errno.h>
#include <fcntl.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/mman.h>

Go to the source code of this file.

Defines

#define MAX_PORT   0x10000
#define __ia64_mf_a()   __asm__ __volatile__ ("mf.a" ::: "memory")

Functions

__inline__ unsigned long int io_offset (unsigned long int port)
int _ioperm (unsigned long int from, unsigned long int num, int turn_on)
int _iopl (unsigned int level)
unsigned int _inb (unsigned long int port)
unsigned int _inw (unsigned long int port)
unsigned int _inl (unsigned long int port)
void _outb (unsigned char val, unsigned long int port)
void _outw (unsigned short val, unsigned long int port)
void _outl (unsigned int val, unsigned long int port)
 weak_alias (_ioperm, ioperm)
 weak_alias (_iopl, iopl)
 weak_alias (_inb, inb)
 weak_alias (_inw, inw)
 weak_alias (_inl, inl)
 weak_alias (_outb, outb)
 weak_alias (_outw, outw)
 weak_alias (_outl, outl)

Variables

struct {
unsigned long int base
unsigned long int page_mask
io

Define Documentation

#define __ia64_mf_a ( )    __asm__ __volatile__ ("mf.a" ::: "memory")

Definition at line 45 of file ioperm.c.

#define MAX_PORT   0x10000

Definition at line 39 of file ioperm.c.


Function Documentation

unsigned int _inb ( unsigned long int  port)

Definition at line 151 of file ioperm.c.

{
  volatile unsigned char *addr = (void *) io.base + io_offset (port);
  unsigned char ret;

  ret = *addr;
  __ia64_mf_a();
  return ret;
}

Here is the call graph for this function:

unsigned int _inl ( unsigned long int  port)

Definition at line 173 of file ioperm.c.

{
  volatile unsigned int *addr = (void *) io.base + io_offset (port);
  unsigned int ret;

  ret = *addr;
  __ia64_mf_a();
  return ret;
}

Here is the call graph for this function:

unsigned int _inw ( unsigned long int  port)

Definition at line 162 of file ioperm.c.

{
  volatile unsigned short *addr = (void *) io.base + io_offset (port);
  unsigned short ret;

  ret = *addr;
  __ia64_mf_a();
  return ret;
}

Here is the call graph for this function:

int _ioperm ( unsigned long int  from,
unsigned long int  num,
int  turn_on 
)

Definition at line 61 of file ioperm.c.

{
#if 0
  unsigned long int addr, len, base;
#endif
  unsigned long int base;
  int prot;

  /* 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 (!io.base)
       {
         unsigned long phys_io_base, len;
         int fd;

         io.page_mask = ~(__getpagesize() - 1);

         /* get I/O base physical address from ar.k0 as per PRM: */
         __asm__ ("mov %0=ar.k0" : "=r"(phys_io_base));

         /* The O_SYNC flag tells the /dev/mem driver to map the
             memory uncached: */
         fd = __open ("/dev/mem", O_RDWR | O_SYNC);
         if (fd < 0)
           return -1;

         len = io_offset (MAX_PORT);
#if 1
         /* see comment below */
         base = (unsigned long int) __mmap (0, len, PROT_READ | PROT_WRITE, MAP_SHARED,
                                          fd, phys_io_base);
#else
         base = (unsigned long int) __mmap (0, len, PROT_NONE, MAP_SHARED,
                                          fd, phys_io_base);
#endif
         __close (fd);

         if ((long) base == -1)
           return -1;

         io.base = base;
       }
      prot = PROT_READ | PROT_WRITE;
    }
  else
    {
      if (!io.base)
       return 0;     /* never was turned on... */

      prot = PROT_NONE;
    }
#if 0
  /* We can't do mprotect because that would cause us to lose the
     uncached flag that the /dev/mem driver turned on.  A MAP_UNCACHED
     flag seems so much cleaner...  */
  addr = (io.base + io_offset (from)) & io.page_mask;
  len  = io.base + io_offset (from + num) - addr;
  return mprotect ((void *) addr, len, prot);
#else
  return 0;
#endif
}

Here is the call graph for this function:

int _iopl ( unsigned int  level)

Definition at line 132 of file ioperm.c.

{
  if (level > 3)
    {
      __set_errno (EINVAL);
      return -1;
    }
  if (level)
    {
      int retval = _ioperm (0, MAX_PORT, 1);
      /* Match the documented error returns of the x86 version.  */
      if (retval < 0 && errno == EACCES)
       __set_errno (EPERM);
      return retval;
    }
  return 0;
}

Here is the call graph for this function:

void _outb ( unsigned char  val,
unsigned long int  port 
)

Definition at line 184 of file ioperm.c.

{
  volatile unsigned char *addr = (void *) io.base + io_offset (port);

  *addr = val;
  __ia64_mf_a();
}

Here is the call graph for this function:

void _outl ( unsigned int  val,
unsigned long int  port 
)

Definition at line 202 of file ioperm.c.

{
  volatile unsigned int *addr = (void *) io.base + io_offset (port);

  *addr = val;
  __ia64_mf_a();
}

Here is the call graph for this function:

void _outw ( unsigned short  val,
unsigned long int  port 
)

Definition at line 193 of file ioperm.c.

{
  volatile unsigned short *addr = (void *) io.base + io_offset (port);

  *addr = val;
  __ia64_mf_a();
}

Here is the call graph for this function:

__inline__ unsigned long int io_offset ( unsigned long int  port)

Definition at line 55 of file ioperm.c.

{
       return ((port >> 2) << 12) | (port & 0xfff);
}

Here is the caller graph for this function:

weak_alias ( _ioperm  ,
ioperm   
)
weak_alias ( _iopl  ,
iopl   
)
weak_alias ( _inb  ,
inb   
)
weak_alias ( _inw  ,
inw   
)
weak_alias ( _inl  ,
inl   
)
weak_alias ( _outb  ,
outb   
)
weak_alias ( _outw  ,
outw   
)
weak_alias ( _outl  ,
outl   
)

Variable Documentation

struct { ... } io [static]