[MPlayer-dev-eng] [PATCH] svgalib_helper support for libdha
Matan Ziv-Av
matan at svgalib.org
Tue Dec 17 23:00:04 CET 2002
Hello,
The attached patch adds to dha the option to use svgalib kernel helper
instead of dha helper. The helper is used in order to access the
hardware without root privileges.
The problem with the current patch is that there is no
autoconfiguration, so libdha/Makefile nneds to be editted to use this.
There is also no runtime detection, so vidix will not work if compiled
for svgalib helper but the module is not loaded.
--
Matan Ziv-Av. matan at svgalib.org
-------------- next part --------------
diff -Nur ../orig/MPlayer-20021206/libdha/Makefile libdha/Makefile
--- ../orig/MPlayer-20021206/libdha/Makefile Mon Oct 21 16:23:19 2002
+++ libdha/Makefile Tue Dec 17 23:42:04 2002
@@ -28,6 +28,12 @@
endif
endif
+
+# If you want libdha to use svgalib_helper module 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 -I/svgalib/kernel/svgalib_helper
+
.SUFFIXES: .c .o
# .PHONY: all clean
diff -Nur ../orig/MPlayer-20021206/libdha/config.h libdha/config.h
--- ../orig/MPlayer-20021206/libdha/config.h Tue Oct 22 17:09:36 2002
+++ libdha/config.h Tue Dec 17 13:40:50 2002
@@ -9,4 +9,8 @@
#endif
#endif
+#ifdef CONFIG_SVGAHELPER
+#undef CONFIG_DHAHELPER
+#endif
+
#endif /* LIBDHA_CONFIG_H */
diff -Nur ../orig/MPlayer-20021206/libdha/libdha.c libdha/libdha.c
--- ../orig/MPlayer-20021206/libdha/libdha.c Fri Apr 19 19:33:54 2002
+++ libdha/libdha.c Tue Dec 17 22:47:24 2002
@@ -108,8 +108,13 @@
/* 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) ;
+ if(mem==-1) {
+#ifdef CONFIG_SVGAHELPER
+ if ( (mem = open(DEV_SVGA,O_RDWR)) == -1)
+#endif
+ if ( (mem = open(DEV_MEM,O_RDWR)) == -1) {
+ perror("libdha: open(/dev/mem) failed") ; exit(1) ;
+ }
}
return mmap(0,size,PROT_READ|PROT_WRITE,MAP_SHARED,mem,base) ;
}
@@ -120,6 +125,7 @@
int res=munmap(ptr,size) ;
if (res == -1) { perror("libdha: munmap() failed") ; exit(1) ; }
close(mem);
+ mem=-1;
}
#endif
diff -Nur ../orig/MPlayer-20021206/libdha/pci.c libdha/pci.c
--- ../orig/MPlayer-20021206/libdha/pci.c Fri Apr 19 19:33:54 2002
+++ libdha/pci.c Tue Dec 17 14:43:29 2002
@@ -478,6 +478,7 @@
#endif
/* cpu depended stuff */
+#ifndef CONFIG_SVGAHELPER
#if defined(__alpha__)
#include "sysdep/pci_alpha.c"
#elif defined(__ia64__)
@@ -490,6 +491,7 @@
#include "sysdep/pci_powerpc.c"
#else
#include "sysdep/pci_x86.c"
+#endif
#endif
diff -Nur ../orig/MPlayer-20021206/libdha/sysdep/AsmMacros_x86.h libdha/sysdep/AsmMacros_x86.h
--- ../orig/MPlayer-20021206/libdha/sysdep/AsmMacros_x86.h Sat Feb 2 09:05:52 2002
+++ libdha/sysdep/AsmMacros_x86.h Tue Dec 17 21:55:41 2002
@@ -13,6 +13,72 @@
#include "config.h"
+#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, short 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 /* SVGAHELPER */
+
#ifdef CONFIG_DHAHELPER
#include <sys/ioctl.h>
#include "../kernelhelper/dhahelper.h"
@@ -37,6 +103,10 @@
}
else
#endif
+ if(svgahelper_initialized==1) {
+ svga_outb(port, val);
+ return ;
+ }
__asm__ __volatile__("outb %0,%1" : :"a" (val), "d" (port));
return;
}
@@ -57,6 +127,10 @@
}
else
#endif
+ if(svgahelper_initialized==1) {
+ svga_outw(port, val);
+ return ;
+ }
__asm__ __volatile__("outw %0,%1" : :"a" (val), "d" (port));
return;
}
@@ -77,6 +151,10 @@
}
else
#endif
+ if(svgahelper_initialized==1) {
+ svga_outl(port, val);
+ return ;
+ }
__asm__ __volatile__("outl %0,%1" : :"a" (val), "d" (port));
return;
}
@@ -97,6 +175,9 @@
}
else
#endif
+ if(svgahelper_initialized==1) {
+ return svga_inb(port);
+ }
__asm__ __volatile__("inb %1,%0" :
"=a" (ret) :
"d" (port));
@@ -119,6 +200,9 @@
}
else
#endif
+ if(svgahelper_initialized==1) {
+ return svga_inw(port);
+ }
__asm__ __volatile__("inw %1,%0" :
"=a" (ret) :
"d" (port));
@@ -141,6 +225,9 @@
}
else
#endif
+ if(svgahelper_initialized==1) {
+ return svga_inl(port);
+ }
__asm__ __volatile__("inl %1,%0" :
"=a" (ret) :
"d" (port));
@@ -149,11 +236,13 @@
static __inline__ void intr_disable()
{
+ if(svgahelper_initialized==1) return ;
__asm__ __volatile__("cli");
}
static __inline__ void intr_enable()
{
+ if(svgahelper_initialized==1) return ;
__asm__ __volatile__("sti");
}
diff -Nur ../orig/MPlayer-20021206/libdha/sysdep/pci_linux.c libdha/sysdep/pci_linux.c
--- ../orig/MPlayer-20021206/libdha/sysdep/pci_linux.c Tue Oct 22 14:22:40 2002
+++ libdha/sysdep/pci_linux.c Tue Dec 17 22:55:01 2002
@@ -14,6 +14,43 @@
#include "config.h"
+#ifdef CONFIG_SVGAHELPER
+#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 /* SVGAHELPER */
+
#ifdef CONFIG_DHAHELPER
#include <fcntl.h>
int dhahelper_initialized = 0;
@@ -31,7 +68,15 @@
}
dhahelper_initialized = -1;
#endif
-
+#ifdef CONFIG_SVGAHELPER
+ svgahelper_fd = open(DEV_SVGA, O_RDWR);
+ if (svgahelper_fd > 0)
+ {
+ svgahelper_initialized = 1;
+ return(0);
+ }
+ svgahelper_initialized = -1;
+#endif
#if defined(__powerpc__) && defined(__linux__)
/* should be fixed? */
#else
@@ -46,6 +91,13 @@
#ifdef CONFIG_DHAHELPER
if (dhahelper_initialized == 1)
close(dhahelper_fd);
+ else
+#endif
+#ifdef CONFIG_SVGAHELPER
+ if (svgahelper_initialized == 1) {
+ close(svgahelper_fd);
+ svgahelper_initialized=0;
+ }
else
#endif
#if defined(__powerpc__) && defined(__linux__)
More information about the MPlayer-dev-eng
mailing list