Back to index

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

Go to the source code of this file.

Classes

struct  platform

Defines

#define PATH_ARM_SYSTYPE   "/etc/arm_systype"
#define PATH_CPUINFO   "/proc/cpuinfo"
#define MAX_PORT   0x10000
#define IO_BASE_FOOTBRIDGE   0x7c000000
#define IO_SHIFT_FOOTBRIDGE   0
#define IO_ADDR(port)   (io.base + ((port) << io.shift))
#define BUS_ISA   CTL_BUS_ISA

Functions

static int init_iosys (void)
int _ioperm (unsigned long int from, unsigned long int num, int turn_on)
int _iopl (unsigned int level)
void _outb (unsigned char b, unsigned long int port)
void _outw (unsigned short b, unsigned long int port)
void _outl (unsigned int b, unsigned long int port)
unsigned int _inb (unsigned long int port)
unsigned int _inw (unsigned long int port)
unsigned int _inl (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 io_base
unsigned int shift
unsigned int initdone
io
static struct platform platform []

Class Documentation

struct platform

Definition at line 65 of file ioperm.c.

Class Members
unsigned long int io_base
iosys_t io_sys
const char * name
unsigned int shift

Define Documentation

#define BUS_ISA   CTL_BUS_ISA

Definition at line 101 of file ioperm.c.

#define IO_ADDR (   port)    (io.base + ((port) << io.shift))

Definition at line 77 of file ioperm.c.

#define IO_BASE_FOOTBRIDGE   0x7c000000

Definition at line 62 of file ioperm.c.

#define IO_SHIFT_FOOTBRIDGE   0

Definition at line 63 of file ioperm.c.

#define MAX_PORT   0x10000

Definition at line 53 of file ioperm.c.

#define PATH_ARM_SYSTYPE   "/etc/arm_systype"

Definition at line 50 of file ioperm.c.

#define PATH_CPUINFO   "/proc/cpuinfo"

Definition at line 51 of file ioperm.c.


Function Documentation

unsigned int _inb ( unsigned long int  port)

Definition at line 254 of file ioperm.c.

{
  return *((volatile unsigned char *)(IO_ADDR (port)));
}
unsigned int _inl ( unsigned long int  port)

Definition at line 268 of file ioperm.c.

{
  return *((volatile unsigned long *)(IO_ADDR (port)));
}
unsigned int _inw ( unsigned long int  port)

Definition at line 261 of file ioperm.c.

{
  return *((volatile unsigned short *)(IO_ADDR (port)));
}
int _ioperm ( unsigned long int  from,
unsigned long int  num,
int  turn_on 
)

Definition at line 180 of file ioperm.c.

{
  if (! io.initdone && init_iosys () < 0)
    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 (! io.base)
       {
         int fd;

         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)
           return -1;
       }
    }

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int _iopl ( unsigned int  level)

Definition at line 217 of file ioperm.c.

{
    if (level > 3)
      {
       __set_errno (EINVAL);
       return -1;
      }
    if (level)
      {
       return _ioperm (0, MAX_PORT, 1);
      }
    return 0;
}

Here is the call graph for this function:

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

Definition at line 233 of file ioperm.c.

{
  *((volatile unsigned char *)(IO_ADDR (port))) = b;
}
void _outl ( unsigned int  b,
unsigned long int  port 
)

Definition at line 247 of file ioperm.c.

{
  *((volatile unsigned long *)(IO_ADDR (port))) = b;
}
void _outw ( unsigned short  b,
unsigned long int  port 
)

Definition at line 240 of file ioperm.c.

{
  *((volatile unsigned short *)(IO_ADDR (port))) = b;
}
static int init_iosys ( void  ) [static]

Definition at line 105 of file ioperm.c.

{
  char systype[256];
  int i, n;
  static int iobase_name[] = { CTL_BUS, BUS_ISA, BUS_ISA_PORT_BASE };
  static int ioshift_name[] = { CTL_BUS, BUS_ISA, BUS_ISA_PORT_SHIFT };
  size_t len = sizeof(io.base);

  if (! __sysctl (iobase_name, 3, &io.io_base, &len, NULL, 0)
      && ! __sysctl (ioshift_name, 3, &io.shift, &len, NULL, 0))
    {
      io.initdone = 1;
      return 0;
    }

  n = __readlink (PATH_ARM_SYSTYPE, systype, sizeof (systype) - 1);
  if (n > 0)
    {
      systype[n] = '\0';
      if (isdigit (systype[0]))
       {
         if (sscanf (systype, "%li,%i", &io.io_base, &io.shift) == 2)
           {
             io.initdone = 1;
             return 0;
           }
         /* else we're likely going to fail with the system match below */
       }
    }
  else
    {
      FILE * fp;

      fp = fopen (PATH_CPUINFO, "r");
      if (! fp)
       return -1;
      while ((n = fscanf (fp, "Hardware\t: %256[^\n]\n", systype))
            != EOF)
       {
         if (n == 1)
           break;
         else
           fgets_unlocked (systype, 256, fp);
       }
      fclose (fp);

      if (n == EOF)
       {
         /* this can happen if the format of /proc/cpuinfo changes...  */
         fprintf (stderr,
                 "ioperm: Unable to determine system type.\n"
                 "\t(May need " PATH_ARM_SYSTYPE " symlink?)\n");
         __set_errno (ENODEV);
         return -1;
       }
    }

  /* translate systype name into i/o system: */
  for (i = 0; i < sizeof (platform) / sizeof (platform[0]); ++i)
    {
      if (strcmp (platform[i].name, systype) == 0)
       {
         io.shift = platform[i].shift;
         io.io_base = platform[i].io_base;
         io.initdone = 1;
         return 0;
       }
    }

  /* systype is not a known platform name... */
  __set_errno (ENODEV);
  return -1;
}

Here is the call graph for this function:

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]
struct platform platform[] [static]