1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate #include <regex.h>
30*0Sstevel@tonic-gate #include <devfsadm.h>
31*0Sstevel@tonic-gate #include <stdio.h>
32*0Sstevel@tonic-gate #include <strings.h>
33*0Sstevel@tonic-gate #include <stdlib.h>
34*0Sstevel@tonic-gate #include <limits.h>
35*0Sstevel@tonic-gate #include <sys/zone.h>
36*0Sstevel@tonic-gate #include <sys/zcons.h>
37*0Sstevel@tonic-gate #include <sys/cpuid_drv.h>
38*0Sstevel@tonic-gate 
39*0Sstevel@tonic-gate static int display(di_minor_t minor, di_node_t node);
40*0Sstevel@tonic-gate static int parallel(di_minor_t minor, di_node_t node);
41*0Sstevel@tonic-gate static int node_slash_minor(di_minor_t minor, di_node_t node);
42*0Sstevel@tonic-gate static int driver_minor(di_minor_t minor, di_node_t node);
43*0Sstevel@tonic-gate static int node_name(di_minor_t minor, di_node_t node);
44*0Sstevel@tonic-gate static int minor_name(di_minor_t minor, di_node_t node);
45*0Sstevel@tonic-gate static int conskbd(di_minor_t minor, di_node_t node);
46*0Sstevel@tonic-gate static int consms(di_minor_t minor, di_node_t node);
47*0Sstevel@tonic-gate static int power_button(di_minor_t minor, di_node_t node);
48*0Sstevel@tonic-gate static int fc_port(di_minor_t minor, di_node_t node);
49*0Sstevel@tonic-gate static int printer_create(di_minor_t minor, di_node_t node);
50*0Sstevel@tonic-gate static int se_hdlc_create(di_minor_t minor, di_node_t node);
51*0Sstevel@tonic-gate static int ppm(di_minor_t minor, di_node_t node);
52*0Sstevel@tonic-gate static int gpio(di_minor_t minor, di_node_t node);
53*0Sstevel@tonic-gate static int av_create(di_minor_t minor, di_node_t node);
54*0Sstevel@tonic-gate static int tsalarm_create(di_minor_t minor, di_node_t node);
55*0Sstevel@tonic-gate static int zcons_create(di_minor_t minor, di_node_t node);
56*0Sstevel@tonic-gate static int cpuid(di_minor_t minor, di_node_t node);
57*0Sstevel@tonic-gate static int glvc(di_minor_t minor, di_node_t node);
58*0Sstevel@tonic-gate static int ses_callback(di_minor_t minor, di_node_t node);
59*0Sstevel@tonic-gate 
60*0Sstevel@tonic-gate static devfsadm_create_t misc_cbt[] = {
61*0Sstevel@tonic-gate 	{ "pseudo", "ddi_pseudo", "(^pts$)|(^sad$)",
62*0Sstevel@tonic-gate 	    TYPE_EXACT | DRV_RE, ILEVEL_0, node_slash_minor
63*0Sstevel@tonic-gate 	},
64*0Sstevel@tonic-gate 	{ "pseudo", "ddi_pseudo", "zsh",
65*0Sstevel@tonic-gate 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, driver_minor
66*0Sstevel@tonic-gate 	},
67*0Sstevel@tonic-gate 	{ "network", "ddi_network", NULL,
68*0Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_0, minor_name
69*0Sstevel@tonic-gate 	},
70*0Sstevel@tonic-gate 	{ "display", "ddi_display", NULL,
71*0Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_0, display
72*0Sstevel@tonic-gate 	},
73*0Sstevel@tonic-gate 	{ "parallel", "ddi_parallel", NULL,
74*0Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_0, parallel
75*0Sstevel@tonic-gate 	},
76*0Sstevel@tonic-gate 	{ "enclosure", DDI_NT_SCSI_ENCLOSURE, NULL,
77*0Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_0, ses_callback
78*0Sstevel@tonic-gate 	},
79*0Sstevel@tonic-gate 	{ "pseudo", "ddi_pseudo", "(^winlock$)|(^pm$)",
80*0Sstevel@tonic-gate 	    TYPE_EXACT | DRV_RE, ILEVEL_0, node_name
81*0Sstevel@tonic-gate 	},
82*0Sstevel@tonic-gate 	{ "pseudo", "ddi_pseudo", "conskbd",
83*0Sstevel@tonic-gate 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, conskbd
84*0Sstevel@tonic-gate 	},
85*0Sstevel@tonic-gate 	{ "pseudo", "ddi_pseudo", "consms",
86*0Sstevel@tonic-gate 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, consms
87*0Sstevel@tonic-gate 	},
88*0Sstevel@tonic-gate 	{ "pseudo", "ddi_pseudo", "rsm",
89*0Sstevel@tonic-gate 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, minor_name
90*0Sstevel@tonic-gate 	},
91*0Sstevel@tonic-gate 	{ "pseudo", "ddi_pseudo",
92*0Sstevel@tonic-gate 	    "(^lockstat$)|(^SUNW,rtvc$)|(^vol$)|(^log$)|(^sy$)|"
93*0Sstevel@tonic-gate 	    "(^ksyms$)|(^clone$)|(^tl$)|(^tnf$)|(^kstat$)|(^mdesc$)|"
94*0Sstevel@tonic-gate 	    "(^eeprom$)|(^ptsl$)|(^mm$)|(^wc$)|(^dump$)|(^cn$)|(^lo$)|(^ptm$)|"
95*0Sstevel@tonic-gate 	    "(^ptc$)|(^openeepr$)|(^poll$)|(^sysmsg$)|(^random$)|(^trapstat$)|"
96*0Sstevel@tonic-gate 	    "(^cryptoadm$)|(^crypto$)|(^pool$)|(^poolctl$)|(^bl$)|(^kmdb$)|"
97*0Sstevel@tonic-gate 	    "(^sysevent$)",
98*0Sstevel@tonic-gate 	    TYPE_EXACT | DRV_RE, ILEVEL_1, minor_name
99*0Sstevel@tonic-gate 	},
100*0Sstevel@tonic-gate 	{ "pseudo", "ddi_pseudo",
101*0Sstevel@tonic-gate 	    "(^ip$)|(^tcp$)|(^udp$)|(^icmp$)|(^sctp$)|"
102*0Sstevel@tonic-gate 	    "(^ip6$)|(^tcp6$)|(^udp6$)|(^icmp6$)|(^sctp6$)|"
103*0Sstevel@tonic-gate 	    "(^rts$)|(^arp$)|(^ipsecah$)|(^ipsecesp$)|(^keysock$)|(^spdsock$)|"
104*0Sstevel@tonic-gate 	    "(^nca$)",
105*0Sstevel@tonic-gate 	    TYPE_EXACT | DRV_RE, ILEVEL_1, minor_name
106*0Sstevel@tonic-gate 	},
107*0Sstevel@tonic-gate 	{ "pseudo", "ddi_pseudo",
108*0Sstevel@tonic-gate 	    "(^pfil$)|(^ipf$)|(^ipnat$)|(^ipstate$)|(^ipauth$)|"
109*0Sstevel@tonic-gate 	    "(^ipsync$)|(^ipscan$)|(^iplookup$)",
110*0Sstevel@tonic-gate 	    TYPE_EXACT | DRV_RE, ILEVEL_0, minor_name,
111*0Sstevel@tonic-gate 	},
112*0Sstevel@tonic-gate 	{ "pseudo", "ddi_pseudo",
113*0Sstevel@tonic-gate 	    "(^kdmouse$)|(^logi$)|(^rootprop$)|(^msm$)",
114*0Sstevel@tonic-gate 	    TYPE_EXACT | DRV_RE, ILEVEL_0, node_name
115*0Sstevel@tonic-gate 	},
116*0Sstevel@tonic-gate 	{ "pseudo", "ddi_pseudo", "tod",
117*0Sstevel@tonic-gate 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, node_name
118*0Sstevel@tonic-gate 	},
119*0Sstevel@tonic-gate 	{ "pseudo", "ddi_pseudo", "envctrl(two)?",
120*0Sstevel@tonic-gate 	    TYPE_EXACT | DRV_RE, ILEVEL_1, minor_name,
121*0Sstevel@tonic-gate 	},
122*0Sstevel@tonic-gate 	{ "pseudo", "ddi_pseudo", "fcode",
123*0Sstevel@tonic-gate 	    TYPE_EXACT | DRV_RE, ILEVEL_0, minor_name,
124*0Sstevel@tonic-gate 	},
125*0Sstevel@tonic-gate 	{ "power_button", "ddi_power_button", NULL,
126*0Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_0, power_button,
127*0Sstevel@tonic-gate 	},
128*0Sstevel@tonic-gate 	{ "FC port", "ddi_ctl:devctl", "fp",
129*0Sstevel@tonic-gate 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, fc_port
130*0Sstevel@tonic-gate 	},
131*0Sstevel@tonic-gate 	{ "printer", "ddi_printer", NULL,
132*0Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_0, printer_create
133*0Sstevel@tonic-gate 	},
134*0Sstevel@tonic-gate 	{ "pseudo", "ddi_pseudo", "se",
135*0Sstevel@tonic-gate 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, se_hdlc_create
136*0Sstevel@tonic-gate 	},
137*0Sstevel@tonic-gate 	{ "ppm",  "ddi_ppm", NULL,
138*0Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_0, ppm
139*0Sstevel@tonic-gate 	},
140*0Sstevel@tonic-gate 	{ "pseudo", "ddi_pseudo", "gpio_87317",
141*0Sstevel@tonic-gate 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, gpio
142*0Sstevel@tonic-gate 	},
143*0Sstevel@tonic-gate 	{ "pseudo", "ddi_pseudo", "sckmdrv",
144*0Sstevel@tonic-gate 	    TYPE_EXACT | DRV_RE, ILEVEL_0, minor_name,
145*0Sstevel@tonic-gate 	},
146*0Sstevel@tonic-gate 	{ "av", "^ddi_av:(isoch|async)$", NULL,
147*0Sstevel@tonic-gate 	    TYPE_RE, ILEVEL_0, av_create,
148*0Sstevel@tonic-gate 	},
149*0Sstevel@tonic-gate 	{ "pseudo", "ddi_pseudo", "tsalarm",
150*0Sstevel@tonic-gate 	    TYPE_EXACT | DRV_RE, ILEVEL_0, tsalarm_create,
151*0Sstevel@tonic-gate 	},
152*0Sstevel@tonic-gate 	{ "pseudo", "ddi_pseudo", "daplt",
153*0Sstevel@tonic-gate 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, minor_name
154*0Sstevel@tonic-gate 	},
155*0Sstevel@tonic-gate 	{ "pseudo", "ddi_pseudo", "zcons",
156*0Sstevel@tonic-gate 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, zcons_create,
157*0Sstevel@tonic-gate 	},
158*0Sstevel@tonic-gate 	{ "pseudo", "ddi_pseudo", CPUID_DRIVER_NAME,
159*0Sstevel@tonic-gate 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, cpuid,
160*0Sstevel@tonic-gate 	},
161*0Sstevel@tonic-gate 	{ "pseudo", "ddi_pseudo", "glvc",
162*0Sstevel@tonic-gate 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, glvc,
163*0Sstevel@tonic-gate 	},
164*0Sstevel@tonic-gate };
165*0Sstevel@tonic-gate 
166*0Sstevel@tonic-gate DEVFSADM_CREATE_INIT_V0(misc_cbt);
167*0Sstevel@tonic-gate 
168*0Sstevel@tonic-gate static devfsadm_remove_t misc_remove_cbt[] = {
169*0Sstevel@tonic-gate 	{ "pseudo", "^profile$",
170*0Sstevel@tonic-gate 	    RM_PRE | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all
171*0Sstevel@tonic-gate 	},
172*0Sstevel@tonic-gate 	{ "pseudo", "^rsm$",
173*0Sstevel@tonic-gate 	    RM_PRE | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all
174*0Sstevel@tonic-gate 	},
175*0Sstevel@tonic-gate 	{ "printer", "^printers/[0-9]+$",
176*0Sstevel@tonic-gate 	    RM_PRE | RM_HOT | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all
177*0Sstevel@tonic-gate 	},
178*0Sstevel@tonic-gate 	{ "av", "^av/[0-9]+/(async|isoch)$",
179*0Sstevel@tonic-gate 	    RM_PRE | RM_HOT | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all
180*0Sstevel@tonic-gate 	},
181*0Sstevel@tonic-gate 	{ "pseudo", "^daplt$",
182*0Sstevel@tonic-gate 	    RM_PRE | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all
183*0Sstevel@tonic-gate 	},
184*0Sstevel@tonic-gate 	{ "pseudo", "^zcons/" ZONENAME_REGEXP "/(" ZCONS_MASTER_NAME "|"
185*0Sstevel@tonic-gate 		ZCONS_SLAVE_NAME ")$",
186*0Sstevel@tonic-gate 	    RM_PRE | RM_HOT | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all
187*0Sstevel@tonic-gate 	},
188*0Sstevel@tonic-gate 	{ "pseudo", "^cpu/self/cpuid$", RM_ALWAYS | RM_PRE | RM_HOT,
189*0Sstevel@tonic-gate 	    ILEVEL_0, devfsadm_rm_all
190*0Sstevel@tonic-gate 	},
191*0Sstevel@tonic-gate 	{ "enclosure", "^es/ses[0-9]+$", RM_POST,
192*0Sstevel@tonic-gate 		ILEVEL_0, devfsadm_rm_all
193*0Sstevel@tonic-gate 	}
194*0Sstevel@tonic-gate };
195*0Sstevel@tonic-gate 
196*0Sstevel@tonic-gate /* Rules for gpio devices */
197*0Sstevel@tonic-gate static devfsadm_enumerate_t gpio_rules[1] =
198*0Sstevel@tonic-gate 	{"^gpio([0-9]+)$", 1, MATCH_ALL};
199*0Sstevel@tonic-gate 
200*0Sstevel@tonic-gate DEVFSADM_REMOVE_INIT_V0(misc_remove_cbt);
201*0Sstevel@tonic-gate 
202*0Sstevel@tonic-gate /*
203*0Sstevel@tonic-gate  * Handles minor node type "ddi_display".
204*0Sstevel@tonic-gate  *
205*0Sstevel@tonic-gate  * type=ddi_display fbs/\M0 fb\N0
206*0Sstevel@tonic-gate  */
207*0Sstevel@tonic-gate static int
208*0Sstevel@tonic-gate display(di_minor_t minor, di_node_t node)
209*0Sstevel@tonic-gate {
210*0Sstevel@tonic-gate 	char l_path[PATH_MAX + 1], contents[PATH_MAX + 1], *buf;
211*0Sstevel@tonic-gate 	devfsadm_enumerate_t rules[1] = {"^fb([0-9]+)$", 1, MATCH_ALL};
212*0Sstevel@tonic-gate 	char *mn = di_minor_name(minor);
213*0Sstevel@tonic-gate 
214*0Sstevel@tonic-gate 	/* create fbs/\M0 primary link */
215*0Sstevel@tonic-gate 	(void) strcpy(l_path, "fbs/");
216*0Sstevel@tonic-gate 	(void) strcat(l_path, mn);
217*0Sstevel@tonic-gate 	(void) devfsadm_mklink(l_path, node, minor, 0);
218*0Sstevel@tonic-gate 
219*0Sstevel@tonic-gate 	/* create fb\N0 which links to fbs/\M0 */
220*0Sstevel@tonic-gate 	if (devfsadm_enumerate_int(l_path, 0, &buf, rules, 1)) {
221*0Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
222*0Sstevel@tonic-gate 	}
223*0Sstevel@tonic-gate 	(void) strcpy(contents, l_path);
224*0Sstevel@tonic-gate 	(void) strcpy(l_path, "fb");
225*0Sstevel@tonic-gate 	(void) strcat(l_path, buf);
226*0Sstevel@tonic-gate 	free(buf);
227*0Sstevel@tonic-gate 	(void) devfsadm_secondary_link(l_path, contents, 0);
228*0Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
229*0Sstevel@tonic-gate }
230*0Sstevel@tonic-gate 
231*0Sstevel@tonic-gate /*
232*0Sstevel@tonic-gate  * Handles minor node type "ddi_parallel".
233*0Sstevel@tonic-gate  * type=ddi_parallel;name=mcpp     mcpp\N0
234*0Sstevel@tonic-gate  */
235*0Sstevel@tonic-gate static int
236*0Sstevel@tonic-gate parallel(di_minor_t minor, di_node_t node)
237*0Sstevel@tonic-gate {
238*0Sstevel@tonic-gate 	char path[PATH_MAX + 1], *buf;
239*0Sstevel@tonic-gate 	devfsadm_enumerate_t rules[1] = {"mcpp([0-9]+)$", 1, MATCH_ALL};
240*0Sstevel@tonic-gate 
241*0Sstevel@tonic-gate 
242*0Sstevel@tonic-gate 	if (strcmp(di_node_name(node), "mcpp") != 0) {
243*0Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
244*0Sstevel@tonic-gate 	}
245*0Sstevel@tonic-gate 
246*0Sstevel@tonic-gate 	if (NULL == (buf = di_devfs_path(node))) {
247*0Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
248*0Sstevel@tonic-gate 	}
249*0Sstevel@tonic-gate 
250*0Sstevel@tonic-gate 	(void) snprintf(path, sizeof (path), "%s:%s",
251*0Sstevel@tonic-gate 	    buf, di_minor_name(minor));
252*0Sstevel@tonic-gate 
253*0Sstevel@tonic-gate 	di_devfs_path_free(buf);
254*0Sstevel@tonic-gate 
255*0Sstevel@tonic-gate 	if (devfsadm_enumerate_int(path, 0, &buf, rules, 1)) {
256*0Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
257*0Sstevel@tonic-gate 	}
258*0Sstevel@tonic-gate 	(void) snprintf(path, sizeof (path), "mcpp%s", buf);
259*0Sstevel@tonic-gate 	free(buf);
260*0Sstevel@tonic-gate 
261*0Sstevel@tonic-gate 	(void) devfsadm_mklink(path, node, minor, 0);
262*0Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
263*0Sstevel@tonic-gate }
264*0Sstevel@tonic-gate 
265*0Sstevel@tonic-gate static int
266*0Sstevel@tonic-gate ses_callback(di_minor_t minor, di_node_t node)
267*0Sstevel@tonic-gate {
268*0Sstevel@tonic-gate 	char l_path[PATH_MAX];
269*0Sstevel@tonic-gate 	char *buf;
270*0Sstevel@tonic-gate 	char *devfspath;
271*0Sstevel@tonic-gate 	char p_path[PATH_MAX];
272*0Sstevel@tonic-gate 	devfsadm_enumerate_t re[] = {"^es$/^ses([0-9]+)$", 1, MATCH_ALL};
273*0Sstevel@tonic-gate 
274*0Sstevel@tonic-gate 	/* find devices path -- need to free mem */
275*0Sstevel@tonic-gate 	if (NULL == (devfspath = di_devfs_path(node))) {
276*0Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
277*0Sstevel@tonic-gate 	}
278*0Sstevel@tonic-gate 
279*0Sstevel@tonic-gate 	(void) snprintf(p_path, sizeof (p_path), "%s:%s", devfspath,
280*0Sstevel@tonic-gate 	    di_minor_name(minor));
281*0Sstevel@tonic-gate 
282*0Sstevel@tonic-gate 
283*0Sstevel@tonic-gate 	/* find next number to use; buf is an ascii number */
284*0Sstevel@tonic-gate 	if (devfsadm_enumerate_int(p_path, 0, &buf, re, 1)) {
285*0Sstevel@tonic-gate 		/* free memory */
286*0Sstevel@tonic-gate 		di_devfs_path_free(devfspath);
287*0Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
288*0Sstevel@tonic-gate 	}
289*0Sstevel@tonic-gate 
290*0Sstevel@tonic-gate 	(void) snprintf(l_path, sizeof (l_path), "es/ses%s", buf);
291*0Sstevel@tonic-gate 
292*0Sstevel@tonic-gate 	(void) devfsadm_mklink(l_path, node, minor, 0);
293*0Sstevel@tonic-gate 	/* free memory */
294*0Sstevel@tonic-gate 	free(buf);
295*0Sstevel@tonic-gate 	di_devfs_path_free(devfspath);
296*0Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
297*0Sstevel@tonic-gate 
298*0Sstevel@tonic-gate }
299*0Sstevel@tonic-gate 
300*0Sstevel@tonic-gate static int
301*0Sstevel@tonic-gate node_slash_minor(di_minor_t minor, di_node_t node)
302*0Sstevel@tonic-gate {
303*0Sstevel@tonic-gate 
304*0Sstevel@tonic-gate 	char path[PATH_MAX + 1];
305*0Sstevel@tonic-gate 
306*0Sstevel@tonic-gate 	(void) strcpy(path, di_node_name(node));
307*0Sstevel@tonic-gate 	(void) strcat(path, "/");
308*0Sstevel@tonic-gate 	(void) strcat(path, di_minor_name(minor));
309*0Sstevel@tonic-gate 	(void) devfsadm_mklink(path, node, minor, 0);
310*0Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
311*0Sstevel@tonic-gate }
312*0Sstevel@tonic-gate 
313*0Sstevel@tonic-gate static int
314*0Sstevel@tonic-gate driver_minor(di_minor_t minor, di_node_t node)
315*0Sstevel@tonic-gate {
316*0Sstevel@tonic-gate 	char path[PATH_MAX + 1];
317*0Sstevel@tonic-gate 
318*0Sstevel@tonic-gate 	(void) strcpy(path, di_driver_name(node));
319*0Sstevel@tonic-gate 	(void) strcat(path, di_minor_name(minor));
320*0Sstevel@tonic-gate 	(void) devfsadm_mklink(path, node, minor, 0);
321*0Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
322*0Sstevel@tonic-gate }
323*0Sstevel@tonic-gate 
324*0Sstevel@tonic-gate /*
325*0Sstevel@tonic-gate  * Handles links of the form:
326*0Sstevel@tonic-gate  * type=ddi_pseudo;name=xyz  \D
327*0Sstevel@tonic-gate  */
328*0Sstevel@tonic-gate static int
329*0Sstevel@tonic-gate node_name(di_minor_t minor, di_node_t node)
330*0Sstevel@tonic-gate {
331*0Sstevel@tonic-gate 	(void) devfsadm_mklink(di_node_name(node), node, minor, 0);
332*0Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
333*0Sstevel@tonic-gate }
334*0Sstevel@tonic-gate 
335*0Sstevel@tonic-gate /*
336*0Sstevel@tonic-gate  * Handles links of the form:
337*0Sstevel@tonic-gate  * type=ddi_pseudo;name=xyz  \M0
338*0Sstevel@tonic-gate  */
339*0Sstevel@tonic-gate static int
340*0Sstevel@tonic-gate minor_name(di_minor_t minor, di_node_t node)
341*0Sstevel@tonic-gate {
342*0Sstevel@tonic-gate 	char *mn = di_minor_name(minor);
343*0Sstevel@tonic-gate 
344*0Sstevel@tonic-gate 	(void) devfsadm_mklink(mn, node, minor, 0);
345*0Sstevel@tonic-gate 	if (strcmp(mn, "icmp") == 0) {
346*0Sstevel@tonic-gate 		(void) devfsadm_mklink("rawip", node, minor, 0);
347*0Sstevel@tonic-gate 	}
348*0Sstevel@tonic-gate 	if (strcmp(mn, "icmp6") == 0) {
349*0Sstevel@tonic-gate 		(void) devfsadm_mklink("rawip6", node, minor, 0);
350*0Sstevel@tonic-gate 	}
351*0Sstevel@tonic-gate 	if (strcmp(mn, "ipf") == 0) {
352*0Sstevel@tonic-gate 		(void) devfsadm_mklink("ipl", node, minor, 0);
353*0Sstevel@tonic-gate 	}
354*0Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
355*0Sstevel@tonic-gate }
356*0Sstevel@tonic-gate 
357*0Sstevel@tonic-gate 
358*0Sstevel@tonic-gate static int
359*0Sstevel@tonic-gate conskbd(di_minor_t minor, di_node_t node)
360*0Sstevel@tonic-gate {
361*0Sstevel@tonic-gate 	(void) devfsadm_mklink("kbd", node, minor, 0);
362*0Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
363*0Sstevel@tonic-gate }
364*0Sstevel@tonic-gate 
365*0Sstevel@tonic-gate static int
366*0Sstevel@tonic-gate consms(di_minor_t minor, di_node_t node)
367*0Sstevel@tonic-gate {
368*0Sstevel@tonic-gate 	(void) devfsadm_mklink("mouse", node, minor, 0);
369*0Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
370*0Sstevel@tonic-gate }
371*0Sstevel@tonic-gate 
372*0Sstevel@tonic-gate static int
373*0Sstevel@tonic-gate power_button(di_minor_t minor, di_node_t node)
374*0Sstevel@tonic-gate {
375*0Sstevel@tonic-gate 	(void) devfsadm_mklink("power_button", node, minor, 0);
376*0Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
377*0Sstevel@tonic-gate }
378*0Sstevel@tonic-gate 
379*0Sstevel@tonic-gate static int
380*0Sstevel@tonic-gate fc_port(di_minor_t minor, di_node_t node)
381*0Sstevel@tonic-gate {
382*0Sstevel@tonic-gate 	devfsadm_enumerate_t rules[1] = {"fc/fp([0-9]+)$", 1, MATCH_ALL};
383*0Sstevel@tonic-gate 	char *buf, path[PATH_MAX + 1];
384*0Sstevel@tonic-gate 	char *ptr;
385*0Sstevel@tonic-gate 
386*0Sstevel@tonic-gate 	if (NULL == (ptr = di_devfs_path(node))) {
387*0Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
388*0Sstevel@tonic-gate 	}
389*0Sstevel@tonic-gate 
390*0Sstevel@tonic-gate 	(void) strcpy(path, ptr);
391*0Sstevel@tonic-gate 	(void) strcat(path, ":");
392*0Sstevel@tonic-gate 	(void) strcat(path, di_minor_name(minor));
393*0Sstevel@tonic-gate 
394*0Sstevel@tonic-gate 	di_devfs_path_free(ptr);
395*0Sstevel@tonic-gate 
396*0Sstevel@tonic-gate 	if (devfsadm_enumerate_int(path, 0, &buf, rules, 1) != 0) {
397*0Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
398*0Sstevel@tonic-gate 	}
399*0Sstevel@tonic-gate 
400*0Sstevel@tonic-gate 	(void) strcpy(path, "fc/fp");
401*0Sstevel@tonic-gate 	(void) strcat(path, buf);
402*0Sstevel@tonic-gate 	free(buf);
403*0Sstevel@tonic-gate 
404*0Sstevel@tonic-gate 	(void) devfsadm_mklink(path, node, minor, 0);
405*0Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
406*0Sstevel@tonic-gate }
407*0Sstevel@tonic-gate 
408*0Sstevel@tonic-gate /*
409*0Sstevel@tonic-gate  * Handles:
410*0Sstevel@tonic-gate  *	minor node type "ddi_printer".
411*0Sstevel@tonic-gate  * 	rules of the form: type=ddi_printer;name=bpp  \M0
412*0Sstevel@tonic-gate  */
413*0Sstevel@tonic-gate static int
414*0Sstevel@tonic-gate printer_create(di_minor_t minor, di_node_t node)
415*0Sstevel@tonic-gate {
416*0Sstevel@tonic-gate 	char *mn;
417*0Sstevel@tonic-gate 	char path[PATH_MAX + 1], *buf;
418*0Sstevel@tonic-gate 	devfsadm_enumerate_t rules[1] = {"^printers$/^([0-9]+)$", 1, MATCH_ALL};
419*0Sstevel@tonic-gate 
420*0Sstevel@tonic-gate 	mn = di_minor_name(minor);
421*0Sstevel@tonic-gate 
422*0Sstevel@tonic-gate 	if (strcmp(di_driver_name(node), "bpp") == 0) {
423*0Sstevel@tonic-gate 		(void) devfsadm_mklink(mn, node, minor, 0);
424*0Sstevel@tonic-gate 	}
425*0Sstevel@tonic-gate 
426*0Sstevel@tonic-gate 	if (NULL == (buf = di_devfs_path(node))) {
427*0Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
428*0Sstevel@tonic-gate 	}
429*0Sstevel@tonic-gate 
430*0Sstevel@tonic-gate 	(void) snprintf(path, sizeof (path), "%s:%s", buf, mn);
431*0Sstevel@tonic-gate 	di_devfs_path_free(buf);
432*0Sstevel@tonic-gate 
433*0Sstevel@tonic-gate 	if (devfsadm_enumerate_int(path, 0, &buf, rules, 1)) {
434*0Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
435*0Sstevel@tonic-gate 	}
436*0Sstevel@tonic-gate 
437*0Sstevel@tonic-gate 	(void) snprintf(path, sizeof (path), "printers/%s", buf);
438*0Sstevel@tonic-gate 	free(buf);
439*0Sstevel@tonic-gate 
440*0Sstevel@tonic-gate 	(void) devfsadm_mklink(path, node, minor, 0);
441*0Sstevel@tonic-gate 
442*0Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
443*0Sstevel@tonic-gate }
444*0Sstevel@tonic-gate 
445*0Sstevel@tonic-gate /*
446*0Sstevel@tonic-gate  * Handles links of the form:
447*0Sstevel@tonic-gate  * type=ddi_pseudo;name=se;minor2=hdlc	se_hdlc\N0
448*0Sstevel@tonic-gate  * type=ddi_pseudo;name=serial;minor2=hdlc	se_hdlc\N0
449*0Sstevel@tonic-gate  */
450*0Sstevel@tonic-gate static int
451*0Sstevel@tonic-gate se_hdlc_create(di_minor_t minor, di_node_t node)
452*0Sstevel@tonic-gate {
453*0Sstevel@tonic-gate 	devfsadm_enumerate_t rules[1] = {"^se_hdlc([0-9]+)$", 1, MATCH_ALL};
454*0Sstevel@tonic-gate 	char *buf, path[PATH_MAX + 1];
455*0Sstevel@tonic-gate 	char *ptr;
456*0Sstevel@tonic-gate 	char *mn;
457*0Sstevel@tonic-gate 
458*0Sstevel@tonic-gate 	mn = di_minor_name(minor);
459*0Sstevel@tonic-gate 
460*0Sstevel@tonic-gate 	/* minor node should be of the form: "?,hdlc" */
461*0Sstevel@tonic-gate 	if (strcmp(mn + 1, ",hdlc") != 0) {
462*0Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
463*0Sstevel@tonic-gate 	}
464*0Sstevel@tonic-gate 
465*0Sstevel@tonic-gate 	if (NULL == (ptr = di_devfs_path(node))) {
466*0Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
467*0Sstevel@tonic-gate 	}
468*0Sstevel@tonic-gate 
469*0Sstevel@tonic-gate 	(void) strcpy(path, ptr);
470*0Sstevel@tonic-gate 	(void) strcat(path, ":");
471*0Sstevel@tonic-gate 	(void) strcat(path, mn);
472*0Sstevel@tonic-gate 
473*0Sstevel@tonic-gate 	di_devfs_path_free(ptr);
474*0Sstevel@tonic-gate 
475*0Sstevel@tonic-gate 	if (devfsadm_enumerate_int(path, 0, &buf, rules, 1) != 0) {
476*0Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
477*0Sstevel@tonic-gate 	}
478*0Sstevel@tonic-gate 
479*0Sstevel@tonic-gate 	(void) strcpy(path, "se_hdlc");
480*0Sstevel@tonic-gate 	(void) strcat(path, buf);
481*0Sstevel@tonic-gate 	free(buf);
482*0Sstevel@tonic-gate 
483*0Sstevel@tonic-gate 	(void) devfsadm_mklink(path, node, minor, 0);
484*0Sstevel@tonic-gate 
485*0Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
486*0Sstevel@tonic-gate }
487*0Sstevel@tonic-gate 
488*0Sstevel@tonic-gate static int
489*0Sstevel@tonic-gate gpio(di_minor_t minor, di_node_t node)
490*0Sstevel@tonic-gate {
491*0Sstevel@tonic-gate 	char l_path[PATH_MAX], p_path[PATH_MAX], *buf, *devfspath;
492*0Sstevel@tonic-gate 	char *minor_nm, *drvr_nm;
493*0Sstevel@tonic-gate 
494*0Sstevel@tonic-gate 
495*0Sstevel@tonic-gate 	minor_nm = di_minor_name(minor);
496*0Sstevel@tonic-gate 	drvr_nm = di_driver_name(node);
497*0Sstevel@tonic-gate 	if ((minor_nm == NULL) || (drvr_nm == NULL)) {
498*0Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
499*0Sstevel@tonic-gate 	}
500*0Sstevel@tonic-gate 
501*0Sstevel@tonic-gate 	devfspath = di_devfs_path(node);
502*0Sstevel@tonic-gate 
503*0Sstevel@tonic-gate 	(void) strcpy(p_path, devfspath);
504*0Sstevel@tonic-gate 	(void) strcat(p_path, ":");
505*0Sstevel@tonic-gate 	(void) strcat(p_path, minor_nm);
506*0Sstevel@tonic-gate 	di_devfs_path_free(devfspath);
507*0Sstevel@tonic-gate 
508*0Sstevel@tonic-gate 	/* build the physical path from the components */
509*0Sstevel@tonic-gate 	if (devfsadm_enumerate_int(p_path, 0, &buf, gpio_rules, 1)) {
510*0Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
511*0Sstevel@tonic-gate 	}
512*0Sstevel@tonic-gate 
513*0Sstevel@tonic-gate 	(void) snprintf(l_path, sizeof (l_path), "%s%s", "gpio", buf);
514*0Sstevel@tonic-gate 
515*0Sstevel@tonic-gate 	free(buf);
516*0Sstevel@tonic-gate 
517*0Sstevel@tonic-gate 	(void) devfsadm_mklink(l_path, node, minor, 0);
518*0Sstevel@tonic-gate 
519*0Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
520*0Sstevel@tonic-gate }
521*0Sstevel@tonic-gate 
522*0Sstevel@tonic-gate /*
523*0Sstevel@tonic-gate  * Creates /dev/ppm nodes for Platform Specific PM module
524*0Sstevel@tonic-gate  */
525*0Sstevel@tonic-gate static int
526*0Sstevel@tonic-gate ppm(di_minor_t minor, di_node_t node)
527*0Sstevel@tonic-gate {
528*0Sstevel@tonic-gate 	(void) devfsadm_mklink("ppm", node, minor, 0);
529*0Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
530*0Sstevel@tonic-gate }
531*0Sstevel@tonic-gate 
532*0Sstevel@tonic-gate /*
533*0Sstevel@tonic-gate  * Handles:
534*0Sstevel@tonic-gate  *	/dev/av/[0-9]+/(async|isoch)
535*0Sstevel@tonic-gate  */
536*0Sstevel@tonic-gate static int
537*0Sstevel@tonic-gate av_create(di_minor_t minor, di_node_t node)
538*0Sstevel@tonic-gate {
539*0Sstevel@tonic-gate 	devfsadm_enumerate_t rules[1] = {"^av$/^([0-9]+)$", 1, MATCH_ADDR};
540*0Sstevel@tonic-gate 	char	*minor_str;
541*0Sstevel@tonic-gate 	char	path[PATH_MAX + 1];
542*0Sstevel@tonic-gate 	char	*buf;
543*0Sstevel@tonic-gate 
544*0Sstevel@tonic-gate 	if ((buf = di_devfs_path(node)) == NULL) {
545*0Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
546*0Sstevel@tonic-gate 	}
547*0Sstevel@tonic-gate 
548*0Sstevel@tonic-gate 	minor_str = di_minor_name(minor);
549*0Sstevel@tonic-gate 	(void) snprintf(path, sizeof (path), "%s:%s", buf, minor_str);
550*0Sstevel@tonic-gate 	di_devfs_path_free(buf);
551*0Sstevel@tonic-gate 
552*0Sstevel@tonic-gate 	if (devfsadm_enumerate_int(path, 0, &buf, rules, 1)) {
553*0Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
554*0Sstevel@tonic-gate 	}
555*0Sstevel@tonic-gate 
556*0Sstevel@tonic-gate 	(void) snprintf(path, sizeof (path), "av/%s/%s", buf, minor_str);
557*0Sstevel@tonic-gate 	free(buf);
558*0Sstevel@tonic-gate 
559*0Sstevel@tonic-gate 	(void) devfsadm_mklink(path, node, minor, 0);
560*0Sstevel@tonic-gate 
561*0Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
562*0Sstevel@tonic-gate }
563*0Sstevel@tonic-gate 
564*0Sstevel@tonic-gate /*
565*0Sstevel@tonic-gate  * Creates /dev/lom and /dev/tsalarm:ctl for tsalarm node
566*0Sstevel@tonic-gate  */
567*0Sstevel@tonic-gate static int
568*0Sstevel@tonic-gate tsalarm_create(di_minor_t minor, di_node_t node)
569*0Sstevel@tonic-gate {
570*0Sstevel@tonic-gate 	char buf[PATH_MAX + 1];
571*0Sstevel@tonic-gate 	char *mn = di_minor_name(minor);
572*0Sstevel@tonic-gate 
573*0Sstevel@tonic-gate 	(void) snprintf(buf, sizeof (buf), "%s%s", di_node_name(node), ":ctl");
574*0Sstevel@tonic-gate 
575*0Sstevel@tonic-gate 	(void) devfsadm_mklink(mn, node, minor, 0);
576*0Sstevel@tonic-gate 	(void) devfsadm_mklink(buf, node, minor, 0);
577*0Sstevel@tonic-gate 
578*0Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
579*0Sstevel@tonic-gate }
580*0Sstevel@tonic-gate 
581*0Sstevel@tonic-gate static int
582*0Sstevel@tonic-gate zcons_create(di_minor_t minor, di_node_t node)
583*0Sstevel@tonic-gate {
584*0Sstevel@tonic-gate 	char	*minor_str;
585*0Sstevel@tonic-gate 	char	*zonename;
586*0Sstevel@tonic-gate 	char	path[MAXPATHLEN];
587*0Sstevel@tonic-gate 
588*0Sstevel@tonic-gate 	minor_str = di_minor_name(minor);
589*0Sstevel@tonic-gate 
590*0Sstevel@tonic-gate 	if (di_prop_lookup_strings(DDI_DEV_T_ANY, node, "zonename",
591*0Sstevel@tonic-gate 	    &zonename) == -1) {
592*0Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
593*0Sstevel@tonic-gate 	}
594*0Sstevel@tonic-gate 
595*0Sstevel@tonic-gate 	(void) snprintf(path, sizeof (path), "zcons/%s/%s", zonename,
596*0Sstevel@tonic-gate 	    minor_str);
597*0Sstevel@tonic-gate 	(void) devfsadm_mklink(path, node, minor, 0);
598*0Sstevel@tonic-gate 
599*0Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
600*0Sstevel@tonic-gate }
601*0Sstevel@tonic-gate 
602*0Sstevel@tonic-gate /*
603*0Sstevel@tonic-gate  *	/dev/cpu/self/cpuid 	->	/devices/pseudo/cpuid@0:self
604*0Sstevel@tonic-gate  */
605*0Sstevel@tonic-gate static int
606*0Sstevel@tonic-gate cpuid(di_minor_t minor, di_node_t node)
607*0Sstevel@tonic-gate {
608*0Sstevel@tonic-gate 	(void) devfsadm_mklink(CPUID_SELF_NAME, node, minor, 0);
609*0Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
610*0Sstevel@tonic-gate }
611*0Sstevel@tonic-gate 
612*0Sstevel@tonic-gate /*
613*0Sstevel@tonic-gate  * For device
614*0Sstevel@tonic-gate  *      /dev/spfma -> /devices/virtual-devices/fma@5:glvc
615*0Sstevel@tonic-gate  */
616*0Sstevel@tonic-gate static int
617*0Sstevel@tonic-gate glvc(di_minor_t minor, di_node_t node)
618*0Sstevel@tonic-gate {
619*0Sstevel@tonic-gate 	char node_name[MAXNAMELEN + 1];
620*0Sstevel@tonic-gate 
621*0Sstevel@tonic-gate 	(void) strcpy(node_name, di_node_name(node));
622*0Sstevel@tonic-gate 
623*0Sstevel@tonic-gate 	if (strncmp(node_name, "fma", 3) == 0) {
624*0Sstevel@tonic-gate 		/* Only one fma channel */
625*0Sstevel@tonic-gate 		(void) devfsadm_mklink("spfma", node, minor, 0);
626*0Sstevel@tonic-gate 	}
627*0Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
628*0Sstevel@tonic-gate }
629