changeset 4174:4cfb6b9a6da3

api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
author alex
date Tue, 15 Jan 2002 15:59:53 +0000
parents 250f39dedede
children 8110b321f2ca
files libdha/libdha.c libdha/libdha.h libdha/pci.c libdha/sysdep/pci_386bsd.c libdha/sysdep/pci_bsdi.c libdha/sysdep/pci_freebsd.c libdha/sysdep/pci_isc.c libdha/sysdep/pci_linux.c libdha/sysdep/pci_mach386.c libdha/sysdep/pci_netbsd.c libdha/sysdep/pci_openbsd.c libdha/sysdep/pci_os2.c libdha/sysdep/pci_sco.c libdha/sysdep/pci_svr4.c libdha/sysdep/pci_win32.c
diffstat 15 files changed, 118 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/libdha/libdha.c	Tue Jan 15 15:31:30 2002 +0000
+++ b/libdha/libdha.c	Tue Jan 15 15:59:53 2002 +0000
@@ -7,6 +7,7 @@
     		  Modified for GATOS/win/gfxdump.
 		  
     2002	- library implementation by Nick Kurshev
+		- some changes by Alex Beregszaszi
     
     supported O/S's:	SVR4, UnixWare, SCO, Solaris,
 			FreeBSD, NetBSD, 386BSD, BSDI BSD/386,
@@ -26,6 +27,14 @@
 #include <sys/types.h>
 #include <unistd.h>
 
+/* 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 */
+}
+
 #if defined(_WIN32)
 #include "sysdep/libdha_win32.c"
 #elif defined (__EMX__)
@@ -97,3 +106,4 @@
 {
   outl(idx,val);
 }
+
--- a/libdha/libdha.h	Tue Jan 15 15:31:30 2002 +0000
+++ b/libdha/libdha.h	Tue Jan 15 15:59:53 2002 +0000
@@ -32,6 +32,9 @@
   unsigned	base0,base1,base2,baserom ;	/* Memory and I/O base addresses */
 }pciinfo_t;
 
+/* needed for mga_vid */
+extern int pci_config_read(unsigned char bus, unsigned char dev, unsigned char offset,
+			int len, unsigned long *val);
 			/* Fill array pci_list which must have size MAX_PCI_DEVICES
 			   and return 0 if sucessful */
 extern int  pci_scan(pciinfo_t *pci_list,unsigned *num_card);
--- a/libdha/pci.c	Tue Jan 15 15:31:30 2002 +0000
+++ b/libdha/pci.c	Tue Jan 15 15:59:53 2002 +0000
@@ -122,7 +122,7 @@
 #define PCIBIOS_DEVICE_NOT_FOUND	0x86
 #define PCIBIOS_SUCCESSFUL		0x00
  
