2 * Copyright (C) 1994-2003 The XFree86 Project, Inc. All Rights Reserved.
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE
19 * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 * Except as contained in this notice, the name of the XFree86 Project
24 * shall not be used in advertising or otherwise to promote the sale,
25 * use or other dealings in this Software without prior written
26 * authorization from the XFree86 Project.
29 #ifdef HAVE_XORG_CONFIG_H
30 #include <xorg-config.h>
33 #include <sys/types.h>
35 #include <sys/ioctl.h>
39 #include <dev/pci/pciio.h>
43 #include "xf86OSpriv.h"
47 static CARD32
netbsdPciConfRead(PCITAG
, int);
48 static void netbsdPciConfWrite(PCITAG
, int, CARD32
);
49 static void netbsdPciSetBits(PCITAG
, int, CARD32
, CARD32
);
51 static int devpci
= -1;
53 static pciBusFuncs_t netbsdFuncs0
= {
54 /* pciReadLong */ netbsdPciConfRead
,
55 /* pciWriteLong */ netbsdPciConfWrite
,
56 /* pciSetBitsLong */ netbsdPciSetBits
,
57 /* pciAddrHostToBus */ pciAddrNOOP
,
58 /* pciAddrBusToHost */ pciAddrNOOP
61 static pciBusInfo_t netbsdPci0
= {
62 /* configMech */ PCI_CFG_MECH_OTHER
,
64 /* secondary */ FALSE
,
66 /* funcs */ &netbsdFuncs0
,
67 /* pciBusPriv */ NULL
,
74 struct pciio_businfo pci_businfo
;
76 devpci
= open("/dev/pci0", O_RDWR
);
78 FatalError("netbsdPciInit: can't open /dev/pci0\n");
81 pciBusInfo
[0] = &netbsdPci0
;
82 pciFindFirstFP
= pciGenFindFirst
;
83 pciFindNextFP
= pciGenFindNext
;
84 /* use businfo to get the number of devs */
85 if (ioctl(devpci
, PCI_IOC_BUSINFO
, &pci_businfo
) != 0)
86 FatalError("netbsdPciInit: not a PCI bus device");
87 netbsdPci0
.numDevices
= pci_businfo
.maxdevs
;
91 netbsdPciConfRead(PCITAG tag
, int reg
)
93 struct pciio_bdf_cfgreg bdfr
;
95 bdfr
.bus
= PCI_BUS_FROM_TAG(tag
);
96 bdfr
.device
= PCI_DEV_FROM_TAG(tag
);
97 bdfr
.function
= PCI_FUNC_FROM_TAG(tag
);
98 bdfr
.cfgreg
.reg
= reg
;
100 if (ioctl(devpci
, PCI_IOC_BDF_CFGREAD
, &bdfr
) == -1)
101 FatalError("netbsdPciConfRead: failed on %d/%d/%d\n",
102 bdfr
.bus
, bdfr
.device
, bdfr
.function
);
104 return (bdfr
.cfgreg
.val
);
108 netbsdPciConfWrite(PCITAG tag
, int reg
, CARD32 val
)
110 struct pciio_bdf_cfgreg bdfr
;
112 bdfr
.bus
= PCI_BUS_FROM_TAG(tag
);
113 bdfr
.device
= PCI_DEV_FROM_TAG(tag
);
114 bdfr
.function
= PCI_FUNC_FROM_TAG(tag
);
115 bdfr
.cfgreg
.reg
= reg
;
116 bdfr
.cfgreg
.val
= val
;
118 if (ioctl(devpci
, PCI_IOC_BDF_CFGWRITE
, &bdfr
) == -1)
119 FatalError("netbsdPciConfWrite: failed on %d/%d/%d\n",
120 bdfr
.bus
, bdfr
.device
, bdfr
.function
);
124 netbsdPciSetBits(PCITAG tag
, int reg
, CARD32 mask
, CARD32 bits
)
128 val
= netbsdPciConfRead(tag
, reg
);
129 val
= (val
& ~mask
) | (bits
& mask
);
130 netbsdPciConfWrite(tag
, reg
, val
);