~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to hw/xfree86/os-support/bus/freebsdPci.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
ImportĀ upstreamĀ versionĀ 7.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bus/freebsdPci.c,v 1.4 2002/07/24 19:06:52 tsi Exp $ */
 
2
/*
 
3
 * Copyright 1998 by Concurrent Computer Corporation
 
4
 *
 
5
 * Permission to use, copy, modify, distribute, and sell this software
 
6
 * and its documentation for any purpose is hereby granted without fee,
 
7
 * provided that the above copyright notice appear in all copies and that
 
8
 * both that copyright notice and this permission notice appear in
 
9
 * supporting documentation, and that the name of Concurrent Computer
 
10
 * Corporation not be used in advertising or publicity pertaining to
 
11
 * distribution of the software without specific, written prior
 
12
 * permission.  Concurrent Computer Corporation makes no representations
 
13
 * about the suitability of this software for any purpose.  It is
 
14
 * provided "as is" without express or implied warranty.
 
15
 *
 
16
 * CONCURRENT COMPUTER CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD
 
17
 * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
 
18
 * AND FITNESS, IN NO EVENT SHALL CONCURRENT COMPUTER CORPORATION BE
 
19
 * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
 
20
 * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
 
21
 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
 
22
 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 
23
 * SOFTWARE.
 
24
 *
 
25
 * Copyright 1998 by Metro Link Incorporated
 
26
 *
 
27
 * Permission to use, copy, modify, distribute, and sell this software
 
28
 * and its documentation for any purpose is hereby granted without fee,
 
29
 * provided that the above copyright notice appear in all copies and that
 
30
 * both that copyright notice and this permission notice appear in
 
31
 * supporting documentation, and that the name of Metro Link
 
32
 * Incorporated not be used in advertising or publicity pertaining to
 
33
 * distribution of the software without specific, written prior
 
34
 * permission.  Metro Link Incorporated makes no representations
 
35
 * about the suitability of this software for any purpose.  It is
 
36
 * provided "as is" without express or implied warranty.
 
37
 *
 
38
 * METRO LINK INCORPORATED DISCLAIMS ALL WARRANTIES WITH REGARD
 
39
 * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
 
40
 * AND FITNESS, IN NO EVENT SHALL METRO LINK INCORPORATED BE
 
41
 * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
 
42
 * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
 
43
 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
 
44
 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 
45
 * SOFTWARE.
 
46
 */
 
47
 
 
48
#ifdef HAVE_XORG_CONFIG_H
 
49
#include <xorg-config.h>
 
50
#endif
 
51
 
 
52
#include <stdio.h>
 
53
#include "compiler.h"
 
54
#include "xf86.h"
 
55
#include "xf86Priv.h"
 
56
#include "xf86_OSlib.h"
 
57
#include "Pci.h"
 
58
 
 
59
#include <sys/pciio.h>
 
60
 
 
61
/*
 
62
 * freebsd platform specific PCI access functions -- using /dev/pci
 
63
 * needs kernel version 2.2.x
 
64
 */
 
65
static CARD32 freebsdPciCfgRead(PCITAG tag, int off);
 
66
static void freebsdPciCfgWrite(PCITAG, int off, CARD32 val);
 
67
static void freebsdPciCfgSetBits(PCITAG tag, int off, CARD32 mask, CARD32 bits);
 
68
 
 
69
static pciBusFuncs_t freebsdFuncs0 = {
 
70
/* pciReadLong      */  freebsdPciCfgRead,
 
71
/* pciWriteLong     */  freebsdPciCfgWrite,
 
72
/* pciSetBitsLong   */  freebsdPciCfgSetBits,
 
73
/* pciAddrHostToBus */  pciAddrNOOP,
 
74
/* pciAddrBusToHost */  pciAddrNOOP
 
75
};
 
