1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <sys/types.h>
#include <sys/cmn_err.h>
#include <sys/errno.h>
#include <sys/systm.h>
#include <sys/sunddi.h>
#include <sys/pci_cfgspace.h>
#include <sys/pci.h>
#include <sys/pcie.h>
#include <vm/seg_kmem.h>
#include <sys/mman.h>
#include <sys/cpu_module.h>
#include "intel_nhm.h"
static ddi_acc_handle_t dev_pci_hdl[MAX_CPU_NODES][CPU_PCI_DEVS][CPU_PCI_FUNCS];
void
nhm_pci_cfg_setup(dev_info_t *dip)
{
pci_regspec_t reg;
int i, j, k;
reg.pci_phys_mid = 0;
reg.pci_phys_low = 0;
reg.pci_size_hi = 0;
reg.pci_size_low = PCIE_CONF_HDR_SIZE; /* overriden in pciex */
for (i = 0; i < MAX_CPU_NODES; i++) {
for (j = 0; j < CPU_PCI_DEVS; j++) {
for (k = 0; k < CPU_PCI_FUNCS; k++) {
reg.pci_phys_hi = ((SOCKET_BUS(i))
<< PCI_REG_BUS_SHIFT) +
(j << PCI_REG_DEV_SHIFT) +
(k << PCI_REG_FUNC_SHIFT);
if (ddi_prop_update_int_array(
DDI_MAJOR_T_UNKNOWN, dip, "reg",
(int *)®, sizeof (reg)/sizeof (int)) !=
DDI_PROP_SUCCESS)
cmn_err(CE_WARN, "nhm_pci_cfg_setup: "
"cannot create reg property");
if (pci_config_setup(dip,
&dev_pci_hdl[i][j][k]) != DDI_SUCCESS)
cmn_err(CE_WARN, "intel_nhm: "
"pci_config_setup failed");
}
}
}
ddi_prop_remove_all(dip);
}
void
nhm_pci_cfg_free()
{
int i, j, k;
for (i = 0; i < MAX_CPU_NODES; i++) {
for (j = 0; j < CPU_PCI_DEVS; j++) {
for (k = 0; k < CPU_PCI_FUNCS; k++) {
pci_config_teardown(&dev_pci_hdl[i][j][k]);
}
}
}
}
static ddi_acc_handle_t
nhm_get_hdl(int bus, int dev, int func)
{
ddi_acc_handle_t hdl;
int slot;
if (bus >= SOCKET_BUS(MAX_CPU_NODES) && bus <= SOCKET_BUS(0) &&
dev < CPU_PCI_DEVS && func < CPU_PCI_FUNCS) {
slot = SOCKET_BUS(0) - bus;
ASSERT(slot >= 0 && slot < MAX_CPU_NODES);
hdl = dev_pci_hdl[slot][dev][func];
} else {
hdl = 0;
}
return (hdl);
}
uint8_t
nhm_pci_getb(int bus, int dev, int func, int reg, int *interpose)
{
ddi_acc_handle_t hdl;
hdl = nhm_get_hdl(bus, dev, func);
return (cmi_pci_getb(bus, dev, func, reg, interpose, hdl));
}
uint16_t
nhm_pci_getw(int bus, int dev, int func, int reg, int *interpose)
{
ddi_acc_handle_t hdl;
hdl = nhm_get_hdl(bus, dev, func);
return (cmi_pci_getw(bus, dev, func, reg, interpose, hdl));
}
uint32_t
nhm_pci_getl(int bus, int dev, int func, int reg, int *interpose)
{
ddi_acc_handle_t hdl;
hdl = nhm_get_hdl(bus, dev, func);
return (cmi_pci_getl(bus, dev, func, reg, interpose, hdl));
}
void
nhm_pci_putb(int bus, int dev, int func, int reg, uint8_t val)
{
ddi_acc_handle_t hdl;
hdl = nhm_get_hdl(bus, dev, func);
cmi_pci_putb(bus, dev, func, reg, hdl, val);
}
void
nhm_pci_putw(int bus, int dev, int func, int reg, uint16_t val)
{
ddi_acc_handle_t hdl;
hdl = nhm_get_hdl(bus, dev, func);
cmi_pci_putw(bus, dev, func, reg, hdl, val);
}
void
nhm_pci_putl(int bus, int dev, int func, int reg, uint32_t val)
{
ddi_acc_handle_t hdl;
hdl = nhm_get_hdl(bus, dev, func);
cmi_pci_putl(bus, dev, func, reg, hdl, val);
}
|