summaryrefslogtreecommitdiffstats
path: root/libdha
diff options
context:
space:
mode:
authoralex <alex@b3059339-0415-0410-9bf9-f77b7e298cf2>2002-12-20 21:07:27 +0000
committeralex <alex@b3059339-0415-0410-9bf9-f77b7e298cf2>2002-12-20 21:07:27 +0000
commit6429f7e4fd55a230f471a4f1c12387db793a71dd (patch)
tree16ba159231ad1bae6e9c8583f94d8436354d65b2 /libdha
parenta75ffd19d6f674d0f05f8fc5e1763a47343c929f (diff)
downloadmpv-6429f7e4fd55a230f471a4f1c12387db793a71dd.tar.bz2
mpv-6429f7e4fd55a230f471a4f1c12387db793a71dd.tar.xz
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@8504 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libdha')
-rw-r--r--libdha/Makefile5
-rw-r--r--libdha/config.h4
-rw-r--r--libdha/libdha.c80
-rw-r--r--libdha/pci.c3
-rw-r--r--libdha/sysdep/AsmMacros_x86.h127
-rw-r--r--libdha/sysdep/pci_linux.c127
-rw-r--r--libdha/sysdep/pci_powerpc.c66
7 files changed, 314 insertions, 98 deletions
diff --git a/libdha/Makefile b/libdha/Makefile
index 0afd4a5524..af0cd30d1a 100644
--- a/libdha/Makefile
+++ b/libdha/Makefile
@@ -28,6 +28,11 @@ LIBS += -li386
endif
endif
+# If you want libdha to use svgalib_helper for hardware access,
+# uncomment this statement, and change the -I to the correct directory
+# that includes svgalib_helper.o:
+#CFLAGS += -DDEV_SVGA=\"/dev/svga\" -DCONFIG_SVGAHELPER -Isvgalib_helper/
+
.SUFFIXES: .c .o
# .PHONY: all clean
diff --git a/libdha/config.h b/libdha/config.h
index 97d929e6c1..15f61eecc7 100644
--- a/libdha/config.h
+++ b/libdha/config.h
@@ -9,4 +9,8 @@
#endif
#endif
+#if defined(__powerpc__) && defined(CONFIG_SVGAHELPER)
+#undef CONFIG_SVGAHELPER
+#endif
+
#endif /* LIBDHA_CONFIG_H */
diff --git a/libdha/libdha.c b/libdha/libdha.c
index 800b68bcf2..e0739e1a03 100644
--- a/libdha/libdha.c
+++ b/libdha/libdha.c
@@ -66,21 +66,40 @@ void libdha_exit(const char *message, int level)
#endif
#ifdef CONFIG_DHAHELPER
-
#include "kernelhelper/dhahelper.h"
+#endif
+
+#ifdef CONFIG_SVGAHELPER
+#include <svgalib_helper.h>
+#endif
static int mem=-1;
void *map_phys_mem(unsigned long base, unsigned long size)
-{
+{
#ifdef ARCH_ALPHA
/* TODO: move it into sysdep */
base += bus_base();
#endif
+
+#ifdef CONFIG_SVGAHELPER
+ if ( (mem = open(DEV_SVGA,O_RDWR)) == -1) {
+ 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
+dha_helper_way:
if ( (mem = open("/dev/dhahelper",O_RDWR)) < 0)
{
- if ( (mem = open(DEV_MEM,O_RDWR)) == -1) {
- perror("libdha: open(/dev/mem) failed") ; exit(1) ;
- }
+ perror("libdha: DHA kernelhelper failed");
+ goto dev_mem_way;
}
else
{
@@ -93,37 +112,41 @@ void *map_phys_mem(unsigned long base, unsigned long size)
if (ioctl(mem, DHAHELPER_MEMORY, &mem_req) < 0)
{
- perror("libdha: failed mapping throught kernel helper");
- return NULL;
+ perror("libdha: DHA kernelhelper failed");
+ close(mem);
+ goto dev_mem_way;
}
+ else
+ goto mmap;
}
- return mmap(0,size,PROT_READ|PROT_WRITE,MAP_SHARED,mem,base) ;
-}
-#else
-
-static int mem=-1;
-void *map_phys_mem(unsigned long base, unsigned long size)
-{
-#ifdef ARCH_ALPHA
-/* TODO: move it into sysdep */
- base += bus_base();
#endif
- if ( (mem = open(DEV_MEM,O_RDWR)) == -1) {
- perror("libdha: open(/dev/mem) failed") ; exit(1) ;
+
+dev_mem_way:
+ if ( (mem = open(DEV_MEM,O_RDWR)) == -1)
+ {
+ perror("libdha: opening /dev/mem failed");
+ exit(1);
}
- return mmap(0,size,PROT_READ|PROT_WRITE,MAP_SHARED,mem,base) ;
+
+mmap:
+ return mmap(0,size,PROT_READ|PROT_WRITE,MAP_SHARED,mem,base);
}
#endif /* CONFIG_DHAHELPER */
void unmap_phys_mem(void *ptr, unsigned long size)
{
- int res=munmap(ptr,size) ;
- if (res == -1) { perror("libdha: munmap() failed") ; exit(1) ; }
+ int res = munmap(ptr,size);
+
+ if (res == -1)
+ {
+ perror("libdha: unmapping memory failed");
+ exit(1);
+ }
close(mem);
+ mem = -1;
}
-#endif
-unsigned char INPORT8(unsigned idx)
+unsigned char INPORT8(unsigned idx)
{
return inb(idx);
}
@@ -133,23 +156,22 @@ unsigned short INPORT16(unsigned idx)
return inw(idx);
}
-unsigned INPORT32(unsigned idx)
+unsigned INPORT32(unsigned idx)
{
return inl(idx);
}
-void OUTPORT8(unsigned idx,unsigned char val)
+void OUTPORT8(unsigned idx,unsigned char val)
{
outb(idx,val);
}
-void OUTPORT16(unsigned idx,unsigned short val)
+void OUTPORT16(unsigned idx,unsigned short val)
{
outw(idx,val);
}
-void OUTPORT32(unsigned idx,unsigned val)
+void OUTPORT32(unsigned idx,unsigned val)
{
outl(idx,val);
}
-
diff --git a/libdha/pci.c b/libdha/pci.c
index 350a5be42c..bfdc25bc13 100644
--- a/libdha/pci.c
+++ b/libdha/pci.c
@@ -478,6 +478,7 @@ static int pcibus=-1, pcicard=-1, pcifunc=-1 ;
#endif
/* cpu depended stuff */
+#ifndef CONFIG_SVGAHELPER
#if defined(__alpha__)
#include "sysdep/pci_alpha.c"
#elif defined(__ia64__)
@@ -491,7 +492,7 @@ static int pcibus=-1, pcicard=-1, pcifunc=-1 ;
#else
#include "sysdep/pci_x86.c"
#endif
-
+#endif
static int pcicards=0 ;
static pciinfo_t *pci_lst;
diff --git a/libdha/sysdep/AsmMacros_x86.h b/libdha/sysdep/AsmMacros_x86.h
index c10f24f2dd..fd6591152c 100644
--- a/libdha/sysdep/AsmMacros_x86.h
+++ b/libdha/sysdep/AsmMacros_x86.h
@@ -21,8 +21,81 @@ extern int dhahelper_fd;
extern int dhahelper_initialized;
#endif
+#ifdef CONFIG_SVGAHELPER
+#include <sys/ioctl.h>
+#include <svgalib_helper.h>
+
+extern int svgahelper_fd;
+extern int svgahelper_initialized;
+
+static __inline__ void svga_outb(short port, char value)
+{
+ io_t iov;
+
+ iov.val = value;
+ iov.port = port;
+ ioctl(svgahelper_fd, SVGALIB_HELPER_IOCSOUTB, &iov);
+}
+
+static __inline__ void svga_outw(short port, char value)
+{
+ io_t iov;
+
+ iov.val = value;
+ iov.port = port;
+ ioctl(svgahelper_fd, SVGALIB_HELPER_IOCSOUTW, &iov);
+}
+
+static __inline__ void svga_outl(short port, unsigned int value)
+{
+ io_t iov;
+
+ iov.val = value;
+ iov.port = port;
+ ioctl(svgahelper_fd, SVGALIB_HELPER_IOCSOUTL, &iov);
+}
+
+static __inline__ unsigned int svga_inb(short port)
+{
+ io_t iov;
+
+ iov.port = port;
+ ioctl(svgahelper_fd, SVGALIB_HELPER_IOCGINB, &iov);
+
+ return iov.val;
+}
+
+static __inline__ unsigned int svga_inw(short port)
+{
+ io_t iov;
+
+ iov.port = port;
+ ioctl(svgahelper_fd, SVGALIB_HELPER_IOCGINW, &iov);
+
+ return iov.val;
+}
+
+static __inline__ unsigned int svga_inl(short port)
+{
+ io_t iov;
+
+ iov.port = port;
+ ioctl(svgahelper_fd, SVGALIB_HELPER_IOCGINL, &iov);
+
+ return iov.val;
+}
+#endif /* CONIFG_SVGAHELPER */
+
static __inline__ void outb(short port,char val)
{
+#ifdef CONFIG_SVGAHELPER
+ if (svgahelper_initialized == 1)
+ {
+ svga_outb(port, val);
+ return;
+ }
+#endif
+
#ifdef CONFIG_DHAHELPER
if (dhahelper_initialized == 1)
{
@@ -43,6 +116,14 @@ static __inline__ void outb(short port,char val)
static __inline__ void outw(short port,short val)
{
+#ifdef CONFIG_SVGAHELPER
+ if (svgahelper_initialized == 1)
+ {
+ svga_outw(port, val);
+ return;
+ }
+#endif
+
#ifdef CONFIG_DHAHELPER
if (dhahelper_initialized == 1)
{
@@ -63,6 +144,14 @@ static __inline__ void outw(short port,short val)
static __inline__ void outl(short port,unsigned int val)
{
+#ifdef CONFIG_SVGAHELPER
+ if (svgahelper_initialized == 1)
+ {
+ svga_outl(port, val);
+ return;
+ }
+#endif
+
#ifdef CONFIG_DHAHELPER
if (dhahelper_initialized == 1)
{
@@ -83,7 +172,15 @@ static __inline__ void outl(short port,unsigned int val)
static __inline__ unsigned int inb(short port)
{
- unsigned char ret;
+ unsigned char ret = 0;
+
+#ifdef CONFIG_SVGAHELPER
+ if (svgahelper_initialized == 1)
+ {
+ return svga_inb(port);
+ }
+#endif
+
#ifdef CONFIG_DHAHELPER
if (dhahelper_initialized == 1)
{
@@ -105,7 +202,15 @@ static __inline__ unsigned int inb(short port)
static __inline__ unsigned int inw(short port)
{
- unsigned short ret;
+ unsigned short ret = 0;
+
+#ifdef CONFIG_SVGAHELPER
+ if (svgahelper_initialized == 1)
+ {
+ return svga_inw(port);
+ }
+#endif
+
#ifdef CONFIG_DHAHELPER
if (dhahelper_initialized == 1)
{
@@ -127,7 +232,15 @@ static __inline__ unsigned int inw(short port)
static __inline__ unsigned int inl(short port)
{
- unsigned int ret;
+ unsigned int ret = 0;
+
+#ifdef CONFIG_SVGAHELPER
+ if (svgahelper_initialized == 1)
+ {
+ return svga_inl(port);
+ }
+#endif
+
#ifdef CONFIG_DHAHELPER
if (dhahelper_initialized == 1)
{
@@ -149,11 +262,19 @@ static __inline__ unsigned int inl(short port)
static __inline__ void intr_disable()
{
+#ifdef CONFIG_SVGAHELPER
+ if (svgahelper_initialized == 1)
+ return;
+#endif
__asm__ __volatile__("cli");
}
static __inline__ void intr_enable()
{
+#ifdef CONFIG_SVGAHELPER
+ if (svgahelper_initialized == 1)
+ return;
+#endif
__asm__ __volatile__("sti");
}
diff --git a/libdha/sysdep/pci_linux.c b/libdha/sysdep/pci_linux.c
index e53ae20721..ad9715b2d8 100644
--- a/libdha/sysdep/pci_linux.c
+++ b/libdha/sysdep/pci_linux.c
@@ -20,8 +20,59 @@ int dhahelper_initialized = 0;
int dhahelper_fd = 0;
#endif
+#ifdef CONFIG_SVGAHELPER
+#include <svgalib_helper.h>
+#ifdef __linux__
+#include <linux/ioctl.h>
+#endif
+#include <fcntl.h>
+int svgahelper_initialized = 0;
+int svgahelper_fd = 0;
+
+static int pci_config_type(void)
+{
+ return 1;
+}
+
+static long pci_config_read_long(
+ unsigned char bus,
+ unsigned char dev,
+ int func,
+ unsigned cmd)
+{
+ unsigned long config_cmd;
+ pcic_t p;
+
+ p.address = cmd;
+ p.pcipos = (bus << 8) | dev | (func << 5);
+
+ if (ioctl(svgahelper_fd, SVGALIB_HELPER_IOCGPCIINL, &p))
+ return -1;
+
+ return p.val;
+}
+
+static int pci_get_vendor(
+ unsigned char bus,
+ unsigned char dev,
+ int func)
+{
+ return pci_config_read_long(bus, dev, func, 0);
+}
+#endif
+
static __inline__ int enable_os_io(void)
{
+#ifdef CONFIG_SVGAHELPER
+ svgahelper_fd = open(DEV_SVGA, O_RDWR);
+ if (svgahelper_fd > 0)
+ {
+ svgahelper_initialized = 1;
+ return(0);
+ }
+ svgahelper_initialized = -1;
+#endif
+
#ifdef CONFIG_DHAHELPER
dhahelper_fd = open("/dev/dhahelper", O_RDWR);
if (dhahelper_fd > 0)
@@ -43,6 +94,11 @@ static __inline__ int enable_os_io(void)
static __inline__ int disable_os_io(void)
{
+#ifdef CONFIG_SVGAHELPER
+ if (svgahelper_initialized == 1)
+ close(svgahelper_fd);
+ else
+#endif
#ifdef CONFIG_DHAHELPER
if (dhahelper_initialized == 1)
close(dhahelper_fd);
@@ -56,3 +112,74 @@ static __inline__ int disable_os_io(void)
#endif
return(0);
}
+
+#if (defined(__powerpc__) || defined(__sparc__) || defined(__sparc64__)) \
+ && defined(__linux__) && !defined(CONFIG_SVGAHELPER)
+#define CONFIG_PCI_LINUX_PROC
+#endif
+
+#if defined(CONFIG_PCI_LINUX_PROC)
+static int pci_config_type( void ) { return 1; }
+
+/* pci operations for (powerpc) Linux
+ questions, suggestions etc:
+ mplayer-dev-eng@mplayerhq.hu, colin@colino.net*/
+#include <fcntl.h>
+//#include <sys/io.h>
+#include <linux/pci.h>
+#include "../../bswap.h"
+
+static int pci_get_vendor(
+ unsigned char bus,
+ unsigned char dev,
+ int func)
+{
+ int retval;
+ char path[100];
+ int fd;
+ short vendor, device;
+ sprintf(path,"/proc/bus/pci/%02d/%02x.0", bus, dev);
+ fd = open(path,O_RDONLY|O_SYNC);
+ if (fd == -1) {
+ retval=0xFFFF;
+ }
+ else if (pread(fd, &vendor, 2, PCI_VENDOR_ID) == 2 &&
+ pread(fd, &device, 2, PCI_DEVICE_ID) == 2) {
+ vendor = le2me_16(vendor);
+ device = le2me_16(device);
+ retval = vendor + (device<<16); /*no worries about byte order,
+ all ppc are bigendian*/
+ } else {
+ retval = 0xFFFF;
+ }
+ if (fd > 0) {
+ close(fd);
+ }
+ return retval;
+}
+
+static long pci_config_read_long(
+ unsigned char bus,
+ unsigned char dev,
+ int func,
+ unsigned cmd)
+{
+ long retval;
+ char path[100];
+ int fd;
+ sprintf(path,"/proc/bus/pci/%02d/%02x.0", bus, dev);
+ fd = open(path,O_RDONLY|O_SYNC);
+ if (fd == -1) {
+ retval=0;
+ }
+ else if (pread(fd, &retval, 4, cmd) == 4) {
+ retval = le2me_32(retval);
+ } else {
+ retval = 0;
+ }
+ if (fd > 0) {
+ close(fd);
+ }
+ return retval;
+}
+#endif
diff --git a/libdha/sysdep/pci_powerpc.c b/libdha/sysdep/pci_powerpc.c
index 82f40b4d05..94529037b6 100644
--- a/libdha/sysdep/pci_powerpc.c
+++ b/libdha/sysdep/pci_powerpc.c
@@ -4,73 +4,9 @@
Modified for readability by Nick Kurshev
*/
+#if defined(Lynx) || defined(__OpenBSD__)
static int pci_config_type( void ) { return 1; }
-#if defined(__powerpc__) && defined(__linux__)
-/* pci operations for powerpc Linux
- questions, suggestions etc:
- mplayer-dev-eng@mplayerhq.hu, colin@colino.net*/
-#include <fcntl.h>
-//#include <sys/io.h>
-#include <linux/pci.h>
-#include "../../bswap.h"
-
-static int pci_get_vendor(
- unsigned char bus,
- unsigned char dev,
- int func)
-{
- int retval;
- char path[100];
- int fd;
- short vendor, device;
- sprintf(path,"/proc/bus/pci/%02d/%02x.0", bus, dev);
- fd = open(path,O_RDONLY|O_SYNC);
- if (fd == -1) {
- retval=0xFFFF;
- }
- else if (pread(fd, &vendor, 2, PCI_VENDOR_ID) == 2 &&
- pread(fd, &device, 2, PCI_DEVICE_ID) == 2) {
- vendor = bswap_16(vendor);
- device = bswap_16(device);
- retval = vendor + (device<<16); /*no worries about byte order,
- all ppc are bigendian*/
- } else {
- retval = 0xFFFF;
- }
- if (fd > 0) {
- close(fd);
- }
- return retval;
-}
-
-static long pci_config_read_long(
- unsigned char bus,
- unsigned char dev,
- int func,
- unsigned cmd)
-{
- long retval;
- char path[100];
- int fd;
- sprintf(path,"/proc/bus/pci/%02d/%02x.0", bus, dev);
- fd = open(path,O_RDONLY|O_SYNC);
- if (fd == -1) {
- retval=0;
- }
- else if (pread(fd, &retval, 4, cmd) == 4) {
- retval = bswap_32(retval);
- } else {
- retval = 0;
- }
- if (fd > 0) {
- close(fd);
- }
- return retval;
-}
-
-#else /*Lynx/OpenBSD*/
-
static int pci_get_vendor(
unsigned char bus,
unsigned char dev,