4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 * The MDESC picl plugin serves 2 different functionalities.
29 * --The first is to look up certain CPU properties in the MDESC an to add
30 * these properties in the already created CPU PICL nodes in the /platform
31 * section of the tree.
32 * --The second functionality is to create a /disk_discovery section of the
33 * PICL tree which will have a disk node created for each disk node in the
34 * machine description.
37 #include "mdescplugin.h"
38 #include <libnvpair.h>
40 #pragma init(mdescplugin_register) /* place in .init section */
42 picl_nodehdl_t root_node
;
44 mde_cookie_t rootnode
;
46 void mdescplugin_init(void);
47 void mdescplugin_fini(void);
48 static void signal_devtree(void);
50 extern int add_cpu_prop(picl_nodehdl_t node
, void *args
);
51 extern int disk_discovery(void);
52 extern md_t
*mdesc_devinit(void);
53 extern void mdesc_devfini(md_t
*mdp
);
54 extern int update_devices(char *dev
, int op
);
56 picld_plugin_reg_t mdescplugin_reg
= {
57 PICLD_PLUGIN_VERSION_1
,
58 PICLD_PLUGIN_CRITICAL
,
64 #define DISK_FOUND 0x00
65 #define DISK_NOT_FOUND 0x01
67 typedef struct disk_lookup
{
74 find_disk(picl_nodehdl_t node
, void *args
)
76 disk_lookup_t
*lookup
= (disk_lookup_t
*)args
;
78 char path
[PICL_PROPNAMELEN_MAX
];
80 status
= ptree_get_propval_by_name(node
, "Path", (void *)&path
,
81 PICL_PROPNAMELEN_MAX
);
82 if (status
!= PICL_SUCCESS
) {
83 return (PICL_WALK_CONTINUE
);
86 if (strcmp(path
, lookup
->path
) == 0) {
88 lookup
->result
= DISK_FOUND
;
89 return (PICL_WALK_TERMINATE
);
92 return (PICL_WALK_CONTINUE
);
97 * respond to the picl events:
98 * PICLEVENT_DR_AP_STATE_CHANGE
101 dr_handler(const char *ename
, const void *earg
, size_t size
, void *cookie
)
103 nvlist_t
*nvlp
= NULL
;
109 if (strcmp(ename
, PICLEVENT_DR_AP_STATE_CHANGE
) != 0) {
113 if (nvlist_unpack((char *)earg
, size
, &nvlp
, NULL
)) {
117 if (nvlist_lookup_string(nvlp
, PICLEVENTARG_DATA_TYPE
, &dtype
)) {
122 if (strcmp(dtype
, PICLEVENTARG_PICLEVENT_DATA
) != 0) {
127 if (nvlist_lookup_string(nvlp
, PICLEVENTARG_AP_ID
, &ap_id
)) {
132 if (nvlist_lookup_string(nvlp
, PICLEVENTARG_HINT
, &hint
)) {
137 mdp
= mdesc_devinit();
143 rootnode
= md_root_node(mdp
);
145 if (strcmp(hint
, DR_HINT_INSERT
) == 0)
146 (void) update_devices(ap_id
, DEV_ADD
);
147 else if (strcmp(hint
, DR_HINT_REMOVE
) == 0)
148 (void) update_devices(ap_id
, DEV_REMOVE
);
154 * Signal the devtree plugin to add more cpu properties.
160 * Discovery event handler
161 * respond to the picl events:
162 * PICLEVENT_SYSEVENT_DEVICE_ADDED
163 * PICLEVENT_SYSEVENT_DEVICE_REMOVED
166 dsc_handler(const char *ename
, const void *earg
, size_t size
, void *cookie
)
168 nvlist_t
*nvlp
= NULL
;
170 disk_lookup_t lookup
;
174 * retrieve the device's physical path from the event arg
175 * and determine which disk (if any) we are working with
177 if (nvlist_unpack((char *)earg
, size
, &nvlp
, NULL
))
179 if (nvlist_lookup_string(nvlp
, "devfs-path", &path
))
182 lookup
.path
= strdup(path
);
184 lookup
.result
= DISK_NOT_FOUND
;
186 status
= ptree_walk_tree_by_class(root_node
, "disk", (void *)&lookup
,
188 if (status
!= PICL_SUCCESS
) {
192 if (lookup
.result
== DISK_FOUND
) {
193 if (strcmp(ename
, PICLEVENT_SYSEVENT_DEVICE_ADDED
) == 0)
194 ptree_update_propval_by_name(lookup
.disk
, "State",
195 (void *)strdup(CONFIGURED
), PICL_PROPNAMELEN_MAX
);
196 else if (strcmp(ename
, PICLEVENT_SYSEVENT_DEVICE_REMOVED
) == 0)
197 ptree_update_propval_by_name(lookup
.disk
, "State",
198 (void *)strdup(UNCONFIGURED
), PICL_PROPNAMELEN_MAX
);
206 mdesc_ev_completion_handler(char *ename
, void *earg
, size_t size
)
219 if (nvlist_alloc(&nvl
, NV_UNIQUE_NAME_TYPE
, NULL
) != 0)
223 * Right now (Aug. 2007) snowbird is the only other platform
224 * which uses this event. Since that's a sun4u platform and
225 * this is sun4v we do not have to worry about possible confusion
226 * or interference between the two by grabbing this event for
227 * our own use here. This event is consumed by the devtree
228 * plug-in. The event signals the plug-in to re-run its
229 * cpu initialization function, which will cause it to add
230 * additional information to the cpu devtree nodes (particularly,
231 * the administrative state of the cpus.)
233 if (nvlist_add_string(nvl
, PICLEVENTARG_EVENT_NAME
,
234 PICLEVENT_CPU_STATE_CHANGE
) != 0) {
240 * The devtree plug-in needs to see a devfs path argument for
241 * any event it considers. We supply one here which is essentially
242 * a dummy since it is not processed by the devtree plug-in for
245 if (nvlist_add_string(nvl
, PICLEVENTARG_DEVFS_PATH
, "/cpu") != 0) {
250 if (nvlist_pack(nvl
, &packed_nvl
, &nvl_size
, NV_ENCODE_NATIVE
,
255 if ((status
= ptree_post_event(PICLEVENT_CPU_STATE_CHANGE
,
256 packed_nvl
, nvl_size
, mdesc_ev_completion_handler
)) !=
260 "signal_devtree: can't post cpu event: %d\n", status
);
265 mdescplugin_init(void)
269 status
= ptree_get_root(&root_node
);
270 if (status
!= PICL_SUCCESS
) {
274 mdp
= mdesc_devinit();
279 * update the cpu configuration in case the snapshot cache used by the
280 * devtree plugin is out of date.
282 (void) update_devices(OBP_CPU
, DEV_ADD
);
283 (void) update_devices(OBP_CPU
, DEV_REMOVE
);
285 rootnode
= md_root_node(mdp
);
288 * This is the start of the CPU property augmentation code.
289 * add_cpu_prop and the rest of the CPU code lives in cpu_prop_update.c
291 status
= ptree_walk_tree_by_class(root_node
, "cpu", NULL
, add_cpu_prop
);
292 if (status
!= PICL_SUCCESS
) {
298 (void) disk_discovery();
301 * register dsc_handler for both "sysevent-device-added" and
302 * and for "sysevent-device-removed" PICL events
304 (void) ptree_register_handler(PICLEVENT_SYSEVENT_DEVICE_ADDED
,
306 (void) ptree_register_handler(PICLEVENT_SYSEVENT_DEVICE_REMOVED
,
308 (void) ptree_register_handler(PICLEVENT_DR_AP_STATE_CHANGE
,
315 mdescplugin_fini(void)
317 /* unregister the event handler */
318 (void) ptree_unregister_handler(PICLEVENT_SYSEVENT_DEVICE_ADDED
,
320 (void) ptree_unregister_handler(PICLEVENT_SYSEVENT_DEVICE_REMOVED
,
322 (void) ptree_unregister_handler(PICLEVENT_DR_AP_STATE_CHANGE
,
327 mdescplugin_register(void)
329 picld_plugin_register(&mdescplugin_reg
);