[MPlayer-dev-eng] libdha rewrite

Dmitry Baryshkov mitya at school.ioffe.ru
Sun Aug 22 15:03:48 CEST 2004


Hello,

correct patch attached.

-- 
With best wishes
Dmitry Baryshkov
-------------- next part --------------
diff -Npur dha2/dha2.c dha2.old/dha2.c
--- dha2/dha2.c	2004-08-22 16:37:11.000000000 +0400
+++ dha2.old/dha2.c	2004-08-20 15:56:38.000000000 +0400
@@ -53,7 +53,6 @@ extern dha2_mtrr_driver_t dha2_mtrr_netb
 #if defined WIN32
 extern dha2_mmap_driver_t dha2_win9x_mmap;
 extern dha2_mmap_driver_t dha2_windha_mmap;
-extern dha2_ports_driver_t dha2_windha_ports;
 #elif defined __EMX__
 extern dha2_mmap_driver_t dha2_os2_mmap;
 #else
@@ -75,9 +74,6 @@ static dha2_ports_driver_t *dha2_ports_d
 	&dha2_svgahelper_ports,
 	&dha2_dhahelper_ports,
 #endif
-#ifdef WIN32
-	&dha2_windha_ports,
-#endif
 	&dha2_ports_direct_ports,
 	NULL
 };
@@ -387,16 +383,3 @@ int disable_app_io(void)
 		close_drivers();
 	return 0;
 }
-
-#ifdef WIN32
-#include <windows.h>
-int IsWinNT()
-{
-  OSVERSIONINFO OSVersionInfo;
-  OSVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
-  GetVersionEx(&OSVersionInfo);
-  return OSVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT;
-}  
-#else
-int IsWinNT(){return 0;}
-#endif
diff -Npur dha2/dha2_win9x_mmap.c dha2.old/dha2_win9x_mmap.c
--- dha2/dha2_win9x_mmap.c	2004-08-22 16:30:29.000000000 +0400
+++ dha2.old/dha2_win9x_mmap.c	2004-08-20 01:19:37.000000000 +0400
@@ -13,6 +13,7 @@
 #include "dha2.h"
 #include "dha2_internal.h"
 
