1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /*
28*7c478bd9Sstevel@tonic-gate  * PICL Cherrystone platform plug-in to remove environment tree nodes
29*7c478bd9Sstevel@tonic-gate  * if corresponding physical device is not present.  For creating
30*7c478bd9Sstevel@tonic-gate  * the picltree nodes, see:
31*7c478bd9Sstevel@tonic-gate  * usr/src/cmd/picl/plugins/sun4u/psvc/psvcplugin/psvcplugin.c
32*7c478bd9Sstevel@tonic-gate  */
33*7c478bd9Sstevel@tonic-gate #define	_POSIX_PRIORITY_SCHEDULING 1
34*7c478bd9Sstevel@tonic-gate 
35*7c478bd9Sstevel@tonic-gate #include <picl.h>
36*7c478bd9Sstevel@tonic-gate #include <picltree.h>
37*7c478bd9Sstevel@tonic-gate #include <stdio.h>
38*7c478bd9Sstevel@tonic-gate #include <time.h>
39*7c478bd9Sstevel@tonic-gate #include <fcntl.h>
40*7c478bd9Sstevel@tonic-gate #include <unistd.h>
41*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
42*7c478bd9Sstevel@tonic-gate #include  <stdio.h>
43*7c478bd9Sstevel@tonic-gate #include  <libintl.h>
44*7c478bd9Sstevel@tonic-gate #include <limits.h>
45*7c478bd9Sstevel@tonic-gate #include  <ctype.h>
46*7c478bd9Sstevel@tonic-gate #include <errno.h>
47*7c478bd9Sstevel@tonic-gate #include <semaphore.h>
48*7c478bd9Sstevel@tonic-gate #include <syslog.h>
49*7c478bd9Sstevel@tonic-gate #include <string.h>
50*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
51*7c478bd9Sstevel@tonic-gate #include <sys/systeminfo.h>
52*7c478bd9Sstevel@tonic-gate #include <psvc_objects.h>
53*7c478bd9Sstevel@tonic-gate 
54*7c478bd9Sstevel@tonic-gate static psvc_opaque_t hdlp;
55*7c478bd9Sstevel@tonic-gate 
56*7c478bd9Sstevel@tonic-gate #define	PSVC_PLUGIN_VERSION	PICLD_PLUGIN_VERSION_1
57*7c478bd9Sstevel@tonic-gate 
58*7c478bd9Sstevel@tonic-gate #pragma init(psvc_psr_plugin_register)	/* place in .init section */
59*7c478bd9Sstevel@tonic-gate 
60*7c478bd9Sstevel@tonic-gate typedef struct {
61*7c478bd9Sstevel@tonic-gate 	char	name[32];
62*7c478bd9Sstevel@tonic-gate 	picl_nodehdl_t  node;
63*7c478bd9Sstevel@tonic-gate } picl_psvc_t;
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate extern struct handle {
66*7c478bd9Sstevel@tonic-gate 	uint32_t	obj_count;
67*7c478bd9Sstevel@tonic-gate 	picl_psvc_t *objects;
68*7c478bd9Sstevel@tonic-gate 	FILE *fp;
69*7c478bd9Sstevel@tonic-gate } psvc_hdl;
70*7c478bd9Sstevel@tonic-gate 
71*7c478bd9Sstevel@tonic-gate void psvc_psr_plugin_init(void);
72*7c478bd9Sstevel@tonic-gate void psvc_psr_plugin_fini(void);
73*7c478bd9Sstevel@tonic-gate 
74*7c478bd9Sstevel@tonic-gate picld_plugin_reg_t psvc_psr_reg = {
75*7c478bd9Sstevel@tonic-gate 	PSVC_PLUGIN_VERSION,
76*7c478bd9Sstevel@tonic-gate 	PICLD_PLUGIN_CRITICAL,
77*7c478bd9Sstevel@tonic-gate 	"PSVC_PSR",
78*7c478bd9Sstevel@tonic-gate 	psvc_psr_plugin_init,
79*7c478bd9Sstevel@tonic-gate 	psvc_psr_plugin_fini
80*7c478bd9Sstevel@tonic-gate };
81*7c478bd9Sstevel@tonic-gate 
82*7c478bd9Sstevel@tonic-gate #define	PSVC_INIT_ERR		gettext("%s: Error in psvc_init(): %s\n")
83*7c478bd9Sstevel@tonic-gate #define	PTREE_DELETE_NODE_ERR	gettext("%s: ptree_delete_node() failed: %s\n")
84*7c478bd9Sstevel@tonic-gate #define	PTREE_GET_NODE_ERR			\
85*7c478bd9Sstevel@tonic-gate 	gettext("%s: ptree_get_node_by_path() failed: %s\n")
86*7c478bd9Sstevel@tonic-gate 
87*7c478bd9Sstevel@tonic-gate extern int ptree_get_node_by_path(const char *, picl_nodehdl_t *);
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate /* ======================================== */
90*7c478bd9Sstevel@tonic-gate struct node_file {
91*7c478bd9Sstevel@tonic-gate 	char	path[256];
92*7c478bd9Sstevel@tonic-gate 	char	file[256];
93*7c478bd9Sstevel@tonic-gate } dev_pr_info[] = {
94*7c478bd9Sstevel@tonic-gate /* Search for memory */
95*7c478bd9Sstevel@tonic-gate {"/SYSTEM/MOTHERBOARD/CPU_0_2_MOD_SLOT/CPU_0_2_MOD_CARD/24C02_A0_0",
96*7c478bd9Sstevel@tonic-gate 	"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@0,a0:fru"},
97*7c478bd9Sstevel@tonic-gate {"/SYSTEM/MOTHERBOARD/CPU_0_2_MOD_SLOT/CPU_0_2_MOD_CARD/24C02_A2_0",
98*7c478bd9Sstevel@tonic-gate 	"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@0,a2:fru"},
99*7c478bd9Sstevel@tonic-gate {"/SYSTEM/MOTHERBOARD/CPU_0_2_MOD_SLOT/CPU_0_2_MOD_CARD/24C02_A4_0",
100*7c478bd9Sstevel@tonic-gate 	"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@0,a4:fru"},
101*7c478bd9Sstevel@tonic-gate {"/SYSTEM/MOTHERBOARD/CPU_0_2_MOD_SLOT/CPU_0_2_MOD_CARD/24C02_A6_0",
102*7c478bd9Sstevel@tonic-gate 	"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@0,a6:fru"},
103*7c478bd9Sstevel@tonic-gate {"/SYSTEM/MOTHERBOARD/CPU_0_2_MOD_SLOT/CPU_0_2_MOD_CARD/24C02_A8_0",
104*7c478bd9Sstevel@tonic-gate 	"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@0,a8:fru"},
105*7c478bd9Sstevel@tonic-gate {"/SYSTEM/MOTHERBOARD/CPU_0_2_MOD_SLOT/CPU_0_2_MOD_CARD/24C02_AA_0",
106*7c478bd9Sstevel@tonic-gate 	"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@0,aa:fru"},
107*7c478bd9Sstevel@tonic-gate {"/SYSTEM/MOTHERBOARD/CPU_0_2_MOD_SLOT/CPU_0_2_MOD_CARD/24C02_AC_0",
108*7c478bd9Sstevel@tonic-gate 	"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@0,ac:fru"},
109*7c478bd9Sstevel@tonic-gate {"/SYSTEM/MOTHERBOARD/CPU_0_2_MOD_SLOT/CPU_0_2_MOD_CARD/24C02_AE_0",
110*7c478bd9Sstevel@tonic-gate 	"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@0,ae:fru"},
111*7c478bd9Sstevel@tonic-gate {"/SYSTEM/MOTHERBOARD/CPU_1_3_MOD_SLOT/CPU_1_3_MOD_CARD/24C02_A0_1",
112*7c478bd9Sstevel@tonic-gate 	"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@1,a0:fru"},
113*7c478bd9Sstevel@tonic-gate {"/SYSTEM/MOTHERBOARD/CPU_1_3_MOD_SLOT/CPU_1_3_MOD_CARD/24C02_A2_1",
114*7c478bd9Sstevel@tonic-gate 	"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@1,a2:fru"},
115*7c478bd9Sstevel@tonic-gate {"/SYSTEM/MOTHERBOARD/CPU_1_3_MOD_SLOT/CPU_1_3_MOD_CARD/24C02_A4_1",
116*7c478bd9Sstevel@tonic-gate 	"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@1,a4:fru"},
117*7c478bd9Sstevel@tonic-gate {"/SYSTEM/MOTHERBOARD/CPU_1_3_MOD_SLOT/CPU_1_3_MOD_CARD/24C02_A6_1",
118*7c478bd9Sstevel@tonic-gate 	"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@1,a6:fru"},
119*7c478bd9Sstevel@tonic-gate {"/SYSTEM/MOTHERBOARD/CPU_1_3_MOD_SLOT/CPU_1_3_MOD_CARD/24C02_A8_1",
120*7c478bd9Sstevel@tonic-gate 	"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@1,a8:fru"},
121*7c478bd9Sstevel@tonic-gate {"/SYSTEM/MOTHERBOARD/CPU_1_3_MOD_SLOT/CPU_1_3_MOD_CARD/24C02_AA_1",
122*7c478bd9Sstevel@tonic-gate 	"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@1,aa:fru"},
123*7c478bd9Sstevel@tonic-gate {"/SYSTEM/MOTHERBOARD/CPU_1_3_MOD_SLOT/CPU_1_3_MOD_CARD/24C02_AC_1",
124*7c478bd9Sstevel@tonic-gate 	"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@1,ac:fru"},
125*7c478bd9Sstevel@tonic-gate {"/SYSTEM/MOTHERBOARD/CPU_1_3_MOD_SLOT/CPU_1_3_MOD_CARD/24C02_AE_1",
126*7c478bd9Sstevel@tonic-gate 	"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@1,ae:fru"},
127*7c478bd9Sstevel@tonic-gate {"/SYSTEM/MOTHERBOARD/CPU_0_2_MOD_SLOT/CPU_0_2_MOD_CARD/24C02_A0_2",
128*7c478bd9Sstevel@tonic-gate 	"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@2,a0:fru"},
129*7c478bd9Sstevel@tonic-gate {"/SYSTEM/MOTHERBOARD/CPU_0_2_MOD_SLOT/CPU_0_2_MOD_CARD/24C02_A2_2",
130*7c478bd9Sstevel@tonic-gate 	"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@2,a2:fru"},
131*7c478bd9Sstevel@tonic-gate {"/SYSTEM/MOTHERBOARD/CPU_0_2_MOD_SLOT/CPU_0_2_MOD_CARD/24C02_A4_2",
132*7c478bd9Sstevel@tonic-gate 	"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@2,a4:fru"},
133*7c478bd9Sstevel@tonic-gate {"/SYSTEM/MOTHERBOARD/CPU_0_2_MOD_SLOT/CPU_0_2_MOD_CARD/24C02_A6_2",
134*7c478bd9Sstevel@tonic-gate 	"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@2,a6:fru"},
135*7c478bd9Sstevel@tonic-gate {"/SYSTEM/MOTHERBOARD/CPU_0_2_MOD_SLOT/CPU_0_2_MOD_CARD/24C02_A8_2",
136*7c478bd9Sstevel@tonic-gate 	"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@2,a8:fru"},
137*7c478bd9Sstevel@tonic-gate {"/SYSTEM/MOTHERBOARD/CPU_0_2_MOD_SLOT/CPU_0_2_MOD_CARD/24C02_AA_2",
138*7c478bd9Sstevel@tonic-gate 	"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@2,aa:fru"},
139*7c478bd9Sstevel@tonic-gate {"/SYSTEM/MOTHERBOARD/CPU_0_2_MOD_SLOT/CPU_0_2_MOD_CARD/24C02_AC_2",
140*7c478bd9Sstevel@tonic-gate 	"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@2,ac:fru"},
141*7c478bd9Sstevel@tonic-gate {"/SYSTEM/MOTHERBOARD/CPU_0_2_MOD_SLOT/CPU_0_2_MOD_CARD/24C02_AE_2",
142*7c478bd9Sstevel@tonic-gate 	"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@2,ae:fru"},
143*7c478bd9Sstevel@tonic-gate {"/SYSTEM/MOTHERBOARD/CPU_1_3_MOD_SLOT/CPU_1_3_MOD_CARD/24C02_A0_3",
144*7c478bd9Sstevel@tonic-gate 	"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@3,a0:fru"},
145*7c478bd9Sstevel@tonic-gate {"/SYSTEM/MOTHERBOARD/CPU_1_3_MOD_SLOT/CPU_1_3_MOD_CARD/24C02_A2_3",
146*7c478bd9Sstevel@tonic-gate 	"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@3,a2:fru"},
147*7c478bd9Sstevel@tonic-gate {"/SYSTEM/MOTHERBOARD/CPU_1_3_MOD_SLOT/CPU_1_3_MOD_CARD/24C02_A4_3",
148*7c478bd9Sstevel@tonic-gate 	"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@3,a4:fru"},
149*7c478bd9Sstevel@tonic-gate {"/SYSTEM/MOTHERBOARD/CPU_1_3_MOD_SLOT/CPU_1_3_MOD_CARD/24C02_A6_3",
150*7c478bd9Sstevel@tonic-gate 	"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@3,a6:fru"},
151*7c478bd9Sstevel@tonic-gate {"/SYSTEM/MOTHERBOARD/CPU_1_3_MOD_SLOT/CPU_1_3_MOD_CARD/24C02_A8_3",
152*7c478bd9Sstevel@tonic-gate 	"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@3,a8:fru"},
153*7c478bd9Sstevel@tonic-gate {"/SYSTEM/MOTHERBOARD/CPU_1_3_MOD_SLOT/CPU_1_3_MOD_CARD/24C02_AA_3",
154*7c478bd9Sstevel@tonic-gate 	"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@3,aa:fru"},
155*7c478bd9Sstevel@tonic-gate {"/SYSTEM/MOTHERBOARD/CPU_1_3_MOD_SLOT/CPU_1_3_MOD_CARD/24C02_AC_3",
156*7c478bd9Sstevel@tonic-gate 	"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@3,ac:fru"},
157*7c478bd9Sstevel@tonic-gate {"/SYSTEM/MOTHERBOARD/CPU_1_3_MOD_SLOT/CPU_1_3_MOD_CARD/24C02_AE_3",
158*7c478bd9Sstevel@tonic-gate 	"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@3,ae:fru"},
159*7c478bd9Sstevel@tonic-gate /* Search for 64Kbit SPD */
160*7c478bd9Sstevel@tonic-gate {"/SYSTEM/MOTHERBOARD/CPU_0_2_MOD_SLOT/CPU_0_2_MOD_CARD/24C64_A0_4",
161*7c478bd9Sstevel@tonic-gate 	"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@4,a0:fru"},
162*7c478bd9Sstevel@tonic-gate {"/SYSTEM/MOTHERBOARD/CPU_1_3_MOD_SLOT/CPU_1_3_MOD_CARD/24C64_A2_4",
163*7c478bd9Sstevel@tonic-gate 	"/devices/pci@9,700000/ebus@1/i2c@1,2e/fru@4,a2:fru"},
164*7c478bd9Sstevel@tonic-gate 
165*7c478bd9Sstevel@tonic-gate /*
166*7c478bd9Sstevel@tonic-gate  * Search for CPU Module cards.  We check one cpu's die temperature
167*7c478bd9Sstevel@tonic-gate  * sensor If not present, then we remove the entire node since module
168*7c478bd9Sstevel@tonic-gate  * cards come with two cpus in them, each cpu having a die temperature
169*7c478bd9Sstevel@tonic-gate  * sensor
170*7c478bd9Sstevel@tonic-gate  */
171*7c478bd9Sstevel@tonic-gate 
172*7c478bd9Sstevel@tonic-gate {"/SYSTEM/MOTHERBOARD/CPU_0_2_MOD_SLOT/CPU_0_2_MOD_CARD",
173*7c478bd9Sstevel@tonic-gate 	"/devices/pci@9,700000/ebus@1/i2c@1,30/temperature@0,30:die_temp"},
174*7c478bd9Sstevel@tonic-gate {"/SYSTEM/MOTHERBOARD/CPU_1_3_MOD_SLOT/CPU_1_3_MOD_CARD",
175*7c478bd9Sstevel@tonic-gate 	"/devices/pci@9,700000/ebus@1/i2c@1,30/temperature@0,52:die_temp"},
176*7c478bd9Sstevel@tonic-gate {"/SYSTEM/SIB_BOARD",
177*7c478bd9Sstevel@tonic-gate 	"/devices/pci@9,700000/ebus@1/i2c@1,30/temperature@0,98:die_temp"},
178*7c478bd9Sstevel@tonic-gate /*
179*7c478bd9Sstevel@tonic-gate  * Check to see if RSC Card FRU is present.  If it is not present,
180*7c478bd9Sstevel@tonic-gate  * then RSC Card is not present, and so we remove those nodes from
181*7c478bd9Sstevel@tonic-gate  * picl tree as well.
182*7c478bd9Sstevel@tonic-gate  */
183*7c478bd9Sstevel@tonic-gate {"/SYSTEM/RSC_SLOT/RSC_CARD/24C64_A6_5",
184*7c478bd9Sstevel@tonic-gate 	"/devices/pci@9,700000/ebus@1/i2c@1,30/fru@0,a6:fru"},
185*7c478bd9Sstevel@tonic-gate {"/SYSTEM/RSC_SLOT/RSC_CARD",
186*7c478bd9Sstevel@tonic-gate 	"/devices/pci@9,700000/ebus@1/i2c@1,30/fru@0,a6:fru"}
187*7c478bd9Sstevel@tonic-gate };
188*7c478bd9Sstevel@tonic-gate 
189*7c478bd9Sstevel@tonic-gate #define	DEV_PR_COUNT (sizeof (dev_pr_info) / sizeof (struct node_file))
190*7c478bd9Sstevel@tonic-gate 
init_err(char * fmt,char * arg1,char * arg2)191*7c478bd9Sstevel@tonic-gate static void init_err(char *fmt, char *arg1, char *arg2)
192*7c478bd9Sstevel@tonic-gate {
193*7c478bd9Sstevel@tonic-gate 	char msg[256];
194*7c478bd9Sstevel@tonic-gate 
195*7c478bd9Sstevel@tonic-gate 	sprintf(msg, fmt, arg1, arg2);
196*7c478bd9Sstevel@tonic-gate 	syslog(LOG_ERR, msg);
197*7c478bd9Sstevel@tonic-gate }
198*7c478bd9Sstevel@tonic-gate 
199*7c478bd9Sstevel@tonic-gate void
psvc_psr_plugin_init(void)200*7c478bd9Sstevel@tonic-gate psvc_psr_plugin_init(void)
201*7c478bd9Sstevel@tonic-gate {
202*7c478bd9Sstevel@tonic-gate 	char *funcname = "psvc_plugin_psr_init";
203*7c478bd9Sstevel@tonic-gate 	int32_t i;
204*7c478bd9Sstevel@tonic-gate 	int err;
205*7c478bd9Sstevel@tonic-gate 	boolean_t present;
206*7c478bd9Sstevel@tonic-gate 	/*
207*7c478bd9Sstevel@tonic-gate 	 * So the volatile read/write routines can retrieve data from
208*7c478bd9Sstevel@tonic-gate 	 * psvc or picl
209*7c478bd9Sstevel@tonic-gate 	 */
210*7c478bd9Sstevel@tonic-gate 	err = psvc_init(&hdlp);
211*7c478bd9Sstevel@tonic-gate 	if (err != 0) {
212*7c478bd9Sstevel@tonic-gate 		init_err(PSVC_INIT_ERR, funcname, strerror(errno));
213*7c478bd9Sstevel@tonic-gate 
214*7c478bd9Sstevel@tonic-gate 	}
215*7c478bd9Sstevel@tonic-gate 
216*7c478bd9Sstevel@tonic-gate 	/*
217*7c478bd9Sstevel@tonic-gate 	 * Remove nodes whose devices aren't present from the picl tree.
218*7c478bd9Sstevel@tonic-gate 	 */
219*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < psvc_hdl.obj_count; ++i) {
220*7c478bd9Sstevel@tonic-gate 		picl_psvc_t *objp;
221*7c478bd9Sstevel@tonic-gate 		uint64_t features;
222*7c478bd9Sstevel@tonic-gate 		objp = &psvc_hdl.objects[i];
223*7c478bd9Sstevel@tonic-gate 
224*7c478bd9Sstevel@tonic-gate 		err = psvc_get_attr(hdlp, objp->name, PSVC_PRESENCE_ATTR,
225*7c478bd9Sstevel@tonic-gate 			&present);
226*7c478bd9Sstevel@tonic-gate 		if (err != PSVC_SUCCESS)
227*7c478bd9Sstevel@tonic-gate 			continue;
228*7c478bd9Sstevel@tonic-gate 		err = psvc_get_attr(hdlp, objp->name, PSVC_FEATURES_ATTR,
229*7c478bd9Sstevel@tonic-gate 			&features);
230*7c478bd9Sstevel@tonic-gate 		if (err != PSVC_SUCCESS)
231*7c478bd9Sstevel@tonic-gate 			continue;
232*7c478bd9Sstevel@tonic-gate 		if ((features & (PSVC_DEV_HOTPLUG | PSVC_DEV_OPTION)) &&
233*7c478bd9Sstevel@tonic-gate 			(present == PSVC_ABSENT)) {
234*7c478bd9Sstevel@tonic-gate 			err = ptree_delete_node(objp->node);
235*7c478bd9Sstevel@tonic-gate 			if (err != 0) {
236*7c478bd9Sstevel@tonic-gate 				init_err(PTREE_DELETE_NODE_ERR, funcname,
237*7c478bd9Sstevel@tonic-gate 					picl_strerror(err));
238*7c478bd9Sstevel@tonic-gate 				return;
239*7c478bd9Sstevel@tonic-gate 			}
240*7c478bd9Sstevel@tonic-gate 		}
241*7c478bd9Sstevel@tonic-gate 	}
242*7c478bd9Sstevel@tonic-gate 
243*7c478bd9Sstevel@tonic-gate 	/*
244*7c478bd9Sstevel@tonic-gate 	 * Remove PICL device nodes if their /devices file isn't present or
245*7c478bd9Sstevel@tonic-gate 	 * if the device file is present but the open returns ENXIO
246*7c478bd9Sstevel@tonic-gate 	 * which indicates that the node file doesn't represent a device
247*7c478bd9Sstevel@tonic-gate 	 * tree node and is probably a relic from some previous boot config
248*7c478bd9Sstevel@tonic-gate 	 */
249*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < DEV_PR_COUNT; ++i) {
250*7c478bd9Sstevel@tonic-gate 		picl_nodehdl_t	dev_pr_node;
251*7c478bd9Sstevel@tonic-gate 		int fd;
252*7c478bd9Sstevel@tonic-gate 		fd = open(dev_pr_info[i].file, O_RDONLY);
253*7c478bd9Sstevel@tonic-gate 		if (fd != -1) {
254*7c478bd9Sstevel@tonic-gate 			close(fd);
255*7c478bd9Sstevel@tonic-gate 			continue;
256*7c478bd9Sstevel@tonic-gate 		}
257*7c478bd9Sstevel@tonic-gate 		if ((errno != ENOENT) && (errno != ENXIO))
258*7c478bd9Sstevel@tonic-gate 			continue;
259*7c478bd9Sstevel@tonic-gate 
260*7c478bd9Sstevel@tonic-gate 		err = ptree_get_node_by_path(dev_pr_info[i].path, &dev_pr_node);
261*7c478bd9Sstevel@tonic-gate 		if (err != 0) {
262*7c478bd9Sstevel@tonic-gate 			syslog(LOG_ERR, "Bad path: %s", dev_pr_info[i].path);
263*7c478bd9Sstevel@tonic-gate 			init_err(PTREE_GET_NODE_ERR, funcname,
264*7c478bd9Sstevel@tonic-gate 				picl_strerror(err));
265*7c478bd9Sstevel@tonic-gate 			return;
266*7c478bd9Sstevel@tonic-gate 		}
267*7c478bd9Sstevel@tonic-gate 
268*7c478bd9Sstevel@tonic-gate 		err = ptree_delete_node(dev_pr_node);
269*7c478bd9Sstevel@tonic-gate 		if (err != 0) {
270*7c478bd9Sstevel@tonic-gate 			init_err(PTREE_DELETE_NODE_ERR, funcname,
271*7c478bd9Sstevel@tonic-gate 				picl_strerror(err));
272*7c478bd9Sstevel@tonic-gate 			return;
273*7c478bd9Sstevel@tonic-gate 		}
274*7c478bd9Sstevel@tonic-gate 	}
275*7c478bd9Sstevel@tonic-gate 	free(psvc_hdl.objects);
276*7c478bd9Sstevel@tonic-gate }
277*7c478bd9Sstevel@tonic-gate 
278*7c478bd9Sstevel@tonic-gate void
psvc_psr_plugin_fini(void)279*7c478bd9Sstevel@tonic-gate psvc_psr_plugin_fini(void)
280*7c478bd9Sstevel@tonic-gate {
281*7c478bd9Sstevel@tonic-gate 	psvc_fini(hdlp);
282*7c478bd9Sstevel@tonic-gate 	hdlp = NULL;
283*7c478bd9Sstevel@tonic-gate }
284*7c478bd9Sstevel@tonic-gate 
285*7c478bd9Sstevel@tonic-gate void
psvc_psr_plugin_register(void)286*7c478bd9Sstevel@tonic-gate psvc_psr_plugin_register(void)
287*7c478bd9Sstevel@tonic-gate {
288*7c478bd9Sstevel@tonic-gate 	picld_plugin_register(&psvc_psr_reg);
289*7c478bd9Sstevel@tonic-gate }
290