1
/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bus/freebsdPci.c,v 1.4 2002/07/24 19:06:52 tsi Exp $ */
3
* Copyright 1998 by Concurrent Computer Corporation
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.
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
25
* Copyright 1998 by Metro Link Incorporated
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.
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
48
#ifdef HAVE_XORG_CONFIG_H
49
#include <xorg-config.h>
56
#include "xf86_OSlib.h"
59
#include <sys/pciio.h>
62
* freebsd platform specific PCI access functions -- using /dev/pci
63
* needs kernel version 2.2.x
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);
69
static pciBusFuncs_t freebsdFuncs0 = {
70
/* pciReadLong */ freebsdPciCfgRead,
71
/* pciWriteLong */ freebsdPciCfgWrite,
72
/* pciSetBitsLong */ freebsdPciCfgSetBits,
73
/* pciAddrHostToBus */ pciAddrNOOP,
74
/* pciAddrBusToHost */ pciAddrNOOP
77
static pciBusInfo_t freebsdPci0 = {
78
/* configMech */ PCI_CFG_MECH_OTHER,
80
/* secondary */ FALSE,
82
/* funcs */ &freebsdFuncs0,
83
/* pciBusPriv */ NULL,
87
#if !defined(__OpenBSD__) && !defined(__FreeBSD__)
88
#if X_BYTE_ORDER == X_BIG_ENDIAN
93
#define PCI_CPU(val) ({ \
95
__asm__ __volatile__("lduwa [%1] %2, %0" : "=r" (__ret) : "r" (&val), "i" (ASI_PL)); \
99
#define PCI_CPU(val) (((val >> 24) & 0x000000ff) | \
100
((val >> 8) & 0x0000ff00) | \
101
((val << 8) & 0x00ff0000) | \
102
((val << 24) & 0xff000000))
105
#define PCI_CPU(val) (val)
107
#else /* ! OpenBSD */
108
/* OpenBSD has already the bytes in the right order
109
for all architectures */
110
#define PCI_CPU(val) (val)
114
#define BUS(tag) (((tag)>>16)&0xff)
115
#define DFN(tag) (((tag)>>8)&0xff)
117
static int pciFd = -1;
122
pciFd = open("/dev/pci", O_RDWR);
127
pciBusInfo[0] = &freebsdPci0;
128
pciFindFirstFP = pciGenFindFirst;
129
pciFindNextFP = pciGenFindNext;
133
freebsdPciCfgRead(PCITAG tag, int off)
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;
142
error = ioctl(pciFd, PCIOCREAD, &io);
145
return PCI_CPU(io.pi_data);
149
freebsdPciCfgWrite(PCITAG tag, int off, CARD32 val)
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;
157
io.pi_data = PCI_CPU(val);
158
ioctl(pciFd, PCIOCWRITE, &io);
162
freebsdPciCfgSetBits(PCITAG tag, int off, CARD32 mask, CARD32 bits)
164
CARD32 val = freebsdPciCfgRead(tag, off);
165
val = (val & ~mask) | (bits & mask);
166
freebsdPciCfgWrite(tag, off, val);