-static int pciconfig_read(
+int pciconfig_read(
           unsigned char bus,
           unsigned char dev,
           unsigned char offset,
@@ -144,7 +144,7 @@
 	return PCIBIOS_SUCCESSFUL;
 }
  
-static int pciconfig_write(
+int pciconfig_write(
           unsigned char bus,
           unsigned char dev,
           unsigned char offset,
@@ -528,10 +528,13 @@
     struct pci_config_reg pcr;
     int do_mode1_scan = 0, do_mode2_scan = 0;
     int func, hostbridges=0;
+    int ret = -1;
     
     pci_lst = pci_list;
  
-    enable_os_io();
+    ret = enable_os_io();
+    if (ret != 0)
+	return(ret);
 
     if((pcr._configtype = pci_config_type()) == 0xFFFF) return ENODEV;
  
@@ -695,3 +698,25 @@
     return 0 ;
  
 }
+
+#if !defined(ENOTSUP)
+#if defined(EOPNOTSUPP)
+#define ENOTSUP EOPNOTSUPP
+#else
+#warning "ENOTSUP nor EOPNOTSUPP defined!"
+#endif
+#endif
+
+int pci_config_read(unsigned char bus, unsigned char dev,
+		    unsigned char offset, int len, unsigned long *val)
+{
+    if (len != 4)
+    {
+	printf("pci_config_read: reading non-dword not supported!\n");
+	return(ENOTSUP);
+    }
+    
+    *val = pci_config_read_long(bus, dev, offset, 0);
+    
+    return(0);
+}
--- a/libdha/sysdep/pci_386bsd.c	Tue Jan 15 15:31:30 2002 +0000
+++ b/libdha/sysdep/pci_386bsd.c	Tue Jan 15 15:59:53 2002 +0000
@@ -3,6 +3,7 @@
    $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 <errno.h>
 #include <sys/file.h>
 #include <machine/console.h>
 #ifndef GCCUSESGAS
@@ -11,25 +12,27 @@
 
 static int io_fd;
 
-static __inline__ void enable_os_io(void)
+static __inline__ int enable_os_io(void)
 {
     io_fd = -1 ;
     if ((io_fd = open("/dev/console", O_RDWR, 0)) < 0) {
         perror("/dev/console");
-        exit(1);
+	return(errno);
     }
     if (ioctl(io_fd, KDENABIO, 0) < 0) {
         perror("ioctl(KDENABIO)");
-        exit(1);
+	return(errno);
     }
+    return(0);
 }
 
-static __inline__ void disable_os_io(void)
+static __inline__ int disable_os_io(void)
 {
     if (ioctl(io_fd, KDDISABIO, 0) < 0) {
         perror("ioctl(KDDISABIO)");
 	close(io_fd);
-        exit(1);
+	return(errno);
     }
     close(io_fd);
+    return(0);
 }
--- a/libdha/sysdep/pci_bsdi.c	Tue Jan 15 15:31:30 2002 +0000
+++ b/libdha/sysdep/pci_bsdi.c	Tue Jan 15 15:59:53 2002 +0000
@@ -3,6 +3,7 @@
    $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 <errno.h>
 #include <sys/file.h>
 #include <sys/ioctl.h>
 #include <i386/isa/pcconsioctl.h>
@@ -12,25 +13,27 @@
 
 static int io_fd;
 
-static __inline__ void enable_os_io(void)
+static __inline__ int enable_os_io(void)
 {
     io_fd = -1 ;
     if ((io_fd = open("/dev/console", O_RDWR, 0)) < 0) {
         perror("/dev/console");
-        exit(1);
+	return(errno);
     }
     if (ioctl(io_fd, PCCONENABIOPL, 0) < 0) {
         perror("ioctl(PCCONENABIOPL)");
-        exit(1);
+        return(errno);
     }
+    return(0);
 }
 
-static __inline__ void disable_os_io(void)
+static __inline__ int disable_os_io(void)
 {
     if (ioctl(io_fd, PCCONDISABIOPL, 0) < 0) {
         perror("ioctl(PCCONDISABIOPL)");
 	close(io_fd);
-        exit(1);
+        return(errno);
     }
     close(io_fd);
+    return(0);
 }
--- a/libdha/sysdep/pci_freebsd.c	Tue Jan 15 15:31:30 2002 +0000
+++ b/libdha/sysdep/pci_freebsd.c	Tue Jan 15 15:59:53 2002 +0000
@@ -3,6 +3,7 @@
    $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 <errno.h>
 #include <sys/file.h>
 #include <machine/console.h>
 #ifndef GCCUSESGAS
@@ -11,25 +12,27 @@
 
 static int io_fd;
 
-static __inline__ void enable_os_io(void)
+static __inline__ int enable_os_io(void)
 {
     io_fd = -1 ;
     if ((io_fd = open("/dev/console", O_RDWR, 0)) < 0) {
         perror("/dev/console");
-        exit(1);
+	return(errno);
     }
     if (ioctl(io_fd, KDENABIO, 0) < 0) {
         perror("ioctl(KDENABIO)");
-        exit(1);
+        return(errno);
     }
+    return(0);
 }
 
-static __inline__ void disable_os_io(void)
+static __inline__ int disable_os_io(void)
 {
     if (ioctl(io_fd, KDDISABIO, 0) < 0) {
         perror("ioctl(KDDISABIO)");
 	close(io_fd);
-        exit(1);
+        return(errno);
     }
     close(io_fd);
+    return(0);
 }
--- a/libdha/sysdep/pci_isc.c	Tue Jan 15 15:31:30 2002 +0000
+++ b/libdha/sysdep/pci_isc.c	Tue Jan 15 15:59:53 2002 +0000
@@ -11,20 +11,22 @@
 #include <sys/sysi86.h>
 #include <sys/v86.h>
 
-static __inline__ void enable_os_io(void)
+static __inline__ int enable_os_io(void)
 {
 #if defined(SI86IOPL)
     sysi86(SI86IOPL, 3);
 #else
     sysi86(SI86V86, V86SC_IOPL, PS_IOPL);
 #endif
+    return(0);
 }
 
-static __inline__ void disable_os_io(void)
+static __inline__ int disable_os_io(void)
 {
 #if defined(SI86IOPL)
     sysi86(SI86IOPL, 0);
 #else
     sysi86(SI86V86, V86SC_IOPL, 0);
 #endif
+    return(0);
 }
--- a/libdha/sysdep/pci_linux.c	Tue Jan 15 15:31:30 2002 +0000
+++ b/libdha/sysdep/pci_linux.c	Tue Jan 15 15:59:53 2002 +0000
@@ -3,18 +3,23 @@
    $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 <errno.h>
 #ifdef __i386__
 #include <sys/perm.h>
 #else
 #include <sys/io.h>
 #endif
 
-static __inline__ void enable_os_io(void)
+static __inline__ int enable_os_io(void)
 {
-    iopl(3);
+    if (iopl(3) != 0)
+	return(errno);
+    return(0);
 }
 
-static __inline__ void disable_os_io(void)
+static __inline__ int disable_os_io(void)
 {
-    iopl(0);
+    if (iopl(0) != 0)
+	return(errno);
+    return(0);
 }
--- a/libdha/sysdep/pci_mach386.c	Tue Jan 15 15:31:30 2002 +0000
+++ b/libdha/sysdep/pci_mach386.c	Tue Jan 15 15:59:53 2002 +0000
@@ -4,18 +4,22 @@
    Modified for readability by Nick Kurshev
 */
 
+#include <errno.h>
+
 static int io_fd;
 
-static __inline__ void enable_os_io(void)
+static __inline__ int enable_os_io(void)
 {
     io_fd = -1 ;
     if ((io_fd = open("/dev/iopl", O_RDWR, 0)) < 0) {
         perror("/dev/iopl");
-        exit(1);
+        return(errno);
     }
+    return(0);
 }
 
-static __inline__ void disable_os_io(void)
+static __inline__ int disable_os_io(void)
 {
     close(io_fd);
+    return(0);
 }
--- a/libdha/sysdep/pci_netbsd.c	Tue Jan 15 15:31:30 2002 +0000
+++ b/libdha/sysdep/pci_netbsd.c	Tue Jan 15 15:59:53 2002 +0000
@@ -3,6 +3,7 @@
    $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 <errno.h>
 #include <sys/param.h>
 #include <sys/file.h>
 #include <machine/sysarch.h>
@@ -12,30 +13,32 @@
 
 static int io_fd;
 
-static __inline__ void enable_os_io(void)
+static __inline__ int enable_os_io(void)
 {
     io_fd = -1 ;
 #if !defined(USE_I386_IOPL)
     if ((io_fd = open("/dev/io", O_RDWR, 0)) < 0) {
 	perror("/dev/io");
-	exit(1);
+	return(errno);
     }
 #else
     if (i386_iopl(1) < 0) {
 	perror("i386_iopl");
-	exit(1);
+	return(errno);
     }
 #endif /* USE_I386_IOPL */
+    return(0);
 }
 
-static __inline__ void disable_os_io(void)
+static __inline__ int disable_os_io(void)
 {
 #if !defined(USE_I386_IOPL)
     close(io_fd);
 #else
     if (i386_iopl(0) < 0) {
 	perror("i386_iopl");
-	exit(1);
+	return(errno);
     }
 #endif /* NetBSD1_1 */
+    return(0);
 }
--- a/libdha/sysdep/pci_openbsd.c	Tue Jan 15 15:31:30 2002 +0000
+++ b/libdha/sysdep/pci_openbsd.c	Tue Jan 15 15:59:53 2002 +0000
@@ -4,15 +4,19 @@
    Modified for readability by Nick Kurshev
 */
 
-static __inline__ void enable_os_io(void)
+#include <errno.h>
+
+static __inline__ int enable_os_io(void)
 {
     if (i386_iopl(1) < 0) {
 	perror("i386_iopl");
-	exit(1);
+	return(errno);
     }
+    return(0);
 }
 
-static __inline__ void disable_os_io(void)
+static __inline__ int disable_os_io(void)
 {
  /* Nothing to do */
+    return(0);
 }
--- a/libdha/sysdep/pci_os2.c	Tue Jan 15 15:31:30 2002 +0000
+++ b/libdha/sysdep/pci_os2.c	Tue Jan 15 15:59:53 2002 +0000
@@ -8,7 +8,7 @@
 
 static USHORT callgate[3] = {0,0,0};
 
-static __inline__ void enable_os_io(void)
+static __inline__ int enable_os_io(void)
 {
 	HFILE hfd;
 	ULONG dlen,action;
@@ -21,7 +21,7 @@
 	   (ULONG)0) != 0) {
 		fprintf(stderr,"Error opening fastio$ driver...\n");
 		fprintf(stderr,"Please install xf86sup.sys in config.sys!\n");
-		exit(42);
+		return(42);
 	}
 	callgate[0] = callgate[1] = 0;
  
@@ -34,7 +34,7 @@
 		fprintf(stderr,"xf86-OS/2: EnableIOPorts failed, rc=%d, dlen=%d; emergency exit\n",
 			rc,dlen);
 		DosClose(hfd);
-		exit(42);
+		return(42);
 	}
  
 /* Calling callgate with function 13 sets IOPL for the program */
