annotate libdha/pci.c @ 6458:766505ef1c33

10l
author michael
date Mon, 17 Jun 2002 17:12:22 +0000
parents 567de708ab3a
children 9dbb9c710480
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 /* $XConsortium: scanpci.c /main/25 1996/10/27 11:48:40 kaleb $ */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
6 /*
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
7 * name: scanpci.c
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
8 *
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
9 * purpose: This program will scan for and print details of
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
10 * devices on the PCI bus.
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
11
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
12 * author: Robin Cutshaw (robin@xfree86.org)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
13 *
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
14 * supported O/S's: SVR4, UnixWare, SCO, Solaris,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
15 * FreeBSD, NetBSD, 386BSD, BSDI BSD/386,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
16 * Linux, Mach/386, ISC
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
17 * DOS (WATCOM 9.5 compiler)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
18 *
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
19 * compiling: [g]cc scanpci.c -o scanpci
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
20 * for SVR4 (not Solaris), UnixWare use:
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
21 * [g]cc -DSVR4 scanpci.c -o scanpci
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
22 * for DOS, watcom 9.5:
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
23 * wcc386p -zq -omaxet -7 -4s -s -w3 -d2 name.c
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
24 * and link with PharLap or other dos extender for exe
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
25 *
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
26 */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
27
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
28 /* $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
29
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
30 /*
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
31 * Copyright 1995 by Robin Cutshaw <robin@XFree86.Org>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
32 *
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
33 * Permission to use, copy, modify, distribute, and sell this software and its
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
34 * documentation for any purpose is hereby granted without fee, provided that
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
35 * the above copyright notice appear in all copies and that both that
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
36 * copyright notice and this permission notice appear in supporting
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
37 * documentation, and that the names of the above listed copyright holder(s)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
38 * not be used in advertising or publicity pertaining to distribution of
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
39 * the software without specific, written prior permission. The above listed
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
40 * copyright holder(s) make(s) no representations about the suitability of this
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
41 * software for any purpose. It is provided "as is" without express or
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
42 * implied warranty.
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
43 *
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
44 * THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM(S) ALL WARRANTIES WITH REGARD
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
45 * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
46 * AND FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
47 * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
48 * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
49 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
50 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
51 *
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
52 */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
53
4164
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
54 #include "libdha.h"
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
55 #include <errno.h>
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
56 #include <string.h>
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
57 #include <stdio.h>
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
58 #ifdef __unix__
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
59 #include <unistd.h>
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
60 #endif
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
61 #include "AsmMacros.h"
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
62 /* OS depended stuff */
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
63 #if defined (linux)
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
64 #include "sysdep/pci_linux.c"
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
65 #elif defined (__FreeBSD__)
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
66 #include "sysdep/pci_freebsd.c"
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
67 #elif defined (__386BSD__)
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
68 #include "sysdep/pci_386bsd.c"
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
69 #elif defined (__NetBSD__)
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
70 #include "sysdep/pci_netbsd.c"
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
71 #elif defined (__OpenBSD__)
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
72 #include "sysdep/pci_openbsd.c"
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
73 #elif defined (__bsdi__)
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
74 #include "sysdep/pci_bsdi.c"
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
75 #elif defined (Lynx)
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
76 #include "sysdep/pci_lynx.c"
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
77 #elif defined (MACH386)
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
78 #include "sysdep/pci_mach386.c"
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
79 #elif defined (__SVR4)
3973
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
80 #if !defined(SVR4)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
81 #define SVR4
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
82 #endif
4164
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
83 #include "sysdep/pci_svr4.c"
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
84 #elif defined (SCO)
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
85 #include "sysdep/pci_sco.c"
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
86 #elif defined (ISC)
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
87 #include "sysdep/pci_isc.c"
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
88 #elif defined (__EMX__)
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
89 #include "sysdep/pci_os2.c"
4173
250f39dedede cygwin compile fix
atmos4
parents: 4164
diff changeset
90 #elif defined (_WIN32) || defined(__CYGWIN__)
4164
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
91 #include "sysdep/pci_win32.c"
3973
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
92 #endif
4164
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
93
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
94 #if 0
3973
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
95 #if defined(__SUNPRO_C) || defined(sun) || defined(__sun)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
96 #include <sys/psw.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
97 #else
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
98 #include <sys/seg.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
99 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
100 #include <sys/v86.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
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
103 #if defined(Lynx) && defined(__powerpc__)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
104 /* 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
105 * to change too much code
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
106 */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
107 #include <smem.h>
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
108
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
109 static unsigned char *pciConfBase;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
110
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
111 static __inline__ unsigned long
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
112 static swapl(unsigned long val)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
113 {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
114 unsigned char *p = (unsigned char *)&val;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
115 return ((p[3] << 24) | (p[2] << 16) | (p[1] << 8) | (p[0] << 0));
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
116 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
117
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
118
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
119 #define BUS(tag) (((tag)>>16)&0xff)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
120 #define DFN(tag) (((tag)>>8)&0xff)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
121
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
122 #define PCIBIOS_DEVICE_NOT_FOUND 0x86
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
123 #define PCIBIOS_SUCCESSFUL 0x00
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
124
4174
4cfb6b9a6da3 api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents: 4173
diff changeset
125 int pciconfig_read(
3973
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
126 unsigned char bus,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
127 unsigned char dev,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
128 unsigned char offset,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
129 int len, /* unused, alway 4 */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
130 unsigned long *val)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
131 {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
132 unsigned long _val;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
133 unsigned long *ptr;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
134
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
135 dev >>= 3;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
136 if (bus || dev >= 16) {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
137 *val = 0xFFFFFFFF;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
138 return PCIBIOS_DEVICE_NOT_FOUND;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
139 } else {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
140 ptr = (unsigned long *)(pciConfBase + ((1<<dev) | offset));
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
141 _val = swapl(*ptr);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
142 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
143 *val = _val;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
144 return PCIBIOS_SUCCESSFUL;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
145 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
146
4174
4cfb6b9a6da3 api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents: 4173
diff changeset
147 int pciconfig_write(
3973
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
148 unsigned char bus,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
149 unsigned char dev,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
150 unsigned char offset,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
151 int len, /* unused, alway 4 */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
152 unsigned long val)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
153 {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
154 unsigned long _val;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
155 unsigned long *ptr;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
156
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
157 dev >>= 3;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
158 _val = swapl(val);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
159 if (bus || dev >= 16) {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
160 return PCIBIOS_DEVICE_NOT_FOUND;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
161 } else {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
162 ptr = (unsigned long *)(pciConfBase + ((1<<dev) | offset));
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
163 *ptr = _val;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
164 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
165 return PCIBIOS_SUCCESSFUL;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
166 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
167 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
168
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
169 #if !defined(__powerpc__)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
170 struct pci_config_reg {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
171 /* start of official PCI config space header */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
172 union {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
173 unsigned long device_vendor;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
174 struct {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
175 unsigned short vendor;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
176 unsigned short device;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
177 } dv;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
178 } dv_id;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
179 #define _device_vendor dv_id.device_vendor
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
180 #define _vendor dv_id.dv.vendor
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
181 #define _device dv_id.dv.device
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
182 union {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
183 unsigned long status_command;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
184 struct {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
185 unsigned short command;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
186 unsigned short status;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
187 } sc;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
188 } stat_cmd;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
189 #define _status_command stat_cmd.status_command
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
190 #define _command stat_cmd.sc.command
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
191 #define _status stat_cmd.sc.status
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
192 union {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
193 unsigned long class_revision;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
194 struct {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
195 unsigned char rev_id;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
196 unsigned char prog_if;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
197 unsigned char sub_class;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
198 unsigned char base_class;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
199 } cr;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
200 } class_rev;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
201 #define _class_revision class_rev.class_revision
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
202 #define _rev_id class_rev.cr.rev_id
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
203 #define _prog_if class_rev.cr.prog_if
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
204 #define _sub_class class_rev.cr.sub_class
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
205 #define _base_class class_rev.cr.base_class
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
206 union {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
207 unsigned long bist_header_latency_cache;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
208 struct {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
209 unsigned char cache_line_size;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
210 unsigned char latency_timer;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
211 unsigned char header_type;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
212 unsigned char bist;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
213 } bhlc;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
214 } bhlc;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
215 #define _bist_header_latency_cache bhlc.bist_header_latency_cache
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
216 #define _cache_line_size bhlc.bhlc.cache_line_size
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
217 #define _latency_timer bhlc.bhlc.latency_timer
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
218 #define _header_type bhlc.bhlc.header_type
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
219 #define _bist bhlc.bhlc.bist
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
220 union {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
221 struct {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
222 unsigned long dv_base0;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
223 unsigned long dv_base1;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
224 unsigned long dv_base2;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
225 unsigned long dv_base3;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
226 unsigned long dv_base4;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
227 unsigned long dv_base5;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
228 } dv;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
229 struct {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
230 unsigned long bg_rsrvd[2];
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
231 unsigned char primary_bus_number;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
232 unsigned char secondary_bus_number;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
233 unsigned char subordinate_bus_number;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
234 unsigned char secondary_latency_timer;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
235 unsigned char io_base;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
236 unsigned char io_limit;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
237 unsigned short secondary_status;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
238 unsigned short mem_base;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
239 unsigned short mem_limit;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
240 unsigned short prefetch_mem_base;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
241 unsigned short prefetch_mem_limit;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
242 } bg;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
243 } bc;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
244 #define _base0 bc.dv.dv_base0
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
245 #define _base1 bc.dv.dv_base1
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
246 #define _base2 bc.dv.dv_base2
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
247 #define _base3 bc.dv.dv_base3
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
248 #define _base4 bc.dv.dv_base4
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
249 #define _base5 bc.dv.dv_base5
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
250 #define _primary_bus_number bc.bg.primary_bus_number
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
251 #define _secondary_bus_number bc.bg.secondary_bus_number
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
252 #define _subordinate_bus_number bc.bg.subordinate_bus_number
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
253 #define _secondary_latency_timer bc.bg.secondary_latency_timer
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
254 #define _io_base bc.bg.io_base
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
255 #define _io_limit bc.bg.io_limit
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
256 #define _secondary_status bc.bg.secondary_status
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
257 #define _mem_base bc.bg.mem_base
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
258 #define _mem_limit bc.bg.mem_limit
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
259 #define _prefetch_mem_base bc.bg.prefetch_mem_base
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
260 #define _prefetch_mem_limit bc.bg.prefetch_mem_limit
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
261 unsigned long rsvd1;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
262 unsigned long rsvd2;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
263 unsigned long _baserom;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
264 unsigned long rsvd3;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
265 unsigned long rsvd4;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
266 union {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
267 unsigned long max_min_ipin_iline;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
268 struct {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
269 unsigned char int_line;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
270 unsigned char int_pin;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
271 unsigned char min_gnt;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
272 unsigned char max_lat;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
273 } mmii;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
274 } mmii;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
275 #define _max_min_ipin_iline mmii.max_min_ipin_iline
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
276 #define _int_line mmii.mmii.int_line
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
277 #define _int_pin mmii.mmii.int_pin
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
278 #define _min_gnt mmii.mmii.min_gnt
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
279 #define _max_lat mmii.mmii.max_lat
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
280 /* I don't know how accurate or standard this is (DHD) */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
281 union {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
282 unsigned long user_config;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
283 struct {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
284 unsigned char user_config_0;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
285 unsigned char user_config_1;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
286 unsigned char user_config_2;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
287 unsigned char user_config_3;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
288 } uc;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
289 } uc;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
290 #define _user_config uc.user_config
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
291 #define _user_config_0 uc.uc.user_config_0
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
292 #define _user_config_1 uc.uc.user_config_1
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
293 #define _user_config_2 uc.uc.user_config_2
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
294 #define _user_config_3 uc.uc.user_config_3
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
295 /* end of official PCI config space header */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
296 unsigned long _pcibusidx;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
297 unsigned long _pcinumbus;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
298 unsigned long _pcibuses[16];
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
299 unsigned short _configtype; /* config type found */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
300 unsigned short _ioaddr; /* config type 1 - private I/O addr */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
301 unsigned long _cardnum; /* config type 2 - private card number */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
302 };
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
303 #else
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
304 /* ppc is big endian, swapping bytes is not quite enough
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
305 * to interpret the PCI config registers...
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
306 */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
307 struct pci_config_reg {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
308 /* start of official PCI config space header */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
309 union {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
310 unsigned long device_vendor;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
311 struct {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
312 unsigned short device;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
313 unsigned short vendor;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
314 } dv;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
315 } dv_id;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
316 #define _device_vendor dv_id.device_vendor
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
317 #define _vendor dv_id.dv.vendor
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
318 #define _device dv_id.dv.device
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
319 union {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
320 unsigned long status_command;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
321 struct {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
322 unsigned short status;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
323 unsigned short command;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
324 } sc;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
325 } stat_cmd;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
326 #define _status_command stat_cmd.status_command
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
327 #define _command stat_cmd.sc.command
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
328 #define _status stat_cmd.sc.status
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
329 union {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
330 unsigned long class_revision;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
331 struct {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
332 unsigned char base_class;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
333 unsigned char sub_class;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
334 unsigned char prog_if;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
335 unsigned char rev_id;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
336 } cr;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
337 } class_rev;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
338 #define _class_revision class_rev.class_revision
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
339 #define _rev_id class_rev.cr.rev_id
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
340 #define _prog_if class_rev.cr.prog_if
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
341 #define _sub_class class_rev.cr.sub_class
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
342 #define _base_class class_rev.cr.base_class
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
343 union {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
344 unsigned long bist_header_latency_cache;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
345 struct {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
346 unsigned char bist;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
347 unsigned char header_type;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
348 unsigned char latency_timer;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
349 unsigned char cache_line_size;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
350 } bhlc;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
351 } bhlc;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
352 #define _bist_header_latency_cache bhlc.bist_header_latency_cache
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
353 #define _cache_line_size bhlc.bhlc.cache_line_size
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
354 #define _latency_timer bhlc.bhlc.latency_timer
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
355 #define _header_type bhlc.bhlc.header_type
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
356 #define _bist bhlc.bhlc.bist
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
357 union {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
358 struct {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
359 unsigned long dv_base0;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
360 unsigned long dv_base1;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
361 unsigned long dv_base2;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
362 unsigned long dv_base3;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
363 unsigned long dv_base4;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
364 unsigned long dv_base5;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
365 } dv;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
366 /* ?? */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
367 struct {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
368 unsigned long bg_rsrvd[2];
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
369
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
370 unsigned char secondary_latency_timer;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
371 unsigned char subordinate_bus_number;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
372 unsigned char secondary_bus_number;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
373 unsigned char primary_bus_number;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
374
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
375 unsigned short secondary_status;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
376 unsigned char io_limit;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
377 unsigned char io_base;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
378
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
379 unsigned short mem_limit;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
380 unsigned short mem_base;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
381
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
382 unsigned short prefetch_mem_limit;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
383 unsigned short prefetch_mem_base;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
384 } bg;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
385 } bc;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
386 #define _base0 bc.dv.dv_base0
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
387 #define _base1 bc.dv.dv_base1
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
388 #define _base2 bc.dv.dv_base2
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
389 #define _base3 bc.dv.dv_base3
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
390 #define _base4 bc.dv.dv_base4
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
391 #define _base5 bc.dv.dv_base5
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
392 #define _primary_bus_number bc.bg.primary_bus_number
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
393 #define _secondary_bus_number bc.bg.secondary_bus_number
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
394 #define _subordinate_bus_number bc.bg.subordinate_bus_number
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
395 #define _secondary_latency_timer bc.bg.secondary_latency_timer
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
396 #define _io_base bc.bg.io_base
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
397 #define _io_limit bc.bg.io_limit
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
398 #define _secondary_status bc.bg.secondary_status
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
399 #define _mem_base bc.bg.mem_base
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
400 #define _mem_limit bc.bg.mem_limit
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
401 #define _prefetch_mem_base bc.bg.prefetch_mem_base
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
402 #define _prefetch_mem_limit bc.bg.prefetch_mem_limit
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
403 unsigned long rsvd1;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
404 unsigned long rsvd2;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
405 unsigned long _baserom;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
406 unsigned long rsvd3;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
407 unsigned long rsvd4;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
408 union {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
409 unsigned long max_min_ipin_iline;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
410 struct {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
411 unsigned char max_lat;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
412 unsigned char min_gnt;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
413 unsigned char int_pin;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
414 unsigned char int_line;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
415 } mmii;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
416 } mmii;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
417 #define _max_min_ipin_iline mmii.max_min_ipin_iline
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
418 #define _int_line mmii.mmii.int_line
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
419 #define _int_pin mmii.mmii.int_pin
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
420 #define _min_gnt mmii.mmii.min_gnt
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
421 #define _max_lat mmii.mmii.max_lat
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
422 /* I don't know how accurate or standard this is (DHD) */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
423 union {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
424 unsigned long user_config;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
425 struct {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
426 unsigned char user_config_3;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
427 unsigned char user_config_2;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
428 unsigned char user_config_1;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
429 unsigned char user_config_0;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
430 } uc;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
431 } uc;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
432 #define _user_config uc.user_config
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
433 #define _user_config_0 uc.uc.user_config_0
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
434 #define _user_config_1 uc.uc.user_config_1
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
435 #define _user_config_2 uc.uc.user_config_2
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
436 #define _user_config_3 uc.uc.user_config_3
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
437 /* end of official PCI config space header */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
438 unsigned long _pcibusidx;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
439 unsigned long _pcinumbus;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
440 unsigned long _pcibuses[16];
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
441 unsigned short _ioaddr; /* config type 1 - private I/O addr */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
442 unsigned short _configtype; /* config type found */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
443 unsigned long _cardnum; /* config type 2 - private card number */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
444 };
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
445 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
446
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
447 #define MAX_DEV_PER_VENDOR_CFG1 64
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
448 #define MAX_PCI_DEVICES_PER_BUS 32
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
449 #define MAX_PCI_DEVICES 64
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
450 #define NF ((void (*)())NULL), { 0.0, 0, 0, NULL }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
451 #define PCI_MULTIFUNC_DEV 0x80
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
452 #define PCI_ID_REG 0x00
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
453 #define PCI_CMD_STAT_REG 0x04
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
454 #define PCI_CLASS_REG 0x08
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
455 #define PCI_HEADER_MISC 0x0C
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
456 #define PCI_MAP_REG_START 0x10
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
457 #define PCI_MAP_ROM_REG 0x30
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
458 #define PCI_INTERRUPT_REG 0x3C
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
459 #define PCI_REG_USERCONFIG 0x40
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
460
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
461 static int pcibus=-1, pcicard=-1, pcifunc=-1 ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
462 /*static struct pci_device *pcidev=NULL ;*/
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
463
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
464 #if defined(__alpha__)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
465 #define PCI_EN 0x00000000
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
466 #else
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
467 #define PCI_EN 0x80000000
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
468 #endif
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
469
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
470 #define PCI_MODE1_ADDRESS_REG 0xCF8
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
471 #define PCI_MODE1_DATA_REG 0xCFC
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
472
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
473 #define PCI_MODE2_ENABLE_REG 0xCF8
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
474 #ifdef PC98
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
475 #define PCI_MODE2_FORWARD_REG 0xCF9
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
476 #else
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
477 #define PCI_MODE2_FORWARD_REG 0xCFA
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
478 #endif
4164
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
479
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
480 /* cpu depended stuff */
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
481 #if defined(__alpha__)
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
482 #include "sysdep/pci_alpha.c"
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
483 #elif defined(__ia64__)
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
484 #include "sysdep/pci_ia64.c"
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
485 #elif defined(__sparc__)
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
486 #include "sysdep/pci_sparc.c"
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
487 #elif defined( __arm32__ )
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
488 #include "sysdep/pci_arm32.c"
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
489 #elif defined(__powerpc__)
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
490 #include "sysdep/pci_powerpc.c"
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
491 #else
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
492 #include "sysdep/pci_x86.c"
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
493 #endif
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
494
3973
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
495
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
496 static int pcicards=0 ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
497 static pciinfo_t *pci_lst;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
498
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
499 static void identify_card(struct pci_config_reg *pcr)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
500 {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
501
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
502 if (pcicards>=MAX_PCI_DEVICES) return ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
503
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
504 pci_lst[pcicards].bus = pcibus ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
505 pci_lst[pcicards].card = pcicard ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
506 pci_lst[pcicards].func = pcifunc ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
507 pci_lst[pcicards].vendor = pcr->_vendor ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
508 pci_lst[pcicards].device = pcr->_device ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
509 pci_lst[pcicards].base0 = 0xFFFFFFFF ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
510 pci_lst[pcicards].base1 = 0xFFFFFFFF ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
511 pci_lst[pcicards].base2 = 0xFFFFFFFF ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
512 pci_lst[pcicards].baserom = 0x000C0000 ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
513 if (pcr->_base0) pci_lst[pcicards].base0 = pcr->_base0 &
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
514 ((pcr->_base0&0x1) ? 0xFFFFFFFC : 0xFFFFFFF0) ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
515 if (pcr->_base1) pci_lst[pcicards].base1 = pcr->_base1 &
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
516 ((pcr->_base1&0x1) ? 0xFFFFFFFC : 0xFFFFFFF0) ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
517 if (pcr->_base2) pci_lst[pcicards].base2 = pcr->_base2 &
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
518 ((pcr->_base2&0x1) ? 0xFFFFFFFC : 0xFFFFFFF0) ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
519 if (pcr->_baserom) pci_lst[pcicards].baserom = pcr->_baserom ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
520
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
521 pcicards++;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
522 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
523
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
524 /*main(int argc, char *argv[])*/
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
525 int pci_scan(pciinfo_t *pci_list,unsigned *num_pci)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
526 {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
527 unsigned int idx;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
528 struct pci_config_reg pcr;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
529 int do_mode1_scan = 0, do_mode2_scan = 0;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
530 int func, hostbridges=0;
4174
4cfb6b9a6da3 api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents: 4173
diff changeset
531 int ret = -1;
3973
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
532
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
533 pci_lst = pci_list;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
534
4174
4cfb6b9a6da3 api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents: 4173
diff changeset
535 ret = enable_os_io();
4cfb6b9a6da3 api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents: 4173
diff changeset
536 if (ret != 0)
4cfb6b9a6da3 api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents: 4173
diff changeset
537 return(ret);
4164
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
538
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
539 if((pcr._configtype = pci_config_type()) == 0xFFFF) return ENODEV;
3973
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
540
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
541 /* Try pci config 1 probe first */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
542
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
543 if ((pcr._configtype == 1) || do_mode1_scan) {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
544 /*printf("\nPCI probing configuration type 1\n");*/
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
545
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
546 pcr._ioaddr = 0xFFFF;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
547
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
548 pcr._pcibuses[0] = 0;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
549 pcr._pcinumbus = 1;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
550 pcr._pcibusidx = 0;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
551 idx = 0;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
552
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
553 do {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
554 /*printf("Probing for devices on PCI bus %d:\n\n", pcr._pcibusidx);*/
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
555
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
556 for (pcr._cardnum = 0x0; pcr._cardnum < MAX_PCI_DEVICES_PER_BUS;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
557 pcr._cardnum += 0x1) {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
558 func = 0;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
559 do { /* loop over the different functions, if present */
4164
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
560 pcr._device_vendor = pci_get_vendor(pcr._pcibuses[pcr._pcibusidx], pcr._cardnum,
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
561 func);
3973
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
562 if ((pcr._vendor == 0xFFFF) || (pcr._device == 0xFFFF))
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
563 break; /* nothing there */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
564
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
565 /*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
566 pcr._pcibuses[pcr._pcibusidx], pcr._cardnum, func,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
567 pcr._vendor, pcr._device);*/
4164
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
568 pcibus = pcr._pcibuses[pcr._pcibusidx];
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
569 pcicard = pcr._cardnum;
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
570 pcifunc = func;
3973
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
571
4164
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
572 pcr._status_command = pci_config_read_long(pcr._pcibuses[pcr._pcibusidx],
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
573 pcr._cardnum,func,PCI_CMD_STAT_REG);
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
574 pcr._class_revision = pci_config_read_long(pcr._pcibuses[pcr._pcibusidx],
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
575 pcr._cardnum,func,PCI_CLASS_REG);
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
576 pcr._bist_header_latency_cache = pci_config_read_long(pcr._pcibuses[pcr._pcibusidx],
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
577 pcr._cardnum,func,PCI_HEADER_MISC);
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
578 pcr._base0 = pci_config_read_long(pcr._pcibuses[pcr._pcibusidx],
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
579 pcr._cardnum,func,PCI_MAP_REG_START);
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
580 pcr._base1 = pci_config_read_long(pcr._pcibuses[pcr._pcibusidx],
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
581 pcr._cardnum,func,PCI_MAP_REG_START+4);
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
582 pcr._base2 = pci_config_read_long(pcr._pcibuses[pcr._pcibusidx],
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
583 pcr._cardnum,func,PCI_MAP_REG_START+8);
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
584 pcr._base3 = pci_config_read_long(pcr._pcibuses[pcr._pcibusidx],
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
585 pcr._cardnum,func,PCI_MAP_REG_START+0x0C);
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
586 pcr._base4 = pci_config_read_long(pcr._pcibuses[pcr._pcibusidx],
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
587 pcr._cardnum,func,PCI_MAP_REG_START+0x10);
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
588 pcr._base5 = pci_config_read_long(pcr._pcibuses[pcr._pcibusidx],
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
589 pcr._cardnum,func,PCI_MAP_REG_START+0x14);
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
590 pcr._baserom = pci_config_read_long(pcr._pcibuses[pcr._pcibusidx],
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
591 pcr._cardnum,func,PCI_MAP_ROM_REG);
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
592 pcr._max_min_ipin_iline = pci_config_read_long(pcr._pcibuses[pcr._pcibusidx],
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
593 pcr._cardnum,func,PCI_INTERRUPT_REG);
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
594 pcr._user_config = pci_config_read_long(pcr._pcibuses[pcr._pcibusidx],
2e3262002acb Improved readability and new stuffs
nick
parents: 4112
diff changeset
595 pcr._cardnum,func,PCI_REG_USERCONFIG);
3973
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
596 /* check for pci-pci bridges */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
597 #define PCI_CLASS_MASK 0xff000000
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
598 #define PCI_SUBCLASS_MASK 0x00ff0000
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
599 #define PCI_CLASS_BRIDGE 0x06000000
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
600 #define PCI_SUBCLASS_BRIDGE_PCI 0x00040000
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
601 switch(pcr._class_revision & (PCI_CLASS_MASK|PCI_SUBCLASS_MASK)) {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
602 case PCI_CLASS_BRIDGE|PCI_SUBCLASS_BRIDGE_PCI:
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
603 if (pcr._secondary_bus_number > 0) {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
604 pcr._pcibuses[pcr._pcinumbus++] = pcr._secondary_bus_number;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
605 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
606 break;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
607 case PCI_CLASS_BRIDGE:
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
608 if ( ++hostbridges > 1) {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
609 pcr._pcibuses[pcr._pcinumbus] = pcr._pcinumbus;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
610 pcr._pcinumbus++;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
611 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
612 break;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
613 default:
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
614 break;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
615 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
616 if((func==0) && ((pcr._header_type & PCI_MULTIFUNC_DEV) == 0)) {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
617 /* not a multi function device */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
618 func = 8;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
619 } else {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
620 func++;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
621 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
622
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
623 if (idx++ >= MAX_PCI_DEVICES)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
624 continue;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
625
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
626 identify_card(&pcr);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
627 } while( func < 8 );
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
628 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
629 } while (++pcr._pcibusidx < pcr._pcinumbus);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
630 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
631
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
632 #if !defined(__alpha__) && !defined(__powerpc__)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
633 /* Now try pci config 2 probe (deprecated) */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
634
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
635 if ((pcr._configtype == 2) || do_mode2_scan) {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
636 outb(PCI_MODE2_ENABLE_REG, 0xF1);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
637 outb(PCI_MODE2_FORWARD_REG, 0x00); /* bus 0 for now */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
638
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
639 /*printf("\nPCI probing configuration type 2\n");*/
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
640
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
641 pcr._pcibuses[0] = 0;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
642 pcr._pcinumbus = 1;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
643 pcr._pcibusidx = 0;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
644 idx = 0;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
645
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
646 do {
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
647 for (pcr._ioaddr = 0xC000; pcr._ioaddr < 0xD000; pcr._ioaddr += 0x0100){
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
648 outb(PCI_MODE2_FORWARD_REG, pcr._pcibuses[pcr._pcibusidx]); /* bus 0 for now */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
649 pcr._device_vendor = inl(pcr._ioaddr);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
650 outb(PCI_MODE2_FORWARD_REG, 0x00); /* bus 0 for now */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
651
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
652 if ((pcr._vendor == 0xFFFF) || (pcr._device == 0xFFFF))
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
653 continue;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
654 if ((pcr._vendor == 0xF0F0) || (pcr._device == 0xF0F0))
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
655 continue; /* catch ASUS P55TP4XE motherboards */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
656
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
657 /*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
658 pcr._pcibuses[pcr._pcibusidx], pcr._ioaddr, pcr._vendor,
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
659 pcr._device);*/
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
660 pcibus = pcr._pcibuses[pcr._pcibusidx] ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
661 pcicard = pcr._ioaddr ; pcifunc = 0 ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
662
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
663 outb(PCI_MODE2_FORWARD_REG, pcr._pcibuses[pcr._pcibusidx]); /* bus 0 for now */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
664 pcr._status_command = inl(pcr._ioaddr + 0x04);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
665 pcr._class_revision = inl(pcr._ioaddr + 0x08);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
666 pcr._bist_header_latency_cache = inl(pcr._ioaddr + 0x0C);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
667 pcr._base0 = inl(pcr._ioaddr + 0x10);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
668 pcr._base1 = inl(pcr._ioaddr + 0x14);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
669 pcr._base2 = inl(pcr._ioaddr + 0x18);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
670 pcr._base3 = inl(pcr._ioaddr + 0x1C);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
671 pcr._base4 = inl(pcr._ioaddr + 0x20);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
672 pcr._base5 = inl(pcr._ioaddr + 0x24);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
673 pcr._baserom = inl(pcr._ioaddr + 0x30);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
674 pcr._max_min_ipin_iline = inl(pcr._ioaddr + 0x3C);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
675 pcr._user_config = inl(pcr._ioaddr + 0x40);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
676 outb(PCI_MODE2_FORWARD_REG, 0x00); /* bus 0 for now */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
677
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
678 /* check for pci-pci bridges (currently we only know Digital) */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
679 if ((pcr._vendor == 0x1011) && (pcr._device == 0x0001))
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
680 if (pcr._secondary_bus_number > 0)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
681 pcr._pcibuses[pcr._pcinumbus++] = pcr._secondary_bus_number;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
682
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
683 if (idx++ >= MAX_PCI_DEVICES)
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
684 continue;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
685
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
686 identify_card(&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 } while (++pcr._pcibusidx < pcr._pcinumbus);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
689
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
690 outb(PCI_MODE2_ENABLE_REG, 0x00);
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
691 }
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
692
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
693 #endif /* __alpha__ */
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
694
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
695 disable_os_io();
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
696 *num_pci = pcicards;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
697
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
698 return 0 ;
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
699
138800dfbe22 preliminary support of direct hardware access
nick
parents:
diff changeset
700 }
4174
4cfb6b9a6da3 api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents: 4173
diff changeset
701
4cfb6b9a6da3 api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents: 4173
diff changeset
702 #if !defined(ENOTSUP)
4cfb6b9a6da3 api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents: 4173
diff changeset
703 #if defined(EOPNOTSUPP)
4cfb6b9a6da3 api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents: 4173
diff changeset
704 #define ENOTSUP EOPNOTSUPP
4cfb6b9a6da3 api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents: 4173
diff changeset
705 #else
4cfb6b9a6da3 api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents: 4173
diff changeset
706 #warning "ENOTSUP nor EOPNOTSUPP defined!"
4cfb6b9a6da3 api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents: 4173
diff changeset
707 #endif
4cfb6b9a6da3 api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents: 4173
diff changeset
708 #endif
4cfb6b9a6da3 api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents: 4173
diff changeset
709
4277
5f74792b6d5e pci_config_read working
alex
parents: 4192
diff changeset
710 int pci_config_read(unsigned char bus, unsigned char dev, unsigned char func,
5f74792b6d5e pci_config_read working
alex
parents: 4192
diff changeset
711 unsigned char cmd, int len, unsigned long *val)
4174
4cfb6b9a6da3 api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents: 4173
diff changeset
712 {
4277
5f74792b6d5e pci_config_read working
alex
parents: 4192
diff changeset
713 int ret;
5f74792b6d5e pci_config_read working
alex
parents: 4192
diff changeset
714
4174
4cfb6b9a6da3 api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents: 4173
diff changeset
715 if (len != 4)
4cfb6b9a6da3 api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents: 4173
diff changeset
716 {
4cfb6b9a6da3 api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents: 4173
diff changeset
717 printf("pci_config_read: reading non-dword not supported!\n");
4cfb6b9a6da3 api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents: 4173
diff changeset
718 return(ENOTSUP);
4cfb6b9a6da3 api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents: 4173
diff changeset
719 }
4cfb6b9a6da3 api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents: 4173
diff changeset
720
4277
5f74792b6d5e pci_config_read working
alex
parents: 4192
diff changeset
721 ret = enable_os_io();
5f74792b6d5e pci_config_read working
alex
parents: 4192
diff changeset
722 if (ret != 0)
5f74792b6d5e pci_config_read working
alex
parents: 4192
diff changeset
723 return(ret);
5f74792b6d5e pci_config_read working
alex
parents: 4192
diff changeset
724 ret = pci_config_read_long(bus, dev, func, cmd);
5f74792b6d5e pci_config_read working
alex
parents: 4192
diff changeset
725 disable_os_io();
5f74792b6d5e pci_config_read working
alex
parents: 4192
diff changeset
726
5f74792b6d5e pci_config_read working
alex
parents: 4192
diff changeset
727 *val = ret;
4174
4cfb6b9a6da3 api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents: 4173
diff changeset
728 return(0);
4cfb6b9a6da3 api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents: 4173
diff changeset
729 }
4192
fb092b45c9cc en(dis)able app io should be exported too
nick
parents: 4174
diff changeset
730
fb092b45c9cc en(dis)able app io should be exported too
nick
parents: 4174
diff changeset
731 int enable_app_io( void )
fb092b45c9cc en(dis)able app io should be exported too
nick
parents: 4174
diff changeset
732 {
fb092b45c9cc en(dis)able app io should be exported too
nick
parents: 4174
diff changeset
733 return enable_os_io();
fb092b45c9cc en(dis)able app io should be exported too
nick
parents: 4174
diff changeset
734 }
fb092b45c9cc en(dis)able app io should be exported too
nick
parents: 4174
diff changeset
735
fb092b45c9cc en(dis)able app io should be exported too
nick
parents: 4174
diff changeset
736 int disable_app_io( void )
fb092b45c9cc en(dis)able app io should be exported too
nick
parents: 4174
diff changeset
737 {
fb092b45c9cc en(dis)able app io should be exported too
nick
parents: 4174
diff changeset
738 return disable_os_io();
5702
567de708ab3a sync with mplayerxp
nick
parents: 4278
diff changeset
739 }