4164
|
1 /*
|
|
2 This file is based on:
|
|
3 $XFree86: xc/programs/Xserver/hw/xfree86/etc/scanpci.c,v 3.34.2.17 1998/11/10 11:55:40 dawes Exp $
|
|
4 Modified for readability by Nick Kurshev
|
|
5 */
|
25132
|
6 /*
|
|
7 * Copyright 1995 by Robin Cutshaw <robin@XFree86.Org>
|
|
8 *
|
|
9 * Permission to use, copy, modify, distribute, and sell this software and its
|
|
10 * documentation for any purpose is hereby granted without fee, provided that
|
|
11 * the above copyright notice appear in all copies and that both that
|
|
12 * copyright notice and this permission notice appear in supporting
|
|
13 * documentation, and that the names of the above listed copyright holder(s)
|
|
14 * not be used in advertising or publicity pertaining to distribution of
|
|
15 * the software without specific, written prior permission. The above listed
|
|
16 * copyright holder(s) make(s) no representations about the suitability of this
|
|
17 * software for any purpose. It is provided "as is" without express or
|
|
18 * implied warranty.
|
|
19 *
|
|
20 * THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM(S) ALL WARRANTIES WITH REGARD
|
|
21 * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
22 * AND FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE
|
|
23 * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
|
|
24 * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
|
|
25 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
26 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
27 */
|
4164
|
28
|
|
29 #if defined(Lynx_22)
|
|
30 #ifndef GCCUSESGAS
|
|
31 #define GCCUSESGAS
|
|
32 #endif
|
|
33
|
|
34 /* let's mimick the Linux Alpha stuff for LynxOS so we don't have
|
|
35 * to change too much code
|
|
36 */
|
|
37 #include <smem.h>
|
29263
|
38
|
4164
|
39 static unsigned char *pciConfBase;
|
|
40
|
|
41 static __inline__ void enable_os_io(void)
|
|
42 {
|
|
43 pciConfBase = (unsigned char *) smem_create("PCI-CONF",
|
|
44 (char *)0x80800000, 64*1024, SM_READ|SM_WRITE);
|
|
45 if (pciConfBase == (void *) -1)
|
|
46 exit(1);
|
|
47 }
|
|
48
|
|
49 static __inline__ void disable_os_io(void)
|
|
50 {
|
|
51 smem_create(NULL, (char *) pciConfBase, 0, SM_DETACH);
|
|
52 smem_remove("PCI-CONF");
|
|
53 pciConfBase = NULL;
|
|
54 }
|
|
55
|
|
56 #include <smem.h>
|
29263
|
57
|
4164
|
58 static unsigned char *pciConfBase;
|
29263
|
59
|
4164
|
60 static __inline__ unsigned long
|
|
61 static swapl(unsigned long val)
|
|
62 {
|
|
63 unsigned char *p = (unsigned char *)&val;
|
26753
|
64 return (p[3] << 24) | (p[2] << 16) | (p[1] << 8) | (p[0] << 0);
|
4164
|
65 }
|
29263
|
66
|
|
67
|
4164
|
68 #define BUS(tag) (((tag)>>16)&0xff)
|
|
69 #define DFN(tag) (((tag)>>8)&0xff)
|
29263
|
70
|
4164
|
71 #define PCIBIOS_DEVICE_NOT_FOUND 0x86
|
|
72 #define PCIBIOS_SUCCESSFUL 0x00
|
29263
|
73
|
4164
|
74 static int pciconfig_read(
|
|
75 unsigned char bus,
|
|
76 unsigned char dev,
|
|
77 unsigned char offset,
|
|
78 int len, /* unused, alway 4 */
|
|
79 unsigned long *val)
|
|
80 {
|
|
81 unsigned long _val;
|
|
82 unsigned long *ptr;
|
29263
|
83
|
4164
|
84 dev >>= 3;
|
|
85 if (bus || dev >= 16) {
|
|
86 *val = 0xFFFFFFFF;
|
|
87 return PCIBIOS_DEVICE_NOT_FOUND;
|
|
88 } else {
|
|
89 ptr = (unsigned long *)(pciConfBase + ((1<<dev) | offset));
|
|
90 _val = swapl(*ptr);
|
|
91 }
|
|
92 *val = _val;
|
|
93 return PCIBIOS_SUCCESSFUL;
|
|
94 }
|
29263
|
95
|
4164
|
96 static int pciconfig_write(
|
|
97 unsigned char bus,
|
|
98 unsigned char dev,
|
|
99 unsigned char offset,
|
|
100 int len, /* unused, alway 4 */
|
|
101 unsigned long val)
|
|
102 {
|
|
103 unsigned long _val;
|
|
104 unsigned long *ptr;
|
29263
|
105
|
4164
|
106 dev >>= 3;
|
|
107 _val = swapl(val);
|
|
108 if (bus || dev >= 16) {
|
|
109 return PCIBIOS_DEVICE_NOT_FOUND;
|
|
110 } else {
|
|
111 ptr = (unsigned long *)(pciConfBase + ((1<<dev) | offset));
|
|
112 *ptr = _val;
|
|
113 }
|
|
114 return PCIBIOS_SUCCESSFUL;
|
|
115 }
|