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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
|
/*
* 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/sysmacros.h>
#include <sys/types.h>
#include <sys/kmem.h>
#include <sys/ddi.h>
#include <sys/sunddi.h>
#include <sys/sunndi.h>
#include <sys/promif.h>
#include <sys/pcie.h>
#include <sys/pci_cap.h>
#include <sys/pcie_impl.h>
#include <sys/pcie_acpi.h>
#include <sys/acpi/acpi.h>
#include <sys/acpica.h>
ACPI_STATUS pcie_acpi_eval_osc(dev_info_t *dip, ACPI_HANDLE osc_hdl,
uint32_t *osc_flags);
static ACPI_STATUS pcie_acpi_find_osc(ACPI_HANDLE busobj,
ACPI_HANDLE *osc_hdlp);
#ifdef DEBUG
static void pcie_dump_acpi_obj(ACPI_HANDLE pcibus_obj);
static ACPI_STATUS pcie_walk_obj_namespace(ACPI_HANDLE hdl, uint32_t nl,
void *context, void **ret);
static ACPI_STATUS pcie_print_acpi_name(ACPI_HANDLE hdl, uint32_t nl,
void *context, void **ret);
#endif /* DEBUG */
int
pcie_acpi_osc(dev_info_t *dip, uint32_t *osc_flags)
{
ACPI_HANDLE pcibus_obj;
int status = AE_ERROR;
ACPI_HANDLE osc_hdl;
pcie_bus_t *bus_p = PCIE_DIP2BUS(dip);
pcie_x86_priv_t *osc_p = (pcie_x86_priv_t *)bus_p->bus_plat_private;
/* Mark this so we know _OSC has been called for this device */
osc_p->bus_osc = B_TRUE;
/*
* (1) Find the ACPI device node for this bus node.
*/
status = acpica_get_handle(dip, &pcibus_obj);
if (status != AE_OK) {
PCIE_DBG("No ACPI device found (dip %p)\n", (void *)dip);
return (DDI_FAILURE);
}
/*
* (2) Check if _OSC method is present.
*/
if (pcie_acpi_find_osc(pcibus_obj, &osc_hdl) != AE_OK) {
/* no _OSC method present */
PCIE_DBG("no _OSC method present for dip %p\n",
(void *)dip);
return (DDI_FAILURE);
}
/*
* (3) _OSC method exists; evaluate _OSC.
*/
if (pcie_acpi_eval_osc(dip, osc_hdl, osc_flags) != AE_OK) {
PCIE_DBG("Failed to evaluate _OSC method for dip 0x%p\n",
(void *)dip);
return (DDI_FAILURE);
}
osc_p->bus_osc_hp = (*osc_flags & OSC_CONTROL_PCIE_NAT_HP) ?
B_TRUE : B_FALSE;
osc_p->bus_osc_aer = (*osc_flags & OSC_CONTROL_PCIE_ADV_ERR) ?
B_TRUE : B_FALSE;
#ifdef DEBUG
if (pcie_debug_flags > 1)
pcie_dump_acpi_obj(pcibus_obj);
#endif /* DEBUG */
return (DDI_SUCCESS);
}
static ACPI_STATUS
pcie_acpi_find_osc(ACPI_HANDLE busobj, ACPI_HANDLE *osc_hdlp)
{
ACPI_HANDLE parentobj = busobj;
ACPI_STATUS status = AE_NOT_FOUND;
*osc_hdlp = NULL;
/*
* Walk up the ACPI device tree looking for _OSC method.
*/
do {
busobj = parentobj;
if ((status = AcpiGetHandle(busobj, "_OSC", osc_hdlp)) == AE_OK)
break;
} while (AcpiGetParent(busobj, &parentobj) == AE_OK);
if (*osc_hdlp == NULL)
status = AE_NOT_FOUND;
return (status);
}
/* UUID for for PCI/PCI-X/PCI-Exp hierarchy as defined in PCI fw ver 3.0 */
static uint8_t pcie_uuid[16] =
{0x5b, 0x4d, 0xdb, 0x33, 0xf7, 0x1f, 0x1c, 0x40,
0x96, 0x57, 0x74, 0x41, 0xc0, 0x3d, 0xd7, 0x66};
/*
* Evaluate _OSC method.
*/
ACPI_STATUS
pcie_acpi_eval_osc(dev_info_t *dip, ACPI_HANDLE osc_hdl, uint32_t *osc_flags)
{
ACPI_STATUS status;
ACPI_OBJECT_LIST arglist;
ACPI_OBJECT args[4];
UINT32 caps_buffer[3];
ACPI_BUFFER rb;
UINT32 *rbuf;
UINT32 tmp_ctrl;
/* construct argument list */
arglist.Count = 4;
arglist.Pointer = args;
/* arg0 - UUID */
args[0].Type = ACPI_TYPE_BUFFER;
args[0].Buffer.Length = 16; /* size of UUID string */
args[0].Buffer.Pointer = pcie_uuid;
/* arg1 - Revision ID */
args[1].Type = ACPI_TYPE_INTEGER;
args[1].Integer.Value = PCIE_OSC_REVISION_ID;
/* arg2 - Count */
args[2].Type = ACPI_TYPE_INTEGER;
args[2].Integer.Value = 3; /* no. of DWORDS in caps_buffer */
/* arg3 - Capabilities Buffer */
args[3].Type = ACPI_TYPE_BUFFER;
args[3].Buffer.Length = 12;
args[3].Buffer.Pointer = (void *)caps_buffer;
/* Initialize Capabilities Buffer */
/* DWORD1: no query flag set */
caps_buffer[0] = 0;
/* DWORD2: Support Field */
caps_buffer[1] = OSC_SUPPORT_FIELD_INIT;
/* DWORD3: Control Field */
caps_buffer[2] = OSC_CONTROL_FIELD_INIT;
/* If hotplug is supported add the corresponding control fields */
if (*osc_flags & OSC_CONTROL_PCIE_NAT_HP)
caps_buffer[2] |= (OSC_CONTROL_PCIE_NAT_HP |
OSC_CONTROL_PCIE_NAT_PM);
tmp_ctrl = caps_buffer[2];
rb.Length = ACPI_ALLOCATE_BUFFER;
rb.Pointer = NULL;
status = AcpiEvaluateObjectTyped(osc_hdl, NULL, &arglist, &rb,
ACPI_TYPE_BUFFER);
if (status != AE_OK) {
PCIE_DBG("Failed to execute _OSC method (status %d)\n",
status);
return (status);
}
/* LINTED pointer alignment */
rbuf = (UINT32 *)((ACPI_OBJECT *)rb.Pointer)->Buffer.Pointer;
/* check the STATUS word in the capability buffer */
if (rbuf[0] & OSC_STATUS_ERRORS) {
PCIE_DBG("_OSC method failed (STATUS %d)\n", rbuf[0]);
AcpiOsFree(rb.Pointer);
return (AE_ERROR);
}
*osc_flags = rbuf[2];
PCIE_DBG("_OSC method evaluation completed for 0x%p: "
"STATUS 0x%x SUPPORT 0x%x CONTROL req 0x%x, CONTROL ret 0x%x\n",
(void *)dip, rbuf[0], rbuf[1], tmp_ctrl, rbuf[2]);
AcpiOsFree(rb.Pointer);
return (AE_OK);
}
/*
* Checks if _OSC method has been called for this device.
*/
boolean_t
pcie_is_osc(dev_info_t *dip)
{
pcie_bus_t *bus_p = PCIE_DIP2BUS(dip);
pcie_x86_priv_t *osc_p = (pcie_x86_priv_t *)bus_p->bus_plat_private;
return (osc_p->bus_osc);
}
#ifdef DEBUG
static void
pcie_dump_acpi_obj(ACPI_HANDLE pcibus_obj)
{
int status;
ACPI_BUFFER retbuf;
if (pcibus_obj == NULL)
return;
/* print the full path name */
retbuf.Pointer = NULL;
retbuf.Length = ACPI_ALLOCATE_BUFFER;
status = AcpiGetName(pcibus_obj, ACPI_FULL_PATHNAME, &retbuf);
if (status != AE_OK)
return;
PCIE_DBG("PCIE BUS PATHNAME: %s\n", (char *)retbuf.Pointer);
AcpiOsFree(retbuf.Pointer);
/* dump all the methods for this bus node */
PCIE_DBG(" METHODS: \n");
status = AcpiWalkNamespace(ACPI_TYPE_METHOD, pcibus_obj, 1,
pcie_print_acpi_name, NULL, " ", NULL);
/* dump all the child devices */
status = AcpiWalkNamespace(ACPI_TYPE_DEVICE, pcibus_obj, 1,
pcie_walk_obj_namespace, NULL, NULL, NULL);
}
/*ARGSUSED*/
static ACPI_STATUS
pcie_walk_obj_namespace(ACPI_HANDLE hdl, uint32_t nl, void *context,
void **ret)
{
int status;
ACPI_BUFFER retbuf;
char buf[32];
/* print the full path name */
retbuf.Pointer = NULL;
retbuf.Length = ACPI_ALLOCATE_BUFFER;
status = AcpiGetName(hdl, ACPI_FULL_PATHNAME, &retbuf);
if (status != AE_OK)
return (status);
buf[0] = 0;
while (nl--)
(void) strcat(buf, " ");
PCIE_DBG("%sDEVICE: %s\n", buf, (char *)retbuf.Pointer);
AcpiOsFree(retbuf.Pointer);
/* dump all the methods for this device */
PCIE_DBG("%s METHODS: \n", buf);
status = AcpiWalkNamespace(ACPI_TYPE_METHOD, hdl, 1,
pcie_print_acpi_name, NULL, (void *)buf, NULL);
return (status);
}
/*ARGSUSED*/
static ACPI_STATUS
pcie_print_acpi_name(ACPI_HANDLE hdl, uint32_t nl, void *context, void **ret)
{
int status;
ACPI_BUFFER retbuf;
char name[16];
retbuf.Pointer = name;
retbuf.Length = 16;
status = AcpiGetName(hdl, ACPI_SINGLE_NAME, &retbuf);
if (status == AE_OK)
PCIE_DBG("%s %s \n", (char *)context, name);
return (AE_OK);
}
#endif /* DEBUG */
|