annotate libdha/libdha.c @ 5037:0ef48d850bc9

hopefully fixed divx5 header + xvid conflict
author arpi
date Mon, 11 Mar 2002 00:39:40 +0000
parents b782efa10c60
children 567de708ab3a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3973
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1 /*
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
2 libgha.c - Library for direct hardware access
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
3 Copyrights:
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
4 1996/10/27 - Robin Cutshaw (robin@xfree86.org)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
5 XFree86 3.3.3 implementation
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
6 1999 - Øyvind Aabling.
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
7 Modified for GATOS/win/gfxdump.
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
8
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
9 2002 - library implementation by Nick Kurshev
4474
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
10 - dhahelper and some changes by Alex Beregszaszi
3973
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
11
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
12 supported O/S's: SVR4, UnixWare, SCO, Solaris,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
13 FreeBSD, NetBSD, 386BSD, BSDI BSD/386,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
14 Linux, Mach/386, ISC
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
15 DOS (WATCOM 9.5 compiler), Win9x (with mapdev.vxd)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
16 Licence: GPL
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
17 Original location: www.linuxvideo.org/gatos
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
18 */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
19
4474
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
20 #include "config.h"
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
21
3973
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
22 #include "libdha.h"
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
23 #include "AsmMacros.h"
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
24 #include <stdio.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
25 #include <stdlib.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
26 #include <string.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
27 #include <fcntl.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
28 #include <sys/stat.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
29 #include <sys/types.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
30 #include <unistd.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
31
4174
4cfb6b9a6da3 api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents: 4164
diff changeset
32 /* instead exit() use libdha_exit, and do the 'mother-application' deinit
4cfb6b9a6da3 api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents: 4164
diff changeset
33 only in this code */
4cfb6b9a6da3 api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents: 4164
diff changeset
34 void libdha_exit(const char *message, int level)
4cfb6b9a6da3 api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents: 4164
diff changeset
35 {
4cfb6b9a6da3 api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents: 4164
diff changeset
36 printf("libdha: FATAL: %s\n", message);
4cfb6b9a6da3 api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents: 4164
diff changeset
37 exit(level); /* FIXME */
4cfb6b9a6da3 api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents: 4164
diff changeset
38 }
4cfb6b9a6da3 api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents: 4164
diff changeset
39
4164
2e3262002acb Improved readability and new stuffs
nick
parents: 3995
diff changeset
40 #if defined(_WIN32)
2e3262002acb Improved readability and new stuffs
nick
parents: 3995
diff changeset
41 #include "sysdep/libdha_win32.c"
2e3262002acb Improved readability and new stuffs
nick
parents: 3995
diff changeset
42 #elif defined (__EMX__)
2e3262002acb Improved readability and new stuffs
nick
parents: 3995
diff changeset
43 #include "sysdep/libdha_os2.c"
2e3262002acb Improved readability and new stuffs
nick
parents: 3995
diff changeset
44 #else
3973
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
45
4164
2e3262002acb Improved readability and new stuffs
nick
parents: 3995
diff changeset
46 #if defined(SVR4) || defined(SCO325)
2e3262002acb Improved readability and new stuffs
nick
parents: 3995
diff changeset
47 # if !(defined(sun) && defined (i386) && defined (SVR4))
2e3262002acb Improved readability and new stuffs
nick
parents: 3995
diff changeset
48 # define DEV_MEM "/dev/pmem"
2e3262002acb Improved readability and new stuffs
nick
parents: 3995
diff changeset
49 # elif defined(PowerMAX_OS)
2e3262002acb Improved readability and new stuffs
nick
parents: 3995
diff changeset
50 # define DEV_MEM "/dev/iomem"
2e3262002acb Improved readability and new stuffs
nick
parents: 3995
diff changeset
51 # endif
2e3262002acb Improved readability and new stuffs
nick
parents: 3995
diff changeset
52 # ifdef SCO325
2e3262002acb Improved readability and new stuffs
nick
parents: 3995
diff changeset
53 # undef DEV_MEM
2e3262002acb Improved readability and new stuffs
nick
parents: 3995
diff changeset
54 # define DEV_MEM "/dev/mem"
2e3262002acb Improved readability and new stuffs
nick
parents: 3995
diff changeset
55 # endif
2e3262002acb Improved readability and new stuffs
nick
parents: 3995
diff changeset
56 # endif /* SVR4 */
3973
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
57
4164
2e3262002acb Improved readability and new stuffs
nick
parents: 3995
diff changeset
58 /* Generic version */
2e3262002acb Improved readability and new stuffs
nick
parents: 3995
diff changeset
59 #include <sys/mman.h>
3973
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
60
4164
2e3262002acb Improved readability and new stuffs
nick
parents: 3995
diff changeset
61 #ifndef DEV_MEM
2e3262002acb Improved readability and new stuffs
nick
parents: 3995
diff changeset
62 #define DEV_MEM "/dev/mem"
2e3262002acb Improved readability and new stuffs
nick
parents: 3995
diff changeset
63 #endif
3973
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
64
4474
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
65 #ifdef CONFIG_DHAHELPER
4938
b782efa10c60 added proper dhahelper includes
alex
parents: 4474
diff changeset
66
b782efa10c60 added proper dhahelper includes
alex
parents: 4474
diff changeset
67 #include "kernelhelper/dhahelper.h"
b782efa10c60 added proper dhahelper includes
alex
parents: 4474
diff changeset
68
3973
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
69 static int mem=-1;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
70 void *map_phys_mem(unsigned base, unsigned size)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
71 {
4474
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
72 if ( (mem = open("/dev/dhahelper",O_RDWR)) < 0)
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
73 {
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
74 if ( (mem = open(DEV_MEM,O_RDWR)) == -1) {
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
75 perror("libdha: open(/dev/mem) failed") ; exit(1) ;
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
76 }
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
77 }
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
78 else
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
79 {
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
80 dhahelper_memory_t mem_req;
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
81
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
82 mem_req.operation = MEMORY_OP_MAP;
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
83 mem_req.start = base;
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
84 mem_req.offset = 0;
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
85 mem_req.size = size;
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
86
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
87 if (ioctl(mem, DHAHELPER_MEMORY, &mem_req) < 0)
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
88 {
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
89 perror("libdha: failed mapping throught kernel helper");
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
90 return NULL;
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
91 }
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
92 }
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
93 return mmap(0,size,PROT_READ|PROT_WRITE,MAP_SHARED,mem,base) ;
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
94 }
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
95 #else
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
96
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
97 static int mem=-1;
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
98 void *map_phys_mem(unsigned base, unsigned size)
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
99 {
4164
2e3262002acb Improved readability and new stuffs
nick
parents: 3995
diff changeset
100 if ( (mem = open(DEV_MEM,O_RDWR)) == -1) {
3973
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
101 perror("libdha: open(/dev/mem) failed") ; exit(1) ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
102 }
4164
2e3262002acb Improved readability and new stuffs
nick
parents: 3995
diff changeset
103 return mmap(0,size,PROT_READ|PROT_WRITE,MAP_SHARED,mem,base) ;
3973
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
104 }
4474
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
105 #endif /* CONFIG_DHAHELPER */
3973
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
106
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
107 void unmap_phys_mem(void *ptr, unsigned size)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
108 {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
109 int res=munmap(ptr,size) ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
110 if (res == -1) { perror("libdha: munmap() failed") ; exit(1) ; }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
111 close(mem);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
112 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
113 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
114
3995
0d9de811e312 minor interface changing
nick
parents: 3973
diff changeset
115 unsigned char INPORT8(unsigned idx)
3973
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
116 {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
117 return inb(idx);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
118 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
119
3995
0d9de811e312 minor interface changing
nick
parents: 3973
diff changeset
120 unsigned short INPORT16(unsigned idx)
3973
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
121 {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
122 return inw(idx);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
123 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
124
3995
0d9de811e312 minor interface changing
nick
parents: 3973
diff changeset
125 unsigned INPORT32(unsigned idx)
3973
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
126 {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
127 return inl(idx);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
128 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
129
3995
0d9de811e312 minor interface changing
nick
parents: 3973
diff changeset
130 void OUTPORT8(unsigned idx,unsigned char val)
3973
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
131 {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
132 outb(idx,val);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
133 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
134
3995
0d9de811e312 minor interface changing
nick
parents: 3973
diff changeset
135 void OUTPORT16(unsigned idx,unsigned short val)
3973
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
136 {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
137 outw(idx,val);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
138 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
139
3995
0d9de811e312 minor interface changing
nick
parents: 3973
diff changeset
140 void OUTPORT32(unsigned idx,unsigned val)
3973
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
141 {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
142 outl(idx,val);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
143 }
4174
4cfb6b9a6da3 api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents: 4164
diff changeset
144