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 Littleneck platform plug-in to create environment tree nodes.
29*7c478bd9Sstevel@tonic-gate */
30*7c478bd9Sstevel@tonic-gate #define _POSIX_PRIORITY_SCHEDULING 1
31*7c478bd9Sstevel@tonic-gate
32*7c478bd9Sstevel@tonic-gate #include <picl.h>
33*7c478bd9Sstevel@tonic-gate #include <picltree.h>
34*7c478bd9Sstevel@tonic-gate #include <stdio.h>
35*7c478bd9Sstevel@tonic-gate #include <time.h>
36*7c478bd9Sstevel@tonic-gate #include <fcntl.h>
37*7c478bd9Sstevel@tonic-gate #include <unistd.h>
38*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
39*7c478bd9Sstevel@tonic-gate #include <stdio.h>
40*7c478bd9Sstevel@tonic-gate #include <libintl.h>
41*7c478bd9Sstevel@tonic-gate #include <limits.h>
42*7c478bd9Sstevel@tonic-gate #include <ctype.h>
43*7c478bd9Sstevel@tonic-gate #include <errno.h>
44*7c478bd9Sstevel@tonic-gate #include <semaphore.h>
45*7c478bd9Sstevel@tonic-gate #include <syslog.h>
46*7c478bd9Sstevel@tonic-gate #include <string.h>
47*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
48*7c478bd9Sstevel@tonic-gate #include <sys/systeminfo.h>
49*7c478bd9Sstevel@tonic-gate #include <psvc_objects.h>
50*7c478bd9Sstevel@tonic-gate
51*7c478bd9Sstevel@tonic-gate static psvc_opaque_t hdlp;
52*7c478bd9Sstevel@tonic-gate
53*7c478bd9Sstevel@tonic-gate #define PSVC_PLUGIN_VERSION PICLD_PLUGIN_VERSION_1
54*7c478bd9Sstevel@tonic-gate
55*7c478bd9Sstevel@tonic-gate #pragma init(psvc_psr_plugin_register) /* place in .init section */
56*7c478bd9Sstevel@tonic-gate
57*7c478bd9Sstevel@tonic-gate typedef struct {
58*7c478bd9Sstevel@tonic-gate char name[32];
59*7c478bd9Sstevel@tonic-gate picl_nodehdl_t node;
60*7c478bd9Sstevel@tonic-gate } picl_psvc_t;
61*7c478bd9Sstevel@tonic-gate
62*7c478bd9Sstevel@tonic-gate extern struct handle {
63*7c478bd9Sstevel@tonic-gate uint32_t obj_count;
64*7c478bd9Sstevel@tonic-gate picl_psvc_t *objects;
65*7c478bd9Sstevel@tonic-gate FILE *fp;
66*7c478bd9Sstevel@tonic-gate } psvc_hdl;
67*7c478bd9Sstevel@tonic-gate
68*7c478bd9Sstevel@tonic-gate void psvc_psr_plugin_init(void);
69*7c478bd9Sstevel@tonic-gate void psvc_psr_plugin_fini(void);
70*7c478bd9Sstevel@tonic-gate
71*7c478bd9Sstevel@tonic-gate picld_plugin_reg_t psvc_psr_reg = {
72*7c478bd9Sstevel@tonic-gate PSVC_PLUGIN_VERSION,
73*7c478bd9Sstevel@tonic-gate PICLD_PLUGIN_CRITICAL,
74*7c478bd9Sstevel@tonic-gate "PSVC_PSR",
75*7c478bd9Sstevel@tonic-gate psvc_psr_plugin_init,
76*7c478bd9Sstevel@tonic-gate psvc_psr_plugin_fini
77*7c478bd9Sstevel@tonic-gate };
78*7c478bd9Sstevel@tonic-gate
79*7c478bd9Sstevel@tonic-gate #define PSVC_INIT_ERR gettext("%s: Error in psvc_init(): %s\n")
80*7c478bd9Sstevel@tonic-gate #define PTREE_DELETE_NODE_ERR gettext("%s: ptree_delete_node() failed: %s\n")
81*7c478bd9Sstevel@tonic-gate #define PTREE_GET_NODE_ERR \
82*7c478bd9Sstevel@tonic-gate gettext("%s: ptree_get_node_by_path() failed: %s\n")
83*7c478bd9Sstevel@tonic-gate
84*7c478bd9Sstevel@tonic-gate extern int ptree_get_node_by_path(const char *, picl_nodehdl_t *);
85*7c478bd9Sstevel@tonic-gate
86*7c478bd9Sstevel@tonic-gate struct node_file {
87*7c478bd9Sstevel@tonic-gate char path[256];
88*7c478bd9Sstevel@tonic-gate char file[256];
89*7c478bd9Sstevel@tonic-gate } dev_pr_info[] = {
90*7c478bd9Sstevel@tonic-gate {"/SYSTEM/CPU0_MOD_CARD",
91*7c478bd9Sstevel@tonic-gate "/devices/pci@8,700000/ebus@5/i2c@1,30/temperature@0,30:die_temp"},
92*7c478bd9Sstevel@tonic-gate {"/SYSTEM/CPU1_MOD_CARD",
93*7c478bd9Sstevel@tonic-gate "/devices/pci@8,700000/ebus@5/i2c@1,30/temperature@0,98:die_temp"},
94*7c478bd9Sstevel@tonic-gate {"/SYSTEM/AT24C64_A0_1",
95*7c478bd9Sstevel@tonic-gate "/devices/pci@8,700000/ebus@5/i2c@1,2e/dimm@1,a0:dimm"},
96*7c478bd9Sstevel@tonic-gate {"/SYSTEM/AT24C64_A2_1",
97*7c478bd9Sstevel@tonic-gate "/devices/pci@8,700000/ebus@5/i2c@1,2e/dimm@1,a2:dimm"},
98*7c478bd9Sstevel@tonic-gate {"/SYSTEM/AT24C64_A4_1",
99*7c478bd9Sstevel@tonic-gate "/devices/pci@8,700000/ebus@5/i2c@1,2e/dimm@1,a4:dimm"},
100*7c478bd9Sstevel@tonic-gate {"/SYSTEM/AT24C64_A6_1",
101*7c478bd9Sstevel@tonic-gate "/devices/pci@8,700000/ebus@5/i2c@1,2e/dimm@1,a6:dimm"},
102*7c478bd9Sstevel@tonic-gate {"/SYSTEM/AT24C64_A8_1",
103*7c478bd9Sstevel@tonic-gate "/devices/pci@8,700000/ebus@5/i2c@1,2e/dimm@1,a8:dimm"},
104*7c478bd9Sstevel@tonic-gate {"/SYSTEM/AT24C64_AA_1",
105*7c478bd9Sstevel@tonic-gate "/devices/pci@8,700000/ebus@5/i2c@1,2e/dimm@1,aa:dimm"},
106*7c478bd9Sstevel@tonic-gate {"/SYSTEM/AT24C64_AC_1",
107*7c478bd9Sstevel@tonic-gate "/devices/pci@8,700000/ebus@5/i2c@1,2e/dimm@1,ac:dimm"},
108*7c478bd9Sstevel@tonic-gate {"/SYSTEM/AT24C64_AE_1",
109*7c478bd9Sstevel@tonic-gate "/devices/pci@8,700000/ebus@5/i2c@1,2e/dimm@1,ae:dimm"}
110*7c478bd9Sstevel@tonic-gate };
111*7c478bd9Sstevel@tonic-gate #define DEV_PR_COUNT (sizeof (dev_pr_info) / sizeof (struct node_file))
112*7c478bd9Sstevel@tonic-gate
init_err(char * fmt,char * arg1,char * arg2)113*7c478bd9Sstevel@tonic-gate static void init_err(char *fmt, char *arg1, char *arg2)
114*7c478bd9Sstevel@tonic-gate {
115*7c478bd9Sstevel@tonic-gate char msg[256];
116*7c478bd9Sstevel@tonic-gate
117*7c478bd9Sstevel@tonic-gate sprintf(msg, fmt, arg1, arg2);
118*7c478bd9Sstevel@tonic-gate syslog(LOG_ERR, msg);
119*7c478bd9Sstevel@tonic-gate }
120*7c478bd9Sstevel@tonic-gate
121*7c478bd9Sstevel@tonic-gate void
psvc_psr_plugin_init(void)122*7c478bd9Sstevel@tonic-gate psvc_psr_plugin_init(void)
123*7c478bd9Sstevel@tonic-gate {
124*7c478bd9Sstevel@tonic-gate char *funcname = "psvc_plugin_init";
125*7c478bd9Sstevel@tonic-gate int32_t i;
126*7c478bd9Sstevel@tonic-gate int err;
127*7c478bd9Sstevel@tonic-gate boolean_t present;
128*7c478bd9Sstevel@tonic-gate /*
129*7c478bd9Sstevel@tonic-gate * So the volatile read/write routines can retrieve data from
130*7c478bd9Sstevel@tonic-gate * psvc or picl
131*7c478bd9Sstevel@tonic-gate */
132*7c478bd9Sstevel@tonic-gate err = psvc_init(&hdlp);
133*7c478bd9Sstevel@tonic-gate if (err != 0) {
134*7c478bd9Sstevel@tonic-gate init_err(PSVC_INIT_ERR, funcname, strerror(errno));
135*7c478bd9Sstevel@tonic-gate
136*7c478bd9Sstevel@tonic-gate }
137*7c478bd9Sstevel@tonic-gate
138*7c478bd9Sstevel@tonic-gate /*
139*7c478bd9Sstevel@tonic-gate * Remove nodes whose devices aren't present from the picl tree.
140*7c478bd9Sstevel@tonic-gate */
141*7c478bd9Sstevel@tonic-gate for (i = 0; i < psvc_hdl.obj_count; ++i) {
142*7c478bd9Sstevel@tonic-gate picl_psvc_t *objp;
143*7c478bd9Sstevel@tonic-gate uint64_t features;
144*7c478bd9Sstevel@tonic-gate objp = &psvc_hdl.objects[i];
145*7c478bd9Sstevel@tonic-gate
146*7c478bd9Sstevel@tonic-gate err = psvc_get_attr(hdlp, objp->name, PSVC_PRESENCE_ATTR,
147*7c478bd9Sstevel@tonic-gate &present);
148*7c478bd9Sstevel@tonic-gate if (err != PSVC_SUCCESS)
149*7c478bd9Sstevel@tonic-gate continue;
150*7c478bd9Sstevel@tonic-gate err = psvc_get_attr(hdlp, objp->name, PSVC_FEATURES_ATTR,
151*7c478bd9Sstevel@tonic-gate &features);
152*7c478bd9Sstevel@tonic-gate if (err != PSVC_SUCCESS)
153*7c478bd9Sstevel@tonic-gate continue;
154*7c478bd9Sstevel@tonic-gate if ((features & (PSVC_DEV_HOTPLUG | PSVC_DEV_OPTION)) &&
155*7c478bd9Sstevel@tonic-gate (present == PSVC_ABSENT)) {
156*7c478bd9Sstevel@tonic-gate err = ptree_delete_node(objp->node);
157*7c478bd9Sstevel@tonic-gate if (err != 0) {
158*7c478bd9Sstevel@tonic-gate init_err(PTREE_DELETE_NODE_ERR, funcname,
159*7c478bd9Sstevel@tonic-gate picl_strerror(err));
160*7c478bd9Sstevel@tonic-gate return;
161*7c478bd9Sstevel@tonic-gate }
162*7c478bd9Sstevel@tonic-gate }
163*7c478bd9Sstevel@tonic-gate }
164*7c478bd9Sstevel@tonic-gate
165*7c478bd9Sstevel@tonic-gate /*
166*7c478bd9Sstevel@tonic-gate * Remove PICL device nodes if their /devices file isn't present or
167*7c478bd9Sstevel@tonic-gate * if the device file is present but the open returns ENXIO
168*7c478bd9Sstevel@tonic-gate * which indicates that the node file doesn't represent a device
169*7c478bd9Sstevel@tonic-gate * tree node and is probably a relic from some previous boot config
170*7c478bd9Sstevel@tonic-gate */
171*7c478bd9Sstevel@tonic-gate for (i = 0; i < DEV_PR_COUNT; ++i) {
172*7c478bd9Sstevel@tonic-gate picl_nodehdl_t dev_pr_node;
173*7c478bd9Sstevel@tonic-gate int fd;
174*7c478bd9Sstevel@tonic-gate fd = open(dev_pr_info[i].file, O_RDONLY);
175*7c478bd9Sstevel@tonic-gate if (fd != -1) {
176*7c478bd9Sstevel@tonic-gate close(fd);
177*7c478bd9Sstevel@tonic-gate continue;
178*7c478bd9Sstevel@tonic-gate }
179*7c478bd9Sstevel@tonic-gate if ((errno != ENOENT) && (errno != ENXIO))
180*7c478bd9Sstevel@tonic-gate continue;
181*7c478bd9Sstevel@tonic-gate
182*7c478bd9Sstevel@tonic-gate err = ptree_get_node_by_path(dev_pr_info[i].path, &dev_pr_node);
183*7c478bd9Sstevel@tonic-gate if (err != 0) {
184*7c478bd9Sstevel@tonic-gate init_err(PTREE_GET_NODE_ERR, funcname,
185*7c478bd9Sstevel@tonic-gate picl_strerror(err));
186*7c478bd9Sstevel@tonic-gate return;
187*7c478bd9Sstevel@tonic-gate }
188*7c478bd9Sstevel@tonic-gate
189*7c478bd9Sstevel@tonic-gate err = ptree_delete_node(dev_pr_node);
190*7c478bd9Sstevel@tonic-gate if (err != 0) {
191*7c478bd9Sstevel@tonic-gate init_err(PTREE_DELETE_NODE_ERR, funcname,
192*7c478bd9Sstevel@tonic-gate picl_strerror(err));
193*7c478bd9Sstevel@tonic-gate return;
194*7c478bd9Sstevel@tonic-gate }
195*7c478bd9Sstevel@tonic-gate }
196*7c478bd9Sstevel@tonic-gate free(psvc_hdl.objects);
197*7c478bd9Sstevel@tonic-gate }
198*7c478bd9Sstevel@tonic-gate
199*7c478bd9Sstevel@tonic-gate void
psvc_psr_plugin_fini(void)200*7c478bd9Sstevel@tonic-gate psvc_psr_plugin_fini(void)
201*7c478bd9Sstevel@tonic-gate {
202*7c478bd9Sstevel@tonic-gate psvc_fini(hdlp);
203*7c478bd9Sstevel@tonic-gate }
204*7c478bd9Sstevel@tonic-gate
205*7c478bd9Sstevel@tonic-gate void
psvc_psr_plugin_register(void)206*7c478bd9Sstevel@tonic-gate psvc_psr_plugin_register(void)
207*7c478bd9Sstevel@tonic-gate {
208*7c478bd9Sstevel@tonic-gate picld_plugin_register(&psvc_psr_reg);
209*7c478bd9Sstevel@tonic-gate }
210