76
 
 
77
static pciBusInfo_t freebsdPci0 = {
 
78
/* configMech  */       PCI_CFG_MECH_OTHER,
 
79
/* numDevices  */       32,
 
80
/* secondary   */       FALSE,
 
81
/* primary_bus */       0,
 
82
/* funcs       */       &freebsdFuncs0,
 
83
/* pciBusPriv  */       NULL,
 
84
/* bridge      */       NULL
 
85
};
 
86
 
 
87
#if !defined(__OpenBSD__) && !defined(__FreeBSD__)
 
88
#if X_BYTE_ORDER == X_BIG_ENDIAN
 
89
#ifdef __sparc__
 
90
#ifndef ASI_PL
 
91
#define ASI_PL 0x88
 
92
#endif
 
93
#define PCI_CPU(val) ({                                                                 \
 
94
int __ret;                                                                              \
 
95
__asm__ __volatile__("lduwa [%1] %2, %0" : "=r" (__ret) : "r" (&val), "i" (ASI_PL));    \
 
96
__ret;                                                                                  \
 
97
})
 
98
#else
 
99
#define PCI_CPU(val)    (((val >> 24) & 0x000000ff) |   \
 
100
                         ((val >>  8) & 0x0000ff00) |   \
 
101
                         ((val <<  8) & 0x00ff0000) |   \
 
102
                         ((val << 24) & 0xff000000))
 
103
#endif
 
104
#else
 
105
#define PCI_CPU(val)    (val)
 
106
#endif
 
107
#else /* ! OpenBSD */
 
108
/* OpenBSD has already the bytes in the right order
 
109
   for all architectures */
 
110
#define PCI_CPU(val)    (val)
 
111
#endif
 
112
 
 
113
 
 
114
#define BUS(tag) (((tag)>>16)&0xff)
 
115
#define DFN(tag) (((tag)>>8)&0xff)
 
116
 
 
117
static int pciFd = -1;
 
118
 
 
119
void
 
120
freebsdPciInit()
 
121
{
 
122
        pciFd = open("/dev/pci", O_RDWR);
 
123
        if (pciFd < 0)
 
124
                return;
 
125
 
 
126
        pciNumBuses    = 1;
 
127
        pciBusInfo[0]  = &freebsdPci0;
 
128
        pciFindFirstFP = pciGenFindFirst;
 
129
        pciFindNextFP  = pciGenFindNext;
 
130
}
 
131
 
 
132
static CARD32
 
133
freebsdPciCfgRead(PCITAG tag, int off)
 
134
{
 
135
        struct pci_io io;
 
136
        int error;
 
137
        io.pi_sel.pc_bus = BUS(tag);
 
138
        io.pi_sel.pc_dev = DFN(tag) >> 3;
 
139
        io.pi_sel.pc_func = DFN(tag) & 7;
 
140
        io.pi_reg = off;
 
141
        io.pi_width = 4;
 
142
        error = ioctl(pciFd, PCIOCREAD, &io);
 
143
        if (error)
 
144
                return ~0;
 
145
        return PCI_CPU(io.pi_data);
 
146
}
 
147
 
 
148
static void
 
149
freebsdPciCfgWrite(PCITAG tag, int off, CARD32 val)
 
150
{
 
151
        struct pci_io io;
 
152
        io.pi_sel.pc_bus = BUS(tag);
 
153
        io.pi_sel.pc_dev = DFN(tag) >> 3;
 
154
        io.pi_sel.pc_func = DFN(tag) & 7;
 
155
        io.pi_reg = off;
 
156
        io.pi_width = 4;
 
157
        io.pi_data = PCI_CPU(val);
 
158
        ioctl(pciFd, PCIOCWRITE, &io);
 
159
}
 
160
 
 
161
static void
 
162
freebsdPciCfgSetBits(PCITAG tag, int off, CARD32 mask, CARD32 bits)
 
163
{
 
164
        CARD32  val = freebsdPciCfgRead(tag, off);
 
165
        val = (val & ~mask) | (bits & mask);
 
166
        freebsdPciCfgWrite(tag, off, val);
 
167
}