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
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* PICL Cherrystone platform plug-in to remove environment tree nodes
* if corresponding physical device is not present. For creating
* the picltree nodes, see:
* usr/src/cmd/picl/plugins/sun4u/psvc/psvcplugin/psvcplugin.c
*/
#define _POSIX_PRIORITY_SCHEDULING 1
#include <picl.h>
#include <picltree.h>
#include <stdio.h>
#include <time.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <libintl.h>
#include <limits.h>
#include <ctype.h>
#include <errno.h>
#include <semaphore.h>
#include <syslog.h>
#include <string.h>
#include <sys/types.h>
#include <sys/systeminfo.h>
#include <psvc_objects.h>
static psvc_opaque_t hdlp;
#define PSVC_PLUGIN_VERSION PICLD_PLUGIN_VERSION_1
#pragma init(psvc_psr_plugin_register) /* place in .init section */
typedef struct {
char name[32];
picl_nodehdl_t node;
} picl_psvc_t;
extern struct handle {
uint32_t obj_count;
picl_psvc_t *objects;
FILE *fp;
} psvc_hdl;
void psvc_psr_plugin_init(void);
void psvc_psr_plugin_fini(void);
picld_plugin_reg_t psvc_psr_reg = {
PSVC_PLUGIN_VERSION,
PICLD_PLUGIN_CRITICAL,
"PSVC_PSR",
psvc_psr_plugin_init,
psvc_psr_plugin_fini
};
#define PSVC_INIT_ERR gettext("%s: Error in psvc_init(): %s\n")
#define PTREE_DELETE_NODE_ERR gettext("%s: ptree_delete_node() failed: %s\n")
#define PTREE_GET_NODE_ERR \
gettext("%s: ptree_get_node_by_path() failed: %s\n")
extern int ptree_get_node_by_path(const char *, picl_nodehdl_t *);
/* ======================================== */
struct node_file {
char path[256];
char file[256];
} dev_pr_info[] = {
/* Search for memory */
{"/SYSTEM/MOTHERBOARD/CPU_0_2_MOD_SLOT/CPU_0_2_MOD_CARD/24C02_A0_0",
"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@0,a0:fru"},
{"/SYSTEM/MOTHERBOARD/CPU_0_2_MOD_SLOT/CPU_0_2_MOD_CARD/24C02_A2_0",
"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@0,a2:fru"},
{"/SYSTEM/MOTHERBOARD/CPU_0_2_MOD_SLOT/CPU_0_2_MOD_CARD/24C02_A4_0",
"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@0,a4:fru"},
{"/SYSTEM/MOTHERBOARD/CPU_0_2_MOD_SLOT/CPU_0_2_MOD_CARD/24C02_A6_0",
"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@0,a6:fru"},
{"/SYSTEM/MOTHERBOARD/CPU_0_2_MOD_SLOT/CPU_0_2_MOD_CARD/24C02_A8_0",
"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@0,a8:fru"},
{"/SYSTEM/MOTHERBOARD/CPU_0_2_MOD_SLOT/CPU_0_2_MOD_CARD/24C02_AA_0",
"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@0,aa:fru"},
{"/SYSTEM/MOTHERBOARD/CPU_0_2_MOD_SLOT/CPU_0_2_MOD_CARD/24C02_AC_0",
"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@0,ac:fru"},
{"/SYSTEM/MOTHERBOARD/CPU_0_2_MOD_SLOT/CPU_0_2_MOD_CARD/24C02_AE_0",
"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@0,ae:fru"},
{"/SYSTEM/MOTHERBOARD/CPU_1_3_MOD_SLOT/CPU_1_3_MOD_CARD/24C02_A0_1",
"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@1,a0:fru"},
{"/SYSTEM/MOTHERBOARD/CPU_1_3_MOD_SLOT/CPU_1_3_MOD_CARD/24C02_A2_1",
"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@1,a2:fru"},
{"/SYSTEM/MOTHERBOARD/CPU_1_3_MOD_SLOT/CPU_1_3_MOD_CARD/24C02_A4_1",
"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@1,a4:fru"},
{"/SYSTEM/MOTHERBOARD/CPU_1_3_MOD_SLOT/CPU_1_3_MOD_CARD/24C02_A6_1",
"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@1,a6:fru"},
{"/SYSTEM/MOTHERBOARD/CPU_1_3_MOD_SLOT/CPU_1_3_MOD_CARD/24C02_A8_1",
"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@1,a8:fru"},
{"/SYSTEM/MOTHERBOARD/CPU_1_3_MOD_SLOT/CPU_1_3_MOD_CARD/24C02_AA_1",
"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@1,aa:fru"},
{"/SYSTEM/MOTHERBOARD/CPU_1_3_MOD_SLOT/CPU_1_3_MOD_CARD/24C02_AC_1",
"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@1,ac:fru"},
{"/SYSTEM/MOTHERBOARD/CPU_1_3_MOD_SLOT/CPU_1_3_MOD_CARD/24C02_AE_1",
"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@1,ae:fru"},
{"/SYSTEM/MOTHERBOARD/CPU_0_2_MOD_SLOT/CPU_0_2_MOD_CARD/24C02_A0_2",
"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@2,a0:fru"},
{"/SYSTEM/MOTHERBOARD/CPU_0_2_MOD_SLOT/CPU_0_2_MOD_CARD/24C02_A2_2",
"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@2,a2:fru"},
{"/SYSTEM/MOTHERBOARD/CPU_0_2_MOD_SLOT/CPU_0_2_MOD_CARD/24C02_A4_2",
"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@2,a4:fru"},
{"/SYSTEM/MOTHERBOARD/CPU_0_2_MOD_SLOT/CPU_0_2_MOD_CARD/24C02_A6_2",
"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@2,a6:fru"},
{"/SYSTEM/MOTHERBOARD/CPU_0_2_MOD_SLOT/CPU_0_2_MOD_CARD/24C02_A8_2",
"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@2,a8:fru"},
{"/SYSTEM/MOTHERBOARD/CPU_0_2_MOD_SLOT/CPU_0_2_MOD_CARD/24C02_AA_2",
"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@2,aa:fru"},
{"/SYSTEM/MOTHERBOARD/CPU_0_2_MOD_SLOT/CPU_0_2_MOD_CARD/24C02_AC_2",
"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@2,ac:fru"},
{"/SYSTEM/MOTHERBOARD/CPU_0_2_MOD_SLOT/CPU_0_2_MOD_CARD/24C02_AE_2",
"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@2,ae:fru"},
{"/SYSTEM/MOTHERBOARD/CPU_1_3_MOD_SLOT/CPU_1_3_MOD_CARD/24C02_A0_3",
"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@3,a0:fru"},
{"/SYSTEM/MOTHERBOARD/CPU_1_3_MOD_SLOT/CPU_1_3_MOD_CARD/24C02_A2_3",
"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@3,a2:fru"},
{"/SYSTEM/MOTHERBOARD/CPU_1_3_MOD_SLOT/CPU_1_3_MOD_CARD/24C02_A4_3",
"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@3,a4:fru"},
{"/SYSTEM/MOTHERBOARD/CPU_1_3_MOD_SLOT/CPU_1_3_MOD_CARD/24C02_A6_3",
"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@3,a6:fru"},
{"/SYSTEM/MOTHERBOARD/CPU_1_3_MOD_SLOT/CPU_1_3_MOD_CARD/24C02_A8_3",
"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@3,a8:fru"},
{"/SYSTEM/MOTHERBOARD/CPU_1_3_MOD_SLOT/CPU_1_3_MOD_CARD/24C02_AA_3",
"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@3,aa:fru"},
{"/SYSTEM/MOTHERBOARD/CPU_1_3_MOD_SLOT/CPU_1_3_MOD_CARD/24C02_AC_3",
"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@3,ac:fru"},
{"/SYSTEM/MOTHERBOARD/CPU_1_3_MOD_SLOT/CPU_1_3_MOD_CARD/24C02_AE_3",
"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@3,ae:fru"},
/* Search for 64Kbit SPD */
{"/SYSTEM/MOTHERBOARD/CPU_0_2_MOD_SLOT/CPU_0_2_MOD_CARD/24C64_A0_4",
"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@4,a0:fru"},
{"/SYSTEM/MOTHERBOARD/CPU_1_3_MOD_SLOT/CPU_1_3_MOD_CARD/24C64_A2_4",
"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@4,a2:fru"},
/*
* Search for CPU Module cards. We check one cpu's die temperature
* sensor If not present, then we remove the entire node since module
* cards come with two cpus in them, each cpu having a die temperature
* sensor
*/
{"/SYSTEM/MOTHERBOARD/CPU_0_2_MOD_SLOT/CPU_0_2_MOD_CARD",
"/devices/pci@9,700000/ebus@1/i2c@1,30/temperature@0,30:die_temp"},
{"/SYSTEM/MOTHERBOARD/CPU_1_3_MOD_SLOT/CPU_1_3_MOD_CARD",
"/devices/pci@9,700000/ebus@1/i2c@1,30/temperature@0,52:die_temp"},
{"/SYSTEM/SIB_BOARD",
"/devices/pci@9,700000/ebus@1/i2c@1,30/temperature@0,98:die_temp"},
/*
* Check to see if RSC Card FRU is present. If it is not present,
* then RSC Card is not present, and so we remove those nodes from
* picl tree as well.
*/
{"/SYSTEM/RSC_SLOT/RSC_CARD/24C64_A6_5",
"/devices/pci@9,700000/ebus@1/i2c@1,30/fru@0,a6:fru"},
{"/SYSTEM/RSC_SLOT/RSC_CARD",
"/devices/pci@9,700000/ebus@1/i2c@1,30/fru@0,a6:fru"}
};
#define DEV_PR_COUNT (sizeof (dev_pr_info) / sizeof (struct node_file))
static void init_err(char *fmt, char *arg1, char *arg2)
{
char msg[256];
sprintf(msg, fmt, arg1, arg2);
syslog(LOG_ERR, msg);
}
void
psvc_psr_plugin_init(void)
{
char *funcname = "psvc_plugin_psr_init";
int32_t i;
int err;
boolean_t present;
/*
* So the volatile read/write routines can retrieve data from
* psvc or picl
*/
err = psvc_init(&hdlp);
if (err != 0) {
init_err(PSVC_INIT_ERR, funcname, strerror(errno));
}
/*
* Remove nodes whose devices aren't present from the picl tree.
*/
for (i = 0; i < psvc_hdl.obj_count; ++i) {
picl_psvc_t *objp;
uint64_t features;
objp = &psvc_hdl.objects[i];
err = psvc_get_attr(hdlp, objp->name, PSVC_PRESENCE_ATTR,
&present);
if (err != PSVC_SUCCESS)
continue;
err = psvc_get_attr(hdlp, objp->name, PSVC_FEATURES_ATTR,
&features);
if (err != PSVC_SUCCESS)
continue;
if ((features & (PSVC_DEV_HOTPLUG | PSVC_DEV_OPTION)) &&
(present == PSVC_ABSENT)) {
err = ptree_delete_node(objp->node);
if (err != 0) {
init_err(PTREE_DELETE_NODE_ERR, funcname,
picl_strerror(err));
return;
}
}
}
/*
* Remove PICL device nodes if their /devices file isn't present or
* if the device file is present but the open returns ENXIO
* which indicates that the node file doesn't represent a device
* tree node and is probably a relic from some previous boot config
*/
for (i = 0; i < DEV_PR_COUNT; ++i) {
picl_nodehdl_t dev_pr_node;
int fd;
fd = open(dev_pr_info[i].file, O_RDONLY);
if (fd != -1) {
close(fd);
continue;
}
if ((errno != ENOENT) && (errno != ENXIO))
continue;
err = ptree_get_node_by_path(dev_pr_info[i].path, &dev_pr_node);
if (err != 0) {
syslog(LOG_ERR, "Bad path: %s", dev_pr_info[i].path);
init_err(PTREE_GET_NODE_ERR, funcname,
picl_strerror(err));
return;
}
err = ptree_delete_node(dev_pr_node);
if (err != 0) {
init_err(PTREE_DELETE_NODE_ERR, funcname,
picl_strerror(err));
return;
}
}
free(psvc_hdl.objects);
}
void
psvc_psr_plugin_fini(void)
{
psvc_fini(hdlp);
hdlp = NULL;
}
void
psvc_psr_plugin_register(void)
{
picld_plugin_register(&psvc_psr_reg);
}
|