@@ -45,9 +45,11 @@
 			: "eax","ebx","ecx","edx","cc");
  
         DosClose(hfd);
+	return(0);
 }
 
-static __inline__ void disable_os_io(void)
+static __inline__ int disable_os_io(void)
 {
 /* Nothing to do */
+        return(0);
 }
--- a/libdha/sysdep/pci_sco.c	Tue Jan 15 15:31:30 2002 +0000
+++ b/libdha/sysdep/pci_sco.c	Tue Jan 15 15:59:53 2002 +0000
@@ -12,20 +12,22 @@
 #include <sys/sysi86.h>
 #include <sys/v86.h>
 
-static __inline__ void enable_os_io(void)
+static __inline__ int enable_os_io(void)
 {
 #if defined(SI86IOPL)
     sysi86(SI86IOPL, 3);
 #else
     sysi86(SI86V86, V86SC_IOPL, PS_IOPL);
 #endif
+    return(0);
 }
 
-static __inline__ void disable_os_io(void)
+static __inline__ int disable_os_io(void)
 {
 #if defined(SI86IOPL)
     sysi86(SI86IOPL, 0);
 #else
     sysi86(SI86V86, V86SC_IOPL, 0);
 #endif
+    return(0);
 }
--- a/libdha/sysdep/pci_svr4.c	Tue Jan 15 15:31:30 2002 +0000
+++ b/libdha/sysdep/pci_svr4.c	Tue Jan 15 15:59:53 2002 +0000
@@ -19,20 +19,22 @@
 #define __EXTENSIONS__
 #endif
 
-static __inline__ void enable_os_io(void)
+static __inline__ int enable_os_io(void)
 {
 #if defined(SI86IOPL)
     sysi86(SI86IOPL, 3);
 #else
     sysi86(SI86V86, V86SC_IOPL, PS_IOPL);
 #endif
+    return(0);
 }
 
-static __inline__ void disable_os_io(void)
+static __inline__ int disable_os_io(void)
 {
 #if defined(SI86IOPL)
     sysi86(SI86IOPL, 0);
 #else
     sysi86(SI86V86, V86SC_IOPL, 0);
 #endif
+    return(0);
 }
--- a/libdha/sysdep/pci_win32.c	Tue Jan 15 15:31:30 2002 +0000
+++ b/libdha/sysdep/pci_win32.c	Tue Jan 15 15:59:53 2002 +0000
@@ -7,10 +7,12 @@
 
 /* Nothing to do for Win9x. For WinNT I have no solution */
 
-static __inline__ void enable_os_io(void)
+static __inline__ int enable_os_io(void)
 {
+    return(0);
 }
 
-static __inline__ void disable_os_io(void)
+static __inline__ int disable_os_io(void)
 {
+    return(0);
 }