2002-01-04 11:32:26 +01:00
|
|
|
/*
|
2007-04-22 16:05:41 +02:00
|
|
|
* VIDIX Direct Hardware Access (DHA).
|
|
|
|
* Copyright (C) 2002 Nick Kurshev
|
|
|
|
*
|
2008-05-12 19:33:35 +02:00
|
|
|
* 1996/10/27 - Robin Cutshaw (robin@xfree86.org)
|
|
|
|
* XFree86 3.3.3 implementation
|
|
|
|
* 1999 - Øyvind Aabling.
|
|
|
|
* Modified for GATOS/win/gfxdump.
|
|
|
|
*
|
|
|
|
* 2002 - library implementation by Nick Kurshev
|
|
|
|
* - dhahelper and some changes by Alex Beregszaszi
|
|
|
|
*
|
|
|
|
* supported OSes: SVR4, UnixWare, SCO, Solaris,
|
|
|
|
* FreeBSD, NetBSD, 386BSD, BSDI BSD/386,
|
|
|
|
* Linux, Mach/386, ISC
|
|
|
|
* DOS (WATCOM 9.5 compiler), Win9x (with mapdev.vxd)
|
|
|
|
* original location: www.linuxvideo.org/gatos
|
|
|
|
*
|
2007-04-22 16:05:41 +02:00
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
2008-05-12 19:39:36 +02:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2007-04-22 16:05:41 +02:00
|
|
|
*/
|
2002-01-04 11:32:26 +01:00
|
|
|
|
2002-02-02 08:05:52 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2007-04-06 17:26:41 +02:00
|
|
|
#include "dha.h"
|
2002-01-04 11:32:26 +01:00
|
|
|
#include "AsmMacros.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
2009-01-16 10:21:21 +01:00
|
|
|
#if ARCH_ALPHA
|
2002-04-19 18:34:04 +02:00
|
|
|
#include <sys/io.h>
|
|
|
|
#endif
|
2002-01-04 11:32:26 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2008-10-13 18:23:55 +02:00
|
|
|
#if defined(__MINGW32__) || defined(__CYGWIN__)
|
2002-01-15 09:33:09 +01:00
|
|
|
#include "sysdep/libdha_win32.c"
|
|
|
|
#elif defined (__EMX__)
|
|
|
|
#include "sysdep/libdha_os2.c"
|
2002-01-04 11:32:26 +01:00
|
|
|
#else
|
2002-01-15 09:33:09 +01: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
|
2007-03-28 20:45:02 +02:00
|
|
|
#elif defined(sun) && defined (i386)
|
|
|
|
#define DEV_MEM "/dev/xsvc"
|
2002-01-15 09:33:09 +01:00
|
|
|
# endif /* SVR4 */
|
|
|
|
|
2005-01-21 22:36:30 +01:00
|
|
|
#if defined(__OpenBSD__)
|
|
|
|
#define DEV_APERTURE "/dev/xf86"
|
|
|
|
#endif
|
|
|
|
|
2002-01-15 09:33:09 +01:00
|
|
|
/* Generic version */
|
2002-01-04 11:32:26 +01:00
|
|
|
#include <sys/mman.h>
|
|
|
|
|
2002-01-15 09:33:09 +01:00
|
|
|
#ifndef DEV_MEM
|
|
|
|
#define DEV_MEM "/dev/mem"
|
|
|
|
#endif
|
|
|
|
|
2002-02-02 08:05:52 +01:00
|
|
|
#ifdef CONFIG_DHAHELPER
|
2008-05-30 21:17:20 +02:00
|
|
|
#include "dhahelper/dhahelper.h"
|
2002-12-20 22:07:27 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_SVGAHELPER
|
|
|
|
#include <svgalib_helper.h>
|
|
|
|
#endif
|
2002-03-04 20:30:02 +01:00
|
|
|
|
2003-01-19 17:44:32 +01:00
|
|
|
static int mem_fd = -1;
|
|
|
|
|
2002-04-19 18:34:04 +02:00
|
|
|
void *map_phys_mem(unsigned long base, unsigned long size)
|
2002-12-20 22:07:27 +01:00
|
|
|
{
|
2009-01-16 10:21:21 +01:00
|
|
|
#if ARCH_ALPHA
|
2002-04-19 18:34:04 +02:00
|
|
|
/* TODO: move it into sysdep */
|
|
|
|
base += bus_base();
|
|
|
|
#endif
|
2002-12-20 22:07:27 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_SVGAHELPER
|
2003-01-19 17:44:32 +01:00
|
|
|
if ( (mem_fd = open(DEV_SVGA,O_RDWR)) == -1) {
|
2002-12-20 22:07:27 +01:00
|
|
|
perror("libdha: SVGAlib kernelhelper failed");
|
|
|
|
#ifdef CONFIG_DHAHELPER
|
|
|
|
goto dha_helper_way;
|
|
|
|
#else
|
|
|
|
goto dev_mem_way;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
goto mmap;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_DHAHELPER
|
2003-02-02 13:27:35 +01:00
|
|
|
#ifdef CONFIG_SVGAHELPER
|
2002-12-20 22:07:27 +01:00
|
|
|
dha_helper_way:
|
2003-02-02 13:27:35 +01:00
|
|
|
#endif
|
2003-01-19 17:44:32 +01:00
|
|
|
if ( (mem_fd = open("/dev/dhahelper",O_RDWR)) < 0)
|
2002-02-02 08:05:52 +01:00
|
|
|
{
|
2002-12-20 22:07:27 +01:00
|
|
|
perror("libdha: DHA kernelhelper failed");
|
|
|
|
goto dev_mem_way;
|
2002-02-02 08:05:52 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dhahelper_memory_t mem_req;
|
|
|
|
|
|
|
|
mem_req.operation = MEMORY_OP_MAP;
|
|
|
|
mem_req.start = base;
|
|
|
|
mem_req.offset = 0;
|
|
|
|
mem_req.size = size;
|
|
|
|
|
2003-01-19 17:44:32 +01:00
|
|
|
if (ioctl(mem_fd, DHAHELPER_MEMORY, &mem_req) < 0)
|
2002-02-02 08:05:52 +01:00
|
|
|
{
|
2002-12-20 22:07:27 +01:00
|
|
|
perror("libdha: DHA kernelhelper failed");
|
2003-01-19 17:44:32 +01:00
|
|
|
close(mem_fd);
|
2002-12-20 22:07:27 +01:00
|
|
|
goto dev_mem_way;
|
2002-02-02 08:05:52 +01:00
|
|
|
}
|
2002-12-20 22:07:27 +01:00
|
|
|
else
|
|
|
|
goto mmap;
|
2002-02-02 08:05:52 +01:00
|
|
|
}
|
2002-04-19 18:34:04 +02:00
|
|
|
#endif
|
2002-12-20 22:07:27 +01:00
|
|
|
|
2007-04-22 21:02:05 +02:00
|
|
|
#if defined(CONFIG_DHAHELPER) || defined (CONFIG_SVGAHELPER)
|
2002-12-20 22:07:27 +01:00
|
|
|
dev_mem_way:
|
2007-04-22 15:28:54 +02:00
|
|
|
#endif
|
2005-01-21 22:36:30 +01:00
|
|
|
#ifdef DEV_APERTURE
|
|
|
|
if ((mem_fd = open(DEV_APERTURE, O_RDWR)) == -1)
|
|
|
|
perror("libdha: opening aperture failed");
|
|
|
|
else {
|
|
|
|
void *p = mmap(0,size,PROT_READ|PROT_WRITE,MAP_SHARED,mem_fd,base);
|
|
|
|
|
|
|
|
if (p == MAP_FAILED) {
|
|
|
|
perror("libdha: mapping aperture failed");
|
|
|
|
close(mem_fd);
|
|
|
|
} else
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-01-19 17:44:32 +01:00
|
|
|
if ( (mem_fd = open(DEV_MEM,O_RDWR)) == -1)
|
2002-12-20 22:07:27 +01:00
|
|
|
{
|
|
|
|
perror("libdha: opening /dev/mem failed");
|
2003-02-02 13:27:35 +01:00
|
|
|
return MAP_FAILED;
|
2002-01-04 11:32:26 +01:00
|
|
|
}
|
2002-12-20 22:07:27 +01:00
|
|
|
|
2007-04-22 21:02:05 +02:00
|
|
|
#if defined(CONFIG_DHAHELPER) || defined (CONFIG_SVGAHELPER)
|
2002-12-20 22:07:27 +01:00
|
|
|
mmap:
|
2007-04-22 15:28:54 +02:00
|
|
|
#endif
|
2003-01-19 17:44:32 +01:00
|
|
|
return mmap(0,size,PROT_READ|PROT_WRITE,MAP_SHARED,mem_fd,base);
|
2002-01-04 11:32:26 +01:00
|
|
|
}
|
|
|
|
|
2002-04-19 18:34:04 +02:00
|
|
|
void unmap_phys_mem(void *ptr, unsigned long size)
|
2002-01-04 11:32:26 +01:00
|
|
|
{
|
2002-12-20 22:07:27 +01:00
|
|
|
int res = munmap(ptr,size);
|
|
|
|
|
2003-02-02 13:27:35 +01:00
|
|
|
if (res == (int)MAP_FAILED)
|
2002-12-20 22:07:27 +01:00
|
|
|
{
|
|
|
|
perror("libdha: unmapping memory failed");
|
2003-02-02 13:27:35 +01:00
|
|
|
return;
|
2002-12-20 22:07:27 +01:00
|
|
|
}
|
2003-01-19 17:44:32 +01:00
|
|
|
|
|
|
|
close(mem_fd);
|
|
|
|
mem_fd = -1;
|
|
|
|
|
|
|
|
return;
|
2002-01-04 11:32:26 +01:00
|
|
|
}
|
|
|
|
|
2003-10-02 16:48:17 +02:00
|
|
|
#endif /* Generic mmap (not win32, nor os2) */
|
|
|
|
|
2008-08-12 01:04:03 +02:00
|
|
|
#if !defined(__alpha__) && !defined(__powerpc__) && !defined(__sh__)
|
2002-12-20 22:07:27 +01:00
|
|
|
unsigned char INPORT8(unsigned idx)
|
2002-01-04 11:32:26 +01:00
|
|
|
{
|
|
|
|
return inb(idx);
|
|
|
|
}
|
|
|
|
|
2002-01-05 19:16:19 +01:00
|
|
|
unsigned short INPORT16(unsigned idx)
|
2002-01-04 11:32:26 +01:00
|
|
|
{
|
|
|
|
return inw(idx);
|
|
|
|
}
|
|
|
|
|
2002-12-20 22:07:27 +01:00
|
|
|
unsigned INPORT32(unsigned idx)
|
2002-01-04 11:32:26 +01:00
|
|
|
{
|
|
|
|
return inl(idx);
|
|
|
|
}
|
|
|
|
|
2002-12-20 22:07:27 +01:00
|
|
|
void OUTPORT8(unsigned idx,unsigned char val)
|
2002-01-04 11:32:26 +01:00
|
|
|
{
|
|
|
|
outb(idx,val);
|
|
|
|
}
|
|
|
|
|
2002-12-20 22:07:27 +01:00
|
|
|
void OUTPORT16(unsigned idx,unsigned short val)
|
2002-01-04 11:32:26 +01:00
|
|
|
{
|
|
|
|
outw(idx,val);
|
|
|
|
}
|
|
|
|
|
2002-12-20 22:07:27 +01:00
|
|
|
void OUTPORT32(unsigned idx,unsigned val)
|
2002-01-04 11:32:26 +01:00
|
|
|
{
|
|
|
|
outl(idx,val);
|
|
|
|
}
|
2007-09-15 19:51:05 +02:00
|
|
|
#endif
|