aboutsummaryrefslogtreecommitdiffhomepage
path: root/libdha
diff options
context:
space:
mode:
authorGravatar nick <nick@b3059339-0415-0410-9bf9-f77b7e298cf2>2002-01-15 08:33:09 +0000
committerGravatar nick <nick@b3059339-0415-0410-9bf9-f77b7e298cf2>2002-01-15 08:33:09 +0000
commit5f3109cf1215c57e1dcada1fb27182240d01c79b (patch)
tree2a95aa1d83190202c9b3e0bf988080251bcb8645 /libdha
parent798a238afabbd6238469028da2109bd5d739a618 (diff)
Improved readability and new stuffs
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@4165 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libdha')
-rw-r--r--libdha/AsmMacros.h352
-rw-r--r--libdha/libdha.c97
-rw-r--r--libdha/pci.c635
-rw-r--r--libdha/sysdep/AsmMacros_alpha.h26
-rw-r--r--libdha/sysdep/AsmMacros_arm32.h50
-rw-r--r--libdha/sysdep/AsmMacros_ia64.h16
-rw-r--r--libdha/sysdep/AsmMacros_powerpc.h62
-rw-r--r--libdha/sysdep/AsmMacros_sparc.h53
-rw-r--r--libdha/sysdep/AsmMacros_x86.h68
-rw-r--r--libdha/sysdep/libdha_os2.c161
-rw-r--r--libdha/sysdep/libdha_win32.c70
-rw-r--r--libdha/sysdep/pci_386bsd.c35
-rw-r--r--libdha/sysdep/pci_alpha.c29
-rw-r--r--libdha/sysdep/pci_arm32.c60
-rw-r--r--libdha/sysdep/pci_bsdi.c36
-rw-r--r--libdha/sysdep/pci_freebsd.c35
-rw-r--r--libdha/sysdep/pci_ia64.c60
-rw-r--r--libdha/sysdep/pci_isc.c30
-rw-r--r--libdha/sysdep/pci_linux.c20
-rw-r--r--libdha/sysdep/pci_lynx.c93
-rw-r--r--libdha/sysdep/pci_mach386.c21
-rw-r--r--libdha/sysdep/pci_netbsd.c41
-rw-r--r--libdha/sysdep/pci_openbsd.c18
-rw-r--r--libdha/sysdep/pci_os2.c53
-rw-r--r--libdha/sysdep/pci_powerpc.c28
-rw-r--r--libdha/sysdep/pci_sco.c31
-rw-r--r--libdha/sysdep/pci_sparc.c60
-rw-r--r--libdha/sysdep/pci_svr4.c38
-rw-r--r--libdha/sysdep/pci_win32.c16
-rw-r--r--libdha/sysdep/pci_x86.c60
30 files changed, 1394 insertions, 960 deletions
diff --git a/libdha/AsmMacros.h b/libdha/AsmMacros.h
index 3a1a9a5e52..5e4e1addc4 100644
--- a/libdha/AsmMacros.h
+++ b/libdha/AsmMacros.h
@@ -59,347 +59,25 @@
/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/chips/util/AsmMacros.h,v 1.1 2001/11/16 21:13:34 tsi Exp $ */
+/*
+ * Modified for readability by Nick Kurshev
+*/
+
#if defined(__GNUC__)
-#if defined(linux) && (defined(__alpha__) || defined(__ia64__))
-#include <sys/io.h>
+#if defined(__alpha__)
+#include "sysdep/AsmMacros_alpha.h"
+#elif defined(__ia64__)
+#include "sysdep/AsmMacros_ia64.h"
+#elif defined(__sparc__)
+#include "sysdep/AsmMacros_sparc.h"
+#elif defined( __arm32__ )
+#include "sysdep/AsmMacros_arm32.h"
+#elif defined(__powerpc__)
+#include "sysdep/AsmMacros_powerpc.h"
#else
-#if defined(__sparc__)
-#ifndef ASI_PL
-#define ASI_PL 0x88
+#include "sysdep/AsmMacros_x86.h"
#endif
-static __inline__ void
-outb(port, val)
-unsigned long port;
-char val;
-{
- __asm__ __volatile__("stba %0, [%1] %2" : : "r" (val), "r" (port), "i" (ASI_PL));
-}
-
-static __inline__ void
-outw(port, val)
-unsigned long port;
-char val;
-{
- __asm__ __volatile__("stha %0, [%1] %2" : : "r" (val), "r" (port), "i" (ASI_PL));
-}
-
-static __inline__ void
-outl(port, val)
-unsigned long port;
-char val;
-{
- __asm__ __volatile__("sta %0, [%1] %2" : : "r" (val), "r" (port), "i" (ASI_PL));
-}
-
-static __inline__ unsigned int
-inb(port)
-unsigned long port;
-{
- unsigned char ret;
- __asm__ __volatile__("lduba [%1] %2, %0" : "=r" (ret) : "r" (port), "i" (ASI_PL));
- return ret;
-}
-
-static __inline__ unsigned int
-inw(port)
-unsigned long port;
-{
- unsigned char ret;
- __asm__ __volatile__("lduha [%1] %2, %0" : "=r" (ret) : "r" (port), "i" (ASI_PL));
- return ret;
-}
-
-static __inline__ unsigned int
-inl(port)
-unsigned long port;
-{
- unsigned char ret;
- __asm__ __volatile__("lda [%1] %2, %0" : "=r" (ret) : "r" (port), "i" (ASI_PL));
- return ret;
-}
-#else
-#ifdef __arm32__
-unsigned int IOPortBase; /* Memory mapped I/O port area */
-
-static __inline__ void
-outb(port, val)
- short port;
- char val;
-{
- if ((unsigned short)port >= 0x400) return;
-
- *(volatile unsigned char*)(((unsigned short)(port))+IOPortBase) = val;
-}
-
-static __inline__ void
-outw(port, val)
- short port;
- short val;
-{
- if ((unsigned short)port >= 0x400) return;
-
- *(volatile unsigned short*)(((unsigned short)(port))+IOPortBase) = val;
-}
-
-static __inline__ void
-outl(port, val)
- short port;
- int val;
-{
- if ((unsigned short)port >= 0x400) return;
-
- *(volatile unsigned long*)(((unsigned short)(port))+IOPortBase) = val;
-}
-
-static __inline__ unsigned int
-inb(port)
- short port;
-{
- if ((unsigned short)port >= 0x400) return((unsigned int)-1);
-
- return(*(volatile unsigned char*)(((unsigned short)(port))+IOPortBase));
-}
-
-static __inline__ unsigned int
-inw(port)
- short port;
-{
- if ((unsigned short)port >= 0x400) return((unsigned int)-1);
-
- return(*(volatile unsigned short*)(((unsigned short)(port))+IOPortBase));
-}
-
-static __inline__ unsigned int
-inl(port)
- short port;
-{
- if ((unsigned short)port >= 0x400) return((unsigned int)-1);
-
- return(*(volatile unsigned long*)(((unsigned short)(port))+IOPortBase));
-}
-#else /* __arm32__ */
-#if defined(Lynx) && defined(__powerpc__)
-extern unsigned char *ioBase;
-
-static volatile void
-eieio()
-{
- __asm__ __volatile__ ("eieio");
-}
-
-static void
-outb(port, value)
-short port;
-unsigned char value;
-{
- *(uchar *)(ioBase + port) = value; eieio();
-}
-
-static void
-outw(port, value)
-short port;
-unsigned short value;
-{
- *(unsigned short *)(ioBase + port) = value; eieio();
-}
-
-static void
-outl(port, value)
-short port;
-unsigned long value;
-{
- *(unsigned long *)(ioBase + port) = value; eieio();
-}
-
-static unsigned char
-inb(port)
-short port;
-{
- unsigned char val;
-
- val = *((unsigned char *)(ioBase + port)); eieio();
- return(val);
-}
-
-static unsigned short
-inw(port)
-short port;
-{
- unsigned short val;
-
- val = *((unsigned short *)(ioBase + port)); eieio();
- return(val);
-}
-
-static unsigned long
-inl(port)
-short port;
-{
- unsigned long val;
-
- val = *((unsigned long *)(ioBase + port)); eieio();
- return(val);
-}
-
-#else
-#if defined(__FreeBSD__) && defined(__alpha__)
-
-#include <sys/types.h>
-
-extern void outb(u_int32_t port, u_int8_t val);
-extern void outw(u_int32_t port, u_int16_t val);
-extern void outl(u_int32_t port, u_int32_t val);
-extern u_int8_t inb(u_int32_t port);
-extern u_int16_t inw(u_int32_t port);
-extern u_int32_t inl(u_int32_t port);
-
-#else
-#ifdef GCCUSESGAS
-static __inline__ void
-outb(port, val)
-short port;
-char val;
-{
- __asm__ __volatile__("outb %0,%1" : :"a" (val), "d" (port));
-}
-
-static __inline__ void
-outw(port, val)
-short port;
-short val;
-{
- __asm__ __volatile__("outw %0,%1" : :"a" (val), "d" (port));
-}
-
-static __inline__ void
-outl(port, val)
-short port;
-unsigned int val;
-{
- __asm__ __volatile__("outl %0,%1" : :"a" (val), "d" (port));
-}
-
-static __inline__ unsigned int
-inb(port)
-short port;
-{
- unsigned char ret;
- __asm__ __volatile__("inb %1,%0" :
- "=a" (ret) :
- "d" (port));
- return ret;
-}
-
-static __inline__ unsigned int
-inw(port)
-short port;
-{
- unsigned short ret;
- __asm__ __volatile__("inw %1,%0" :
- "=a" (ret) :
- "d" (port));
- return ret;
-}
-
-static __inline__ unsigned int
-inl(port)
-short port;
-{
- unsigned int ret;
- __asm__ __volatile__("inl %1,%0" :
- "=a" (ret) :
- "d" (port));
- return ret;
-}
-
-#else /* GCCUSESGAS */
-
-static __inline__ void
-outb(port, val)
- short port;
- char val;
-{
- __asm__ __volatile__("out%B0 (%1)" : :"a" (val), "d" (port));
-}
-
-static __inline__ void
-outw(port, val)
- short port;
- short val;
-{
- __asm__ __volatile__("out%W0 (%1)" : :"a" (val), "d" (port));
-}
-
-static __inline__ void
-outl(port, val)
- short port;
- unsigned int val;
-{
- __asm__ __volatile__("out%L0 (%1)" : :"a" (val), "d" (port));
-}
-
-static __inline__ unsigned int
-inb(port)
- short port;
-{
- unsigned int ret;
- __asm__ __volatile__("in%B0 (%1)" :
- "=a" (ret) :
- "d" (port));
- return ret;
-}
-
-static __inline__ unsigned int
-inw(port)
- short port;
-{
- unsigned int ret;
- __asm__ __volatile__("in%W0 (%1)" :
- "=a" (ret) :
- "d" (port));
- return ret;
-}
-
-static __inline__ unsigned int
-inl(port)
- short port;
-{
- unsigned int ret;
- __asm__ __volatile__("in%L0 (%1)" :
- "=a" (ret) :
- "d" (port));
- return ret;
-}
-
-#endif /* GCCUSESGAS */
-#endif /* Lynx && __powerpc__ */
-#endif /* arm32 */
-#endif /* linux && __sparc__ */
-#endif /* linux && __alpha__ */
-#endif /* __FreeBSD__ && __alpha__ */
-
-#if defined(linux) || defined(__arm32__) || (defined(Lynx) && defined(__powerpc__))
-
-#define intr_disable()
-#define intr_enable()
-
-#else
-
-static __inline__ void
-intr_disable()
-{
- __asm__ __volatile__("cli");
-}
-
-static __inline__ void
-intr_enable()
-{
- __asm__ __volatile__("sti");
-}
-
-#endif /* else !linux && !__arm32__ */
-
#else /* __GNUC__ */
#if defined(_MINIX) && defined(_ACK)
diff --git a/libdha/libdha.c b/libdha/libdha.c
index 923ed766d4..ddd27aca5e 100644
--- a/libdha/libdha.c
+++ b/libdha/libdha.c
@@ -26,87 +26,38 @@
#include <sys/types.h>
#include <unistd.h>
-#ifdef _WIN32
-// MAPDEV.h - include file for VxD MAPDEV
-// Copyright (c) 1996 Vireo Software, Inc.
-
-#include <windows.h>
-
-// This is the request structure that applications use
-// to request services from the MAPDEV VxD.
-
-typedef struct _MapDevRequest
-{
- DWORD mdr_ServiceID; // supplied by caller
- LPVOID mdr_PhysicalAddress; // supplied by caller
- DWORD mdr_SizeInBytes; // supplied by caller
- LPVOID mdr_LinearAddress; // returned by VxD
- WORD mdr_Selector; // returned if 16-bit caller
- WORD mdr_Status; // MDR_xxxx code below
-} MAPDEVREQUEST, *PMAPDEVREQUEST;
-
-#define MDR_SERVICE_MAP CTL_CODE(FILE_DEVICE_UNKNOWN, 1, METHOD_NEITHER, FILE_ANY_ACCESS)
-#define MDR_SERVICE_UNMAP CTL_CODE(FILE_DEVICE_UNKNOWN, 2, METHOD_NEITHER, FILE_ANY_ACCESS)
-
-#define MDR_STATUS_SUCCESS 1
-#define MDR_STATUS_ERROR 0
-/*#include "winioctl.h"*/
-#define FILE_DEVICE_UNKNOWN 0x00000022
-#define METHOD_NEITHER 3
-#define FILE_ANY_ACCESS 0
-#define CTL_CODE( DeviceType, Function, Method, Access ) ( \
- ((DeviceType)<<16) | ((Access)<<14) | ((Function)<<2) | (Method) )
-
-/* Memory Map a piece of Real Memory */
-void *map_phys_mem(unsigned base, unsigned size) {
-
- HANDLE hDevice ;
- PVOID inBuf[1] ; /* buffer for struct pointer to VxD */
- DWORD RetInfo[2] ; /* buffer to receive data from VxD */
- DWORD cbBytesReturned ; /* count of bytes returned from VxD */
- MAPDEVREQUEST req ; /* map device request structure */
- DWORD *pNicstar, Status, Time ; int i ; char *endptr ;
- const PCHAR VxDName = "\\\\.\\MAPDEV.VXD" ;
- const PCHAR VxDNameAlreadyLoaded = "\\\\.\\MAPDEV" ;
-
- hDevice = CreateFile(VxDName, 0,0,0,
- CREATE_NEW, FILE_FLAG_DELETE_ON_CLOSE, 0) ;
- if (hDevice == INVALID_HANDLE_VALUE)
- hDevice = CreateFile(VxDNameAlreadyLoaded, 0,0,0,
- CREATE_NEW, FILE_FLAG_DELETE_ON_CLOSE, 0) ;
- if (hDevice == INVALID_HANDLE_VALUE) {
- fprintf(stderr, "Cannot open driver, error=%08lx\n", GetLastError()) ;
- exit(1) ; }
-
- req.mdr_ServiceID = MDR_SERVICE_MAP ;
- req.mdr_PhysicalAddress = (PVOID)base ;
- req.mdr_SizeInBytes = size ;
- inBuf[0] = &req ;
-
- if ( ! DeviceIoControl(hDevice, MDR_SERVICE_MAP, inBuf, sizeof(PVOID),
- NULL, 0, &cbBytesReturned, NULL) ) {
- fprintf(stderr, "Failed to map device\n") ; exit(1) ; }
-
- return (void*)req.mdr_LinearAddress ;
-}
-
-void unmap_phys_mem(void *ptr, unsigned size) { }
-
+#if defined(_WIN32)
+#include "sysdep/libdha_win32.c"
+#elif defined (__EMX__)
+#include "sysdep/libdha_os2.c"
#else
+
+#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
+# endif /* SVR4 */
+
+/* Generic version */
#include <sys/mman.h>
+#ifndef DEV_MEM
+#define DEV_MEM "/dev/mem"
+#endif
+
static int mem=-1;
void *map_phys_mem(unsigned base, unsigned size)
{
- void *ptr;
- if ( (mem = open("/dev/mem",O_RDWR)) == -1) {
+ if ( (mem = open(DEV_MEM,O_RDWR)) == -1) {
perror("libdha: open(/dev/mem) failed") ; exit(1) ;
}
- ptr=mmap(0,size,PROT_READ|PROT_WRITE,MAP_SHARED,mem,base) ;
- if ((int)ptr == -1) {
- perror("libdha: mmap() failed") ; exit(1) ;
- }
- return ptr;
+ return mmap(0,size,PROT_READ|PROT_WRITE,MAP_SHARED,mem,base) ;
}
void unmap_phys_mem(void *ptr, unsigned size)
diff --git a/libdha/pci.c b/libdha/pci.c
index 2daa48c36a..74efb96611 100644
--- a/libdha/pci.c
+++ b/libdha/pci.c
@@ -2,26 +2,6 @@
(C) 2002 - library implementation by Nick Kyrshev
XFree86 3.3.3 scanpci.c, modified for GATOS/win/gfxdump by Øyvind Aabling.
*/
-
-#include "libdha.h"
-
-#include <errno.h>
-#include <string.h>
-#include "AsmMacros.h"
-#ifdef __unix__
-#include <unistd.h>
-#include <sys/mman.h>
-#elif defined ( _WIN32 )
-#include <windows.h>
-#else
-#include <dos.h>
-#endif
-
-#define outb pcioutb
-#define outl pcioutl
-#define inb pciinb
-#define inl pciinl
-
/* $XConsortium: scanpci.c /main/25 1996/10/27 11:48:40 kaleb $ */
/*
* name: scanpci.c
@@ -71,34 +51,47 @@
*
*/
-#if defined(__SVR4)
-#if !defined(SVR4)
-#define SVR4
-#endif
-#endif
-
-#ifdef __EMX__
-#define INCL_DOSFILEMGR
-#include <os2.h>
-#endif
-
+#include "libdha.h"
+#include <errno.h>
+#include <string.h>
#include <stdio.h>
-#include <sys/types.h>
-#if defined(SVR4)
-#if defined(sun)
-#ifndef __EXTENSIONS__
-#define __EXTENSIONS__
+#ifdef __unix__
+#include <unistd.h>
#endif
+#include "AsmMacros.h"
+/* OS depended stuff */
+#if defined (linux)
+#include "sysdep/pci_linux.c"
+#elif defined (__FreeBSD__)
+#include "sysdep/pci_freebsd.c"
+#elif defined (__386BSD__)
+#include "sysdep/pci_386bsd.c"
+#elif defined (__NetBSD__)
+#include "sysdep/pci_netbsd.c"
+#elif defined (__OpenBSD__)
+#include "sysdep/pci_openbsd.c"
+#elif defined (__bsdi__)
+#include "sysdep/pci_bsdi.c"
+#elif defined (Lynx)
+#include "sysdep/pci_lynx.c"
+#elif defined (MACH386)
+#include "sysdep/pci_mach386.c"
+#elif defined (__SVR4)
+#if !defined(SVR4)
+#define SVR4
#endif
-#include <sys/proc.h>
-#include <sys/tss.h>
-#if defined(NCR)
-#define __STDC
-#include <sys/sysi86.h>
-#undef __STDC
-#else
-#include <sys/sysi86.h>
+#include "sysdep/pci_svr4.c"
+#elif defined (SCO)
+#include "sysdep/pci_sco.c"
+#elif defined (ISC)
+#include "sysdep/pci_isc.c"
+#elif defined (__EMX__)
+#include "sysdep/pci_os2.c"
+#elif defined (_WIN32)
+#include "sysdep/pci_win32.c"
#endif
+
+#if 0
#if defined(__SUNPRO_C) || defined(sun) || defined(__sun)
#include <sys/psw.h>
#else
@@ -106,186 +99,7 @@
#endif
#include <sys/v86.h>
#endif
-#if defined(__FreeBSD__) || defined(__386BSD__)
-#include <sys/file.h>
-#include <machine/console.h>
-#ifndef GCCUSESGAS
-#define GCCUSESGAS
-#endif
-#endif
-#if defined(__NetBSD__)
-#include <sys/param.h>
-#include <sys/file.h>
-#include <machine/sysarch.h>
-#ifndef GCCUSESGAS
-#define GCCUSESGAS
-#endif
-#endif
-#if defined(__bsdi__)
-#include <sys/file.h>
-#include <sys/ioctl.h>
-#include <i386/isa/pcconsioctl.h>
-#ifndef GCCUSESGAS
-#define GCCUSESGAS
-#endif
-#endif
-#if defined(SCO) || defined(ISC)
-#ifndef ISC
-#include <sys/console.h>
-#endif
-#include <sys/param.h>
-#include <sys/immu.h>
-#include <sys/region.h>
-#include <sys/proc.h>
-#include <sys/tss.h>
-#include <sys/sysi86.h>
-#include <sys/v86.h>
-#endif
-#if defined(Lynx_22)
-#ifndef GCCUSESGAS
-#define GCCUSESGAS
-#endif
-#endif
-
-
-#if defined(__WATCOMC__)
-
-#include <stdlib.h>
-static void outl(unsigned port, unsigned data);
-#pragma aux outl = "out dx, eax" parm [dx] [eax];
-static void outb(unsigned port, unsigned data);
-#pragma aux outb = "out dx, al" parm [dx] [eax];
-static unsigned inl(unsigned port);
-#pragma aux inl = "in eax, dx" parm [dx];
-static unsigned inb(unsigned port);
-#pragma aux inb = "xor eax,eax" "in al, dx" parm [dx];
-#else /* __WATCOMC__ */
-
-#if defined(__GNUC__)
-
-#if !defined(__alpha__) && !defined(__powerpc__)
-#if defined(GCCUSESGAS)
-#define OUTB_GCC "outb %0,%1"
-#define OUTL_GCC "outl %0,%1"
-#define INB_GCC "inb %1,%0"
-#define INL_GCC "inl %1,%0"
-#else
-#define OUTB_GCC "out%B0 (%1)"
-#define OUTL_GCC "out%L0 (%1)"
-#define INB_GCC "in%B0 (%1)"
-#define INL_GCC "in%L0 (%1)"
-#endif /* GCCUSESGAS */
-
-static void outb(unsigned short port, unsigned char val) {
- __asm__ __volatile__(OUTB_GCC : :"a" (val), "d" (port)); }
-static void outl(unsigned short port, unsigned long val) {
- __asm__ __volatile__(OUTL_GCC : :"a" (val), "d" (port)); }
-static unsigned char inb(unsigned short port) { unsigned char ret;
- __asm__ __volatile__(INB_GCC : "=a" (ret) : "d" (port)); return ret; }
-static unsigned long inl(unsigned short port) { unsigned long ret;
- __asm__ __volatile__(INL_GCC : "=a" (ret) : "d" (port)); return ret; }
-
-#endif /* !defined(__alpha__) && !defined(__powerpc__) */
-#else /* __GNUC__ */
-
-#if defined(__STDC__) && (__STDC__ == 1)
-# if !defined(NCR)
-# define asm __asm
-# endif
-#endif
-
-#if defined(__SUNPRO_C)
-/*
- * This section is a gross hack in if you tell anyone that I wrote it,
- * I'll deny it. :-)
- * The leave/ret instructions are the big hack to leave %eax alone on return.
- */
-static unsigned char inb(int port) {
- asm(" movl 8(%esp),%edx");
- asm(" subl %eax,%eax");
- asm(" inb (%dx)");
- asm(" leave");
- asm(" ret");
- }
-
-static unsigned short inw(int port) {
- asm(" movl 8(%esp),%edx");
- asm(" subl %eax,%eax");
- asm(" inw (%dx)");
- asm(" leave");
- asm(" ret");
- }
-
-static unsigned long inl(int port) {
- asm(" movl 8(%esp),%edx");
- asm(" inl (%dx)");
- asm(" leave");
- asm(" ret");
- }
-
-static void outb(int port, unsigned char value) {
- asm(" movl 8(%esp),%edx");
- asm(" movl 12(%esp),%eax");
- asm(" outb (%dx)");
- }
-
-static void outw(int port, unsigned short value) {
- asm(" movl 8(%esp),%edx");
- asm(" movl 12(%esp),%eax");
- asm(" outw (%dx)");
- }
-
-static void outl(int port, unsigned long value) {
- asm(" movl 8(%esp),%edx");
- asm(" movl 12(%esp),%eax");
- asm(" outl (%dx)");
- }
-#else
-
-#if defined(SVR4)
-# if !defined(__USLC__)
-# define __USLC__
-# endif
-#endif
-
-#ifdef __unix__
-#ifndef SCO325
-# include <sys/inline.h>
-#else
-# include "scoasm.h"
-#endif
-#endif
-
-#endif /* SUNPRO_C */
-
-#endif /* __GNUC__ */
-#endif /* __WATCOMC__ */
-
-#undef outb
-#undef outl
-#undef inb
-#undef inl
-
-#if defined(__GLIBC__) && __GLIBC__ >= 2
-#if defined(linux)
-#ifdef __i386__
-#include <sys/perm.h>
-#else
-#include <sys/io.h>
-#endif
-#endif
-#endif
-
-#if defined(__alpha__)
-#if defined(linux)
-#include <asm/unistd.h>
-#define BUS(tag) (((tag)>>16)&0xff)
-#define DFN(tag) (((tag)>>8)&0xff)
-#else
-Generate compiler error - scanpci unsupported on non-linux alpha platforms
-#endif /* linux */
-#endif /* __alpha__ */
#if defined(Lynx) && defined(__powerpc__)
/* let's mimick the Linux Alpha stuff for LynxOS so we don't have
* to change too much code
@@ -635,7 +449,6 @@ struct pci_config_reg {
#define MAX_PCI_DEVICES 64
#define NF ((void (*)())NULL), { 0.0, 0, 0, NULL }
#define PCI_MULTIFUNC_DEV 0x80
-#if defined(__alpha__) || defined(__powerpc__)
#define PCI_ID_REG 0x00
#define PCI_CMD_STAT_REG 0x04
#define PCI_CLASS_REG 0x08
@@ -644,7 +457,6 @@ struct pci_config_reg {
#define PCI_MAP_ROM_REG 0x30
#define PCI_INTERRUPT_REG 0x3C
#define PCI_REG_USERCONFIG 0x40
-#endif
static int pcibus=-1, pcicard=-1, pcifunc=-1 ;
/*static struct pci_device *pcidev=NULL ;*/
@@ -664,6 +476,22 @@ static int pcibus=-1, pcicard=-1, pcifunc=-1 ;
#else
#define PCI_MODE2_FORWARD_REG 0xCFA
#endif
+
+/* cpu depended stuff */
+#if defined(__alpha__)
+#include "sysdep/pci_alpha.c"
+#elif defined(__ia64__)
+#include "sysdep/pci_ia64.c"
+#elif defined(__sparc__)
+#include "sysdep/pci_sparc.c"
+#elif defined( __arm32__ )
+#include "sysdep/pci_arm32.c"
+#elif defined(__powerpc__)
+#include "sysdep/pci_powerpc.c"
+#else
+#include "sysdep/pci_x86.c"
+#endif
+
static int pcicards=0 ;
static pciinfo_t *pci_lst;
@@ -693,168 +521,9 @@ static void identify_card(struct pci_config_reg *pcr)
pcicards++;
}
-static int io_fd;
-#ifdef __EMX__
-static USHORT callgate[3] = {0,0,0};
-#endif
-
-static void enable_os_io(void)
-{
- io_fd = -1 ;
-#if defined(SVR4) || defined(SCO) || defined(ISC)
-#if defined(SI86IOPL)
- sysi86(SI86IOPL, 3);
-#else
- sysi86(SI86V86, V86SC_IOPL, PS_IOPL);
-#endif
-#endif
-#if defined(linux)
- iopl(3);
-#endif
-#if defined(__FreeBSD__) || defined(__386BSD__) || defined(__bsdi__)
- if ((io_fd = open("/dev/console", O_RDWR, 0)) < 0) {
- perror("/dev/console");
- exit(1);
- }
-#if defined(__FreeBSD__) || defined(__386BSD__)
- if (ioctl(io_fd, KDENABIO, 0) < 0) {
- perror("ioctl(KDENABIO)");
- exit(1);
- }
-#endif
-#if defined(__bsdi__)
- if (ioctl(io_fd, PCCONENABIOPL, 0) < 0) {
- perror("ioctl(PCCONENABIOPL)");
- exit(1);
- }
-#endif
-#endif
-#if defined(__NetBSD__)
-#if !defined(USE_I386_IOPL)
- if ((io_fd = open("/dev/io", O_RDWR, 0)) < 0) {
- perror("/dev/io");
- exit(1);
- }
-#else
- if (i386_iopl(1) < 0) {
- perror("i386_iopl");
- exit(1);
- }
-#endif /* USE_I386_IOPL */
-#endif /* __NetBSD__ */
-#if defined(__OpenBSD__)
- if (i386_iopl(1) < 0) {
- perror("i386_iopl");
- exit(1);
- }
-#endif /* __OpenBSD__ */
-#if defined(MACH386)
- if ((io_fd = open("/dev/iopl", O_RDWR, 0)) < 0) {
- perror("/dev/iopl");
- exit(1);
- }
-#endif
-#ifdef __EMX__
- {
- HFILE hfd;
- ULONG dlen,action;
- APIRET rc;
- static char *ioDrvPath = "/dev/fastio$";
-
- if (DosOpen((PSZ)ioDrvPath, (PHFILE)&hfd, (PULONG)&action,
- (ULONG)0, FILE_SYSTEM, FILE_OPEN,
- OPEN_SHARE_DENYNONE|OPEN_FLAGS_NOINHERIT|OPEN_ACCESS_READONLY,
- (ULONG)0) != 0) {
- fprintf(stderr,"Error opening fastio$ driver...\n");
- fprintf(stderr,"Please install xf86sup.sys in config.sys!\n");
- exit(42);
- }
- callgate[0] = callgate[1] = 0;
-
-/* Get callgate from driver for fast io to ports and other stuff */
-
- rc = DosDevIOCtl(hfd, (ULONG)0x76, (ULONG)0x64,
- NULL, 0, NULL,
- (ULONG*)&callgate[2], sizeof(USHORT), &dlen);
- if (rc) {
- fprintf(stderr,"xf86-OS/2: EnableIOPorts failed, rc=%d, dlen=%d; emergency exit\n",
- rc,dlen);
- DosClose(hfd);
- exit(42);
- }
-
-/* Calling callgate with function 13 sets IOPL for the program */
-
- asm volatile ("movl $13,%%ebx;.byte 0xff,0x1d;.long _callgate"
- : /*no outputs */
- : /*no inputs */
- : "eax","ebx","ecx","edx","cc");
-
- DosClose(hfd);
- }
-#endif
-#if defined(Lynx) && defined(__powerpc__)
- pciConfBase = (unsigned char *) smem_create("PCI-CONF",
- (char *)0x80800000, 64*1024, SM_READ|SM_WRITE);
- if (pciConfBase == (void *) -1)
- exit(1);
-#endif
-}
-
-
-static void disable_os_io(void)
-{
-#if defined(SVR4) || defined(SCO) || defined(ISC)
-#if defined(SI86IOPL)
- sysi86(SI86IOPL, 0);
-#else
- sysi86(SI86V86, V86SC_IOPL, 0);
-#endif
-#endif
-#if defined(linux)
- iopl(0);
-#endif
-#if defined(__FreeBSD__) || defined(__386BSD__)
- if (ioctl(io_fd, KDDISABIO, 0) < 0) {
- perror("ioctl(KDDISABIO)");
- close(io_fd);
- exit(1);
- }
- close(io_fd);
-#endif
-#if defined(__NetBSD__)
-#if !defined(USE_I386_IOPL)
- close(io_fd);
-#else
- if (i386_iopl(0) < 0) {
- perror("i386_iopl");
- exit(1);
- }
-#endif /* NetBSD1_1 */
-#endif /* __NetBSD__ */
-#if defined(__bsdi__)
- if (ioctl(io_fd, PCCONDISABIOPL, 0) < 0) {
- perror("ioctl(PCCONDISABIOPL)");
- close(io_fd);
- exit(1);
- }
- close(io_fd);
-#endif
-#if defined(MACH386)
- close(io_fd);
-#endif
-#if defined(Lynx) && defined(__powerpc__)
- smem_create(NULL, (char *) pciConfBase, 0, SM_DETACH);
- smem_remove("PCI-CONF");
- pciConfBase = NULL;
-#endif
-}
-
/*main(int argc, char *argv[])*/
int pci_scan(pciinfo_t *pci_list,unsigned *num_pci)
{
- unsigned long tmplong1, tmplong2, config_cmd;
- unsigned char tmp1, tmp2;
unsigned int idx;
struct pci_config_reg pcr;
int do_mode1_scan = 0, do_mode2_scan = 0;
@@ -863,35 +532,8 @@ int pci_scan(pciinfo_t *pci_list,unsigned *num_pci)
pci_lst = pci_list;
enable_os_io();
-
-#if !defined(__alpha__) && !defined(__powerpc__)
- pcr._configtype = 0;
-
- outb(PCI_MODE2_ENABLE_REG, 0x00);
- outb(PCI_MODE2_FORWARD_REG, 0x00);
- tmp1 = inb(PCI_MODE2_ENABLE_REG);
- tmp2 = inb(PCI_MODE2_FORWARD_REG);
- if ((tmp1 == 0x00) && (tmp2 == 0x00)) {
- pcr._configtype = 2;
- /*printf("PCI says configuration type 2\n");*/
- } else {
- tmplong1 = inl(PCI_MODE1_ADDRESS_REG);
- outl(PCI_MODE1_ADDRESS_REG, PCI_EN);
- tmplong2 = inl(PCI_MODE1_ADDRESS_REG);
- outl(PCI_MODE1_ADDRESS_REG, tmplong1);
- if (tmplong2 == PCI_EN) {
- pcr._configtype = 1;
- /*printf("PCI says configuration type 1\n");*/
- } else {
- /*printf("No PCI !\n");*/
- disable_os_io();
- /*exit(1);*/
- return ENODEV ;
- }
- }
-#else
- pcr._configtype = 1;
-#endif
+
+ if((pcr._configtype = pci_config_type()) == 0xFFFF) return ENODEV;
/* Try pci config 1 probe first */
@@ -912,78 +554,42 @@ int pci_scan(pciinfo_t *pci_list,unsigned *num_pci)
pcr._cardnum += 0x1) {
func = 0;
do { /* loop over the different functions, if present */
-#if !defined(__alpha__) && !defined(__powerpc__)
- config_cmd = PCI_EN | (pcr._pcibuses[pcr._pcibusidx]<<16) |
- (pcr._cardnum<<11) | (func<<8);
-
- outl(PCI_MODE1_ADDRESS_REG, config_cmd); /* ioreg 0 */
- pcr._device_vendor = inl(PCI_MODE1_DATA_REG);
-#else
- pciconfig_read(pcr._pcibuses[pcr._pcibusidx], pcr._cardnum<<3,
- PCI_ID_REG, 4, &pcr._device_vendor);
-#endif
-
+ pcr._device_vendor = pci_get_vendor(pcr._pcibuses[pcr._pcibusidx], pcr._cardnum,
+ func);
if ((pcr._vendor == 0xFFFF) || (pcr._device == 0xFFFF))
break; /* nothing there */
/*printf("\npci bus 0x%x cardnum 0x%02x function 0x%04x: vendor 0x%04x device 0x%04x\n",
pcr._pcibuses[pcr._pcibusidx], pcr._cardnum, func,
pcr._vendor, pcr._device);*/
- pcibus = pcr._pcibuses[pcr._pcibusidx] ;
- pcicard = pcr._cardnum ; pcifunc = func ;
-
-#if !defined(__alpha__) && !defined(__powerpc__)
- outl(PCI_MODE1_ADDRESS_REG, config_cmd | 0x04);
- pcr._status_command = inl(PCI_MODE1_DATA_REG);
- outl(PCI_MODE1_ADDRESS_REG, config_cmd | 0x08);
- pcr._class_revision = inl(PCI_MODE1_DATA_REG);
- outl(PCI_MODE1_ADDRESS_REG, config_cmd | 0x0C);
- pcr._bist_header_latency_cache = inl(PCI_MODE1_DATA_REG);
- outl(PCI_MODE1_ADDRESS_REG, config_cmd | 0x10);
- pcr._base0 = inl(PCI_MODE1_DATA_REG);
- outl(PCI_MODE1_ADDRESS_REG, config_cmd | 0x14);
- pcr._base1 = inl(PCI_MODE1_DATA_REG);
- outl(PCI_MODE1_ADDRESS_REG, config_cmd | 0x18);
- pcr._base2 = inl(PCI_MODE1_DATA_REG);
- outl(PCI_MODE1_ADDRESS_REG, config_cmd | 0x1C);
- pcr._base3 = inl(PCI_MODE1_DATA_REG);
- outl(PCI_MODE1_ADDRESS_REG, config_cmd | 0x20);
- pcr._base4 = inl(PCI_MODE1_DATA_REG);
- outl(PCI_MODE1_ADDRESS_REG, config_cmd | 0x24);
- pcr._base5 = inl(PCI_MODE1_DATA_REG);
- outl(PCI_MODE1_ADDRESS_REG, config_cmd | 0x30);
- pcr._baserom = inl(PCI_MODE1_DATA_REG);
- outl(PCI_MODE1_ADDRESS_REG, config_cmd | 0x3C);
- pcr._max_min_ipin_iline = inl(PCI_MODE1_DATA_REG);
- outl(PCI_MODE1_ADDRESS_REG, config_cmd | 0x40);
- pcr._user_config = inl(PCI_MODE1_DATA_REG);
-#else
- pciconfig_read(pcr._pcibuses[pcr._pcibusidx], pcr._cardnum<<3,
- PCI_CMD_STAT_REG, 4, &pcr._status_command);
- pciconfig_read(pcr._pcibuses[pcr._pcibusidx], pcr._cardnum<<3,
- PCI_CLASS_REG, 4, &pcr._class_revision);
- pciconfig_read(pcr._pcibuses[pcr._pcibusidx], pcr._cardnum<<3,
- PCI_HEADER_MISC, 4, &pcr._bist_header_latency_cache);
- pciconfig_read(pcr._pcibuses[pcr._pcibusidx], pcr._cardnum<<3,
- PCI_MAP_REG_START, 4, &pcr._base0);
- pciconfig_read(pcr._pcibuses[pcr._pcibusidx], pcr._cardnum<<3,
- PCI_MAP_REG_START + 0x04, 4, &pcr._base1);
- pciconfig_read(pcr._pcibuses[pcr._pcibusidx], pcr._cardnum<<3,
- PCI_MAP_REG_START + 0x08, 4, &pcr._base2);
- pciconfig_read(pcr._pcibuses[pcr._pcibusidx], pcr._cardnum<<3,
- PCI_MAP_REG_START + 0x0C, 4, &pcr._base3);
- pciconfig_read(pcr._pcibuses[pcr._pcibusidx], pcr._cardnum<<3,
- PCI_MAP_REG_START + 0x10, 4, &pcr._base4);
- pciconfig_read(pcr._pcibuses[pcr._pcibusidx], pcr._cardnum<<3,
- PCI_MAP_REG_START + 0x14, 4, &pcr._base5);
- pciconfig_read(pcr._pcibuses[pcr._pcibusidx], pcr._cardnum<<3,
- PCI_MAP_ROM_REG, 4, &pcr._baserom);
- pciconfig_read(pcr._pcibuses[pcr._pcibusidx], pcr._cardnum<<3,
- PCI_INTERRUPT_REG, 4, &pcr._max_min_ipin_iline);
- pciconfig_read(pcr._pcibuses[pcr._pcibusidx], pcr._cardnum<<3,
- PCI_REG_USERCONFIG, 4, &pcr._user_config);
-#endif
-
+ pcibus = pcr._pcibuses[pcr._pcibusidx];
+ pcicard = pcr._cardnum;
+ pcifunc = func;
+
+ pcr._status_command = pci_config_read_long(pcr._pcibuses[pcr._pcibusidx],
+ pcr._cardnum,func,PCI_CMD_STAT_REG);
+ pcr._class_revision = pci_config_read_long(pcr._pcibuses[pcr._pcibusidx],
+ pcr._cardnum,func,PCI_CLASS_REG);
+ pcr._bist_header_latency_cache = pci_config_read_long(pcr._pcibuses[pcr._pcibusidx],
+ pcr._cardnum,func,PCI_HEADER_MISC);
+ pcr._base0 = pci_config_read_long(pcr._pcibuses[pcr._pcibusidx],
+ pcr._cardnum,func,PCI_MAP_REG_START);
+ pcr._base1 = pci_config_read_long(pcr._pcibuses[pcr._pcibusidx],
+ pcr._cardnum,func,PCI_MAP_REG_START+4);
+ pcr._base2 = pci_config_read_long(pcr._pcibuses[pcr._pcibusidx],
+ pcr._cardnum,func,PCI_MAP_REG_START+8);
+ pcr._base3 = pci_config_read_long(pcr._pcibuses[pcr._pcibusidx],
+ pcr._cardnum,func,PCI_MAP_REG_START+0x0C);
+ pcr._base4 = pci_config_read_long(pcr._pcibuses[pcr._pcibusidx],
+ pcr._cardnum,func,PCI_MAP_REG_START+0x10);
+ pcr._base5 = pci_config_read_long(pcr._pcibuses[pcr._pcibusidx],
+ pcr._cardnum,func,PCI_MAP_REG_START+0x14);
+ pcr._baserom = pci_config_read_long(pcr._pcibuses[pcr._pcibusidx],
+ pcr._cardnum,func,PCI_MAP_ROM_REG);
+ pcr._max_min_ipin_iline = pci_config_read_long(pcr._pcibuses[pcr._pcibusidx],
+ pcr._cardnum,func,PCI_INTERRUPT_REG);
+ pcr._user_config = pci_config_read_long(pcr._pcibuses[pcr._pcibusidx],
+ pcr._cardnum,func,PCI_REG_USERCONFIG);
/* check for pci-pci bridges */
#define PCI_CLASS_MASK 0xff000000
#define PCI_SUBCLASS_MASK 0x00ff0000
@@ -1089,74 +695,3 @@ int pci_scan(pciinfo_t *pci_list,unsigned *num_pci)
return 0 ;
}
-
-#if 0
-void
-print_i128(struct pci_config_reg *pcr)
-{
- /*
- if (pcr->_status_command)
- printf(" STATUS 0x%04x COMMAND 0x%04x\n",
- pcr->_status, pcr->_command);
- if (pcr->_class_revision)
- printf(" CLASS 0x%02x 0x%02x 0x%02x REVISION 0x%02x\n",
- pcr->_base_class, pcr->_sub_class, pcr->_prog_if, pcr->_rev_id);
- if (pcr->_bist_header_latency_cache)
- printf(" BIST 0x%02x HEADER 0x%02x LATENCY 0x%02x CACHE 0x%02x\n",
- pcr->_bist, pcr->_header_type, pcr->_latency_timer,
- pcr->_cache_line_size);
- printf(" MW0_AD 0x%08x addr 0x%08x %spre-fetchable\n",
- pcr->_base0, pcr->_base0 & 0xFFC00000,
- pcr->_base0 & 0x8 ? "" : "not-");
- printf(" MW1_AD 0x%08x addr 0x%08x %spre-fetchable\n",
- pcr->_base1, pcr->_base1 & 0xFFC00000,
- pcr->_base1 & 0x8 ? "" : "not-");
- printf(" XYW_AD(A) 0x%08x addr 0x%08x\n",
- pcr->_base2, pcr->_base2 & 0xFFC00000);
- printf(" XYW_AD(B) 0x%08x addr 0x%08x\n",
- pcr->_base3, pcr->_base3 & 0xFFC00000);
- printf(" RBASE_G 0x%08x addr 0x%08x\n",
- pcr->_base4, pcr->_base4 & 0xFFFF0000);
- printf(" IO 0x%08x addr 0x%08x\n",
- pcr->_base5, pcr->_base5 & 0xFFFFFF00);
- printf(" RBASE_E 0x%08x addr 0x%08x %sdecode-enabled\n",
- pcr->_baserom, pcr->_baserom & 0xFFFF8000,
- pcr->_baserom & 0x1 ? "" : "not-");
- if (pcr->_max_min_ipin_iline)
- printf(" MAX_LAT 0x%02x MIN_GNT 0x%02x INT_PIN 0x%02x INT_LINE 0x%02x\n",
- pcr->_max_lat, pcr->_min_gnt, pcr->_int_pin, pcr->_int_line);
- */
-}
-
-void
-print_pcibridge(struct pci_config_reg *pcr)
-{
- /*
- if (pcr->_status_command)
- printf(" STATUS 0x%04x COMMAND 0x%04x\n",
- pcr->_status, pcr->_command);
- if (pcr->_class_revision)
- printf(" CLASS 0x%02x 0x%02x 0x%02x REVISION 0x%02x\n",
- pcr->_base_class, pcr->_sub_class, pcr->_prog_if, pcr->_rev_id);
- if (pcr->_bist_header_latency_cache)
- printf(" BIST 0x%02x HEADER 0x%02x LATENCY 0x%02x CACHE 0x%02x\n",
- pcr->_bist, pcr->_header_type, pcr->_latency_timer,
- pcr->_cache_line_size);
- printf(" PRIBUS 0x%02x SECBUS 0x%02x SUBBUS 0x%02x SECLT 0x%02x\n",
- pcr->_primary_bus_number, pcr->_secondary_bus_number,
- pcr->_subordinate_bus_number, pcr->_secondary_latency_timer);
- printf(" IOBASE: 0x%02x00 IOLIM 0x%02x00 SECSTATUS 0x%04x\n",
- pcr->_io_base, pcr->_io_limit, pcr->_secondary_status);
- printf(" NOPREFETCH MEMBASE: 0x%08x MEMLIM 0x%08x\n",
- pcr->_mem_base, pcr->_mem_limit);
- printf(" PREFETCH MEMBASE: 0x%08x MEMLIM 0x%08x\n",
- pcr->_prefetch_mem_base, pcr->_prefetch_mem_limit);
- printf(" RBASE_E 0x%08x addr 0x%08x %sdecode-enabled\n",
- pcr->_baserom, pcr->_baserom & 0xFFFF8000,
- pcr->_baserom & 0x1 ? "" : "not-");
- if (pcr->_max_min_ipin_iline)
- printf(" MAX_LAT 0x%02x MIN_GNT 0x%02x INT_PIN 0x%02x INT_LINE 0x%02x\n",
- pcr->_max_lat, pcr->_min_gnt, pcr->_int_pin, pcr->_int_line);
- */
-}
-#endif
diff --git a/libdha/sysdep/AsmMacros_alpha.h b/libdha/sysdep/AsmMacros_alpha.h
new file mode 100644
index 0000000000..482b59000e
--- /dev/null
+++ b/libdha/sysdep/AsmMacros_alpha.h
@@ -0,0 +1,26 @@
+/*
+ This file is based on:
+ $XFree86: xc/programs/Xserver/hw/xfree86/drivers/chips/util/AsmMacros.h,v 1.1 2001/11/16 21:13:34 tsi Exp $
+ Modified for readability by Nick Kurshev
+*/
+
+#ifndef __ASM_MACROS_ALPHA_H
+#define __ASM_MACROS_ALPHA_H
+#if defined (linux)
+#include <sys/io.h>
+#elif defined (__FreeBSD__)
+#include <sys/types.h>
+extern void outb(u_int32_t port, u_int8_t val);
+extern void outw(u_int32_t port, u_int16_t val);
+extern void outl(u_int32_t port, u_int32_t val);
+extern u_int8_t inb(u_int32_t port);
+extern u_int16_t inw(u_int32_t port);
+extern u_int32_t inl(u_int32_t port);
+#else
+#error This stuff is not ported on your system
+#endif
+
+#define intr_disable()
+#define intr_enable()
+
+#endif
diff --git a/libdha/sysdep/AsmMacros_arm32.h b/libdha/sysdep/AsmMacros_arm32.h
new file mode 100644
index 0000000000..e618d32ee0
--- /dev/null
+++ b/libdha/sysdep/AsmMacros_arm32.h
@@ -0,0 +1,50 @@
+/*
+ This file is based on:
+ $XFree86: xc/programs/Xserver/hw/xfree86/drivers/chips/util/AsmMacros.h,v 1.1 2001/11/16 21:13:34 tsi Exp $
+ Modified for readability by Nick Kurshev
+*/
+
+#ifndef __ASM_MACROS_ARM32_H
+#define __ASM_MACROS_ARM32_H
+unsigned int IOPortBase; /* Memory mapped I/O port area */
+
+static __inline__ void outb(short port,char val)
+{
+ if ((unsigned short)port >= 0x400) return;
+ *(volatile unsigned char*)(((unsigned short)(port))+IOPortBase) = val;
+}
+
+static __inline__ void outw(short port,short val)
+{
+ if ((unsigned short)port >= 0x400) return;
+ *(volatile unsigned short*)(((unsigned short)(port))+IOPortBase) = val;
+}
+
+static __inline__ void outl(short port,int val)
+{
+ if ((unsigned short)port >= 0x400) return;
+ *(volatile unsigned long*)(((unsigned short)(port))+IOPortBase) = val;
+}
+
+static __inline__ unsigned int inb(short port)
+{
+ if ((unsigned short)port >= 0x400) return((unsigned int)-1);
+ return(*(volatile unsigned char*)(((unsigned short)(port))+IOPortBase));
+}
+
+static __inline__ unsigned int inw(short port)
+{
+ if ((unsigned short)port >= 0x400) return((unsigned int)-1);
+ return(*(volatile unsigned short*)(((unsigned short)(port))+IOPortBase));
+}
+
+static __inline__ unsigned int inl(short port)
+{
+ if ((unsigned short)port >= 0x400) return((unsigned int)-1);
+ return(*(volatile unsigned long*)(((unsigned short)(port))+IOPortBase));
+}
+
+#define intr_disable()
+#define intr_enable()
+
+#endif
diff --git a/libdha/sysdep/AsmMacros_ia64.h b/libdha/sysdep/AsmMacros_ia64.h
new file mode 100644
index 0000000000..e59732fda5
--- /dev/null
+++ b/libdha/sysdep/AsmMacros_ia64.h
@@ -0,0 +1,16 @@
+/*
+ This file is based on:
+ $XFree86: xc/programs/Xserver/hw/xfree86/drivers/chips/util/AsmMacros.h,v 1.1 2001/11/16 21:13:34 tsi Exp $
+ Modified for readability by Nick Kurshev
+*/
+
+#ifndef __ASM_MACROS_IA64_H
+#define __ASM_MACROS_IA64_H
+
+#if defined(linux)
+#include <sys/io.h>
+#else
+#error This stuff is not ported on your system
+#endif
+
+#endif
diff --git a/libdha/sysdep/AsmMacros_powerpc.h b/libdha/sysdep/AsmMacros_powerpc.h
new file mode 100644
index 0000000000..b17daddbdf
--- /dev/null
+++ b/libdha/sysdep/AsmMacros_powerpc.h
@@ -0,0 +1,62 @@
+/*
+ This file is based on:
+ $XFree86: xc/programs/Xserver/hw/xfree86/drivers/chips/util/AsmMacros.h,v 1.1 2001/11/16 21:13:34 tsi Exp $
+ Modified for readability by Nick Kurshev
+*/
+
+#ifndef __ASM_MACROS_POWERPC_H
+#define __ASM_MACROS_POWERPC_H
+
+#if defined(Lynx)
+
+extern unsigned char *ioBase;
+
+static __inline__ volatile void eieio()
+{
+ __asm__ __volatile__ ("eieio");
+}
+
+static __inline__ void outb(short port, unsigned char value)
+{
+ *(uchar *)(ioBase + port) = value; eieio();
+}
+
+static __inline__ void outw(short port, unsigned short value)
+{
+ *(unsigned short *)(ioBase + port) = value; eieio();
+}
+
+static __inline__ void outl(short port, unsigned short value)
+{
+ *(unsigned long *)(ioBase + port) = value; eieio();
+}
+
+static __inline__ unsigned char inb(short port)
+{
+ unsigned char val;
+ val = *((unsigned char *)(ioBase + port)); eieio();
+ return(val);
+}
+
+static __inline__ unsigned short inw(short port)
+{
+ unsigned short val;
+ val = *((unsigned short *)(ioBase + port)); eieio();
+ return(val);
+}
+
+static __inline__ unsigned long inl(short port)
+{
+ unsigned long val;
+ val = *((unsigned long *)(ioBase + port)); eieio();
+ return(val);
+}
+
+#define intr_disable()
+#define intr_enable()
+
+#else
+#error This stuff is not ported on your system
+#endif
+
+#endif
diff --git a/libdha/sysdep/AsmMacros_sparc.h b/libdha/sysdep/AsmMacros_sparc.h
new file mode 100644
index 0000000000..f6717b4bb7
--- /dev/null
+++ b/libdha/sysdep/AsmMacros_sparc.h
@@ -0,0 +1,53 @@
+/*
+ This file is based on:
+ $XFree86: xc/programs/Xserver/hw/xfree86/drivers/chips/util/AsmMacros.h,v 1.1 2001/11/16 21:13:34 tsi Exp $
+ Modified for readability by Nick Kurshev
+*/
+
+#ifndef __ASM_MACROS_SPARC_H
+#define __ASM_MACROS_SPARC_H
+
+#ifndef ASI_PL
+#define ASI_PL 0x88
+#endif
+
+static __inline__ void outb(unsigned long port, char val)
+{
+ __asm__ __volatile__("stba %0, [%1] %2" : : "r" (val), "r" (port), "i" (ASI_PL));
+}
+
+static __inline__ void outw(unsigned long port, char val)
+{
+ __asm__ __volatile__("stha %0, [%1] %2" : : "r" (val), "r" (port), "i" (ASI_PL));
+}
+
+static __inline__ void outl(unsigned long port, char val)
+{
+ __asm__ __volatile__("sta %0, [%1] %2" : : "r" (val), "r" (port), "i" (ASI_PL));
+}
+
+static __inline__ unsigned int inb(unsigned long port)
+{
+ unsigned char ret;
+ __asm__ __volatile__("lduba [%1] %2, %0" : "=r" (ret) : "r" (port), "i" (ASI_PL));
+ return ret;
+}
+
+static __inline__ unsigned int inw(unsigned long port)
+{
+ unsigned char ret;
+ __asm__ __volatile__("lduha [%1] %2, %0" : "=r" (ret) : "r" (port), "i" (ASI_PL));
+ return ret;
+}
+
+static __inline__ unsigned int inl(unsigned long port)
+{
+ unsigned char ret;
+ __asm__ __volatile__("lda [%1] %2, %0" : "=r" (ret) : "r" (port), "i" (ASI_PL));
+ return ret;
+}
+
+#define intr_disable()
+#define intr_enable()
+
+#endif
diff --git a/libdha/sysdep/AsmMacros_x86.h b/libdha/sysdep/AsmMacros_x86.h
new file mode 100644
index 0000000000..9b9719c17a
--- /dev/null
+++ b/libdha/sysdep/AsmMacros_x86.h
@@ -0,0 +1,68 @@
+/*
+ This file is based on:
+ $XFree86: xc/programs/Xserver/hw/xfree86/drivers/chips/util/AsmMacros.h,v 1.1 2001/11/16 21:13:34 tsi Exp $
+ Modified for readability by Nick Kurshev
+*/
+
+#ifndef __ASM_MACROS_X86_H
+#define __ASM_MACROS_X86_H
+
+#if defined (WINNT)
+#error This stuff is not ported on your system
+#else
+
+static __inline__ void outb(short port,char val)
+{
+ __asm__ __volatile__("outb %0,%1" : :"a" (val), "d" (port));
+}
+
+static __inline__ void outw(short port,short val)
+{
+ __asm__ __volatile__("outw %0,%1" : :"a" (val), "d" (port));
+}
+
+static __inline__ void outl(short port,unsigned int val)
+{
+ __asm__ __volatile__("outl %0,%1" : :"a" (val), "d" (port));
+}
+
+static __inline__ unsigned int inb(short port)
+{
+ unsigned char ret;
+ __asm__ __volatile__("inb %1,%0" :
+ "=a" (ret) :
+ "d" (port));
+ return ret;
+}
+
+static __inline__ unsigned int inw(short port)
+{
+ unsigned short ret;
+ __asm__ __volatile__("inw %1,%0" :
+ "=a" (ret) :
+ "d" (port));
+ return ret;
+}
+
+static __inline__ unsigned int inl(short port)
+{
+ unsigned int ret;
+ __asm__ __volatile__("inl %1,%0" :
+ "=a" (ret) :
+ "d" (port));
+ return ret;
+}
+
+static __inline__ void intr_disable()
+{
+ __asm__ __volatile__("cli");
+}
+
+static __inline__ void intr_enable()
+{
+ __asm__ __volatile__("sti");
+}
+
+#endif
+
+#endif
diff --git a/libdha/sysdep/libdha_os2.c b/libdha/sysdep/libdha_os2.c
new file mode 100644
index 0000000000..041f6be71c
--- /dev/null
+++ b/libdha/sysdep/libdha_os2.c
@@ -0,0 +1,161 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/os2/os2_video.c,v 3.14 2000/10/28 01:42:28 mvojkovi Exp $ */
+/* Modified for libdha by Nick Kurshev. */
+/*
+ * (c) Copyright 1994,1999 by Holger Veit
+ * <Holger.Veit@gmd.de>
+ * Modified 1996 by Sebastien Marineau <marineau@genie.uottawa.ca>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * HOLGER VEIT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Holger Veit shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Holger Veit.
+ *
+ */
+/* $XConsortium: os2_video.c /main/8 1996/10/27 11:49:02 kaleb $ */
+
+#define INCL_DOSFILEMGR
+#include "os2.h"
+
+/***************************************************************************/
+/* Video Memory Mapping helper functions */
+/***************************************************************************/
+
+/* This section uses the xf86sup.sys driver developed for xfree86.
+ * The driver allows mapping of physical memory
+ * You must install it with a line DEVICE=path\xf86sup.sys in config.sys.
+ */
+
+static HFILE mapdev = -1;
+static ULONG stored_virt_addr;
+static char* mappath = "\\DEV\\PMAP$";
+static HFILE open_mmap()
+{
+ APIRET rc;
+ ULONG action;
+
+ if (mapdev != -1)
+ return mapdev;
+
+ rc = DosOpen((PSZ)mappath, (PHFILE)&mapdev, (PULONG)&action,
+ (ULONG)0, FILE_SYSTEM, FILE_OPEN,
+ OPEN_SHARE_DENYNONE|OPEN_FLAGS_NOINHERIT|OPEN_ACCESS_READONLY,
+ (ULONG)0);
+ if (rc!=0)
+ mapdev = -1;
+ return mapdev;
+}
+
+static void close_mmap()
+{
+ if (mapdev != -1)
+ DosClose(mapdev);
+ mapdev = -1;
+}
+
+/* this structure is used as a parameter packet for the direct access
+ * ioctl of pmap$
+ */
+
+/* Changed here for structure of driver PMAP$ */
+
+typedef struct{
+ ULONG addr;
+ ULONG size;
+} DIOParPkt;
+
+/* This is the data packet for the mapping function */
+
+typedef struct {
+ ULONG addr;
+ USHORT sel;
+} DIODtaPkt;
+
+/***************************************************************************/
+/* Video Memory Mapping section */
+/***************************************************************************/
+
+static long callcount = 0L;
+
+/* ARGSUSED */
+void * map_phys_mem(unsigned long base, unsigned long size)
+{
+ DIOParPkt par;
+ ULONG plen;
+ DIODtaPkt dta;
+ ULONG dlen;
+ static BOOL ErrRedir = FALSE;
+ APIRET rc;
+
+ par.addr = (ULONG)base;
+ par.size = (ULONG)size;
+ plen = sizeof(par);
+ dlen = sizeof(dta);
+
+ open_mmap();
+ if (mapdev == -1)
+ {
+ perror("libdha: device xf86sup.sys is not installed");
+ exit(1);
+ }
+ if ((rc=DosDevIOCtl(mapdev, (ULONG)0x76, (ULONG)0x44,
+ (PVOID)&par, (ULONG)plen, (PULONG)&plen,
+ (PVOID)&dta, (ULONG)dlen, (PULONG)&dlen)) == 0) {
+ if (dlen==sizeof(dta)) {
+ callcount++;
+ return (void *)dta.addr;
+ }
+ /*else fail*/
+ }
+ return (void *)-1;
+}
+
+/* ARGSUSED */
+void unmap_phys_mem(void * base, unsigned long size)
+{
+ DIOParPkt par;
+ ULONG plen,vmaddr;
+
+/* We need here the VIRTADDR for unmapping, not the physical address */
+/* This should be taken care of either here by keeping track of allocated */
+/* pointers, but this is also already done in the driver... Thus it would */
+/* be a waste to do this tracking twice. Can this be changed when the fn. */
+/* is called? This would require tracking this function in all servers, */
+/* and changing it appropriately to call this with the virtual adress */
+/* If the above mapping function is only called once, then we can store */
+/* the virtual adress and use it here.... */
+
+ par.addr = (ULONG)base;
+ par.size = 0xffffffff; /* This is the virtual address parameter. Set this to ignore */
+ plen = sizeof(par);
+
+ if (mapdev != -1)
+ {
+ DosDevIOCtl(mapdev, (ULONG)0x76, (ULONG)0x46,
+ (PVOID)&par, (ULONG)plen, (PULONG)&plen,
+ &vmaddr, sizeof(ULONG), &plen);
+ callcount--;
+ }
+/* Now if more than one region has been allocated and we close the driver,
+ * the other pointers will immediately become invalid. We avoid closing
+ * driver for now, but this should be fixed for server exit
+ */
+
+ if(!callcount) close_mmap();
+}
diff --git a/libdha/sysdep/libdha_win32.c b/libdha/sysdep/libdha_win32.c
new file mode 100644
index 0000000000..75c5dfb942
--- /dev/null
+++ b/libdha/sysdep/libdha_win32.c
@@ -0,0 +1,70 @@
+/*
+ MAPDEV.h - include file for VxD MAPDEV
+ Copyright (c) 1996 Vireo Software, Inc.
+ Modified for libdha by Nick Kurshev.
+*/
+
+#include <windows.h>
+
+/*
+ This is the request structure that applications use
+ to request services from the MAPDEV VxD.
+*/
+
+typedef struct _MapDevRequest
+{
+ DWORD mdr_ServiceID; /* supplied by caller */
+ LPVOID mdr_PhysicalAddress; /* supplied by caller */
+ DWORD mdr_SizeInBytes; /* supplied by caller */
+ LPVOID mdr_LinearAddress; /* returned by VxD */
+ WORD mdr_Selector; /* returned if 16-bit caller */
+ WORD mdr_Status; /* MDR_xxxx code below */
+} MAPDEVREQUEST, *PMAPDEVREQUEST;
+
+#define MDR_SERVICE_MAP CTL_CODE(FILE_DEVICE_UNKNOWN, 1, METHOD_NEITHER, FILE_ANY_ACCESS)
+#define MDR_SERVICE_UNMAP CTL_CODE(FILE_DEVICE_UNKNOWN, 2, METHOD_NEITHER, FILE_ANY_ACCESS)
+
+#define MDR_STATUS_SUCCESS 1
+#define MDR_STATUS_ERROR 0
+/*#include "winioctl.h"*/
+#define FILE_DEVICE_UNKNOWN 0x00000022
+#define METHOD_NEITHER 3
+#define FILE_ANY_ACCESS 0
+#define CTL_CODE( DeviceType, Function, Method, Access ) ( \
+ ((DeviceType)<<16) | ((Access)<<14) | ((Function)<<2) | (Method) )
+
+/* Memory Map a piece of Real Memory */
+void *map_phys_mem(unsigned base, unsigned size) {
+
+ HANDLE hDevice ;
+ PVOID inBuf[1] ; /* buffer for struct pointer to VxD */
+ DWORD RetInfo[2] ; /* buffer to receive data from VxD */
+ DWORD cbBytesReturned ; /* count of bytes returned from VxD */
+ MAPDEVREQUEST req ; /* map device request structure */
+ DWORD *pNicstar, Status, Time ; int i ; char *endptr ;
+ const PCHAR VxDName = "\\\\.\\MAPDEV.VXD" ;
+ const PCHAR VxDNameAlreadyLoaded = "\\\\.\\MAPDEV" ;
+
+ hDevice = CreateFile(VxDName, 0,0,0,
+ CREATE_NEW, FILE_FLAG_DELETE_ON_CLOSE, 0) ;
+ if (hDevice == INVALID_HANDLE_VALUE)
+ hDevice = CreateFile(VxDNameAlreadyLoaded, 0,0,0,
+ CREATE_NEW, FILE_FLAG_DELETE_ON_CLOSE, 0) ;
+ if (hDevice == INVALID_HANDLE_VALUE) {
+ fprintf(stderr, "Cannot open driver, error=%08lx\n", GetLastError()) ;
+ exit(1) ; }
+
+ req.mdr_ServiceID = MDR_SERVICE_MAP ;
+ req.mdr_PhysicalAddress = (PVOID)base ;
+ req.mdr_SizeInBytes = size ;
+ inBuf[0] = &req ;
+
+ if ( ! DeviceIoControl(hDevice, MDR_SERVICE_MAP, inBuf, sizeof(PVOID),
+ NULL, 0, &cbBytesReturned, NULL) ) {
+ fprintf(stderr, "Failed to map device\n") ; exit(1) ; }
+
+ return (void*)req.mdr_LinearAddress ;
+}
+
+void unmap_phys_mem(void *ptr, unsigned size) { }
+
diff --git a/libdha/sysdep/pci_386bsd.c b/libdha/sysdep/pci_386bsd.c
new file mode 100644
index 0000000000..a8040d60ad
--- /dev/null
+++ b/libdha/sysdep/pci_386bsd.c
@@ -0,0 +1,35 @@
+/*
+ This file is based on:
+ $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 <sys/file.h>
+#include <machine/console.h>
+#ifndef GCCUSESGAS
+#define GCCUSESGAS
+#endif
+
+static int io_fd;
+
+static __inline__ void enable_os_io(void)
+{
+ io_fd = -1 ;
+ if ((io_fd = open("/dev/console", O_RDWR, 0)) < 0) {
+ perror("/dev/console");
+ exit(1);
+ }
+ if (ioctl(io_fd, KDENABIO, 0) < 0) {
+ perror("ioctl(KDENABIO)");
+ exit(1);
+ }
+}
+
+static __inline__ void disable_os_io(void)
+{
+ if (ioctl(io_fd, KDDISABIO, 0) < 0) {
+ perror("ioctl(KDDISABIO)");
+ close(io_fd);
+ exit(1);
+ }
+ close(io_fd);
+}
diff --git a/libdha/sysdep/pci_alpha.c b/libdha/sysdep/pci_alpha.c
new file mode 100644
index 0000000000..1ab1db2aa4
--- /dev/null
+++ b/libdha/sysdep/pci_alpha.c
@@ -0,0 +1,29 @@
+/*
+ This file is based on:
+ $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
+*/
+
+static int pci_config_type( void ) { return 1; }
+
+static int pci_get_vendor(
+ unsigned char bus,
+ unsigned char dev,
+ int func)
+{
+ int retval;
+ pciconfig_read(bus, dev<<3, PCI_ID_REG, 4, &retval);
+ return retval;
+}
+
+static long pci_config_read_long(
+ unsigned char bus,
+ unsigned char dev,
+ int func,
+ unsigned cmd)
+{
+ long retval;
+ pciconfig_read(bus, dev<<3, cmd, 4, &retval);
+ return retval;
+}
+
diff --git a/libdha/sysdep/pci_arm32.c b/libdha/sysdep/pci_arm32.c
new file mode 100644
index 0000000000..a631887da3
--- /dev/null
+++ b/libdha/sysdep/pci_arm32.c
@@ -0,0 +1,60 @@
+/*
+ This file is based on:
+ $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
+*/
+
+static int pci_config_type( void )
+{
+ unsigned long tmplong1, tmplong2;
+ unsigned char tmp1, tmp2;
+ int retval;
+ retval = 0;
+
+ outb(PCI_MODE2_ENABLE_REG, 0x00);
+ outb(PCI_MODE2_FORWARD_REG, 0x00);
+ tmp1 = inb(PCI_MODE2_ENABLE_REG);
+ tmp2 = inb(PCI_MODE2_FORWARD_REG);
+ if ((tmp1 == 0x00) && (tmp2 == 0x00)) {
+ retval = 2;
+ /*printf("PCI says configuration type 2\n");*/
+ } else {
+ tmplong1 = inl(PCI_MODE1_ADDRESS_REG);
+ outl(PCI_MODE1_ADDRESS_REG, PCI_EN);
+ tmplong2 = inl(PCI_MODE1_ADDRESS_REG);
+ outl(PCI_MODE1_ADDRESS_REG, tmplong1);
+ if (tmplong2 == PCI_EN) {
+ retval = 1;
+ /*printf("PCI says configuration type 1\n");*/
+ } else {
+ /*printf("No PCI !\n");*/
+ disable_os_io();
+ /*exit(1);*/
+ retval = 0xFFFF;
+ }
+ }
+ return retval;
+}
+
+static int pci_get_vendor(
+ unsigned char bus,
+ unsigned char dev,
+ int func)
+{
+ unsigned long config_cmd;
+ config_cmd = PCI_EN | (bus<<16) | (dev<<11) | (func<<8);
+ outl(PCI_MODE1_ADDRESS_REG, config_cmd);
+ return inl(PCI_MODE1_DATA_REG);
+}
+
+static long pci_config_read_long(
+ unsigned char bus,
+ unsigned char dev,
+ int func,
+ unsigned cmd)
+{
+ unsigned long config_cmd;
+ config_cmd = PCI_EN | (bus<<16) | (dev<<11) | (func<<8);
+ outl(PCI_MODE1_ADDRESS_REG, config_cmd | cmd);
+ return inl(PCI_MODE1_DATA_REG);
+}
diff --git a/libdha/sysdep/pci_bsdi.c b/libdha/sysdep/pci_bsdi.c
new file mode 100644
index 0000000000..1e7b877a3b
--- /dev/null
+++ b/libdha/sysdep/pci_bsdi.c
@@ -0,0 +1,36 @@
+/*
+ This file is based on:
+ $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 <sys/file.h>
+#include <sys/ioctl.h>
+#include <i386/isa/pcconsioctl.h>
+#ifndef GCCUSESGAS
+#define GCCUSESGAS
+#endif
+
+static int io_fd;
+
+static __inline__ void enable_os_io(void)
+{
+ io_fd = -1 ;
+ if ((io_fd = open("/dev/console", O_RDWR, 0)) < 0) {
+ perror("/dev/console");
+ exit(1);
+ }
+ if (ioctl(io_fd, PCCONENABIOPL, 0) < 0) {
+ perror("ioctl(PCCONENABIOPL)");
+ exit(1);
+ }
+}
+
+static __inline__ void disable_os_io(void)
+{
+ if (ioctl(io_fd, PCCONDISABIOPL, 0) < 0) {
+ perror("ioctl(PCCONDISABIOPL)");
+ close(io_fd);
+ exit(1);
+ }
+ close(io_fd);
+}
diff --git a/libdha/sysdep/pci_freebsd.c b/libdha/sysdep/pci_freebsd.c
new file mode 100644
index 0000000000..a8040d60ad
--- /dev/null
+++ b/libdha/sysdep/pci_freebsd.c
@@ -0,0 +1,35 @@
+/*
+ This file is based on:
+ $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 <sys/file.h>
+#include <machine/console.h>
+#ifndef GCCUSESGAS
+#define GCCUSESGAS
+#endif
+
+static int io_fd;
+
+static __inline__ void enable_os_io(void)
+{
+ io_fd = -1 ;
+ if ((io_fd = open("/dev/console", O_RDWR, 0)) < 0) {
+ perror("/dev/console");
+ exit(1);
+ }
+ if (ioctl(io_fd, KDENABIO, 0) < 0) {
+ perror("ioctl(KDENABIO)");
+ exit(1);
+ }
+}
+
+static __inline__ void disable_os_io(void)
+{
+ if (ioctl(io_fd, KDDISABIO, 0) < 0) {
+ perror("ioctl(KDDISABIO)");
+ close(io_fd);
+ exit(1);
+ }
+ close(io_fd);
+}
diff --git a/libdha/sysdep/pci_ia64.c b/libdha/sysdep/pci_ia64.c
new file mode 100644
index 0000000000..a631887da3
--- /dev/null
+++ b/libdha/sysdep/pci_ia64.c
@@ -0,0 +1,60 @@
+/*
+ This file is based on:
+ $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
+*/
+
+static int pci_config_type( void )
+{
+ unsigned long tmplong1, tmplong2;
+ unsigned char tmp1, tmp2;
+ int retval;
+ retval = 0;
+
+ outb(PCI_MODE2_ENABLE_REG, 0x00);
+ outb(PCI_MODE2_FORWARD_REG, 0x00);
+ tmp1 = inb(PCI_MODE2_ENABLE_REG);
+ tmp2 = inb(PCI_MODE2_FORWARD_REG);
+ if ((tmp1 == 0x00) && (tmp2 == 0x00)) {
+ retval = 2;
+ /*printf("PCI says configuration type 2\n");*/
+ } else {
+ tmplong1 = inl(PCI_MODE1_ADDRESS_REG);
+ outl(PCI_MODE1_ADDRESS_REG, PCI_EN);
+ tmplong2 = inl(PCI_MODE1_ADDRESS_REG);
+ outl(PCI_MODE1_ADDRESS_REG, tmplong1);
+ if (tmplong2 == PCI_EN) {
+ retval = 1;
+ /*printf("PCI says configuration type 1\n");*/
+ } else {
+ /*printf("No PCI !\n");*/
+ disable_os_io();
+ /*exit(1);*/
+ retval = 0xFFFF;
+ }
+ }
+ return retval;
+}
+
+static int pci_get_vendor(
+ unsigned char bus,
+ unsigned char dev,
+ int func)
+{
+ unsigned long config_cmd;
+ config_cmd = PCI_EN | (bus<<16) | (dev<<11) | (func<<8);
+ outl(PCI_MODE1_ADDRESS_REG, config_cmd);
+ return inl(PCI_MODE1_DATA_REG);
+}
+
+static long pci_config_read_long(
+ unsigned char bus,
+ unsigned char dev,
+ int func,
+ unsigned cmd)
+{
+ unsigned long config_cmd;
+ config_cmd = PCI_EN | (bus<<16) | (dev<<11) | (func<<8);
+ outl(PCI_MODE1_ADDRESS_REG, config_cmd | cmd);
+ return inl(PCI_MODE1_DATA_REG);
+}
diff --git a/libdha/sysdep/pci_isc.c b/libdha/sysdep/pci_isc.c
new file mode 100644
index 0000000000..0fabba5972
--- /dev/null
+++ b/libdha/sysdep/pci_isc.c
@@ -0,0 +1,30 @@
+/*
+ This file is based on:
+ $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 <sys/param.h>
+#include <sys/immu.h>
+#include <sys/region.h>
+#include <sys/proc.h>
+#include <sys/tss.h>
+#include <sys/sysi86.h>
+#include <sys/v86.h>
+
+static __inline__ void enable_os_io(void)
+{
+#if defined(SI86IOPL)
+ sysi86(SI86IOPL, 3);
+#else
+ sysi86(SI86V86, V86SC_IOPL, PS_IOPL);
+#endif
+}
+
+static __inline__ void disable_os_io(void)
+{
+#if defined(SI86IOPL)
+ sysi86(SI86IOPL, 0);
+#else
+ sysi86(SI86V86, V86SC_IOPL, 0);
+#endif
+}
diff --git a/libdha/sysdep/pci_linux.c b/libdha/sysdep/pci_linux.c
new file mode 100644
index 0000000000..96a520b65d
--- /dev/null
+++ b/libdha/sysdep/pci_linux.c
@@ -0,0 +1,20 @@
+/*
+ This file is based on:
+ $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
+*/
+#ifdef __i386__
+#include <sys/perm.h>
+#else
+#include <sys/io.h>
+#endif
+
+static __inline__ void enable_os_io(void)
+{
+ iopl(3);
+}
+
+static __inline__ void disable_os_io(void)
+{
+ iopl(0);
+}
diff --git a/libdha/sysdep/pci_lynx.c b/libdha/sysdep/pci_lynx.c
new file mode 100644
index 0000000000..b698f63083
--- /dev/null
+++ b/libdha/sysdep/pci_lynx.c
@@ -0,0 +1,93 @@
+/*
+ This file is based on:
+ $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
+*/
+
+#if defined(Lynx_22)
+#ifndef GCCUSESGAS
+#define GCCUSESGAS
+#endif
+
+/* let's mimick the Linux Alpha stuff for LynxOS so we don't have
+ * to change too much code
+ */
+#include <smem.h>
+
+static unsigned char *pciConfBase;
+
+static __inline__ void enable_os_io(void)
+{
+ pciConfBase = (unsigned char *) smem_create("PCI-CONF",
+ (char *)0x80800000, 64*1024, SM_READ|SM_WRITE);
+ if (pciConfBase == (void *) -1)
+ exit(1);
+}
+
+static __inline__ void disable_os_io(void)
+{
+ smem_create(NULL, (char *) pciConfBase, 0, SM_DETACH);
+ smem_remove("PCI-CONF");
+ pciConfBase = NULL;
+}
+
+#include <smem.h>
+
+static unsigned char *pciConfBase;
+
+static __inline__ unsigned long
+static swapl(unsigned long val)
+{
+ unsigned char *p = (unsigned char *)&val;
+ return ((p[3] << 24) | (p[2] << 16) | (p[1] << 8) | (p[0] << 0));
+}
+
+
+#define BUS(tag) (((tag)>>16)&0xff)
+#define DFN(tag) (((tag)>>8)&0xff)
+
+#define PCIBIOS_DEVICE_NOT_FOUND 0x86
+#define PCIBIOS_SUCCESSFUL 0x00
+
+static int pciconfig_read(
+ unsigned char bus,
+ unsigned char dev,
+ unsigned char offset,
+ int len, /* unused, alway 4 */
+ unsigned long *val)
+{
+ unsigned long _val;
+ unsigned long *ptr;
+
+ dev >>= 3;
+ if (bus || dev >= 16) {
+ *val = 0xFFFFFFFF;
+ return PCIBIOS_DEVICE_NOT_FOUND;
+ } else {
+ ptr = (unsigned long *)(pciConfBase + ((1<<dev) | offset));
+ _val = swapl(*ptr);
+ }
+ *val = _val;
+ return PCIBIOS_SUCCESSFUL;
+}
+
+static int pciconfig_write(
+ unsigned char bus,
+ unsigned char dev,
+ unsigned char offset,
+ int len, /* unused, alway 4 */
+ unsigned long val)
+{
+ unsigned long _val;
+ unsigned long *ptr;
+
+ dev >>= 3;
+ _val = swapl(val);
+ if (bus || dev >= 16) {
+ return PCIBIOS_DEVICE_NOT_FOUND;
+ } else {
+ ptr = (unsigned long *)(pciConfBase + ((1<<dev) | offset));
+ *ptr = _val;
+ }
+ return PCIBIOS_SUCCESSFUL;
+}
diff --git a/libdha/sysdep/pci_mach386.c b/libdha/sysdep/pci_mach386.c
new file mode 100644
index 0000000000..32e2a657ff
--- /dev/null
+++ b/libdha/sysdep/pci_mach386.c
@@ -0,0 +1,21 @@
+/*
+ This file is based on:
+ $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
+*/
+
+static int io_fd;
+
+static __inline__ void enable_os_io(void)
+{
+ io_fd = -1 ;
+ if ((io_fd = open("/dev/iopl", O_RDWR, 0)) < 0) {
+ perror("/dev/iopl");
+ exit(1);
+ }
+}
+
+static __inline__ void disable_os_io(void)
+{
+ close(io_fd);
+}
diff --git a/libdha/sysdep/pci_netbsd.c b/libdha/sysdep/pci_netbsd.c
new file mode 100644
index 0000000000..19fa771fbd
--- /dev/null
+++ b/libdha/sysdep/pci_netbsd.c
@@ -0,0 +1,41 @@
+/*
+ This file is based on:
+ $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 <sys/param.h>
+#include <sys/file.h>
+#include <machine/sysarch.h>
+#ifndef GCCUSESGAS
+#define GCCUSESGAS
+#endif
+
+static int io_fd;
+
+static __inline__ void 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);
+ }
+#else
+ if (i386_iopl(1) < 0) {
+ perror("i386_iopl");
+ exit(1);
+ }
+#endif /* USE_I386_IOPL */
+}
+
+static __inline__ void disable_os_io(void)
+{
+#if !defined(USE_I386_IOPL)
+ close(io_fd);
+#else
+ if (i386_iopl(0) < 0) {
+ perror("i386_iopl");
+ exit(1);
+ }
+#endif /* NetBSD1_1 */
+}
diff --git a/libdha/sysdep/pci_openbsd.c b/libdha/sysdep/pci_openbsd.c
new file mode 100644
index 0000000000..ef835b405f
--- /dev/null
+++ b/libdha/sysdep/pci_openbsd.c
@@ -0,0 +1,18 @@
+/*
+ This file is based on:
+ $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
+*/
+
+static __inline__ void enable_os_io(void)
+{
+ if (i386_iopl(1) < 0) {
+ perror("i386_iopl");
+ exit(1);
+ }
+}
+
+static __inline__ void disable_os_io(void)
+{
+ /* Nothing to do */
+}
diff --git a/libdha/sysdep/pci_os2.c b/libdha/sysdep/pci_os2.c
new file mode 100644
index 0000000000..4f0df53b30
--- /dev/null
+++ b/libdha/sysdep/pci_os2.c
@@ -0,0 +1,53 @@
+/*
+ This file is based on:
+ $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
+*/
+#define INCL_DOSFILEMGR
+#include <os2.h>
+
+static USHORT callgate[3] = {0,0,0};
+
+static __inline__ void enable_os_io(void)
+{
+ HFILE hfd;
+ ULONG dlen,action;
+ APIRET rc;
+ static char *ioDrvPath = "/dev/fastio$";
+
+ if (DosOpen((PSZ)ioDrvPath, (PHFILE)&hfd, (PULONG)&action,
+ (ULONG)0, FILE_SYSTEM, FILE_OPEN,
+ OPEN_SHARE_DENYNONE|OPEN_FLAGS_NOINHERIT|OPEN_ACCESS_READONLY,
+ (ULONG)0) != 0) {
+ fprintf(stderr,"Error opening fastio$ driver...\n");
+ fprintf(stderr,"Please install xf86sup.sys in config.sys!\n");
+ exit(42);
+ }
+ callgate[0] = callgate[1] = 0;
+
+/* Get callgate from driver for fast io to ports and other stuff */
+
+ rc = DosDevIOCtl(hfd, (ULONG)0x76, (ULONG)0x64,
+ NULL, 0, NULL,
+ (ULONG*)&callgate[2], sizeof(USHORT), &dlen);
+ if (rc) {
+ fprintf(stderr,"xf86-OS/2: EnableIOPorts failed, rc=%d, dlen=%d; emergency exit\n",
+ rc,dlen);
+ DosClose(hfd);
+ exit(42);
+ }
+
+/* Calling callgate with function 13 sets IOPL for the program */
+
+ asm volatile ("movl $13,%%ebx;.byte 0xff,0x1d;.long _callgate"
+ : /*no outputs */
+ : /*no inputs */
+ : "eax","ebx","ecx","edx","cc");
+
+ DosClose(hfd);
+}
+
+static __inline__ void disable_os_io(void)
+{
+/* Nothing to do */
+}
diff --git a/libdha/sysdep/pci_powerpc.c b/libdha/sysdep/pci_powerpc.c
new file mode 100644
index 0000000000..9239521ec3
--- /dev/null
+++ b/libdha/sysdep/pci_powerpc.c
@@ -0,0 +1,28 @@
+/*
+ This file is based on:
+ $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
+*/
+
+static int pci_config_type( void ) { return 1; }
+
+static int pci_get_vendor(
+ unsigned char bus,
+ unsigned char dev,
+ int func)
+{
+ int retval;
+ pciconfig_read(bus, dev<<3, PCI_ID_REG, 4, &retval);
+ return retval;
+}
+
+static long pci_config_read_long(
+ unsigned char bus,
+ unsigned char dev,
+ int func,
+ unsigned cmd)
+{
+ long retval;
+ pciconfig_read(bus, dev<<3, cmd, 4, &retval);
+ return retval;
+}
diff --git a/libdha/sysdep/pci_sco.c b/libdha/sysdep/pci_sco.c
new file mode 100644
index 0000000000..1d5c355989
--- /dev/null
+++ b/libdha/sysdep/pci_sco.c
@@ -0,0 +1,31 @@
+/*
+ This file is based on:
+ $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 <sys/console.h>
+#include <sys/param.h>
+#include <sys/immu.h>
+#include <sys/region.h>
+#include <sys/proc.h>
+#include <sys/tss.h>
+#include <sys/sysi86.h>
+#include <sys/v86.h>
+
+static __inline__ void enable_os_io(void)
+{
+#if defined(SI86IOPL)
+ sysi86(SI86IOPL, 3);
+#else
+ sysi86(SI86V86, V86SC_IOPL, PS_IOPL);
+#endif
+}
+
+static __inline__ void disable_os_io(void)
+{
+#if defined(SI86IOPL)
+ sysi86(SI86IOPL, 0);
+#else
+ sysi86(SI86V86, V86SC_IOPL, 0);
+#endif
+}
diff --git a/libdha/sysdep/pci_sparc.c b/libdha/sysdep/pci_sparc.c
new file mode 100644
index 0000000000..a631887da3
--- /dev/null
+++ b/libdha/sysdep/pci_sparc.c
@@ -0,0 +1,60 @@
+/*
+ This file is based on:
+ $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
+*/
+
+static int pci_config_type( void )
+{
+ unsigned long tmplong1, tmplong2;
+ unsigned char tmp1, tmp2;
+ int retval;
+ retval = 0;
+
+ outb(PCI_MODE2_ENABLE_REG, 0x00);
+ outb(PCI_MODE2_FORWARD_REG, 0x00);
+ tmp1 = inb(PCI_MODE2_ENABLE_REG);
+ tmp2 = inb(PCI_MODE2_FORWARD_REG);
+ if ((tmp1 == 0x00) && (tmp2 == 0x00)) {
+ retval = 2;
+ /*printf("PCI says configuration type 2\n");*/
+ } else {
+ tmplong1 = inl(PCI_MODE1_ADDRESS_REG);
+ outl(PCI_MODE1_ADDRESS_REG, PCI_EN);
+ tmplong2 = inl(PCI_MODE1_ADDRESS_REG);
+ outl(PCI_MODE1_ADDRESS_REG, tmplong1);
+ if (tmplong2 == PCI_EN) {
+ retval = 1;
+ /*printf("PCI says configuration type 1\n");*/
+ } else {
+ /*printf("No PCI !\n");*/
+ disable_os_io();
+ /*exit(1);*/
+ retval = 0xFFFF;
+ }
+ }
+ return retval;
+}
+
+static int pci_get_vendor(
+ unsigned char bus,
+ unsigned char dev,
+ int func)
+{
+ unsigned long config_cmd;
+ config_cmd = PCI_EN | (bus<<16) | (dev<<11) | (func<<8);
+ outl(PCI_MODE1_ADDRESS_REG, config_cmd);
+ return inl(PCI_MODE1_DATA_REG);
+}
+
+static long pci_config_read_long(
+ unsigned char bus,
+ unsigned char dev,
+ int func,
+ unsigned cmd)
+{
+ unsigned long config_cmd;
+ config_cmd = PCI_EN | (bus<<16) | (dev<<11) | (func<<8);
+ outl(PCI_MODE1_ADDRESS_REG, config_cmd | cmd);
+ return inl(PCI_MODE1_DATA_REG);
+}
diff --git a/libdha/sysdep/pci_svr4.c b/libdha/sysdep/pci_svr4.c
new file mode 100644
index 0000000000..7acdd9f3e4
--- /dev/null
+++ b/libdha/sysdep/pci_svr4.c
@@ -0,0 +1,38 @@
+/*
+ This file is based on:
+ $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 <sys/types.h>
+#include <sys/proc.h>
+#include <sys/tss.h>
+#if defined(NCR)
+#define __STDC
+#include <sys/sysi86.h>
+#undef __STDC
+#else
+#include <sys/sysi86.h>
+#endif
+
+#if defined(sun)
+#ifndef __EXTENSIONS__
+#define __EXTENSIONS__
+#endif
+
+static __inline__ void enable_os_io(void)
+{
+#if defined(SI86IOPL)
+ sysi86(SI86IOPL, 3);
+#else
+ sysi86(SI86V86, V86SC_IOPL, PS_IOPL);
+#endif
+}
+
+static __inline__ void disable_os_io(void)
+{
+#if defined(SI86IOPL)
+ sysi86(SI86IOPL, 0);
+#else
+ sysi86(SI86V86, V86SC_IOPL, 0);
+#endif
+}
diff --git a/libdha/sysdep/pci_win32.c b/libdha/sysdep/pci_win32.c
new file mode 100644
index 0000000000..363fa23485
--- /dev/null
+++ b/libdha/sysdep/pci_win32.c
@@ -0,0 +1,16 @@
+/*
+ This file is based on:
+ $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>
+
+/* Nothing to do for Win9x. For WinNT I have no solution */
+
+static __inline__ void enable_os_io(void)
+{
+}
+
+static __inline__ void disable_os_io(void)
+{
+}
diff --git a/libdha/sysdep/pci_x86.c b/libdha/sysdep/pci_x86.c
new file mode 100644
index 0000000000..a631887da3
--- /dev/null
+++ b/libdha/sysdep/pci_x86.c
@@ -0,0 +1,60 @@
+/*
+ This file is based on:
+ $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
+*/
+
+static int pci_config_type( void )
+{
+ unsigned long tmplong1, tmplong2;
+ unsigned char tmp1, tmp2;
+ int retval;
+ retval = 0;
+
+ outb(PCI_MODE2_ENABLE_REG, 0x00);
+ outb(PCI_MODE2_FORWARD_REG, 0x00);
+ tmp1 = inb(PCI_MODE2_ENABLE_REG);
+ tmp2 = inb(PCI_MODE2_FORWARD_REG);
+ if ((tmp1 == 0x00) && (tmp2 == 0x00)) {
+ retval = 2;
+ /*printf("PCI says configuration type 2\n");*/
+ } else {
+ tmplong1 = inl(PCI_MODE1_ADDRESS_REG);
+ outl(PCI_MODE1_ADDRESS_REG, PCI_EN);
+ tmplong2 = inl(PCI_MODE1_ADDRESS_REG);
+ outl(PCI_MODE1_ADDRESS_REG, tmplong1);
+ if (tmplong2 == PCI_EN) {
+ retval = 1;
+ /*printf("PCI says configuration type 1\n");*/
+ } else {
+ /*printf("No PCI !\n");*/
+ disable_os_io();
+ /*exit(1);*/
+ retval = 0xFFFF;
+ }
+ }
+ return retval;
+}
+
+static int pci_get_vendor(
+ unsigned char bus,
+ unsigned char dev,
+ int func)
+{
+ unsigned long config_cmd;
+ config_cmd = PCI_EN | (bus<<16) | (dev<<11) | (func<<8);
+ outl(PCI_MODE1_ADDRESS_REG, config_cmd);
+ return inl(PCI_MODE1_DATA_REG);
+}
+
+static long pci_config_read_long(
+ unsigned char bus,
+ unsigned char dev,
+ int func,
+ unsigned cmd)
+{
+ unsigned long config_cmd;
+ config_cmd = PCI_EN | (bus<<16) | (dev<<11) | (func<<8);
+ outl(PCI_MODE1_ADDRESS_REG, config_cmd | cmd);
+ return inl(PCI_MODE1_DATA_REG);
+}