1*c0da6274SZhi-Jun Robin Fu /*
2*c0da6274SZhi-Jun Robin Fu * CDDL HEADER START
3*c0da6274SZhi-Jun Robin Fu *
4*c0da6274SZhi-Jun Robin Fu * The contents of this file are subject to the terms of the
5*c0da6274SZhi-Jun Robin Fu * Common Development and Distribution License (the "License").
6*c0da6274SZhi-Jun Robin Fu * You may not use this file except in compliance with the License.
7*c0da6274SZhi-Jun Robin Fu *
8*c0da6274SZhi-Jun Robin Fu * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*c0da6274SZhi-Jun Robin Fu * or http://www.opensolaris.org/os/licensing.
10*c0da6274SZhi-Jun Robin Fu * See the License for the specific language governing permissions
11*c0da6274SZhi-Jun Robin Fu * and limitations under the License.
12*c0da6274SZhi-Jun Robin Fu *
13*c0da6274SZhi-Jun Robin Fu * When distributing Covered Code, include this CDDL HEADER in each
14*c0da6274SZhi-Jun Robin Fu * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*c0da6274SZhi-Jun Robin Fu * If applicable, add the following below this CDDL HEADER, with the
16*c0da6274SZhi-Jun Robin Fu * fields enclosed by brackets "[]" replaced with your own identifying
17*c0da6274SZhi-Jun Robin Fu * information: Portions Copyright [yyyy] [name of copyright owner]
18*c0da6274SZhi-Jun Robin Fu *
19*c0da6274SZhi-Jun Robin Fu * CDDL HEADER END
20*c0da6274SZhi-Jun Robin Fu */
21*c0da6274SZhi-Jun Robin Fu /*
22*c0da6274SZhi-Jun Robin Fu * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23*c0da6274SZhi-Jun Robin Fu * Use is subject to license terms.
24*c0da6274SZhi-Jun Robin Fu */
25*c0da6274SZhi-Jun Robin Fu
26*c0da6274SZhi-Jun Robin Fu #include <sys/pci_cfgacc.h>
27*c0da6274SZhi-Jun Robin Fu
28*c0da6274SZhi-Jun Robin Fu #define PCI_CFGACC_FILLREQ(r, d, b, o, s, w, v) \
29*c0da6274SZhi-Jun Robin Fu {(r).rcdip = (d); (r).bdf = (b); (r).offset = (o); \
30*c0da6274SZhi-Jun Robin Fu (r).size = (s); (r).write = w; (r).ioacc = B_FALSE; \
31*c0da6274SZhi-Jun Robin Fu VAL64(&(r)) = (v); }
32*c0da6274SZhi-Jun Robin Fu
33*c0da6274SZhi-Jun Robin Fu /*
34*c0da6274SZhi-Jun Robin Fu * Common interfaces for accessing pci config space
35*c0da6274SZhi-Jun Robin Fu */
36*c0da6274SZhi-Jun Robin Fu
37*c0da6274SZhi-Jun Robin Fu /*
38*c0da6274SZhi-Jun Robin Fu * This pointer should be initialized before using, here doesn't check it.
39*c0da6274SZhi-Jun Robin Fu * For x86:
40*c0da6274SZhi-Jun Robin Fu * initialized at the end of pci_check();
41*c0da6274SZhi-Jun Robin Fu * For Sparc:
42*c0da6274SZhi-Jun Robin Fu * initialized in the px_attach().
43*c0da6274SZhi-Jun Robin Fu */
44*c0da6274SZhi-Jun Robin Fu void (*pci_cfgacc_acc_p)(pci_cfgacc_req_t *req);
45*c0da6274SZhi-Jun Robin Fu
46*c0da6274SZhi-Jun Robin Fu uint8_t
pci_cfgacc_get8(dev_info_t * rcdip,uint16_t bdf,uint16_t off)47*c0da6274SZhi-Jun Robin Fu pci_cfgacc_get8(dev_info_t *rcdip, uint16_t bdf, uint16_t off)
48*c0da6274SZhi-Jun Robin Fu {
49*c0da6274SZhi-Jun Robin Fu pci_cfgacc_req_t req;
50*c0da6274SZhi-Jun Robin Fu
51*c0da6274SZhi-Jun Robin Fu PCI_CFGACC_FILLREQ(req, rcdip, bdf, off, 1, B_FALSE, 0);
52*c0da6274SZhi-Jun Robin Fu (*pci_cfgacc_acc_p)(&req);
53*c0da6274SZhi-Jun Robin Fu return (VAL8(&req));
54*c0da6274SZhi-Jun Robin Fu }
55*c0da6274SZhi-Jun Robin Fu
56*c0da6274SZhi-Jun Robin Fu void
pci_cfgacc_put8(dev_info_t * rcdip,uint16_t bdf,uint16_t off,uint8_t data)57*c0da6274SZhi-Jun Robin Fu pci_cfgacc_put8(dev_info_t *rcdip, uint16_t bdf, uint16_t off, uint8_t data)
58*c0da6274SZhi-Jun Robin Fu {
59*c0da6274SZhi-Jun Robin Fu pci_cfgacc_req_t req;
60*c0da6274SZhi-Jun Robin Fu
61*c0da6274SZhi-Jun Robin Fu PCI_CFGACC_FILLREQ(req, rcdip, bdf, off, 1, B_TRUE, data);
62*c0da6274SZhi-Jun Robin Fu (*pci_cfgacc_acc_p)(&req);
63*c0da6274SZhi-Jun Robin Fu }
64*c0da6274SZhi-Jun Robin Fu
65*c0da6274SZhi-Jun Robin Fu uint16_t
pci_cfgacc_get16(dev_info_t * rcdip,uint16_t bdf,uint16_t off)66*c0da6274SZhi-Jun Robin Fu pci_cfgacc_get16(dev_info_t *rcdip, uint16_t bdf, uint16_t off)
67*c0da6274SZhi-Jun Robin Fu {
68*c0da6274SZhi-Jun Robin Fu pci_cfgacc_req_t req;
69*c0da6274SZhi-Jun Robin Fu
70*c0da6274SZhi-Jun Robin Fu PCI_CFGACC_FILLREQ(req, rcdip, bdf, off, 2, B_FALSE, 0);
71*c0da6274SZhi-Jun Robin Fu (*pci_cfgacc_acc_p)(&req);
72*c0da6274SZhi-Jun Robin Fu return (VAL16(&req));
73*c0da6274SZhi-Jun Robin Fu }
74*c0da6274SZhi-Jun Robin Fu
75*c0da6274SZhi-Jun Robin Fu void
pci_cfgacc_put16(dev_info_t * rcdip,uint16_t bdf,uint16_t off,uint16_t data)76*c0da6274SZhi-Jun Robin Fu pci_cfgacc_put16(dev_info_t *rcdip, uint16_t bdf, uint16_t off, uint16_t data)
77*c0da6274SZhi-Jun Robin Fu {
78*c0da6274SZhi-Jun Robin Fu pci_cfgacc_req_t req;
79*c0da6274SZhi-Jun Robin Fu
80*c0da6274SZhi-Jun Robin Fu PCI_CFGACC_FILLREQ(req, rcdip, bdf, off, 2, B_TRUE, data);
81*c0da6274SZhi-Jun Robin Fu (*pci_cfgacc_acc_p)(&req);
82*c0da6274SZhi-Jun Robin Fu }
83*c0da6274SZhi-Jun Robin Fu
84*c0da6274SZhi-Jun Robin Fu uint32_t
pci_cfgacc_get32(dev_info_t * rcdip,uint16_t bdf,uint16_t off)85*c0da6274SZhi-Jun Robin Fu pci_cfgacc_get32(dev_info_t *rcdip, uint16_t bdf, uint16_t off)
86*c0da6274SZhi-Jun Robin Fu {
87*c0da6274SZhi-Jun Robin Fu pci_cfgacc_req_t req;
88*c0da6274SZhi-Jun Robin Fu
89*c0da6274SZhi-Jun Robin Fu PCI_CFGACC_FILLREQ(req, rcdip, bdf, off, 4, B_FALSE, 0);
90*c0da6274SZhi-Jun Robin Fu (*pci_cfgacc_acc_p)(&req);
91*c0da6274SZhi-Jun Robin Fu return (VAL32(&req));
92*c0da6274SZhi-Jun Robin Fu }
93*c0da6274SZhi-Jun Robin Fu
94*c0da6274SZhi-Jun Robin Fu void
pci_cfgacc_put32(dev_info_t * rcdip,uint16_t bdf,uint16_t off,uint32_t data)95*c0da6274SZhi-Jun Robin Fu pci_cfgacc_put32(dev_info_t *rcdip, uint16_t bdf, uint16_t off, uint32_t data)
96*c0da6274SZhi-Jun Robin Fu {
97*c0da6274SZhi-Jun Robin Fu pci_cfgacc_req_t req;
98*c0da6274SZhi-Jun Robin Fu
99*c0da6274SZhi-Jun Robin Fu PCI_CFGACC_FILLREQ(req, rcdip, bdf, off, 4, B_TRUE, data);
100*c0da6274SZhi-Jun Robin Fu (*pci_cfgacc_acc_p)(&req);
101*c0da6274SZhi-Jun Robin Fu }
102*c0da6274SZhi-Jun Robin Fu
103*c0da6274SZhi-Jun Robin Fu uint64_t
pci_cfgacc_get64(dev_info_t * rcdip,uint16_t bdf,uint16_t off)104*c0da6274SZhi-Jun Robin Fu pci_cfgacc_get64(dev_info_t *rcdip, uint16_t bdf, uint16_t off)
105*c0da6274SZhi-Jun Robin Fu {
106*c0da6274SZhi-Jun Robin Fu pci_cfgacc_req_t req;
107*c0da6274SZhi-Jun Robin Fu
108*c0da6274SZhi-Jun Robin Fu PCI_CFGACC_FILLREQ(req, rcdip, bdf, off, 8, B_FALSE, 0);
109*c0da6274SZhi-Jun Robin Fu (*pci_cfgacc_acc_p)(&req);
110*c0da6274SZhi-Jun Robin Fu return (VAL64(&req));
111*c0da6274SZhi-Jun Robin Fu }
112*c0da6274SZhi-Jun Robin Fu
113*c0da6274SZhi-Jun Robin Fu void
pci_cfgacc_put64(dev_info_t * rcdip,uint16_t bdf,uint16_t off,uint64_t data)114*c0da6274SZhi-Jun Robin Fu pci_cfgacc_put64(dev_info_t *rcdip, uint16_t bdf, uint16_t off, uint64_t data)
115*c0da6274SZhi-Jun Robin Fu {
116*c0da6274SZhi-Jun Robin Fu pci_cfgacc_req_t req;
117*c0da6274SZhi-Jun Robin Fu
118*c0da6274SZhi-Jun Robin Fu PCI_CFGACC_FILLREQ(req, rcdip, bdf, off, 8, B_TRUE, data);
119*c0da6274SZhi-Jun Robin Fu (*pci_cfgacc_acc_p)(&req);
120*c0da6274SZhi-Jun Robin Fu }
121