+
 /*
   This is the request structure that applications use
   to request services from the MAPDEV VxD.
@@ -44,6 +45,14 @@ typedef struct _MapDevRequest
     ((DeviceType)<<16) | ((Access)<<14) | ((Function)<<2) | (Method) )
 #endif
 
+    
+static int IsWinNT(){
+  OSVERSIONINFO OSVersionInfo;
+  OSVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+  GetVersionEx(&OSVersionInfo);
+  return OSVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT;
+}  
+
 static HANDLE hDriver = INVALID_HANDLE_VALUE;  
     
 extern dha2_mmap_driver_t dha2_win9x_mmap;
diff -Npur dha2/dha2_windha.c dha2.old/dha2_windha.c
--- dha2/dha2_windha.c	2004-08-22 16:39:22.000000000 +0400
+++ dha2.old/dha2_windha.c	1970-01-01 03:00:00.000000000 +0300
@@ -1,112 +0,0 @@
-#ifdef WIN32
-/*
-  MAPDEV.h - include file for VxD MAPDEV
-  Copyright (c) 1996 Vireo Software, Inc.
-  Modified for libdha by Nick Kurshev.
-*/
-
-#include <windows.h>
-#include <ddk/ntddk.h>
-#include "dhahelperwin/dhahelper.h"
-#include <stdio.h>
-
-#include "dha2.h"
-#include "dha2_internal.h"
-
-static HANDLE hDriver = INVALID_HANDLE_VALUE;  
-    
-extern dha2_ports_driver_t dha2_windha_ports;
-extern dha2_mmap_driver_t dha2_windha_mmap;
-
-static int dha2_windha_init(void)
-{
-	if(!IsWinNT())
-	{
-		dha2_windha_ports.status = -1;
-		dha2_windha_mmap.status = -1;
-		return -1;
-	}
-
-	if (hDriver == INVALID_HANDLE_VALUE)
-		hDriver = CreateFile("\\\\.\\DHAHELPER",GENERIC_READ | GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
-	if (hDriver == INVALID_HANDLE_VALUE)
-	{
-		fprintf(stderr, "Cannot open driver, error=%08lx\n", GetLastError()) ;
-		dha2_windha_ports.status = -1;
-		dha2_windha_mmap.status = -1;
-		return -1;
-	}
-
-	dha2_windha_mmap.status = 1;
-	return 0;
-}
-
-static void dha2_windha_shutdown(void)
-{
-	if (hDriver != INVALID_HANDLE_VALUE)
-	{
-		dha2_windha_ports.status = 0;
-		dha2_windha_mmap.status = 0;
-
-		/* FIXME I'm not sure if the right call is CloseHandle. */
-		CloseHandle(hDriver);
-
-		hDriver = INVALID_HANDLE_VALUE;
-	}
-}
-
-#include "portio/portio_x86.h"
-
-dha2_ports_driver_t dha2_windha_ports =
-{
-	.name = "DHA windows helper driver (IO)",
-	.status = 0,
-	.init = dha2_windha_init,
-	.shutdown = dha2_windha_shutdown,
-
-	.dha2_inb = dha2_ports_direct_inb,
-	.dha2_inw = dha2_ports_direct_inw,
-	.dha2_inl = dha2_ports_direct_inl,
-
-	.dha2_outb = dha2_ports_direct_outb,
-	.dha2_outw = dha2_ports_direct_outw,
-	.dha2_outl = dha2_ports_direct_outl,
-};
-
-/* Memory Map a piece of Real Memory */
-static void *dha2_windha_map_phys_mem(unsigned long base, unsigned long size)
-{
-	dhahelper_t dhahelper_priv;
-	DWORD dwBytesReturned;
-	dhahelper_priv.size = size;
-	dhahelper_priv.base = (void*)base;
-
-	if (!DeviceIoControl(hDriver, IOCTL_DHAHELPER_MAPPHYSTOLIN, &dhahelper_priv,sizeof(dhahelper_t), &dhahelper_priv, sizeof(dhahelper_t),&dwBytesReturned, NULL))
-	{
-		printf("unable to map thre requested memory region\n");
-		return MAP_FAILED;
-	}
-	else
-		return dhahelper_priv.ptr;
-}
-
-static void dha2_windha_unmap_phys_mem(void *ptr, unsigned long size)
-{
-	dhahelper_t dhahelper_priv;
-	DWORD dwBytesReturned;
-	dhahelper_priv.ptr = ptr;
-	DeviceIoControl(hDriver, IOCTL_DHAHELPER_UNMAPPHYSADDR, &dhahelper_priv,sizeof(dhahelper_t), NULL, 0, &dwBytesReturned, NULL);
-}
-
-dha2_mmap_driver_t dha2_windha_mmap =
-{
-	.name = "DHA windows helper driver (mmap)",
-	.status = 0,
-	.init = dha2_windha_init,
-	.shutdown = dha2_windha_shutdown,
-
-	.map_phys_mem = dha2_windha_map_phys_mem,
-	.unmap_phys_mem = dha2_windha_unmap_phys_mem,
-};
-
-#endif
diff -Npur dha2/dha2_windha_mmap.c dha2.old/dha2_windha_mmap.c
--- dha2/dha2_windha_mmap.c	1970-01-01 03:00:00.000000000 +0300
+++ dha2.old/dha2_windha_mmap.c	2004-08-20 13:11:01.000000000 +0400
@@ -0,0 +1,97 @@
+#ifdef WIN32
+/*
+  MAPDEV.h - include file for VxD MAPDEV
+  Copyright (c) 1996 Vireo Software, Inc.
+  Modified for libdha by Nick Kurshev.
+*/
+
+#include <windows.h>
+#include <ddk/ntddk.h>
+#include "dhahelperwin/dhahelper.h"
+#include <stdio.h>
+
+#include "dha2.h"
+#include "dha2_internal.h"
+
+static int IsWinNT(){
+  OSVERSIONINFO OSVersionInfo;
+  OSVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+  GetVersionEx(&OSVersionInfo);
+  return OSVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT;
+}  
+
+static HANDLE hDriver = INVALID_HANDLE_VALUE;  
+    
+extern dha2_mmap_driver_t dha2_windha_mmap;
+
+static int dha2_windha_init(void)
+{
+	if(!IsWinNT())
+	{
+		dha2_windha_mmap.status = -1;
+		return -1;
+	}
+
+	if (hDriver == INVALID_HANDLE_VALUE)
+		hDriver = CreateFile("\\\\.\\DHAHELPER",GENERIC_READ | GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
+	if (hDriver == INVALID_HANDLE_VALUE)
+	{
+		fprintf(stderr, "Cannot open driver, error=%08lx\n", GetLastError()) ;
+		dha2_windha_mmap.status = -1;
+		return -1;
+	}
+
+	dha2_windha_mmap.status = 1;
+	return 0;
+}
+
+static void dha2_windha_shutdown(void)
+{
+	if (hDriver != INVALID_HANDLE_VALUE)
+	{
+		dha2_windha_mmap.status = 0;
+
+		/* FIXME I'm not sure if the right call is CloseHandle. */
+		CloseHandle(hDriver);
+
+		hDriver = INVALID_HANDLE_VALUE;
+	}
+}
+
+/* Memory Map a piece of Real Memory */
+static void *dha2_windha_map_phys_mem(unsigned long base, unsigned long size)
+{
+	dhahelper_t dhahelper_priv;
+	DWORD dwBytesReturned;
+	dhahelper_priv.size = size;
+	dhahelper_priv.base = (void*)base;
+
+	if (!DeviceIoControl(hDriver, IOCTL_DHAHELPER_MAPPHYSTOLIN, &dhahelper_priv,sizeof(dhahelper_t), &dhahelper_priv, sizeof(dhahelper_t),&dwBytesReturned, NULL))
+	{
+		printf("unable to map thre requested memory region\n");
+		return MAP_FAILED;
+	}
+	else
+		return dhahelper_priv.ptr;
+}
+
+static void dha2_windha_unmap_phys_mem(void *ptr, unsigned long size)
+{
+	dhahelper_t dhahelper_priv;
+	DWORD dwBytesReturned;
+	dhahelper_priv.ptr = ptr;
+	DeviceIoControl(hDriver, IOCTL_DHAHELPER_UNMAPPHYSADDR, &dhahelper_priv,sizeof(dhahelper_t), NULL, 0, &dwBytesReturned, NULL);
+}
+
+dha2_mmap_driver_t dha2_windha_mmap =
+{
+	.name = "DHA windows helper driver (mmap)",
+	.status = 0,
+	.init = dha2_windha_init,
+	.shutdown = dha2_windha_shutdown,
+
+	.map_phys_mem = dha2_windha_map_phys_mem,
+	.unmap_phys_mem = dha2_windha_unmap_phys_mem,
+};
+
+#endif
diff -Npur dha2/include/dha2_internal.h dha2.old/include/dha2_internal.h
--- dha2/include/dha2_internal.h	2004-08-22 16:29:49.000000000 +0400
+++ dha2.old/include/dha2_internal.h	2004-08-20 14:32:29.000000000 +0400
@@ -113,8 +113,6 @@ int pci_get_vendor(unsigned char bus, un
 #define PCI_EN 0x80000000
 #endif
 
-int IsWinNT();
-
 #ifndef DONT_POISON_PORTS
 #if defined __GNUC__ && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 303)
 #pragma GCC poison inb inw inl outb outw outl
diff -Npur dha2/io/io_win32.c dha2.old/io/io_win32.c
--- dha2/io/io_win32.c	2004-08-22 16:31:27.000000000 +0400
+++ dha2.old/io/io_win32.c	2004-08-20 00:49:01.000000000 +0400
@@ -3,21 +3,40 @@
    $XFree86: xc/programs/Xserver/hw/xfree86/etc/scanpci.c,v 3.34.2.17 1998/11/10 11:55:40 dawes Exp $
    Modified for readability by Nick Kurshev
 */
+#include <windows.h>
+#include <ddk/ntddk.h>
+#include "../dhahelperwin/dhahelper.h"
 
-#include "dha2_internal.h"
+static HANDLE hDriver;
+extern int IsWinNT();
+
+static int IsWinNT(){
+  OSVERSIONINFO OSVersionInfo;
+  OSVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+  GetVersionEx(&OSVersionInfo);
+  return OSVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT;
+}  
 
-#include <stdio.h>
 
 static int start_port_access(void)
 {
     if(IsWinNT()){
-        printf("unable to use directio please install dhahelper.sys\n");
+      DWORD dwBytesReturned;
+      hDriver = CreateFile("\\\\.\\DHAHELPER",GENERIC_READ | GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
+      if(!DeviceIoControl(hDriver, IOCTL_DHAHELPER_ENABLEDIRECTIO, NULL,0, NULL, 0, &dwBytesReturned, NULL)){
+        printf("unable to enable directio please install dhahelper.sys\n");
         return(1);       
+      }
     }
     return(0);
 }
 
 static int stop_port_access(void)
 {
+    if(IsWinNT()){
+      DWORD dwBytesReturned;
+      DeviceIoControl(hDriver, IOCTL_DHAHELPER_DISABLEDIRECTIO, NULL,0, NULL, 0, &dwBytesReturned, NULL);
+      CloseHandle(hDriver);
+    }
     return(0);
 }
diff -Npur dha2/Makefile dha2.old/Makefile
--- dha2/Makefile	2004-08-22 16:35:56.000000000 +0400
+++ dha2.old/Makefile	2004-08-20 16:24:05.000000000 +0400
@@ -9,7 +9,6 @@ MAJOR_VERSION = 1
 MINOR_VERSION = 0
 VERSION = $(MAJOR_VERSION).$(MINOR_VERSION) 
 
-CFLAGS  = $(OPTFLAGS) -I. -I.. -Iinclude -Wall
 ifeq ($(TARGET_OS),CYGWIN)
 SHORTNAME = libdha2.dll
 else
@@ -21,9 +20,9 @@ LIBNAME = libdha2.a
 SHORTNAME = libdha2.a
 else
 LIBNAME = libdha2.so.$(VERSION)
-CFLAGS += -fPIC
 endif
 
+CFLAGS  = $(OPTFLAGS) -fPIC -I. -I.. -Iinclude -Wall
 LIBS = 
 ifeq ($(TARGET_OS),OpenBSD)
 ifeq ($(TARGET_ARCH_X86),yes)
@@ -31,7 +30,7 @@ LIBS += -li386
 endif
 endif
 
-SRCS = dha2.c pciscan.c pci_names.c dha2_svgahelper.c dha2_dhahelper.c dha2_mtrr_linux.c dha2_pci_proc_linux.c dha2_devmem_mmap.c dha2_os2_mmap.c dha2_win9x_mmap.c dha2_windha.c dha2_pci_generic.c dha2_ports_direct.c dha2_mtrr_netbsd.c dha2_pciconfig_pci.c
+SRCS = dha2.c pciscan.c pci_names.c dha2_svgahelper.c dha2_dhahelper.c dha2_mtrr_linux.c dha2_pci_proc_linux.c dha2_devmem_mmap.c dha2_os2_mmap.c dha2_win9x_mmap.c dha2_windha_mmap.c dha2_pci_generic.c dha2_ports_direct.c dha2_mtrr_netbsd.c dha2_pciconfig_pci.c
 
 OBJS=$(SRCS:.c=.o)
 


More information about the MPlayer-dev-eng mailing list