Print this page
11226 Remove NetraCT support
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/picl/plugins/sun4v/mdesc/mdescplugin.c
+++ new/usr/src/cmd/picl/plugins/sun4v/mdesc/mdescplugin.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 + *
26 + * Copyright 2019 Peter Tribble.
25 27 */
26 28
27 29 /*
28 30 * The MDESC picl plugin serves 2 different functionalities.
29 31 * --The first is to look up certain CPU properties in the MDESC an to add
30 32 * these properties in the already created CPU PICL nodes in the /platform
31 33 * section of the tree.
32 34 * --The second functionality is to create a /disk_discovery section of the
33 35 * PICL tree which will have a disk node created for each disk node in the
34 36 * machine description.
35 37 */
36 38
37 39 #include "mdescplugin.h"
38 40 #include <libnvpair.h>
39 41
40 42 #pragma init(mdescplugin_register) /* place in .init section */
41 43
42 44 picl_nodehdl_t root_node;
43 45 md_t *mdp;
44 46 mde_cookie_t rootnode;
45 47
46 48 void mdescplugin_init(void);
47 49 void mdescplugin_fini(void);
48 50 static void signal_devtree(void);
49 51
50 52 extern int add_cpu_prop(picl_nodehdl_t node, void *args);
51 53 extern int disk_discovery(void);
52 54 extern md_t *mdesc_devinit(void);
53 55 extern void mdesc_devfini(md_t *mdp);
54 56 extern int update_devices(char *dev, int op);
55 57
56 58 picld_plugin_reg_t mdescplugin_reg = {
57 59 PICLD_PLUGIN_VERSION_1,
58 60 PICLD_PLUGIN_CRITICAL,
59 61 "mdesc_plugin",
60 62 mdescplugin_init,
61 63 mdescplugin_fini
62 64 };
63 65
64 66 #define DISK_FOUND 0x00
65 67 #define DISK_NOT_FOUND 0x01
66 68
67 69 typedef struct disk_lookup {
68 70 char *path;
69 71 picl_nodehdl_t disk;
70 72 int result;
71 73 } disk_lookup_t;
72 74
73 75 int
74 76 find_disk(picl_nodehdl_t node, void *args)
75 77 {
76 78 disk_lookup_t *lookup = (disk_lookup_t *)args;
77 79 int status;
78 80 char path[PICL_PROPNAMELEN_MAX];
79 81
80 82 status = ptree_get_propval_by_name(node, "Path", (void *)&path,
81 83 PICL_PROPNAMELEN_MAX);
82 84 if (status != PICL_SUCCESS) {
83 85 return (PICL_WALK_CONTINUE);
84 86 }
85 87
86 88 if (strcmp(path, lookup->path) == 0) {
87 89 lookup->disk = node;
88 90 lookup->result = DISK_FOUND;
89 91 return (PICL_WALK_TERMINATE);
90 92 }
91 93
92 94 return (PICL_WALK_CONTINUE);
93 95 }
94 96
95 97 /*
96 98 * DR event handler
97 99 * respond to the picl events:
98 100 * PICLEVENT_DR_AP_STATE_CHANGE
99 101 */
100 102 static void
101 103 dr_handler(const char *ename, const void *earg, size_t size, void *cookie)
102 104 {
103 105 nvlist_t *nvlp = NULL;
104 106 char *dtype;
105 107 char *ap_id;
106 108 char *hint;
107 109
108 110
109 111 if (strcmp(ename, PICLEVENT_DR_AP_STATE_CHANGE) != 0) {
110 112 return;
111 113 }
112 114
113 115 if (nvlist_unpack((char *)earg, size, &nvlp, NULL)) {
114 116 return;
115 117 }
116 118
117 119 if (nvlist_lookup_string(nvlp, PICLEVENTARG_DATA_TYPE, &dtype)) {
118 120 nvlist_free(nvlp);
119 121 return;
120 122 }
121 123
122 124 if (strcmp(dtype, PICLEVENTARG_PICLEVENT_DATA) != 0) {
123 125 nvlist_free(nvlp);
124 126 return;
125 127 }
126 128
127 129 if (nvlist_lookup_string(nvlp, PICLEVENTARG_AP_ID, &ap_id)) {
128 130 nvlist_free(nvlp);
129 131 return;
130 132 }
131 133
132 134 if (nvlist_lookup_string(nvlp, PICLEVENTARG_HINT, &hint)) {
133 135 nvlist_free(nvlp);
134 136 return;
135 137 }
136 138
137 139 mdp = mdesc_devinit();
138 140 if (mdp == NULL) {
139 141 nvlist_free(nvlp);
140 142 return;
141 143 }
142 144
143 145 rootnode = md_root_node(mdp);
144 146
145 147 if (strcmp(hint, DR_HINT_INSERT) == 0)
146 148 (void) update_devices(ap_id, DEV_ADD);
147 149 else if (strcmp(hint, DR_HINT_REMOVE) == 0)
148 150 (void) update_devices(ap_id, DEV_REMOVE);
149 151
150 152 mdesc_devfini(mdp);
151 153 nvlist_free(nvlp);
152 154
153 155 /*
154 156 * Signal the devtree plugin to add more cpu properties.
155 157 */
156 158 signal_devtree();
157 159 }
158 160
159 161 /*
160 162 * Discovery event handler
161 163 * respond to the picl events:
162 164 * PICLEVENT_SYSEVENT_DEVICE_ADDED
163 165 * PICLEVENT_SYSEVENT_DEVICE_REMOVED
164 166 */
165 167 static void
166 168 dsc_handler(const char *ename, const void *earg, size_t size, void *cookie)
167 169 {
168 170 nvlist_t *nvlp = NULL;
169 171 char *path;
170 172 disk_lookup_t lookup;
171 173 int status;
172 174
173 175 /*
174 176 * retrieve the device's physical path from the event arg
175 177 * and determine which disk (if any) we are working with
176 178 */
177 179 if (nvlist_unpack((char *)earg, size, &nvlp, NULL))
178 180 return;
179 181 if (nvlist_lookup_string(nvlp, "devfs-path", &path))
180 182 return;
181 183
182 184 lookup.path = strdup(path);
183 185 lookup.disk = NULL;
184 186 lookup.result = DISK_NOT_FOUND;
185 187
186 188 status = ptree_walk_tree_by_class(root_node, "disk", (void *)&lookup,
187 189 find_disk);
188 190 if (status != PICL_SUCCESS) {
189 191 return;
190 192 }
191 193
192 194 if (lookup.result == DISK_FOUND) {
193 195 if (strcmp(ename, PICLEVENT_SYSEVENT_DEVICE_ADDED) == 0)
194 196 ptree_update_propval_by_name(lookup.disk, "State",
195 197 (void *)strdup(CONFIGURED), PICL_PROPNAMELEN_MAX);
196 198 else if (strcmp(ename, PICLEVENT_SYSEVENT_DEVICE_REMOVED) == 0)
197 199 ptree_update_propval_by_name(lookup.disk, "State",
198 200 (void *)strdup(UNCONFIGURED), PICL_PROPNAMELEN_MAX);
199 201 }
200 202
201 203 nvlist_free(nvlp);
202 204 }
203 205
204 206 /*ARGSUSED*/
205 207 static void
206 208 mdesc_ev_completion_handler(char *ename, void *earg, size_t size)
207 209 {
208 210 free(earg);
209 211 }
210 212
211 213 static void
212 214 signal_devtree(void)
↓ open down ↓ |
178 lines elided |
↑ open up ↑ |
213 215 {
214 216 nvlist_t *nvl;
215 217 char *packed_nvl;
216 218 size_t nvl_size;
217 219 int status;
218 220
219 221 if (nvlist_alloc(&nvl, NV_UNIQUE_NAME_TYPE, NULL) != 0)
220 222 return;
221 223
222 224 /*
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
225 + * This event is consumed by the devtree
228 226 * plug-in. The event signals the plug-in to re-run its
229 227 * cpu initialization function, which will cause it to add
230 228 * additional information to the cpu devtree nodes (particularly,
231 229 * the administrative state of the cpus.)
232 230 */
233 231 if (nvlist_add_string(nvl, PICLEVENTARG_EVENT_NAME,
234 232 PICLEVENT_CPU_STATE_CHANGE) != 0) {
235 233 free(nvl);
236 234 return;
237 235 }
238 236
239 237 /*
240 238 * The devtree plug-in needs to see a devfs path argument for
241 239 * any event it considers. We supply one here which is essentially
242 240 * a dummy since it is not processed by the devtree plug-in for
243 241 * this event.
244 242 */
245 243 if (nvlist_add_string(nvl, PICLEVENTARG_DEVFS_PATH, "/cpu") != 0) {
246 244 free(nvl);
247 245 return;
248 246 }
249 247 packed_nvl = NULL;
250 248 if (nvlist_pack(nvl, &packed_nvl, &nvl_size, NV_ENCODE_NATIVE,
251 249 0) != 0) {
252 250 free(nvl);
253 251 return;
254 252 }
255 253 if ((status = ptree_post_event(PICLEVENT_CPU_STATE_CHANGE,
256 254 packed_nvl, nvl_size, mdesc_ev_completion_handler)) !=
257 255 PICL_SUCCESS) {
258 256 free(nvl);
259 257 syslog(LOG_WARNING,
260 258 "signal_devtree: can't post cpu event: %d\n", status);
261 259 }
262 260 }
263 261
264 262 void
265 263 mdescplugin_init(void)
266 264 {
267 265 int status;
268 266
269 267 status = ptree_get_root(&root_node);
270 268 if (status != PICL_SUCCESS) {
271 269 return;
272 270 }
273 271
274 272 mdp = mdesc_devinit();
275 273 if (mdp == NULL)
276 274 return;
277 275
278 276 /*
279 277 * update the cpu configuration in case the snapshot cache used by the
280 278 * devtree plugin is out of date.
281 279 */
282 280 (void) update_devices(OBP_CPU, DEV_ADD);
283 281 (void) update_devices(OBP_CPU, DEV_REMOVE);
284 282
285 283 rootnode = md_root_node(mdp);
286 284
287 285 /*
288 286 * This is the start of the CPU property augmentation code.
289 287 * add_cpu_prop and the rest of the CPU code lives in cpu_prop_update.c
290 288 */
291 289 status = ptree_walk_tree_by_class(root_node, "cpu", NULL, add_cpu_prop);
292 290 if (status != PICL_SUCCESS) {
293 291 return;
294 292 }
295 293
296 294 signal_devtree();
297 295
298 296 (void) disk_discovery();
299 297
300 298 /*
301 299 * register dsc_handler for both "sysevent-device-added" and
302 300 * and for "sysevent-device-removed" PICL events
303 301 */
304 302 (void) ptree_register_handler(PICLEVENT_SYSEVENT_DEVICE_ADDED,
305 303 dsc_handler, NULL);
306 304 (void) ptree_register_handler(PICLEVENT_SYSEVENT_DEVICE_REMOVED,
307 305 dsc_handler, NULL);
308 306 (void) ptree_register_handler(PICLEVENT_DR_AP_STATE_CHANGE,
309 307 dr_handler, NULL);
310 308
311 309 mdesc_devfini(mdp);
312 310 }
313 311
314 312 void
315 313 mdescplugin_fini(void)
316 314 {
317 315 /* unregister the event handler */
318 316 (void) ptree_unregister_handler(PICLEVENT_SYSEVENT_DEVICE_ADDED,
319 317 dsc_handler, NULL);
320 318 (void) ptree_unregister_handler(PICLEVENT_SYSEVENT_DEVICE_REMOVED,
321 319 dsc_handler, NULL);
322 320 (void) ptree_unregister_handler(PICLEVENT_DR_AP_STATE_CHANGE,
323 321 dr_handler, NULL);
324 322 }
325 323
326 324 void
327 325 mdescplugin_register(void)
328 326 {
329 327 picld_plugin_register(&mdescplugin_reg);
330 328 }
↓ open down ↓ |
93 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX