annotate libdha/pci.c @ 3973:138800dfbe22

preliminary support of direct hardware access
author nick
date Fri, 04 Jan 2002 10:32:26 +0000
parents
children 3822582553d6
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 (C) 2002 - library implementation by Nick Kyrshev
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
3 XFree86 3.3.3 scanpci.c, modified for GATOS/win/gfxdump by Øyvind Aabling.
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
4 */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
5
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
6 #include "libdha.h"
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
7
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
8 #include <errno.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
9 #include <string.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
10 #include "AsmMacros.h"
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
11 #ifdef __unix__
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
12 #include <unistd.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
13 #include <sys/mman.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
14 #elif defined ( _WIN32 )
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
15 #include <windows.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
16 #else
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
17 #include <dos.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
18 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
19
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
20 #define outb pcioutb
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
21 #define outl pcioutl
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
22 #define inb pciinb
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
23 #define inl pciinl
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
24
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
25 /* $XConsortium: scanpci.c /main/25 1996/10/27 11:48:40 kaleb $ */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
26 /*
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
27 * name: scanpci.c
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
28 *
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
29 * purpose: This program will scan for and print details of
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
30 * devices on the PCI bus.
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
31
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
32 * author: Robin Cutshaw (robin@xfree86.org)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
33 *
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
34 * supported O/S's: SVR4, UnixWare, SCO, Solaris,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
35 * FreeBSD, NetBSD, 386BSD, BSDI BSD/386,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
36 * Linux, Mach/386, ISC
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
37 * DOS (WATCOM 9.5 compiler)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
38 *
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
39 * compiling: [g]cc scanpci.c -o scanpci
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
40 * for SVR4 (not Solaris), UnixWare use:
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
41 * [g]cc -DSVR4 scanpci.c -o scanpci
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
42 * for DOS, watcom 9.5:
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
43 * wcc386p -zq -omaxet -7 -4s -s -w3 -d2 name.c
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
44 * and link with PharLap or other dos extender for exe
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
45 *
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
46 */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
47
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
48 /* $XFree86: xc/programs/Xserver/hw/xfree86/etc/scanpci.c,v 3.34.2.17 1998/11/10 11:55:40 dawes Exp $ */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
49
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
50 /*
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
51 * Copyright 1995 by Robin Cutshaw <robin@XFree86.Org>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
52 *
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
53 * Permission to use, copy, modify, distribute, and sell this software and its
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
54 * documentation for any purpose is hereby granted without fee, provided that
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
55 * the above copyright notice appear in all copies and that both that
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
56 * copyright notice and this permission notice appear in supporting
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
57 * documentation, and that the names of the above listed copyright holder(s)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
58 * not be used in advertising or publicity pertaining to distribution of
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
59 * the software without specific, written prior permission. The above listed
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
60 * copyright holder(s) make(s) no representations about the suitability of this
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
61 * software for any purpose. It is provided "as is" without express or
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
62 * implied warranty.
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
63 *
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
64 * THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM(S) ALL WARRANTIES WITH REGARD
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
65 * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
66 * AND FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
67 * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
68 * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
69 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
70 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
71 *
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
72 */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
73
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
74 #if defined(__SVR4)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
75 #if !defined(SVR4)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
76 #define SVR4
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
77 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
78 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
79
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
80 #ifdef __EMX__
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
81 #define INCL_DOSFILEMGR
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
82 #include <os2.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
83 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
84
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
85 #include <stdio.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
86 #include <sys/types.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
87 #if defined(SVR4)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
88 #if defined(sun)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
89 #ifndef __EXTENSIONS__
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
90 #define __EXTENSIONS__
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
91 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
92 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
93 #include <sys/proc.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
94 #include <sys/tss.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
95 #if defined(NCR)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
96 #define __STDC
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
97 #include <sys/sysi86.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
98 #undef __STDC
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
99 #else
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
100 #include <sys/sysi86.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
101 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
102 #if defined(__SUNPRO_C) || defined(sun) || defined(__sun)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
103 #include <sys/psw.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
104 #else
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
105 #include <sys/seg.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
106 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
107 #include <sys/v86.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
108 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
109 #if defined(__FreeBSD__) || defined(__386BSD__)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
110 #include <sys/file.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
111 #include <machine/console.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
112 #ifndef GCCUSESGAS
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
113 #define GCCUSESGAS
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
114 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
115 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
116 #if defined(__NetBSD__)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
117 #include <sys/param.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
118 #include <sys/file.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
119 #include <machine/sysarch.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
120 #ifndef GCCUSESGAS
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
121 #define GCCUSESGAS
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
122 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
123 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
124 #if defined(__bsdi__)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
125 #include <sys/file.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
126 #include <sys/ioctl.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
127 #include <i386/isa/pcconsioctl.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
128 #ifndef GCCUSESGAS
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
129 #define GCCUSESGAS
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
130 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
131 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
132 #if defined(SCO) || defined(ISC)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
133 #ifndef ISC
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
134 #include <sys/console.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
135 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
136 #include <sys/param.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
137 #include <sys/immu.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
138 #include <sys/region.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
139 #include <sys/proc.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
140 #include <sys/tss.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
141 #include <sys/sysi86.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
142 #include <sys/v86.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
143 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
144 #if defined(Lynx_22)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
145 #ifndef GCCUSESGAS
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
146 #define GCCUSESGAS
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
147 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
148 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
149
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
150
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
151 #if defined(__WATCOMC__)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
152
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
153 #include <stdlib.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
154 static void outl(unsigned port, unsigned data);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
155 #pragma aux outl = "out dx, eax" parm [dx] [eax];
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
156 static void outb(unsigned port, unsigned data);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
157 #pragma aux outb = "out dx, al" parm [dx] [eax];
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
158 static unsigned inl(unsigned port);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
159 #pragma aux inl = "in eax, dx" parm [dx];
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
160 static unsigned inb(unsigned port);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
161 #pragma aux inb = "xor eax,eax" "in al, dx" parm [dx];
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
162
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
163 #else /* __WATCOMC__ */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
164
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
165 #if defined(__GNUC__)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
166
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
167 #if !defined(__alpha__) && !defined(__powerpc__)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
168 #if defined(GCCUSESGAS)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
169 #define OUTB_GCC "outb %0,%1"
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
170 #define OUTL_GCC "outl %0,%1"
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
171 #define INB_GCC "inb %1,%0"
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
172 #define INL_GCC "inl %1,%0"
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
173 #else
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
174 #define OUTB_GCC "out%B0 (%1)"
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
175 #define OUTL_GCC "out%L0 (%1)"
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
176 #define INB_GCC "in%B0 (%1)"
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
177 #define INL_GCC "in%L0 (%1)"
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
178 #endif /* GCCUSESGAS */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
179
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
180 static void outb(unsigned short port, unsigned char val) {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
181 __asm__ __volatile__(OUTB_GCC : :"a" (val), "d" (port)); }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
182 static void outl(unsigned short port, unsigned long val) {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
183 __asm__ __volatile__(OUTL_GCC : :"a" (val), "d" (port)); }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
184 static unsigned char inb(unsigned short port) { unsigned char ret;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
185 __asm__ __volatile__(INB_GCC : "=a" (ret) : "d" (port)); return ret; }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
186 static unsigned long inl(unsigned short port) { unsigned long ret;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
187 __asm__ __volatile__(INL_GCC : "=a" (ret) : "d" (port)); return ret; }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
188
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
189 #endif /* !defined(__alpha__) && !defined(__powerpc__) */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
190 #else /* __GNUC__ */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
191
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
192 #if defined(__STDC__) && (__STDC__ == 1)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
193 # if !defined(NCR)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
194 # define asm __asm
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
195 # endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
196 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
197
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
198 #if defined(__SUNPRO_C)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
199 /*
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
200 * This section is a gross hack in if you tell anyone that I wrote it,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
201 * I'll deny it. :-)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
202 * The leave/ret instructions are the big hack to leave %eax alone on return.
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
203 */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
204 static unsigned char inb(int port) {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
205 asm(" movl 8(%esp),%edx");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
206 asm(" subl %eax,%eax");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
207 asm(" inb (%dx)");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
208 asm(" leave");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
209 asm(" ret");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
210 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
211
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
212 static unsigned short inw(int port) {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
213 asm(" movl 8(%esp),%edx");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
214 asm(" subl %eax,%eax");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
215 asm(" inw (%dx)");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
216 asm(" leave");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
217 asm(" ret");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
218 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
219
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
220 static unsigned long inl(int port) {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
221 asm(" movl 8(%esp),%edx");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
222 asm(" inl (%dx)");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
223 asm(" leave");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
224 asm(" ret");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
225 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
226
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
227 static void outb(int port, unsigned char value) {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
228 asm(" movl 8(%esp),%edx");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
229 asm(" movl 12(%esp),%eax");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
230 asm(" outb (%dx)");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
231 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
232
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
233 static void outw(int port, unsigned short value) {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
234 asm(" movl 8(%esp),%edx");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
235 asm(" movl 12(%esp),%eax");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
236 asm(" outw (%dx)");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
237 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
238
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
239 static void outl(int port, unsigned long value) {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
240 asm(" movl 8(%esp),%edx");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
241 asm(" movl 12(%esp),%eax");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
242 asm(" outl (%dx)");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
243 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
244 #else
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
245
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
246 #if defined(SVR4)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
247 # if !defined(__USLC__)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
248 # define __USLC__
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
249 # endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
250 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
251
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
252 #ifdef __unix__
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
253 #ifndef SCO325
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
254 # include <sys/inline.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
255 #else
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
256 # include "scoasm.h"
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
257 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
258 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
259
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
260 #endif /* SUNPRO_C */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
261
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
262 #endif /* __GNUC__ */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
263 #endif /* __WATCOMC__ */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
264
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
265 #undef outb
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
266 #undef outl
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
267 #undef inb
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
268 #undef inl
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
269
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
270 #if defined(__GLIBC__) && __GLIBC__ >= 2
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
271 #if defined(linux)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
272 #include <sys/perm.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
273 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
274 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
275
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
276 #if defined(__alpha__)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
277 #if defined(linux)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
278 #include <asm/unistd.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
279 #define BUS(tag) (((tag)>>16)&0xff)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
280 #define DFN(tag) (((tag)>>8)&0xff)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
281 static int pciconfig_read(
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
282 unsigned char bus,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
283 unsigned char dfn,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
284 unsigned char off,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
285 unsigned char len,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
286 void * buf)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
287 {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
288 return syscall(__NR_pciconfig_read, bus, dfn, off, len, buf);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
289 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
290
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
291 static int pciconfig_write(
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
292 unsigned char bus,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
293 unsigned char dfn,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
294 unsigned char off,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
295 unsigned char len,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
296 void * buf)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
297 {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
298 return syscall(__NR_pciconfig_write, bus, dfn, off, len, buf);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
299 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
300 #else
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
301 Generate compiler error - scanpci unsupported on non-linux alpha platforms
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
302 #endif /* linux */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
303 #endif /* __alpha__ */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
304 #if defined(Lynx) && defined(__powerpc__)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
305 /* let's mimick the Linux Alpha stuff for LynxOS so we don't have
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
306 * to change too much code
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
307 */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
308 #include <smem.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
309
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
310 static unsigned char *pciConfBase;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
311
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
312 static __inline__ unsigned long
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
313 static swapl(unsigned long val)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
314 {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
315 unsigned char *p = (unsigned char *)&val;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
316 return ((p[3] << 24) | (p[2] << 16) | (p[1] << 8) | (p[0] << 0));
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
317 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
318
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
319
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
320 #define BUS(tag) (((tag)>>16)&0xff)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
321 #define DFN(tag) (((tag)>>8)&0xff)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
322
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
323 #define PCIBIOS_DEVICE_NOT_FOUND 0x86
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
324 #define PCIBIOS_SUCCESSFUL 0x00
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
325
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
326 static int pciconfig_read(
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
327 unsigned char bus,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
328 unsigned char dev,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
329 unsigned char offset,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
330 int len, /* unused, alway 4 */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
331 unsigned long *val)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
332 {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
333 unsigned long _val;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
334 unsigned long *ptr;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
335
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
336 dev >>= 3;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
337 if (bus || dev >= 16) {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
338 *val = 0xFFFFFFFF;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
339 return PCIBIOS_DEVICE_NOT_FOUND;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
340 } else {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
341 ptr = (unsigned long *)(pciConfBase + ((1<<dev) | offset));
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
342 _val = swapl(*ptr);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
343 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
344 *val = _val;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
345 return PCIBIOS_SUCCESSFUL;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
346 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
347
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
348 static int pciconfig_write(
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
349 unsigned char bus,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
350 unsigned char dev,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
351 unsigned char offset,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
352 int len, /* unused, alway 4 */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
353 unsigned long val)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
354 {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
355 unsigned long _val;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
356 unsigned long *ptr;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
357
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
358 dev >>= 3;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
359 _val = swapl(val);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
360 if (bus || dev >= 16) {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
361 return PCIBIOS_DEVICE_NOT_FOUND;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
362 } else {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
363 ptr = (unsigned long *)(pciConfBase + ((1<<dev) | offset));
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
364 *ptr = _val;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
365 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
366 return PCIBIOS_SUCCESSFUL;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
367 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
368 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
369
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
370 #if !defined(__powerpc__)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
371 struct pci_config_reg {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
372 /* start of official PCI config space header */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
373 union {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
374 unsigned long device_vendor;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
375 struct {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
376 unsigned short vendor;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
377 unsigned short device;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
378 } dv;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
379 } dv_id;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
380 #define _device_vendor dv_id.device_vendor
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
381 #define _vendor dv_id.dv.vendor
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
382 #define _device dv_id.dv.device
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
383 union {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
384 unsigned long status_command;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
385 struct {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
386 unsigned short command;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
387 unsigned short status;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
388 } sc;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
389 } stat_cmd;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
390 #define _status_command stat_cmd.status_command
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
391 #define _command stat_cmd.sc.command
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
392 #define _status stat_cmd.sc.status
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
393 union {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
394 unsigned long class_revision;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
395 struct {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
396 unsigned char rev_id;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
397 unsigned char prog_if;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
398 unsigned char sub_class;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
399 unsigned char base_class;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
400 } cr;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
401 } class_rev;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
402 #define _class_revision class_rev.class_revision
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
403 #define _rev_id class_rev.cr.rev_id
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
404 #define _prog_if class_rev.cr.prog_if
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
405 #define _sub_class class_rev.cr.sub_class
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
406 #define _base_class class_rev.cr.base_class
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
407 union {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
408 unsigned long bist_header_latency_cache;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
409 struct {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
410 unsigned char cache_line_size;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
411 unsigned char latency_timer;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
412 unsigned char header_type;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
413 unsigned char bist;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
414 } bhlc;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
415 } bhlc;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
416 #define _bist_header_latency_cache bhlc.bist_header_latency_cache
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
417 #define _cache_line_size bhlc.bhlc.cache_line_size
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
418 #define _latency_timer bhlc.bhlc.latency_timer
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
419 #define _header_type bhlc.bhlc.header_type
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
420 #define _bist bhlc.bhlc.bist
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
421 union {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
422 struct {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
423 unsigned long dv_base0;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
424 unsigned long dv_base1;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
425 unsigned long dv_base2;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
426 unsigned long dv_base3;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
427 unsigned long dv_base4;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
428 unsigned long dv_base5;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
429 } dv;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
430 struct {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
431 unsigned long bg_rsrvd[2];
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
432 unsigned char primary_bus_number;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
433 unsigned char secondary_bus_number;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
434 unsigned char subordinate_bus_number;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
435 unsigned char secondary_latency_timer;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
436 unsigned char io_base;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
437 unsigned char io_limit;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
438 unsigned short secondary_status;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
439 unsigned short mem_base;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
440 unsigned short mem_limit;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
441 unsigned short prefetch_mem_base;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
442 unsigned short prefetch_mem_limit;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
443 } bg;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
444 } bc;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
445 #define _base0 bc.dv.dv_base0
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
446 #define _base1 bc.dv.dv_base1
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
447 #define _base2 bc.dv.dv_base2
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
448 #define _base3 bc.dv.dv_base3
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
449 #define _base4 bc.dv.dv_base4
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
450 #define _base5 bc.dv.dv_base5
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
451 #define _primary_bus_number bc.bg.primary_bus_number
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
452 #define _secondary_bus_number bc.bg.secondary_bus_number
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
453 #define _subordinate_bus_number bc.bg.subordinate_bus_number
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
454 #define _secondary_latency_timer bc.bg.secondary_latency_timer
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
455 #define _io_base bc.bg.io_base
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
456 #define _io_limit bc.bg.io_limit
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
457 #define _secondary_status bc.bg.secondary_status
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
458 #define _mem_base bc.bg.mem_base
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
459 #define _mem_limit bc.bg.mem_limit
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
460 #define _prefetch_mem_base bc.bg.prefetch_mem_base
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
461 #define _prefetch_mem_limit bc.bg.prefetch_mem_limit
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
462 unsigned long rsvd1;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
463 unsigned long rsvd2;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
464 unsigned long _baserom;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
465 unsigned long rsvd3;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
466 unsigned long rsvd4;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
467 union {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
468 unsigned long max_min_ipin_iline;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
469 struct {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
470 unsigned char int_line;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
471 unsigned char int_pin;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
472 unsigned char min_gnt;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
473 unsigned char max_lat;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
474 } mmii;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
475 } mmii;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
476 #define _max_min_ipin_iline mmii.max_min_ipin_iline
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
477 #define _int_line mmii.mmii.int_line
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
478 #define _int_pin mmii.mmii.int_pin
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
479 #define _min_gnt mmii.mmii.min_gnt
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
480 #define _max_lat mmii.mmii.max_lat
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
481 /* I don't know how accurate or standard this is (DHD) */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
482 union {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
483 unsigned long user_config;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
484 struct {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
485 unsigned char user_config_0;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
486 unsigned char user_config_1;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
487 unsigned char user_config_2;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
488 unsigned char user_config_3;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
489 } uc;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
490 } uc;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
491 #define _user_config uc.user_config
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
492 #define _user_config_0 uc.uc.user_config_0
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
493 #define _user_config_1 uc.uc.user_config_1
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
494 #define _user_config_2 uc.uc.user_config_2
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
495 #define _user_config_3 uc.uc.user_config_3
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
496 /* end of official PCI config space header */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
497 unsigned long _pcibusidx;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
498 unsigned long _pcinumbus;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
499 unsigned long _pcibuses[16];
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
500 unsigned short _configtype; /* config type found */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
501 unsigned short _ioaddr; /* config type 1 - private I/O addr */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
502 unsigned long _cardnum; /* config type 2 - private card number */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
503 };
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
504 #else
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
505 /* ppc is big endian, swapping bytes is not quite enough
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
506 * to interpret the PCI config registers...
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
507 */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
508 struct pci_config_reg {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
509 /* start of official PCI config space header */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
510 union {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
511 unsigned long device_vendor;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
512 struct {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
513 unsigned short device;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
514 unsigned short vendor;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
515 } dv;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
516 } dv_id;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
517 #define _device_vendor dv_id.device_vendor
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
518 #define _vendor dv_id.dv.vendor
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
519 #define _device dv_id.dv.device
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
520 union {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
521 unsigned long status_command;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
522 struct {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
523 unsigned short status;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
524 unsigned short command;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
525 } sc;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
526 } stat_cmd;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
527 #define _status_command stat_cmd.status_command
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
528 #define _command stat_cmd.sc.command
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
529 #define _status stat_cmd.sc.status
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
530 union {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
531 unsigned long class_revision;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
532 struct {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
533 unsigned char base_class;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
534 unsigned char sub_class;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
535 unsigned char prog_if;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
536 unsigned char rev_id;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
537 } cr;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
538 } class_rev;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
539 #define _class_revision class_rev.class_revision
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
540 #define _rev_id class_rev.cr.rev_id
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
541 #define _prog_if class_rev.cr.prog_if
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
542 #define _sub_class class_rev.cr.sub_class
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
543 #define _base_class class_rev.cr.base_class
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
544 union {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
545 unsigned long bist_header_latency_cache;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
546 struct {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
547 unsigned char bist;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
548 unsigned char header_type;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
549 unsigned char latency_timer;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
550 unsigned char cache_line_size;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
551 } bhlc;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
552 } bhlc;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
553 #define _bist_header_latency_cache bhlc.bist_header_latency_cache
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
554 #define _cache_line_size bhlc.bhlc.cache_line_size
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
555 #define _latency_timer bhlc.bhlc.latency_timer
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
556 #define _header_type bhlc.bhlc.header_type
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
557 #define _bist bhlc.bhlc.bist
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
558 union {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
559 struct {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
560 unsigned long dv_base0;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
561 unsigned long dv_base1;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
562 unsigned long dv_base2;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
563 unsigned long dv_base3;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
564 unsigned long dv_base4;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
565 unsigned long dv_base5;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
566 } dv;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
567 /* ?? */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
568 struct {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
569 unsigned long bg_rsrvd[2];
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
570
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
571 unsigned char secondary_latency_timer;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
572 unsigned char subordinate_bus_number;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
573 unsigned char secondary_bus_number;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
574 unsigned char primary_bus_number;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
575
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
576 unsigned short secondary_status;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
577 unsigned char io_limit;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
578 unsigned char io_base;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
579
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
580 unsigned short mem_limit;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
581 unsigned short mem_base;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
582
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
583 unsigned short prefetch_mem_limit;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
584 unsigned short prefetch_mem_base;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
585 } bg;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
586 } bc;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
587 #define _base0 bc.dv.dv_base0
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
588 #define _base1 bc.dv.dv_base1
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
589 #define _base2 bc.dv.dv_base2
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
590 #define _base3 bc.dv.dv_base3
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
591 #define _base4 bc.dv.dv_base4
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
592 #define _base5 bc.dv.dv_base5
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
593 #define _primary_bus_number bc.bg.primary_bus_number
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
594 #define _secondary_bus_number bc.bg.secondary_bus_number
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
595 #define _subordinate_bus_number bc.bg.subordinate_bus_number
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
596 #define _secondary_latency_timer bc.bg.secondary_latency_timer
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
597 #define _io_base bc.bg.io_base
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
598 #define _io_limit bc.bg.io_limit
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
599 #define _secondary_status bc.bg.secondary_status
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
600 #define _mem_base bc.bg.mem_base
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
601 #define _mem_limit bc.bg.mem_limit
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
602 #define _prefetch_mem_base bc.bg.prefetch_mem_base
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
603 #define _prefetch_mem_limit bc.bg.prefetch_mem_limit
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
604 unsigned long rsvd1;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
605 unsigned long rsvd2;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
606 unsigned long _baserom;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
607 unsigned long rsvd3;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
608 unsigned long rsvd4;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
609 union {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
610 unsigned long max_min_ipin_iline;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
611 struct {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
612 unsigned char max_lat;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
613 unsigned char min_gnt;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
614 unsigned char int_pin;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
615 unsigned char int_line;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
616 } mmii;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
617 } mmii;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
618 #define _max_min_ipin_iline mmii.max_min_ipin_iline
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
619 #define _int_line mmii.mmii.int_line
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
620 #define _int_pin mmii.mmii.int_pin
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
621 #define _min_gnt mmii.mmii.min_gnt
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
622 #define _max_lat mmii.mmii.max_lat
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
623 /* I don't know how accurate or standard this is (DHD) */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
624 union {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
625 unsigned long user_config;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
626 struct {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
627 unsigned char user_config_3;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
628 unsigned char user_config_2;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
629 unsigned char user_config_1;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
630 unsigned char user_config_0;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
631 } uc;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
632 } uc;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
633 #define _user_config uc.user_config
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
634 #define _user_config_0 uc.uc.user_config_0
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
635 #define _user_config_1 uc.uc.user_config_1
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
636 #define _user_config_2 uc.uc.user_config_2
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
637 #define _user_config_3 uc.uc.user_config_3
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
638 /* end of official PCI config space header */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
639 unsigned long _pcibusidx;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
640 unsigned long _pcinumbus;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
641 unsigned long _pcibuses[16];
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
642 unsigned short _ioaddr; /* config type 1 - private I/O addr */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
643 unsigned short _configtype; /* config type found */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
644 unsigned long _cardnum; /* config type 2 - private card number */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
645 };
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
646 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
647
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
648 #define MAX_DEV_PER_VENDOR_CFG1 64
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
649 #define MAX_PCI_DEVICES_PER_BUS 32
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
650 #define MAX_PCI_DEVICES 64
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
651 #define NF ((void (*)())NULL), { 0.0, 0, 0, NULL }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
652 #define PCI_MULTIFUNC_DEV 0x80
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
653 #if defined(__alpha__) || defined(__powerpc__)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
654 #define PCI_ID_REG 0x00
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
655 #define PCI_CMD_STAT_REG 0x04
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
656 #define PCI_CLASS_REG 0x08
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
657 #define PCI_HEADER_MISC 0x0C
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
658 #define PCI_MAP_REG_START 0x10
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
659 #define PCI_MAP_ROM_REG 0x30
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
660 #define PCI_INTERRUPT_REG 0x3C
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
661 #define PCI_REG_USERCONFIG 0x40
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
662 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
663
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
664 static int pcibus=-1, pcicard=-1, pcifunc=-1 ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
665 /*static struct pci_device *pcidev=NULL ;*/
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
666
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
667 #if defined(__alpha__)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
668 #define PCI_EN 0x00000000
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
669 #else
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
670 #define PCI_EN 0x80000000
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
671 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
672
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
673 #define PCI_MODE1_ADDRESS_REG 0xCF8
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
674 #define PCI_MODE1_DATA_REG 0xCFC
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
675
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
676 #define PCI_MODE2_ENABLE_REG 0xCF8
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
677 #ifdef PC98
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
678 #define PCI_MODE2_FORWARD_REG 0xCF9
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
679 #else
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
680 #define PCI_MODE2_FORWARD_REG 0xCFA
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
681 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
682
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
683 static int pcicards=0 ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
684 static pciinfo_t *pci_lst;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
685
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
686 static void identify_card(struct pci_config_reg *pcr)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
687 {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
688
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
689 if (pcicards>=MAX_PCI_DEVICES) return ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
690
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
691 pci_lst[pcicards].bus = pcibus ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
692 pci_lst[pcicards].card = pcicard ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
693 pci_lst[pcicards].func = pcifunc ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
694 pci_lst[pcicards].vendor = pcr->_vendor ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
695 pci_lst[pcicards].device = pcr->_device ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
696 pci_lst[pcicards].base0 = 0xFFFFFFFF ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
697 pci_lst[pcicards].base1 = 0xFFFFFFFF ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
698 pci_lst[pcicards].base2 = 0xFFFFFFFF ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
699 pci_lst[pcicards].baserom = 0x000C0000 ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
700 if (pcr->_base0) pci_lst[pcicards].base0 = pcr->_base0 &
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
701 ((pcr->_base0&0x1) ? 0xFFFFFFFC : 0xFFFFFFF0) ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
702 if (pcr->_base1) pci_lst[pcicards].base1 = pcr->_base1 &
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
703 ((pcr->_base1&0x1) ? 0xFFFFFFFC : 0xFFFFFFF0) ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
704 if (pcr->_base2) pci_lst[pcicards].base2 = pcr->_base2 &
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
705 ((pcr->_base2&0x1) ? 0xFFFFFFFC : 0xFFFFFFF0) ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
706 if (pcr->_baserom) pci_lst[pcicards].baserom = pcr->_baserom ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
707
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
708 pcicards++;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
709 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
710
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
711 static int io_fd;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
712 #ifdef __EMX__
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
713 static USHORT callgate[3] = {0,0,0};
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
714 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
715
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
716 static void enable_os_io(void)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
717 {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
718 io_fd = -1 ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
719 #if defined(SVR4) || defined(SCO) || defined(ISC)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
720 #if defined(SI86IOPL)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
721 sysi86(SI86IOPL, 3);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
722 #else
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
723 sysi86(SI86V86, V86SC_IOPL, PS_IOPL);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
724 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
725 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
726 #if defined(linux)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
727 iopl(3);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
728 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
729 #if defined(__FreeBSD__) || defined(__386BSD__) || defined(__bsdi__)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
730 if ((io_fd = open("/dev/console", O_RDWR, 0)) < 0) {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
731 perror("/dev/console");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
732 exit(1);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
733 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
734 #if defined(__FreeBSD__) || defined(__386BSD__)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
735 if (ioctl(io_fd, KDENABIO, 0) < 0) {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
736 perror("ioctl(KDENABIO)");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
737 exit(1);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
738 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
739 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
740 #if defined(__bsdi__)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
741 if (ioctl(io_fd, PCCONENABIOPL, 0) < 0) {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
742 perror("ioctl(PCCONENABIOPL)");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
743 exit(1);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
744 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
745 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
746 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
747 #if defined(__NetBSD__)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
748 #if !defined(USE_I386_IOPL)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
749 if ((io_fd = open("/dev/io", O_RDWR, 0)) < 0) {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
750 perror("/dev/io");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
751 exit(1);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
752 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
753 #else
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
754 if (i386_iopl(1) < 0) {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
755 perror("i386_iopl");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
756 exit(1);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
757 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
758 #endif /* USE_I386_IOPL */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
759 #endif /* __NetBSD__ */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
760 #if defined(__OpenBSD__)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
761 if (i386_iopl(1) < 0) {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
762 perror("i386_iopl");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
763 exit(1);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
764 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
765 #endif /* __OpenBSD__ */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
766 #if defined(MACH386)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
767 if ((io_fd = open("/dev/iopl", O_RDWR, 0)) < 0) {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
768 perror("/dev/iopl");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
769 exit(1);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
770 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
771 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
772 #ifdef __EMX__
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
773 {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
774 HFILE hfd;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
775 ULONG dlen,action;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
776 APIRET rc;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
777 static char *ioDrvPath = "/dev/fastio$";
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
778
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
779 if (DosOpen((PSZ)ioDrvPath, (PHFILE)&hfd, (PULONG)&action,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
780 (ULONG)0, FILE_SYSTEM, FILE_OPEN,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
781 OPEN_SHARE_DENYNONE|OPEN_FLAGS_NOINHERIT|OPEN_ACCESS_READONLY,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
782 (ULONG)0) != 0) {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
783 fprintf(stderr,"Error opening fastio$ driver...\n");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
784 fprintf(stderr,"Please install xf86sup.sys in config.sys!\n");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
785 exit(42);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
786 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
787 callgate[0] = callgate[1] = 0;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
788
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
789 /* Get callgate from driver for fast io to ports and other stuff */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
790
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
791 rc = DosDevIOCtl(hfd, (ULONG)0x76, (ULONG)0x64,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
792 NULL, 0, NULL,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
793 (ULONG*)&callgate[2], sizeof(USHORT), &dlen);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
794 if (rc) {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
795 fprintf(stderr,"xf86-OS/2: EnableIOPorts failed, rc=%d, dlen=%d; emergency exit\n",
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
796 rc,dlen);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
797 DosClose(hfd);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
798 exit(42);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
799 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
800
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
801 /* Calling callgate with function 13 sets IOPL for the program */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
802
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
803 asm volatile ("movl $13,%%ebx;.byte 0xff,0x1d;.long _callgate"
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
804 : /*no outputs */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
805 : /*no inputs */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
806 : "eax","ebx","ecx","edx","cc");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
807
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
808 DosClose(hfd);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
809 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
810 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
811 #if defined(Lynx) && defined(__powerpc__)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
812 pciConfBase = (unsigned char *) smem_create("PCI-CONF",
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
813 (char *)0x80800000, 64*1024, SM_READ|SM_WRITE);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
814 if (pciConfBase == (void *) -1)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
815 exit(1);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
816 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
817 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
818
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
819
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
820 static void disable_os_io(void)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
821 {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
822 #if defined(SVR4) || defined(SCO) || defined(ISC)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
823 #if defined(SI86IOPL)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
824 sysi86(SI86IOPL, 0);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
825 #else
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
826 sysi86(SI86V86, V86SC_IOPL, 0);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
827 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
828 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
829 #if defined(linux)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
830 iopl(0);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
831 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
832 #if defined(__FreeBSD__) || defined(__386BSD__)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
833 if (ioctl(io_fd, KDDISABIO, 0) < 0) {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
834 perror("ioctl(KDDISABIO)");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
835 close(io_fd);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
836 exit(1);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
837 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
838 close(io_fd);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
839 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
840 #if defined(__NetBSD__)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
841 #if !defined(USE_I386_IOPL)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
842 close(io_fd);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
843 #else
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
844 if (i386_iopl(0) < 0) {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
845 perror("i386_iopl");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
846 exit(1);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
847 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
848 #endif /* NetBSD1_1 */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
849 #endif /* __NetBSD__ */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
850 #if defined(__bsdi__)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
851 if (ioctl(io_fd, PCCONDISABIOPL, 0) < 0) {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
852 perror("ioctl(PCCONDISABIOPL)");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
853 close(io_fd);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
854 exit(1);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
855 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
856 close(io_fd);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
857 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
858 #if defined(MACH386)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
859 close(io_fd);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
860 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
861 #if defined(Lynx) && defined(__powerpc__)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
862 smem_create(NULL, (char *) pciConfBase, 0, SM_DETACH);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
863 smem_remove("PCI-CONF");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
864 pciConfBase = NULL;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
865 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
866 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
867
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
868 /*main(int argc, char *argv[])*/
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
869 int pci_scan(pciinfo_t *pci_list,unsigned *num_pci)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
870 {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
871 unsigned long tmplong1, tmplong2, config_cmd;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
872 unsigned char tmp1, tmp2;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
873 unsigned int idx;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
874 struct pci_config_reg pcr;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
875 int do_mode1_scan = 0, do_mode2_scan = 0;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
876 int func, hostbridges=0;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
877
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
878 pci_lst = pci_list;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
879
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
880 enable_os_io();
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
881
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
882 #if !defined(__alpha__) && !defined(__powerpc__)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
883 pcr._configtype = 0;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
884
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
885 outb(PCI_MODE2_ENABLE_REG, 0x00);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
886 outb(PCI_MODE2_FORWARD_REG, 0x00);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
887 tmp1 = inb(PCI_MODE2_ENABLE_REG);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
888 tmp2 = inb(PCI_MODE2_FORWARD_REG);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
889 if ((tmp1 == 0x00) && (tmp2 == 0x00)) {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
890 pcr._configtype = 2;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
891 /*printf("PCI says configuration type 2\n");*/
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
892 } else {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
893 tmplong1 = inl(PCI_MODE1_ADDRESS_REG);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
894 outl(PCI_MODE1_ADDRESS_REG, PCI_EN);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
895 tmplong2 = inl(PCI_MODE1_ADDRESS_REG);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
896 outl(PCI_MODE1_ADDRESS_REG, tmplong1);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
897 if (tmplong2 == PCI_EN) {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
898 pcr._configtype = 1;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
899 /*printf("PCI says configuration type 1\n");*/
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
900 } else {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
901 /*printf("No PCI !\n");*/
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
902 disable_os_io();
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
903 /*exit(1);*/
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
904 return ENODEV ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
905 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
906 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
907 #else
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
908 pcr._configtype = 1;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
909 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
910
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
911 /* Try pci config 1 probe first */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
912
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
913 if ((pcr._configtype == 1) || do_mode1_scan) {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
914 /*printf("\nPCI probing configuration type 1\n");*/
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
915
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
916 pcr._ioaddr = 0xFFFF;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
917
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
918 pcr._pcibuses[0] = 0;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
919 pcr._pcinumbus = 1;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
920 pcr._pcibusidx = 0;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
921 idx = 0;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
922
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
923 do {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
924 /*printf("Probing for devices on PCI bus %d:\n\n", pcr._pcibusidx);*/
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
925
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
926 for (pcr._cardnum = 0x0; pcr._cardnum < MAX_PCI_DEVICES_PER_BUS;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
927 pcr._cardnum += 0x1) {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
928 func = 0;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
929 do { /* loop over the different functions, if present */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
930 #if !defined(__alpha__) && !defined(__powerpc__)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
931 config_cmd = PCI_EN | (pcr._pcibuses[pcr._pcibusidx]<<16) |
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
932 (pcr._cardnum<<11) | (func<<8);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
933
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
934 outl(PCI_MODE1_ADDRESS_REG, config_cmd); /* ioreg 0 */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
935 pcr._device_vendor = inl(PCI_MODE1_DATA_REG);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
936 #else
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
937 pciconfig_read(pcr._pcibuses[pcr._pcibusidx], pcr._cardnum<<3,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
938 PCI_ID_REG, 4, &pcr._device_vendor);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
939 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
940
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
941 if ((pcr._vendor == 0xFFFF) || (pcr._device == 0xFFFF))
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
942 break; /* nothing there */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
943
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
944 /*printf("\npci bus 0x%x cardnum 0x%02x function 0x%04x: vendor 0x%04x device 0x%04x\n",
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
945 pcr._pcibuses[pcr._pcibusidx], pcr._cardnum, func,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
946 pcr._vendor, pcr._device);*/
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
947 pcibus = pcr._pcibuses[pcr._pcibusidx] ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
948 pcicard = pcr._cardnum ; pcifunc = func ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
949
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
950 #if !defined(__alpha__) && !defined(__powerpc__)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
951 outl(PCI_MODE1_ADDRESS_REG, config_cmd | 0x04);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
952 pcr._status_command = inl(PCI_MODE1_DATA_REG);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
953 outl(PCI_MODE1_ADDRESS_REG, config_cmd | 0x08);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
954 pcr._class_revision = inl(PCI_MODE1_DATA_REG);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
955 outl(PCI_MODE1_ADDRESS_REG, config_cmd | 0x0C);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
956 pcr._bist_header_latency_cache = inl(PCI_MODE1_DATA_REG);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
957 outl(PCI_MODE1_ADDRESS_REG, config_cmd | 0x10);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
958 pcr._base0 = inl(PCI_MODE1_DATA_REG);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
959 outl(PCI_MODE1_ADDRESS_REG, config_cmd | 0x14);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
960 pcr._base1 = inl(PCI_MODE1_DATA_REG);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
961 outl(PCI_MODE1_ADDRESS_REG, config_cmd | 0x18);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
962 pcr._base2 = inl(PCI_MODE1_DATA_REG);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
963 outl(PCI_MODE1_ADDRESS_REG, config_cmd | 0x1C);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
964 pcr._base3 = inl(PCI_MODE1_DATA_REG);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
965 outl(PCI_MODE1_ADDRESS_REG, config_cmd | 0x20);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
966 pcr._base4 = inl(PCI_MODE1_DATA_REG);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
967 outl(PCI_MODE1_ADDRESS_REG, config_cmd | 0x24);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
968 pcr._base5 = inl(PCI_MODE1_DATA_REG);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
969 outl(PCI_MODE1_ADDRESS_REG, config_cmd | 0x30);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
970 pcr._baserom = inl(PCI_MODE1_DATA_REG);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
971 outl(PCI_MODE1_ADDRESS_REG, config_cmd | 0x3C);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
972 pcr._max_min_ipin_iline = inl(PCI_MODE1_DATA_REG);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
973 outl(PCI_MODE1_ADDRESS_REG, config_cmd | 0x40);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
974 pcr._user_config = inl(PCI_MODE1_DATA_REG);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
975 #else
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
976 pciconfig_read(pcr._pcibuses[pcr._pcibusidx], pcr._cardnum<<3,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
977 PCI_CMD_STAT_REG, 4, &pcr._status_command);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
978 pciconfig_read(pcr._pcibuses[pcr._pcibusidx], pcr._cardnum<<3,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
979 PCI_CLASS_REG, 4, &pcr._class_revision);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
980 pciconfig_read(pcr._pcibuses[pcr._pcibusidx], pcr._cardnum<<3,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
981 PCI_HEADER_MISC, 4, &pcr._bist_header_latency_cache);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
982 pciconfig_read(pcr._pcibuses[pcr._pcibusidx], pcr._cardnum<<3,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
983 PCI_MAP_REG_START, 4, &pcr._base0);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
984 pciconfig_read(pcr._pcibuses[pcr._pcibusidx], pcr._cardnum<<3,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
985 PCI_MAP_REG_START + 0x04, 4, &pcr._base1);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
986 pciconfig_read(pcr._pcibuses[pcr._pcibusidx], pcr._cardnum<<3,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
987 PCI_MAP_REG_START + 0x08, 4, &pcr._base2);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
988 pciconfig_read(pcr._pcibuses[pcr._pcibusidx], pcr._cardnum<<3,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
989 PCI_MAP_REG_START + 0x0C, 4, &pcr._base3);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
990 pciconfig_read(pcr._pcibuses[pcr._pcibusidx], pcr._cardnum<<3,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
991 PCI_MAP_REG_START + 0x10, 4, &pcr._base4);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
992 pciconfig_read(pcr._pcibuses[pcr._pcibusidx], pcr._cardnum<<3,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
993 PCI_MAP_REG_START + 0x14, 4, &pcr._base5);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
994 pciconfig_read(pcr._pcibuses[pcr._pcibusidx], pcr._cardnum<<3,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
995 PCI_MAP_ROM_REG, 4, &pcr._baserom);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
996 pciconfig_read(pcr._pcibuses[pcr._pcibusidx], pcr._cardnum<<3,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
997 PCI_INTERRUPT_REG, 4, &pcr._max_min_ipin_iline);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
998 pciconfig_read(pcr._pcibuses[pcr._pcibusidx], pcr._cardnum<<3,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
999 PCI_REG_USERCONFIG, 4, &pcr._user_config);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1000 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1001
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1002 /* check for pci-pci bridges */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1003 #define PCI_CLASS_MASK 0xff000000
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1004 #define PCI_SUBCLASS_MASK 0x00ff0000
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1005 #define PCI_CLASS_BRIDGE 0x06000000
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1006 #define PCI_SUBCLASS_BRIDGE_PCI 0x00040000
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1007 switch(pcr._class_revision & (PCI_CLASS_MASK|PCI_SUBCLASS_MASK)) {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1008 case PCI_CLASS_BRIDGE|PCI_SUBCLASS_BRIDGE_PCI:
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1009 if (pcr._secondary_bus_number > 0) {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1010 pcr._pcibuses[pcr._pcinumbus++] = pcr._secondary_bus_number;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1011 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1012 break;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1013 case PCI_CLASS_BRIDGE:
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1014 if ( ++hostbridges > 1) {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1015 pcr._pcibuses[pcr._pcinumbus] = pcr._pcinumbus;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1016 pcr._pcinumbus++;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1017 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1018 break;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1019 default:
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1020 break;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1021 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1022 if((func==0) && ((pcr._header_type & PCI_MULTIFUNC_DEV) == 0)) {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1023 /* not a multi function device */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1024 func = 8;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1025 } else {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1026 func++;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1027 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1028
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1029 if (idx++ >= MAX_PCI_DEVICES)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1030 continue;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1031
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1032 identify_card(&pcr);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1033 } while( func < 8 );
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1034 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1035 } while (++pcr._pcibusidx < pcr._pcinumbus);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1036 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1037
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1038 #if !defined(__alpha__) && !defined(__powerpc__)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1039 /* Now try pci config 2 probe (deprecated) */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1040
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1041 if ((pcr._configtype == 2) || do_mode2_scan) {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1042 outb(PCI_MODE2_ENABLE_REG, 0xF1);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1043 outb(PCI_MODE2_FORWARD_REG, 0x00); /* bus 0 for now */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1044
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1045 /*printf("\nPCI probing configuration type 2\n");*/
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1046
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1047 pcr._pcibuses[0] = 0;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1048 pcr._pcinumbus = 1;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1049 pcr._pcibusidx = 0;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1050 idx = 0;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1051
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1052 do {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1053 for (pcr._ioaddr = 0xC000; pcr._ioaddr < 0xD000; pcr._ioaddr += 0x0100){
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1054 outb(PCI_MODE2_FORWARD_REG, pcr._pcibuses[pcr._pcibusidx]); /* bus 0 for now */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1055 pcr._device_vendor = inl(pcr._ioaddr);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1056 outb(PCI_MODE2_FORWARD_REG, 0x00); /* bus 0 for now */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1057
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1058 if ((pcr._vendor == 0xFFFF) || (pcr._device == 0xFFFF))
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1059 continue;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1060 if ((pcr._vendor == 0xF0F0) || (pcr._device == 0xF0F0))
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1061 continue; /* catch ASUS P55TP4XE motherboards */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1062
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1063 /*printf("\npci bus 0x%x slot at 0x%04x, vendor 0x%04x device 0x%04x\n",
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1064 pcr._pcibuses[pcr._pcibusidx], pcr._ioaddr, pcr._vendor,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1065 pcr._device);*/
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1066 pcibus = pcr._pcibuses[pcr._pcibusidx] ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1067 pcicard = pcr._ioaddr ; pcifunc = 0 ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1068
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1069 outb(PCI_MODE2_FORWARD_REG, pcr._pcibuses[pcr._pcibusidx]); /* bus 0 for now */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1070 pcr._status_command = inl(pcr._ioaddr + 0x04);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1071 pcr._class_revision = inl(pcr._ioaddr + 0x08);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1072 pcr._bist_header_latency_cache = inl(pcr._ioaddr + 0x0C);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1073 pcr._base0 = inl(pcr._ioaddr + 0x10);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1074 pcr._base1 = inl(pcr._ioaddr + 0x14);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1075 pcr._base2 = inl(pcr._ioaddr + 0x18);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1076 pcr._base3 = inl(pcr._ioaddr + 0x1C);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1077 pcr._base4 = inl(pcr._ioaddr + 0x20);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1078 pcr._base5 = inl(pcr._ioaddr + 0x24);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1079 pcr._baserom = inl(pcr._ioaddr + 0x30);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1080 pcr._max_min_ipin_iline = inl(pcr._ioaddr + 0x3C);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1081 pcr._user_config = inl(pcr._ioaddr + 0x40);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1082 outb(PCI_MODE2_FORWARD_REG, 0x00); /* bus 0 for now */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1083
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1084 /* check for pci-pci bridges (currently we only know Digital) */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1085 if ((pcr._vendor == 0x1011) && (pcr._device == 0x0001))
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1086 if (pcr._secondary_bus_number > 0)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1087 pcr._pcibuses[pcr._pcinumbus++] = pcr._secondary_bus_number;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1088
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1089 if (idx++ >= MAX_PCI_DEVICES)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1090 continue;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1091
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1092 identify_card(&pcr);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1093 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1094 } while (++pcr._pcibusidx < pcr._pcinumbus);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1095
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1096 outb(PCI_MODE2_ENABLE_REG, 0x00);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1097 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1098
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1099 #endif /* __alpha__ */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1100
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1101 disable_os_io();
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1102 *num_pci = pcicards;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1103
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1104 return 0 ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1105
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1106 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1107
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1108 #if 0
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1109 void
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1110 print_i128(struct pci_config_reg *pcr)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1111 {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1112 /*
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1113 if (pcr->_status_command)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1114 printf(" STATUS 0x%04x COMMAND 0x%04x\n",
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1115 pcr->_status, pcr->_command);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1116 if (pcr->_class_revision)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1117 printf(" CLASS 0x%02x 0x%02x 0x%02x REVISION 0x%02x\n",
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1118 pcr->_base_class, pcr->_sub_class, pcr->_prog_if, pcr->_rev_id);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1119 if (pcr->_bist_header_latency_cache)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1120 printf(" BIST 0x%02x HEADER 0x%02x LATENCY 0x%02x CACHE 0x%02x\n",
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1121 pcr->_bist, pcr->_header_type, pcr->_latency_timer,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1122 pcr->_cache_line_size);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1123 printf(" MW0_AD 0x%08x addr 0x%08x %spre-fetchable\n",
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1124 pcr->_base0, pcr->_base0 & 0xFFC00000,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1125 pcr->_base0 & 0x8 ? "" : "not-");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1126 printf(" MW1_AD 0x%08x addr 0x%08x %spre-fetchable\n",
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1127 pcr->_base1, pcr->_base1 & 0xFFC00000,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1128 pcr->_base1 & 0x8 ? "" : "not-");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1129 printf(" XYW_AD(A) 0x%08x addr 0x%08x\n",
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1130 pcr->_base2, pcr->_base2 & 0xFFC00000);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1131 printf(" XYW_AD(B) 0x%08x addr 0x%08x\n",
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1132 pcr->_base3, pcr->_base3 & 0xFFC00000);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1133 printf(" RBASE_G 0x%08x addr 0x%08x\n",
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1134 pcr->_base4, pcr->_base4 & 0xFFFF0000);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1135 printf(" IO 0x%08x addr 0x%08x\n",
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1136 pcr->_base5, pcr->_base5 & 0xFFFFFF00);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1137 printf(" RBASE_E 0x%08x addr 0x%08x %sdecode-enabled\n",
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1138 pcr->_baserom, pcr->_baserom & 0xFFFF8000,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1139 pcr->_baserom & 0x1 ? "" : "not-");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1140 if (pcr->_max_min_ipin_iline)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1141 printf(" MAX_LAT 0x%02x MIN_GNT 0x%02x INT_PIN 0x%02x INT_LINE 0x%02x\n",
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1142 pcr->_max_lat, pcr->_min_gnt, pcr->_int_pin, pcr->_int_line);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1143 */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1144 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1145
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1146 void
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1147 print_pcibridge(struct pci_config_reg *pcr)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1148 {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1149 /*
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1150 if (pcr->_status_command)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1151 printf(" STATUS 0x%04x COMMAND 0x%04x\n",
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1152 pcr->_status, pcr->_command);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1153 if (pcr->_class_revision)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1154 printf(" CLASS 0x%02x 0x%02x 0x%02x REVISION 0x%02x\n",
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1155 pcr->_base_class, pcr->_sub_class, pcr->_prog_if, pcr->_rev_id);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1156 if (pcr->_bist_header_latency_cache)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1157 printf(" BIST 0x%02x HEADER 0x%02x LATENCY 0x%02x CACHE 0x%02x\n",
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1158 pcr->_bist, pcr->_header_type, pcr->_latency_timer,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1159 pcr->_cache_line_size);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1160 printf(" PRIBUS 0x%02x SECBUS 0x%02x SUBBUS 0x%02x SECLT 0x%02x\n",
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1161 pcr->_primary_bus_number, pcr->_secondary_bus_number,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1162 pcr->_subordinate_bus_number, pcr->_secondary_latency_timer);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1163 printf(" IOBASE: 0x%02x00 IOLIM 0x%02x00 SECSTATUS 0x%04x\n",
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1164 pcr->_io_base, pcr->_io_limit, pcr->_secondary_status);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1165 printf(" NOPREFETCH MEMBASE: 0x%08x MEMLIM 0x%08x\n",
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1166 pcr->_mem_base, pcr->_mem_limit);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1167 printf(" PREFETCH MEMBASE: 0x%08x MEMLIM 0x%08x\n",
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1168 pcr->_prefetch_mem_base, pcr->_prefetch_mem_limit);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1169 printf(" RBASE_E 0x%08x addr 0x%08x %sdecode-enabled\n",
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1170 pcr->_baserom, pcr->_baserom & 0xFFFF8000,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1171 pcr->_baserom & 0x1 ? "" : "not-");
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1172 if (pcr->_max_min_ipin_iline)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1173 printf(" MAX_LAT 0x%02x MIN_GNT 0x%02x INT_PIN 0x%02x INT_LINE 0x%02x\n",
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1174 pcr->_max_lat, pcr->_min_gnt, pcr->_int_pin, pcr->_int_line);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1175 */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1176 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
1177 #endif