xref: /illumos-gate/usr/src/cmd/devfsadm/misc_link.c (revision 66073a689fed2fc64a7864ec0fab8072c4f02764)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
23  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
24  * Copyright (c) 2015, Joyent, Inc. All rights reserved.
25  * Copyright 2022 Garrett D'Amore <garrett@damore.org>
26  * Copyright 2023 Oxide Computer Company
27  */
28 
29 #include <regex.h>
30 #include <devfsadm.h>
31 #include <stdio.h>
32 #include <strings.h>
33 #include <stdlib.h>
34 #include <limits.h>
35 #include <sys/zone.h>
36 #include <sys/zcons.h>
37 #include <sys/cpuid_drv.h>
38 
39 static int display(di_minor_t minor, di_node_t node);
40 static int parallel(di_minor_t minor, di_node_t node);
41 static int node_slash_minor(di_minor_t minor, di_node_t node);
42 static int driver_minor(di_minor_t minor, di_node_t node);
43 static int node_name(di_minor_t minor, di_node_t node);
44 static int minor_name(di_minor_t minor, di_node_t node);
45 static int wifi_minor_name(di_minor_t minor, di_node_t node);
46 static int conskbd(di_minor_t minor, di_node_t node);
47 static int consms(di_minor_t minor, di_node_t node);
48 static int power_button(di_minor_t minor, di_node_t node);
49 static int fc_port(di_minor_t minor, di_node_t node);
50 static int printer_create(di_minor_t minor, di_node_t node);
51 static int se_hdlc_create(di_minor_t minor, di_node_t node);
52 static int ppm(di_minor_t minor, di_node_t node);
53 static int gpio(di_minor_t minor, di_node_t node);
54 static int av_create(di_minor_t minor, di_node_t node);
55 static int tsalarm_create(di_minor_t minor, di_node_t node);
56 static int ntwdt_create(di_minor_t minor, di_node_t node);
57 static int zcons_create(di_minor_t minor, di_node_t node);
58 static int cpuid(di_minor_t minor, di_node_t node);
59 static int glvc(di_minor_t minor, di_node_t node);
60 static int ses_callback(di_minor_t minor, di_node_t node);
61 static int kmdrv_create(di_minor_t minor, di_node_t node);
62 static int vio9p_create(di_minor_t minor, di_node_t node);
63 
64 static devfsadm_create_t misc_cbt[] = {
65 	{ "pseudo", "ddi_pseudo", "(^sad$)",
66 	    TYPE_EXACT | DRV_RE, ILEVEL_0, node_slash_minor
67 	},
68 	{ "pseudo", "ddi_pseudo", "zsh",
69 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, driver_minor
70 	},
71 	{ "network", "ddi_network", NULL,
72 	    TYPE_EXACT, ILEVEL_0, minor_name
73 	},
74 	{ "wifi", "ddi_network:wifi", NULL,
75 	    TYPE_EXACT, ILEVEL_0, wifi_minor_name
76 	},
77 	{ "display", "ddi_display", NULL,
78 	    TYPE_EXACT, ILEVEL_0, display
79 	},
80 	{ "parallel", "ddi_parallel", NULL,
81 	    TYPE_EXACT, ILEVEL_0, parallel
82 	},
83 	{ "enclosure", DDI_NT_SCSI_ENCLOSURE, NULL,
84 	    TYPE_EXACT, ILEVEL_0, ses_callback
85 	},
86 	{ "pseudo", "ddi_pseudo", "(^pm$)",
87 	    TYPE_EXACT | DRV_RE, ILEVEL_0, node_name
88 	},
89 	{ "pseudo", "ddi_pseudo", "conskbd",
90 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, conskbd
91 	},
92 	{ "pseudo", "ddi_pseudo", "consms",
93 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, consms
94 	},
95 	{ "pseudo", "ddi_pseudo", "eventfd",
96 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, minor_name
97 	},
98 	{ "pseudo", "ddi_pseudo", "signalfd",
99 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, minor_name
100 	},
101 	{ "pseudo", "ddi_pseudo", "rsm",
102 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, minor_name
103 	},
104 	{ "pseudo", "ddi_pseudo",
105 	    "(^lockstat$)|(^SUNW,rtvc$)|(^vol$)|(^log$)|(^sy$)|"
106 	    "(^ksyms$)|(^clone$)|(^tl$)|(^kstat$)|(^mdesc$)|(^eeprom$)|"
107 	    "(^ptsl$)|(^mm$)|(^wc$)|(^dump$)|(^cn$)|(^svvslo$)|(^ptm$)|"
108 	    "(^ptc$)|(^openeepr$)|(^poll$)|(^sysmsg$)|(^random$)|(^trapstat$)|"
109 	    "(^cryptoadm$)|(^crypto$)|(^pool$)|(^poolctl$)|(^bl$)|(^kmdb$)|"
110 	    "(^sysevent$)|(^physmem$)",
111 	    TYPE_EXACT | DRV_RE, ILEVEL_1, minor_name
112 	},
113 	{ "pseudo", "ddi_pseudo",
114 	    "(^ip$)|(^tcp$)|(^udp$)|(^icmp$)|"
115 	    "(^ip6$)|(^tcp6$)|(^udp6$)|(^icmp6$)|"
116 	    "(^rts$)|(^arp$)|(^ipsecah$)|(^ipsecesp$)|(^keysock$)|(^spdsock$)|"
117 	    "(^rds$)|(^sdp$)|(^ipnet$)|(^dlpistub$)|(^bpf$)",
118 	    TYPE_EXACT | DRV_RE, ILEVEL_1, minor_name
119 	},
120 	{ "pseudo", "ddi_pseudo", "ipd",
121 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, minor_name
122 	},
123 	{ "pseudo", "ddi_pseudo",
124 	    "(^ipf$)|(^ipnat$)|(^ipstate$)|(^ipauth$)|"
125 	    "(^ipsync$)|(^ipscan$)|(^iplookup$)",
126 	    TYPE_EXACT | DRV_RE, ILEVEL_0, minor_name,
127 	},
128 	{ "pseudo", "ddi_pseudo", "dld",
129 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, node_name
130 	},
131 	{ "pseudo", "ddi_pseudo",
132 	    "(^kdmouse$)|(^rootprop$)",
133 	    TYPE_EXACT | DRV_RE, ILEVEL_0, node_name
134 	},
135 	{ "pseudo", "ddi_pseudo", "timerfd",
136 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, minor_name
137 	},
138 	{ "pseudo", "ddi_pseudo", "tod",
139 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, node_name
140 	},
141 	{ "pseudo", "ddi_pseudo", "envctrl(two)?",
142 	    TYPE_EXACT | DRV_RE, ILEVEL_1, minor_name,
143 	},
144 	{ "pseudo", "ddi_pseudo", "fcode",
145 	    TYPE_EXACT | DRV_RE, ILEVEL_0, minor_name,
146 	},
147 	{ "power_button", "ddi_power_button", NULL,
148 	    TYPE_EXACT, ILEVEL_0, power_button,
149 	},
150 	{ "FC port", "ddi_ctl:devctl", "fp",
151 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, fc_port
152 	},
153 	{ "printer", "ddi_printer", NULL,
154 	    TYPE_EXACT, ILEVEL_0, printer_create
155 	},
156 	{ "pseudo", "ddi_pseudo", "se",
157 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, se_hdlc_create
158 	},
159 	{ "ppm",  "ddi_ppm", NULL,
160 	    TYPE_EXACT, ILEVEL_0, ppm
161 	},
162 	{ "pseudo", "ddi_pseudo", "gpio_87317",
163 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, gpio
164 	},
165 	{ "pseudo", "ddi_pseudo", "sckmdrv",
166 	    TYPE_EXACT | DRV_RE, ILEVEL_0, kmdrv_create,
167 	},
168 	{ "pseudo", "ddi_pseudo", "oplkmdrv",
169 	    TYPE_EXACT | DRV_RE, ILEVEL_0, kmdrv_create,
170 	},
171 	{ "av", "^ddi_av:(isoch|async)$", NULL,
172 	    TYPE_RE, ILEVEL_0, av_create,
173 	},
174 	{ "pseudo", "ddi_pseudo", "tsalarm",
175 	    TYPE_EXACT | DRV_RE, ILEVEL_0, tsalarm_create,
176 	},
177 	{ "pseudo", "ddi_pseudo", "ntwdt",
178 	    TYPE_EXACT | DRV_RE, ILEVEL_0, ntwdt_create,
179 	},
180 	{ "pseudo", "ddi_pseudo", "daplt",
181 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, minor_name
182 	},
183 	{ "pseudo", "ddi_pseudo", "zcons",
184 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, zcons_create,
185 	},
186 	{ "pseudo", "ddi_pseudo", CPUID_DRIVER_NAME,
187 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, cpuid,
188 	},
189 	{ "pseudo", "ddi_pseudo", "glvc",
190 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, glvc,
191 	},
192 	{ "pseudo", "ddi_pseudo", "dm2s",
193 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, minor_name,
194 	},
195 	{ "pseudo", "ddi_pseudo", "nsmb",
196 	    TYPE_EXACT | DRV_EXACT, ILEVEL_1, minor_name,
197 	},
198 	{ "pseudo", "ddi_pseudo", "mem_cache",
199 	    TYPE_EXACT | DRV_RE, ILEVEL_1, minor_name,
200 	},
201 	{ "pseudo", "ddi_pseudo", "fm",
202 	    TYPE_EXACT | DRV_RE, ILEVEL_1, minor_name,
203 	},
204 	{ "pseudo", "ddi_pseudo", "smbsrv1?",
205 	    TYPE_EXACT | DRV_RE, ILEVEL_1, minor_name,
206 	},
207 	{ "pseudo", "ddi_pseudo", "tpm",
208 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, minor_name
209 	},
210 	{ "pseudo", "ddi_pseudo", "overlay",
211 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, minor_name
212 	},
213 	{ "9p", "ddi_pseudo", "vio9p",
214 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, vio9p_create,
215 	},
216 	{ "pseudo", "ddi_pseudo", "ktest",
217 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, minor_name
218 	},
219 };
220 
221 DEVFSADM_CREATE_INIT_V0(misc_cbt);
222 
223 static devfsadm_remove_t misc_remove_cbt[] = {
224 	{ "pseudo", "^profile$",
225 	    RM_PRE | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all
226 	},
227 	{ "pseudo", "^rsm$",
228 	    RM_PRE | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all
229 	},
230 	{ "printer", "^printers/[0-9]+$",
231 	    RM_PRE | RM_HOT | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all
232 	},
233 	{ "av", "^av/[0-9]+/(async|isoch)$",
234 	    RM_PRE | RM_HOT | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all
235 	},
236 	{ "pseudo", "^daplt$",
237 	    RM_PRE | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all
238 	},
239 	{ "pseudo", "^zcons/" ZONENAME_REGEXP "/(" ZCONS_MANAGER_NAME "|"
240 		ZCONS_SUBSIDIARY_NAME ")$",
241 	    RM_PRE | RM_HOT | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all
242 	},
243 	{ "pseudo", "^" CPUID_SELF_NAME "$", RM_ALWAYS | RM_PRE | RM_HOT,
244 	    ILEVEL_0, devfsadm_rm_all
245 	},
246 	{ "enclosure", "^es/ses[0-9]+$", RM_POST,
247 		ILEVEL_0, devfsadm_rm_all
248 	},
249 	{ "pseudo", "^pfil$",
250 	    RM_PRE | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all
251 	},
252 	{ "pseudo", "^tpm$",
253 	    RM_PRE | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all
254 	},
255 	{ "pseudo", "^sctp|sctp6$",
256 	    RM_PRE | RM_ALWAYS, ILEVEL_0, devfsadm_rm_link
257 	},
258 	{ "9p", "^9p/[0-9]+$",
259 	    RM_PRE | RM_HOT | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all
260 	},
261 };
262 
263 /* Rules for gpio devices */
264 static devfsadm_enumerate_t gpio_rules[1] =
265 	{"^gpio([0-9]+)$", 1, MATCH_ALL};
266 
267 DEVFSADM_REMOVE_INIT_V0(misc_remove_cbt);
268 
269 /*
270  * Handles minor node type "ddi_display".
271  *
272  * type=ddi_display fbs/\M0 fb\N0
273  */
274 static int
display(di_minor_t minor,di_node_t node)275 display(di_minor_t minor, di_node_t node)
276 {
277 	char l_path[PATH_MAX + 1], contents[PATH_MAX + 1], *buf;
278 	devfsadm_enumerate_t rules[1] = {"^fb([0-9]+)$", 1, MATCH_ALL};
279 	char *mn = di_minor_name(minor);
280 
281 	/* create fbs/\M0 primary link */
282 	(void) strcpy(l_path, "fbs/");
283 	(void) strcat(l_path, mn);
284 	(void) devfsadm_mklink(l_path, node, minor, 0);
285 
286 	/* create fb\N0 which links to fbs/\M0 */
287 	if (devfsadm_enumerate_int(l_path, 0, &buf, rules, 1)) {
288 		return (DEVFSADM_CONTINUE);
289 	}
290 	(void) strcpy(contents, l_path);
291 	(void) strcpy(l_path, "fb");
292 	(void) strcat(l_path, buf);
293 	free(buf);
294 	(void) devfsadm_secondary_link(l_path, contents, 0);
295 	return (DEVFSADM_CONTINUE);
296 }
297 
298 /*
299  * Handles minor node type "ddi_parallel".
300  * type=ddi_parallel;name=mcpp     mcpp\N0
301  */
302 static int
parallel(di_minor_t minor,di_node_t node)303 parallel(di_minor_t minor, di_node_t node)
304 {
305 	char path[PATH_MAX + 1], *buf;
306 	devfsadm_enumerate_t rules[1] = {"mcpp([0-9]+)$", 1, MATCH_ALL};
307 
308 
309 	if (strcmp(di_node_name(node), "mcpp") != 0) {
310 		return (DEVFSADM_CONTINUE);
311 	}
312 
313 	if (NULL == (buf = di_devfs_path(node))) {
314 		return (DEVFSADM_CONTINUE);
315 	}
316 
317 	(void) snprintf(path, sizeof (path), "%s:%s",
318 	    buf, di_minor_name(minor));
319 
320 	di_devfs_path_free(buf);
321 
322 	if (devfsadm_enumerate_int(path, 0, &buf, rules, 1)) {
323 		return (DEVFSADM_CONTINUE);
324 	}
325 	(void) snprintf(path, sizeof (path), "mcpp%s", buf);
326 	free(buf);
327 
328 	(void) devfsadm_mklink(path, node, minor, 0);
329 	return (DEVFSADM_CONTINUE);
330 }
331 
332 static int
ses_callback(di_minor_t minor,di_node_t node)333 ses_callback(di_minor_t minor, di_node_t node)
334 {
335 	char l_path[PATH_MAX];
336 	char *buf;
337 	char *devfspath;
338 	char p_path[PATH_MAX];
339 	devfsadm_enumerate_t re[] = {"^es$/^ses([0-9]+)$", 1, MATCH_ALL};
340 
341 	/* find devices path -- need to free mem */
342 	if (NULL == (devfspath = di_devfs_path(node))) {
343 		return (DEVFSADM_CONTINUE);
344 	}
345 
346 	(void) snprintf(p_path, sizeof (p_path), "%s:%s", devfspath,
347 	    di_minor_name(minor));
348 
349 
350 	/* find next number to use; buf is an ascii number */
351 	if (devfsadm_enumerate_int(p_path, 0, &buf, re, 1)) {
352 		/* free memory */
353 		di_devfs_path_free(devfspath);
354 		return (DEVFSADM_CONTINUE);
355 	}
356 
357 	(void) snprintf(l_path, sizeof (l_path), "es/ses%s", buf);
358 
359 	(void) devfsadm_mklink(l_path, node, minor, 0);
360 	/* free memory */
361 	free(buf);
362 	di_devfs_path_free(devfspath);
363 	return (DEVFSADM_CONTINUE);
364 
365 }
366 
367 static int
node_slash_minor(di_minor_t minor,di_node_t node)368 node_slash_minor(di_minor_t minor, di_node_t node)
369 {
370 
371 	char path[PATH_MAX + 1];
372 
373 	(void) strcpy(path, di_node_name(node));
374 	(void) strcat(path, "/");
375 	(void) strcat(path, di_minor_name(minor));
376 	(void) devfsadm_mklink(path, node, minor, 0);
377 	return (DEVFSADM_CONTINUE);
378 }
379 
380 static int
driver_minor(di_minor_t minor,di_node_t node)381 driver_minor(di_minor_t minor, di_node_t node)
382 {
383 	char path[PATH_MAX + 1];
384 
385 	(void) strcpy(path, di_driver_name(node));
386 	(void) strcat(path, di_minor_name(minor));
387 	(void) devfsadm_mklink(path, node, minor, 0);
388 	return (DEVFSADM_CONTINUE);
389 }
390 
391 /*
392  * Handles links of the form:
393  * type=ddi_pseudo;name=xyz  \D
394  */
395 static int
node_name(di_minor_t minor,di_node_t node)396 node_name(di_minor_t minor, di_node_t node)
397 {
398 	(void) devfsadm_mklink(di_node_name(node), node, minor, 0);
399 	return (DEVFSADM_CONTINUE);
400 }
401 
402 /*
403  * Handles links of the form:
404  * type=ddi_pseudo;name=xyz  \M0
405  */
406 static int
minor_name(di_minor_t minor,di_node_t node)407 minor_name(di_minor_t minor, di_node_t node)
408 {
409 	char *mn = di_minor_name(minor);
410 
411 	(void) devfsadm_mklink(mn, node, minor, 0);
412 	if (strcmp(mn, "icmp") == 0) {
413 		(void) devfsadm_mklink("rawip", node, minor, 0);
414 	}
415 	if (strcmp(mn, "icmp6") == 0) {
416 		(void) devfsadm_mklink("rawip6", node, minor, 0);
417 	}
418 	if (strcmp(mn, "ipf") == 0) {
419 		(void) devfsadm_mklink("ipl", node, minor, 0);
420 	}
421 	return (DEVFSADM_CONTINUE);
422 }
423 
424 /*
425  * create links at /dev/wifi for wifi minor node
426  */
427 static int
wifi_minor_name(di_minor_t minor,di_node_t node)428 wifi_minor_name(di_minor_t minor, di_node_t node)
429 {
430 	char buf[256];
431 	char *mn = di_minor_name(minor);
432 
433 	(void) snprintf(buf, sizeof (buf), "%s%s", "wifi/", mn);
434 	(void) devfsadm_mklink(buf, node, minor, 0);
435 
436 	return (DEVFSADM_CONTINUE);
437 }
438 
439 static int
conskbd(di_minor_t minor,di_node_t node)440 conskbd(di_minor_t minor, di_node_t node)
441 {
442 	(void) devfsadm_mklink("kbd", node, minor, 0);
443 	return (DEVFSADM_CONTINUE);
444 }
445 
446 static int
consms(di_minor_t minor,di_node_t node)447 consms(di_minor_t minor, di_node_t node)
448 {
449 	(void) devfsadm_mklink("mouse", node, minor, 0);
450 	return (DEVFSADM_CONTINUE);
451 }
452 
453 static int
power_button(di_minor_t minor,di_node_t node)454 power_button(di_minor_t minor, di_node_t node)
455 {
456 	(void) devfsadm_mklink("power_button", node, minor, 0);
457 	return (DEVFSADM_CONTINUE);
458 }
459 
460 static int
fc_port(di_minor_t minor,di_node_t node)461 fc_port(di_minor_t minor, di_node_t node)
462 {
463 	devfsadm_enumerate_t rules[1] = {"fc/fp([0-9]+)$", 1, MATCH_ALL};
464 	char *buf, path[PATH_MAX + 1];
465 	char *ptr;
466 
467 	if (NULL == (ptr = di_devfs_path(node))) {
468 		return (DEVFSADM_CONTINUE);
469 	}
470 
471 	(void) strcpy(path, ptr);
472 	(void) strcat(path, ":");
473 	(void) strcat(path, di_minor_name(minor));
474 
475 	di_devfs_path_free(ptr);
476 
477 	if (devfsadm_enumerate_int(path, 0, &buf, rules, 1) != 0) {
478 		return (DEVFSADM_CONTINUE);
479 	}
480 
481 	(void) strcpy(path, "fc/fp");
482 	(void) strcat(path, buf);
483 	free(buf);
484 
485 	(void) devfsadm_mklink(path, node, minor, 0);
486 	return (DEVFSADM_CONTINUE);
487 }
488 
489 /*
490  * Handles:
491  *	minor node type "ddi_printer".
492  *	rules of the form: type=ddi_printer;name=bpp  \M0
493  */
494 static int
printer_create(di_minor_t minor,di_node_t node)495 printer_create(di_minor_t minor, di_node_t node)
496 {
497 	char *mn;
498 	char path[PATH_MAX + 1], *buf;
499 	devfsadm_enumerate_t rules[1] = {"^printers$/^([0-9]+)$", 1, MATCH_ALL};
500 
501 	mn = di_minor_name(minor);
502 
503 	if (strcmp(di_driver_name(node), "bpp") == 0) {
504 		(void) devfsadm_mklink(mn, node, minor, 0);
505 	}
506 
507 	if (NULL == (buf = di_devfs_path(node))) {
508 		return (DEVFSADM_CONTINUE);
509 	}
510 
511 	(void) snprintf(path, sizeof (path), "%s:%s", buf, mn);
512 	di_devfs_path_free(buf);
513 
514 	if (devfsadm_enumerate_int(path, 0, &buf, rules, 1)) {
515 		return (DEVFSADM_CONTINUE);
516 	}
517 
518 	(void) snprintf(path, sizeof (path), "printers/%s", buf);
519 	free(buf);
520 
521 	(void) devfsadm_mklink(path, node, minor, 0);
522 
523 	return (DEVFSADM_CONTINUE);
524 }
525 
526 /*
527  * Handles links of the form:
528  * type=ddi_pseudo;name=se;minor2=hdlc	se_hdlc\N0
529  * type=ddi_pseudo;name=serial;minor2=hdlc	se_hdlc\N0
530  */
531 static int
se_hdlc_create(di_minor_t minor,di_node_t node)532 se_hdlc_create(di_minor_t minor, di_node_t node)
533 {
534 	devfsadm_enumerate_t rules[1] = {"^se_hdlc([0-9]+)$", 1, MATCH_ALL};
535 	char *buf, path[PATH_MAX + 1];
536 	char *ptr;
537 	char *mn;
538 
539 	mn = di_minor_name(minor);
540 
541 	/* minor node should be of the form: "?,hdlc" */
542 	if (strcmp(mn + 1, ",hdlc") != 0) {
543 		return (DEVFSADM_CONTINUE);
544 	}
545 
546 	if (NULL == (ptr = di_devfs_path(node))) {
547 		return (DEVFSADM_CONTINUE);
548 	}
549 
550 	(void) strcpy(path, ptr);
551 	(void) strcat(path, ":");
552 	(void) strcat(path, mn);
553 
554 	di_devfs_path_free(ptr);
555 
556 	if (devfsadm_enumerate_int(path, 0, &buf, rules, 1) != 0) {
557 		return (DEVFSADM_CONTINUE);
558 	}
559 
560 	(void) strcpy(path, "se_hdlc");
561 	(void) strcat(path, buf);
562 	free(buf);
563 
564 	(void) devfsadm_mklink(path, node, minor, 0);
565 
566 	return (DEVFSADM_CONTINUE);
567 }
568 
569 static int
gpio(di_minor_t minor,di_node_t node)570 gpio(di_minor_t minor, di_node_t node)
571 {
572 	char l_path[PATH_MAX], p_path[PATH_MAX], *buf, *devfspath;
573 	char *minor_nm, *drvr_nm;
574 
575 
576 	minor_nm = di_minor_name(minor);
577 	drvr_nm = di_driver_name(node);
578 	if ((minor_nm == NULL) || (drvr_nm == NULL)) {
579 		return (DEVFSADM_CONTINUE);
580 	}
581 
582 	devfspath = di_devfs_path(node);
583 
584 	(void) strcpy(p_path, devfspath);
585 	(void) strcat(p_path, ":");
586 	(void) strcat(p_path, minor_nm);
587 	di_devfs_path_free(devfspath);
588 
589 	/* build the physical path from the components */
590 	if (devfsadm_enumerate_int(p_path, 0, &buf, gpio_rules, 1)) {
591 		return (DEVFSADM_CONTINUE);
592 	}
593 
594 	(void) snprintf(l_path, sizeof (l_path), "%s%s", "gpio", buf);
595 
596 	free(buf);
597 
598 	(void) devfsadm_mklink(l_path, node, minor, 0);
599 
600 	return (DEVFSADM_CONTINUE);
601 }
602 
603 /*
604  * Creates /dev/ppm nodes for Platform Specific PM module
605  */
606 static int
ppm(di_minor_t minor,di_node_t node)607 ppm(di_minor_t minor, di_node_t node)
608 {
609 	(void) devfsadm_mklink("ppm", node, minor, 0);
610 	return (DEVFSADM_CONTINUE);
611 }
612 
613 /*
614  * Handles:
615  *	/dev/av/[0-9]+/(async|isoch)
616  */
617 static int
av_create(di_minor_t minor,di_node_t node)618 av_create(di_minor_t minor, di_node_t node)
619 {
620 	devfsadm_enumerate_t rules[1] = {"^av$/^([0-9]+)$", 1, MATCH_ADDR};
621 	char	*minor_str;
622 	char	path[PATH_MAX + 1];
623 	char	*buf;
624 
625 	if ((buf = di_devfs_path(node)) == NULL) {
626 		return (DEVFSADM_CONTINUE);
627 	}
628 
629 	minor_str = di_minor_name(minor);
630 	(void) snprintf(path, sizeof (path), "%s:%s", buf, minor_str);
631 	di_devfs_path_free(buf);
632 
633 	if (devfsadm_enumerate_int(path, 0, &buf, rules, 1)) {
634 		return (DEVFSADM_CONTINUE);
635 	}
636 
637 	(void) snprintf(path, sizeof (path), "av/%s/%s", buf, minor_str);
638 	free(buf);
639 
640 	(void) devfsadm_mklink(path, node, minor, 0);
641 
642 	return (DEVFSADM_CONTINUE);
643 }
644 
645 /*
646  * Create device nodes for Virtio 9P channels:
647  *	/dev/9p/[0-9]+
648  */
649 static int
vio9p_create(di_minor_t minor,di_node_t node)650 vio9p_create(di_minor_t minor, di_node_t node)
651 {
652 	char *minor_name = di_minor_name(minor);
653 	char path[PATH_MAX + 1];
654 
655 	if (minor_name == NULL || strcmp(minor_name, "9p") != 0) {
656 		return (DEVFSADM_CONTINUE);
657 	}
658 
659 	(void) snprintf(path, sizeof (path), "9p/%d", di_instance(node));
660 	(void) devfsadm_mklink(path, node, minor, 0);
661 
662 	return (DEVFSADM_CONTINUE);
663 }
664 
665 /*
666  * Creates /dev/lom and /dev/tsalarm:ctl for tsalarm node
667  */
668 static int
tsalarm_create(di_minor_t minor,di_node_t node)669 tsalarm_create(di_minor_t minor, di_node_t node)
670 {
671 	char buf[PATH_MAX + 1];
672 	char *mn = di_minor_name(minor);
673 
674 	(void) snprintf(buf, sizeof (buf), "%s%s", di_node_name(node), ":ctl");
675 
676 	(void) devfsadm_mklink(mn, node, minor, 0);
677 	(void) devfsadm_mklink(buf, node, minor, 0);
678 
679 	return (DEVFSADM_CONTINUE);
680 }
681 
682 /*
683  * Creates /dev/ntwdt for ntwdt node
684  */
685 static int
ntwdt_create(di_minor_t minor,di_node_t node)686 ntwdt_create(di_minor_t minor, di_node_t node)
687 {
688 	(void) devfsadm_mklink("ntwdt", node, minor, 0);
689 	return (DEVFSADM_CONTINUE);
690 }
691 
692 static int
zcons_create(di_minor_t minor,di_node_t node)693 zcons_create(di_minor_t minor, di_node_t node)
694 {
695 	char	*minor_str;
696 	char	*zonename;
697 	char	path[MAXPATHLEN];
698 
699 	minor_str = di_minor_name(minor);
700 
701 	if (di_prop_lookup_strings(DDI_DEV_T_ANY, node, "zonename",
702 	    &zonename) == -1) {
703 		return (DEVFSADM_CONTINUE);
704 	}
705 
706 	(void) snprintf(path, sizeof (path), "zcons/%s/%s", zonename,
707 	    minor_str);
708 	(void) devfsadm_mklink(path, node, minor, 0);
709 
710 	return (DEVFSADM_CONTINUE);
711 }
712 
713 /*
714  *	/dev/cpu/self/cpuid	->	/devices/pseudo/cpuid@0:self
715  */
716 static int
cpuid(di_minor_t minor,di_node_t node)717 cpuid(di_minor_t minor, di_node_t node)
718 {
719 	(void) devfsadm_mklink(CPUID_SELF_NAME, node, minor, 0);
720 	return (DEVFSADM_CONTINUE);
721 }
722 
723 /*
724  * For device
725  *      /dev/spfma -> /devices/virtual-devices/fma@5:glvc
726  */
727 static int
glvc(di_minor_t minor,di_node_t node)728 glvc(di_minor_t minor, di_node_t node)
729 {
730 	char node_name[MAXNAMELEN + 1];
731 
732 	(void) strcpy(node_name, di_node_name(node));
733 
734 	if (strncmp(node_name, "fma", 3) == 0) {
735 		/* Only one fma channel */
736 		(void) devfsadm_mklink("spfma", node, minor, 0);
737 	}
738 	return (DEVFSADM_CONTINUE);
739 }
740 
741 /*
742  * Handles links of the form:
743  * type=ddi_pseudo;name=sckmdrv		kmdrv\M0
744  * type=ddi_pseudo;name=oplkmdrv	kmdrv\M0
745  */
746 static int
kmdrv_create(di_minor_t minor,di_node_t node)747 kmdrv_create(di_minor_t minor, di_node_t node)
748 {
749 
750 	(void) devfsadm_mklink("kmdrv", node, minor, 0);
751 	return (DEVFSADM_CONTINUE);
752 }
753