2002-01-04 10:32:26 +00:00
|
|
|
|
/*
|
|
|
|
|
libgha.c - Library for direct hardware access
|
|
|
|
|
Copyrights:
|
|
|
|
|
1996/10/27 - Robin Cutshaw (robin@xfree86.org)
|
|
|
|
|
XFree86 3.3.3 implementation
|
|
|
|
|
1999 - <EFBFBD>yvind Aabling.
|
|
|
|
|
Modified for GATOS/win/gfxdump.
|
|
|
|
|
|
|
|
|
|
2002 - library implementation by Nick Kurshev
|
2002-02-02 07:05:52 +00:00
|
|
|
|
- dhahelper and some changes by Alex Beregszaszi
|
2002-01-04 10:32:26 +00:00
|
|
|
|
|
|
|
|
|
supported O/S's: SVR4, UnixWare, SCO, Solaris,
|
|
|
|
|
FreeBSD, NetBSD, 386BSD, BSDI BSD/386,
|
|
|
|
|
Linux, Mach/386, ISC
|
|
|
|
|
DOS (WATCOM 9.5 compiler), Win9x (with mapdev.vxd)
|
|
|
|
|
Licence: GPL
|
|
|
|
|
Original location: www.linuxvideo.org/gatos
|
|
|
|
|
*/
|
|
|
|
|
|
2002-02-02 07:05:52 +00:00
|
|
|
|
#include "config.h"
|
|
|
|
|
|
2002-01-04 10:32:26 +00:00
|
|
|
|
#include "libdha.h"
|
|
|
|
|
#include "AsmMacros.h"
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
#include <sys/types.h>
|
2002-04-19 16:34:04 +00:00
|
|
|
|
#ifdef ARCH_ALPHA
|
|
|
|
|
#include <sys/io.h>
|
|
|
|
|
#endif
|
2002-01-04 10:32:26 +00:00
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
2002-01-15 15:59:53 +00:00
|
|
|
|
/* instead exit() use libdha_exit, and do the 'mother-application' deinit
|
|
|
|
|
only in this code */
|
|
|
|
|
void libdha_exit(const char *message, int level)
|
|
|
|
|
{
|
|
|
|
|
printf("libdha: FATAL: %s\n", message);
|
|
|
|
|
exit(level); /* FIXME */
|
|
|
|
|
}
|
|
|
|
|
|
2002-01-15 08:33:09 +00:00
|
|
|
|
#if defined(_WIN32)
|
|
|
|
|
#include "sysdep/libdha_win32.c"
|
|
|
|
|
#elif defined (__EMX__)
|
|
|
|
|
#include "sysdep/libdha_os2.c"
|
2002-01-04 10:32:26 +00:00
|
|
|
|
#else
|
2002-01-15 08:33:09 +00:00
|
|
|
|
|
|
|
|
|
#if defined(SVR4) || defined(SCO325)
|
|
|
|
|
# if !(defined(sun) && defined (i386) && defined (SVR4))
|
|
|
|
|
# define DEV_MEM "/dev/pmem"
|
|
|
|
|
# elif defined(PowerMAX_OS)
|
|
|
|
|
# define DEV_MEM "/dev/iomem"
|
|
|
|
|
# endif
|
|
|
|
|
# ifdef SCO325
|
|
|
|
|
# undef DEV_MEM
|
|
|
|
|
# define DEV_MEM "/dev/mem"
|
|
|
|
|
# endif
|
|
|
|
|
# endif /* SVR4 */
|
|
|
|
|
|
|
|
|
|
/* Generic version */
|
2002-01-04 10:32:26 +00:00
|
|
|
|
#include <sys/mman.h>
|
|
|
|
|
|
2002-01-15 08:33:09 +00:00
|
|
|
|
#ifndef DEV_MEM
|
|
|
|
|
#define DEV_MEM "/dev/mem"
|
|
|
|
|
#endif
|
|
|
|
|
|
2002-02-02 07:05:52 +00:00
|
|
|
|
#ifdef CONFIG_DHAHELPER
|
2002-03-04 19:30:02 +00:00
|
|
|
|
|
|
|
|
|
#include "kernelhelper/dhahelper.h"
|
|
|
|
|
|
2002-01-04 10:32:26 +00:00
|
|
|
|
static int mem=-1;
|
2002-04-19 16:34:04 +00:00
|
|
|
|
void *map_phys_mem(unsigned long base, unsigned long size)
|
2002-01-04 10:32:26 +00:00
|
|
|
|
{
|
2002-04-19 16:34:04 +00:00
|
|
|
|
#ifdef ARCH_ALPHA
|
|
|
|
|
/* TODO: move it into sysdep */
|
|
|
|
|
base += bus_base();
|
|
|
|
|
#endif
|
2002-02-02 07:05:52 +00:00
|
|
|
|
if ( (mem = open("/dev/dhahelper",O_RDWR)) < 0)
|
|
|
|
|
{
|
|
|
|
|
if ( (mem = open(DEV_MEM,O_RDWR)) == -1) {
|
|
|
|
|
perror("libdha: open(/dev/mem) failed") ; exit(1) ;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dhahelper_memory_t mem_req;
|
|
|
|
|
|
|
|
|
|
mem_req.operation = MEMORY_OP_MAP;
|
|
|
|
|
mem_req.start = base;
|
|
|
|
|
mem_req.offset = 0;
|
|
|
|
|
mem_req.size = size;
|
|
|
|
|
|
|
|
|
|
if (ioctl(mem, DHAHELPER_MEMORY, &mem_req) < 0)
|
|
|
|
|
{
|
|
|
|
|
perror("libdha: failed mapping throught kernel helper");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return mmap(0,size,PROT_READ|PROT_WRITE,MAP_SHARED,mem,base) ;
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
static int mem=-1;
|
2002-04-19 16:34:04 +00:00
|
|
|
|
void *map_phys_mem(unsigned long base, unsigned long size)
|
2002-02-02 07:05:52 +00:00
|
|
|
|
{
|
2002-04-19 16:34:04 +00:00
|
|
|
|
#ifdef ARCH_ALPHA
|
|
|
|
|
/* TODO: move it into sysdep */
|
|
|
|
|
base += bus_base();
|
|
|
|
|
#endif
|
2002-01-15 08:33:09 +00:00
|
|
|
|
if ( (mem = open(DEV_MEM,O_RDWR)) == -1) {
|
2002-01-04 10:32:26 +00:00
|
|
|
|
perror("libdha: open(/dev/mem) failed") ; exit(1) ;
|
|
|
|
|
}
|
2002-01-15 08:33:09 +00:00
|
|
|
|
return mmap(0,size,PROT_READ|PROT_WRITE,MAP_SHARED,mem,base) ;
|
2002-01-04 10:32:26 +00:00
|
|
|
|
}
|
2002-02-02 07:05:52 +00:00
|
|
|
|
#endif /* CONFIG_DHAHELPER */
|
2002-01-04 10:32:26 +00:00
|
|
|
|
|
2002-04-19 16:34:04 +00:00
|
|
|
|
void unmap_phys_mem(void *ptr, unsigned long size)
|
2002-01-04 10:32:26 +00:00
|
|
|
|
{
|
|
|
|
|
int res=munmap(ptr,size) ;
|
|
|
|
|
if (res == -1) { perror("libdha: munmap() failed") ; exit(1) ; }
|
|
|
|
|
close(mem);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2002-01-05 18:16:19 +00:00
|
|
|
|
unsigned char INPORT8(unsigned idx)
|
2002-01-04 10:32:26 +00:00
|
|
|
|
{
|
|
|
|
|
return inb(idx);
|
|
|
|
|
}
|
|
|
|
|
|
2002-01-05 18:16:19 +00:00
|
|
|
|
unsigned short INPORT16(unsigned idx)
|
2002-01-04 10:32:26 +00:00
|
|
|
|
{
|
|
|
|
|
return inw(idx);
|
|
|
|
|
}
|
|
|
|
|
|
2002-01-05 18:16:19 +00:00
|
|
|
|
unsigned INPORT32(unsigned idx)
|
2002-01-04 10:32:26 +00:00
|
|
|
|
{
|
|
|
|
|
return inl(idx);
|
|
|
|
|
}
|
|
|
|
|
|
2002-01-05 18:16:19 +00:00
|
|
|
|
void OUTPORT8(unsigned idx,unsigned char val)
|
2002-01-04 10:32:26 +00:00
|
|
|
|
{
|
|
|
|
|
outb(idx,val);
|
|
|
|
|
}
|
|
|
|
|
|
2002-01-05 18:16:19 +00:00
|
|
|
|
void OUTPORT16(unsigned idx,unsigned short val)
|
2002-01-04 10:32:26 +00:00
|
|
|
|
{
|
|
|
|
|
outw(idx,val);
|
|
|
|
|
}
|
|
|
|
|
|
2002-01-05 18:16:19 +00:00
|
|
|
|
void OUTPORT32(unsigned idx,unsigned val)
|
2002-01-04 10:32:26 +00:00
|
|
|
|
{
|
|
|
|
|
outl(idx,val);
|
|
|
|
|
}
|
2002-01-15 15:59:53 +00:00
|
|
|
|
|