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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
|
/*
* 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.
* Copyright (c) 2018, Joyent, Inc.
*/
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/fm/protocol.h>
#include <sys/fm/smb/fmsmb.h>
#include <sys/devfm.h>
#include <sys/cpu_module.h>
#define ANY_ID (uint_t)-1
/*
* INIT_HDLS is the initial size of cmi_hdl_t array. We fill the array
* during cmi_hdl_walk, if the array overflows, we will reallocate
* a new array twice the size of the old one.
*/
#define INIT_HDLS 16
typedef struct fm_cmi_walk_t
{
uint_t chipid; /* chipid to match during walk */
uint_t coreid; /* coreid to match */
uint_t strandid; /* strandid to match */
int (*cbfunc)(cmi_hdl_t, void *, void *); /* callback function */
cmi_hdl_t *hdls; /* allocated array to save the handles */
int nhdl_max; /* allocated array size */
int nhdl; /* handles saved */
} fm_cmi_walk_t;
extern int x86gentopo_legacy;
int
fm_get_paddr(nvlist_t *nvl, uint64_t *paddr)
{
uint8_t version;
uint64_t pa;
char *scheme;
int err;
/* Verify FMRI scheme name and version number */
if ((nvlist_lookup_string(nvl, FM_FMRI_SCHEME, &scheme) != 0) ||
(strcmp(scheme, FM_FMRI_SCHEME_HC) != 0) ||
(nvlist_lookup_uint8(nvl, FM_VERSION, &version) != 0) ||
version > FM_HC_SCHEME_VERSION) {
return (EINVAL);
}
if ((err = cmi_mc_unumtopa(NULL, nvl, &pa)) != CMI_SUCCESS &&
err != CMIERR_MC_PARTIALUNUMTOPA)
return (EINVAL);
*paddr = pa;
return (0);
}
/*
* Routines for cmi handles walk.
*/
static void
walk_init(fm_cmi_walk_t *wp, uint_t chipid, uint_t coreid, uint_t strandid,
int (*cbfunc)(cmi_hdl_t, void *, void *))
{
wp->chipid = chipid;
wp->coreid = coreid;
wp->strandid = strandid;
/*
* If callback is not set, we allocate an array to save the
* cmi handles.
*/
if ((wp->cbfunc = cbfunc) == NULL) {
wp->hdls = kmem_alloc(sizeof (cmi_hdl_t) * INIT_HDLS, KM_SLEEP);
wp->nhdl_max = INIT_HDLS;
wp->nhdl = 0;
}
}
static void
walk_fini(fm_cmi_walk_t *wp)
{
if (wp->cbfunc == NULL)
kmem_free(wp->hdls, sizeof (cmi_hdl_t) * wp->nhdl_max);
}
static int
select_cmi_hdl(cmi_hdl_t hdl, void *arg1, void *arg2, void *arg3)
{
fm_cmi_walk_t *wp = (fm_cmi_walk_t *)arg1;
if (wp->chipid != ANY_ID && wp->chipid != cmi_hdl_chipid(hdl))
return (CMI_HDL_WALK_NEXT);
if (wp->coreid != ANY_ID && wp->coreid != cmi_hdl_coreid(hdl))
return (CMI_HDL_WALK_NEXT);
if (wp->strandid != ANY_ID && wp->strandid != cmi_hdl_strandid(hdl))
return (CMI_HDL_WALK_NEXT);
/*
* Call the callback function if any exists, otherwise we hold a
* reference of the handle and push it to preallocated array.
* If the allocated array is going to overflow, reallocate a
* bigger one to replace it.
*/
if (wp->cbfunc != NULL)
return (wp->cbfunc(hdl, arg2, arg3));
if (wp->nhdl == wp->nhdl_max) {
size_t sz = sizeof (cmi_hdl_t) * wp->nhdl_max;
cmi_hdl_t *newarray = kmem_alloc(sz << 1, KM_SLEEP);
bcopy(wp->hdls, newarray, sz);
kmem_free(wp->hdls, sz);
wp->hdls = newarray;
wp->nhdl_max <<= 1;
}
cmi_hdl_hold(hdl);
wp->hdls[wp->nhdl++] = hdl;
return (CMI_HDL_WALK_NEXT);
}
static void
populate_cpu(nvlist_t **nvlp, cmi_hdl_t hdl)
{
uint_t fm_chipid;
uint16_t smbios_id;
const char *idstr;
(void) nvlist_alloc(nvlp, NV_UNIQUE_NAME, KM_SLEEP);
/*
* If SMBIOS satisfies FMA Topology needs, gather
* more information on the chip's physical roots
* like /chassis=x/motherboard=y/cpuboard=z and
* set the chip_id to match the SMBIOS' Type 4
* ordering & this has to match the ereport's chip
* resource instance derived off of SMBIOS.
* Multi-Chip-Module support should set the chipid
* in terms of the processor package rather than
* the die/node in the processor package, for FM.
*/
if (!x86gentopo_legacy) {
smbios_id = cmi_hdl_smbiosid(hdl);
fm_chipid = cmi_hdl_smb_chipid(hdl);
(void) nvlist_add_nvlist(*nvlp, FM_PHYSCPU_INFO_CHIP_ROOTS,
cmi_hdl_smb_bboard(hdl));
(void) nvlist_add_uint16(*nvlp, FM_PHYSCPU_INFO_SMBIOS_ID,
(uint16_t)smbios_id);
} else
fm_chipid = cmi_hdl_chipid(hdl);
fm_payload_set(*nvlp,
FM_PHYSCPU_INFO_VENDOR_ID, DATA_TYPE_STRING,
cmi_hdl_vendorstr(hdl),
FM_PHYSCPU_INFO_FAMILY, DATA_TYPE_INT32,
(int32_t)cmi_hdl_family(hdl),
FM_PHYSCPU_INFO_MODEL, DATA_TYPE_INT32,
(int32_t)cmi_hdl_model(hdl),
FM_PHYSCPU_INFO_STEPPING, DATA_TYPE_INT32,
(int32_t)cmi_hdl_stepping(hdl),
FM_PHYSCPU_INFO_CHIP_ID, DATA_TYPE_INT32,
(int32_t)fm_chipid,
FM_PHYSCPU_INFO_NPROCNODES, DATA_TYPE_INT32,
(int32_t)cmi_hdl_procnodes_per_pkg(hdl),
FM_PHYSCPU_INFO_PROCNODE_ID, DATA_TYPE_INT32,
(int32_t)cmi_hdl_procnodeid(hdl),
FM_PHYSCPU_INFO_CORE_ID, DATA_TYPE_INT32,
(int32_t)cmi_hdl_coreid(hdl),
FM_PHYSCPU_INFO_STRAND_ID, DATA_TYPE_INT32,
(int32_t)cmi_hdl_strandid(hdl),
FM_PHYSCPU_INFO_STRAND_APICID, DATA_TYPE_INT32,
(int32_t)cmi_hdl_strand_apicid(hdl),
FM_PHYSCPU_INFO_CHIP_REV, DATA_TYPE_STRING,
cmi_hdl_chiprevstr(hdl),
FM_PHYSCPU_INFO_SOCKET_TYPE, DATA_TYPE_UINT32,
(uint32_t)cmi_hdl_getsockettype(hdl),
FM_PHYSCPU_INFO_CPU_ID, DATA_TYPE_INT32,
(int32_t)cmi_hdl_logical_id(hdl),
NULL);
/*
* Do this separately so that way if there is no ident string we do not
* trigger an error.
*/
if ((idstr = cmi_hdl_chipident(hdl)) != NULL) {
fm_payload_set(*nvlp,
FM_PHYSCPU_INFO_CHIP_IDENTSTR, DATA_TYPE_STRING, idstr,
NULL);
}
}
/*ARGSUSED*/
int
fm_ioctl_physcpu_info(int cmd, nvlist_t *invl, nvlist_t **onvlp)
{
nvlist_t **cpus, *nvl;
int i, err;
fm_cmi_walk_t wk;
/*
* Do a walk to save all the cmi handles in the array.
*/
walk_init(&wk, ANY_ID, ANY_ID, ANY_ID, NULL);
cmi_hdl_walk(select_cmi_hdl, &wk, NULL, NULL);
if (wk.nhdl == 0) {
walk_fini(&wk);
return (ENOENT);
}
cpus = kmem_alloc(sizeof (nvlist_t *) * wk.nhdl, KM_SLEEP);
for (i = 0; i < wk.nhdl; i++) {
populate_cpu(cpus + i, wk.hdls[i]);
cmi_hdl_rele(wk.hdls[i]);
}
walk_fini(&wk);
(void) nvlist_alloc(&nvl, NV_UNIQUE_NAME, KM_SLEEP);
err = nvlist_add_nvlist_array(nvl, FM_PHYSCPU_INFO_CPUS,
cpus, wk.nhdl);
for (i = 0; i < wk.nhdl; i++)
nvlist_free(cpus[i]);
kmem_free(cpus, sizeof (nvlist_t *) * wk.nhdl);
if (err != 0) {
nvlist_free(nvl);
return (err);
}
*onvlp = nvl;
return (0);
}
int
fm_ioctl_cpu_retire(int cmd, nvlist_t *invl, nvlist_t **onvlp)
{
int32_t chipid, coreid, strandid;
int rc, new_status, old_status;
cmi_hdl_t hdl;
nvlist_t *nvl;
switch (cmd) {
case FM_IOC_CPU_RETIRE:
new_status = P_FAULTED;
break;
case FM_IOC_CPU_STATUS:
new_status = P_STATUS;
break;
case FM_IOC_CPU_UNRETIRE:
new_status = P_ONLINE;
break;
default:
return (ENOTTY);
}
if (nvlist_lookup_int32(invl, FM_CPU_RETIRE_CHIP_ID, &chipid) != 0 ||
nvlist_lookup_int32(invl, FM_CPU_RETIRE_CORE_ID, &coreid) != 0 ||
nvlist_lookup_int32(invl, FM_CPU_RETIRE_STRAND_ID, &strandid) != 0)
return (EINVAL);
hdl = cmi_hdl_lookup(CMI_HDL_NEUTRAL, chipid, coreid, strandid);
if (hdl == NULL)
return (EINVAL);
rc = cmi_hdl_online(hdl, new_status, &old_status);
cmi_hdl_rele(hdl);
if (rc == 0) {
(void) nvlist_alloc(&nvl, NV_UNIQUE_NAME, KM_SLEEP);
(void) nvlist_add_int32(nvl, FM_CPU_RETIRE_OLDSTATUS,
old_status);
*onvlp = nvl;
}
return (rc);
}
/*
* Retrun the value of x86gentopo_legacy variable as an nvpair.
*
* The caller is responsible for freeing the nvlist.
*/
/* ARGSUSED */
int
fm_ioctl_gentopo_legacy(int cmd, nvlist_t *invl, nvlist_t **onvlp)
{
nvlist_t *nvl;
if (cmd != FM_IOC_GENTOPO_LEGACY) {
return (ENOTTY);
}
/*
* Inform the caller of the intentions of the ereport generators to
* generate either a "generic" or "legacy" x86 topology.
*/
(void) nvlist_alloc(&nvl, NV_UNIQUE_NAME, KM_SLEEP);
(void) nvlist_add_int32(nvl, FM_GENTOPO_LEGACY, x86gentopo_legacy);
*onvlp = nvl;
return (0);
}
|