annotate vidix/sysdep/pci_lynx.c @ 25522:f427bb6d868e

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