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 <ctype.h>
36*0Sstevel@tonic-gate 
37*0Sstevel@tonic-gate static int lp(di_minor_t minor, di_node_t node);
38*0Sstevel@tonic-gate static int serial_dialout(di_minor_t minor, di_node_t node);
39*0Sstevel@tonic-gate static int serial(di_minor_t minor, di_node_t node);
40*0Sstevel@tonic-gate static int diskette(di_minor_t minor, di_node_t node);
41*0Sstevel@tonic-gate static int vt00(di_minor_t minor, di_node_t node);
42*0Sstevel@tonic-gate static int kdmouse(di_minor_t minor, di_node_t node);
43*0Sstevel@tonic-gate static int bmc(di_minor_t minor, di_node_t node);
44*0Sstevel@tonic-gate static int agp_process(di_minor_t minor, di_node_t node);
45*0Sstevel@tonic-gate 
46*0Sstevel@tonic-gate static devfsadm_create_t misc_cbt[] = {
47*0Sstevel@tonic-gate 	{ "vt00", "ddi_display", NULL,
48*0Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_0,	vt00
49*0Sstevel@tonic-gate 	},
50*0Sstevel@tonic-gate 	{ "mouse", "ddi_mouse", "mouse8042",
51*0Sstevel@tonic-gate 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, kdmouse
52*0Sstevel@tonic-gate 	},
53*0Sstevel@tonic-gate 	{ "pseudo", "ddi_pseudo", "bmc",
54*0Sstevel@tonic-gate 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, bmc,
55*0Sstevel@tonic-gate 	},
56*0Sstevel@tonic-gate 	{ "disk",  "ddi_block:diskette", NULL,
57*0Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_1, diskette
58*0Sstevel@tonic-gate 	},
59*0Sstevel@tonic-gate 	{ "parallel",  "ddi_printer", NULL,
60*0Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_1, lp
61*0Sstevel@tonic-gate 	},
62*0Sstevel@tonic-gate 	{ "serial", "ddi_serial:mb", NULL,
63*0Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_1, serial
64*0Sstevel@tonic-gate 	},
65*0Sstevel@tonic-gate 	{ "serial",  "ddi_serial:dialout,mb", NULL,
66*0Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_1, serial_dialout
67*0Sstevel@tonic-gate 	},
68*0Sstevel@tonic-gate 	{"agp", "ddi_agp:pseudo", NULL,
69*0Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_0, agp_process
70*0Sstevel@tonic-gate 	},
71*0Sstevel@tonic-gate 	{"agp", "ddi_agp:target", NULL,
72*0Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_0, agp_process
73*0Sstevel@tonic-gate 	},
74*0Sstevel@tonic-gate 	{"agp", "ddi_agp:cpugart", NULL,
75*0Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_0, agp_process
76*0Sstevel@tonic-gate 	},
77*0Sstevel@tonic-gate 	{"agp", "ddi_agp:master", NULL,
78*0Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_0, agp_process
79*0Sstevel@tonic-gate 	}
80*0Sstevel@tonic-gate };
81*0Sstevel@tonic-gate 
82*0Sstevel@tonic-gate DEVFSADM_CREATE_INIT_V0(misc_cbt);
83*0Sstevel@tonic-gate 
84*0Sstevel@tonic-gate static char *debug_mid = "agp_mid";
85*0Sstevel@tonic-gate 
86*0Sstevel@tonic-gate typedef enum {
87*0Sstevel@tonic-gate 	DRIVER_AGPPSEUDO = 0,
88*0Sstevel@tonic-gate 	DRIVER_AGPTARGET,
89*0Sstevel@tonic-gate 	DRIVER_CPUGART,
90*0Sstevel@tonic-gate 	DRIVER_AGPMASTER,
91*0Sstevel@tonic-gate 	DRIVER_UNKNOWN
92*0Sstevel@tonic-gate } driver_defs_t;
93*0Sstevel@tonic-gate 
94*0Sstevel@tonic-gate typedef struct {
95*0Sstevel@tonic-gate 	char	*driver_name;
96*0Sstevel@tonic-gate 	int	index;
97*0Sstevel@tonic-gate } driver_name_table_entry_t;
98*0Sstevel@tonic-gate 
99*0Sstevel@tonic-gate static driver_name_table_entry_t driver_name_table[] = {
100*0Sstevel@tonic-gate 	{ "agpgart",		DRIVER_AGPPSEUDO },
101*0Sstevel@tonic-gate 	{ "agptarget",		DRIVER_AGPTARGET },
102*0Sstevel@tonic-gate 	{ "amd64_gart",		DRIVER_CPUGART },
103*0Sstevel@tonic-gate 	{ "vgatext",		DRIVER_AGPMASTER },
104*0Sstevel@tonic-gate 	{ NULL,			DRIVER_UNKNOWN }
105*0Sstevel@tonic-gate };
106*0Sstevel@tonic-gate 
107*0Sstevel@tonic-gate static devfsadm_enumerate_t agptarget_rules[1] =
108*0Sstevel@tonic-gate 	{ "^agp$/^agptarget([0-9]+)$", 1, MATCH_ALL };
109*0Sstevel@tonic-gate static devfsadm_enumerate_t cpugart_rules[1] =
110*0Sstevel@tonic-gate 	{ "^agp$/^cpugart([0-9]+)$", 1, MATCH_ALL };
111*0Sstevel@tonic-gate static devfsadm_enumerate_t agpmaster_rules[1] =
112*0Sstevel@tonic-gate 	{  "^agp$/^agpmaster([0-9]+)$", 1, MATCH_ALL };
113*0Sstevel@tonic-gate 
114*0Sstevel@tonic-gate static devfsadm_remove_t misc_remove_cbt[] = {
115*0Sstevel@tonic-gate 	{ "vt", "vt[0-9][0-9]", RM_PRE|RM_ALWAYS,
116*0Sstevel@tonic-gate 		ILEVEL_0, devfsadm_rm_all
117*0Sstevel@tonic-gate 	}
118*0Sstevel@tonic-gate };
119*0Sstevel@tonic-gate 
120*0Sstevel@tonic-gate DEVFSADM_REMOVE_INIT_V0(misc_remove_cbt);
121*0Sstevel@tonic-gate 
122*0Sstevel@tonic-gate /*
123*0Sstevel@tonic-gate  * Handles minor node type "ddi_display", in addition to generic processing
124*0Sstevel@tonic-gate  * done by display().
125*0Sstevel@tonic-gate  *
126*0Sstevel@tonic-gate  * This creates a /dev/vt00 link to /dev/fb, for backwards compatibility.
127*0Sstevel@tonic-gate  */
128*0Sstevel@tonic-gate /* ARGSUSED */
129*0Sstevel@tonic-gate int
130*0Sstevel@tonic-gate vt00(di_minor_t minor, di_node_t node)
131*0Sstevel@tonic-gate {
132*0Sstevel@tonic-gate 	(void) devfsadm_secondary_link("vt00", "fb", 0);
133*0Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
134*0Sstevel@tonic-gate }
135*0Sstevel@tonic-gate 
136*0Sstevel@tonic-gate /*
137*0Sstevel@tonic-gate  * type=ddi_block:diskette;addr=0,0;minor=c        diskette
138*0Sstevel@tonic-gate  * type=ddi_block:diskette;addr=0,0;minor=c,raw    rdiskette
139*0Sstevel@tonic-gate  * type=ddi_block:diskette;addr1=0;minor=c diskette\A2
140*0Sstevel@tonic-gate  * type=ddi_block:diskette;addr1=0;minor=c,raw     rdiskette\A2
141*0Sstevel@tonic-gate  */
142*0Sstevel@tonic-gate static int
143*0Sstevel@tonic-gate diskette(di_minor_t minor, di_node_t node)
144*0Sstevel@tonic-gate {
145*0Sstevel@tonic-gate 	char *a2;
146*0Sstevel@tonic-gate 	char link[PATH_MAX];
147*0Sstevel@tonic-gate 	char *addr = di_bus_addr(node);
148*0Sstevel@tonic-gate 	char *mn = di_minor_name(minor);
149*0Sstevel@tonic-gate 
150*0Sstevel@tonic-gate 	if (strcmp(addr, "0,0") == 0) {
151*0Sstevel@tonic-gate 		if (strcmp(mn, "c") == 0) {
152*0Sstevel@tonic-gate 			(void) devfsadm_mklink("diskette", node, minor, 0);
153*0Sstevel@tonic-gate 		} else if (strcmp(mn, "c,raw") == 0) {
154*0Sstevel@tonic-gate 			(void) devfsadm_mklink("rdiskette", node, minor, 0);
155*0Sstevel@tonic-gate 		}
156*0Sstevel@tonic-gate 
157*0Sstevel@tonic-gate 	}
158*0Sstevel@tonic-gate 
159*0Sstevel@tonic-gate 	if (addr[0] == '0') {
160*0Sstevel@tonic-gate 		if ((a2 = strchr(addr, ',')) != NULL) {
161*0Sstevel@tonic-gate 			a2++;
162*0Sstevel@tonic-gate 			if (strcmp(mn, "c") == 0) {
163*0Sstevel@tonic-gate 				(void) strcpy(link, "diskette");
164*0Sstevel@tonic-gate 				(void) strcat(link, a2);
165*0Sstevel@tonic-gate 				(void) devfsadm_mklink(link, node, minor, 0);
166*0Sstevel@tonic-gate 			} else if (strcmp(mn, "c,raw") == 0) {
167*0Sstevel@tonic-gate 				(void) strcpy(link, "rdiskette");
168*0Sstevel@tonic-gate 				(void) strcat(link, a2);
169*0Sstevel@tonic-gate 				(void) devfsadm_mklink(link, node, minor, 0);
170*0Sstevel@tonic-gate 			}
171*0Sstevel@tonic-gate 		}
172*0Sstevel@tonic-gate 	}
173*0Sstevel@tonic-gate 
174*0Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
175*0Sstevel@tonic-gate }
176*0Sstevel@tonic-gate 
177*0Sstevel@tonic-gate /*
178*0Sstevel@tonic-gate  * type=ddi_printer;name=lp;addr=1,3bc      lp0
179*0Sstevel@tonic-gate  * type=ddi_printer;name=lp;addr=1,378      lp1
180*0Sstevel@tonic-gate  * type=ddi_printer;name=lp;addr=1,278      lp2
181*0Sstevel@tonic-gate  */
182*0Sstevel@tonic-gate static int
183*0Sstevel@tonic-gate lp(di_minor_t minor, di_node_t node)
184*0Sstevel@tonic-gate {
185*0Sstevel@tonic-gate 	char *addr = di_bus_addr(node);
186*0Sstevel@tonic-gate 	char *buf;
187*0Sstevel@tonic-gate 	char path[PATH_MAX + 1];
188*0Sstevel@tonic-gate 	devfsadm_enumerate_t rules[1] = {"^ecpp([0-9]+)$", 1, MATCH_ALL};
189*0Sstevel@tonic-gate 
190*0Sstevel@tonic-gate 	if (strcmp(addr, "1,3bc") == 0) {
191*0Sstevel@tonic-gate 		(void) devfsadm_mklink("lp0", node, minor, 0);
192*0Sstevel@tonic-gate 
193*0Sstevel@tonic-gate 	} else if (strcmp(addr, "1,378") == 0) {
194*0Sstevel@tonic-gate 		(void) devfsadm_mklink("lp1", node, minor, 0);
195*0Sstevel@tonic-gate 
196*0Sstevel@tonic-gate 	} else if (strcmp(addr, "1,278") == 0) {
197*0Sstevel@tonic-gate 		(void) devfsadm_mklink("lp2", node, minor, 0);
198*0Sstevel@tonic-gate 	}
199*0Sstevel@tonic-gate 
200*0Sstevel@tonic-gate 	if (strcmp(di_driver_name(node), "ecpp") != 0) {
201*0Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
202*0Sstevel@tonic-gate 	}
203*0Sstevel@tonic-gate 
204*0Sstevel@tonic-gate 	if ((buf = di_devfs_path(node)) == NULL) {
205*0Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
206*0Sstevel@tonic-gate 	}
207*0Sstevel@tonic-gate 
208*0Sstevel@tonic-gate 	(void) snprintf(path, sizeof (path), "%s:%s",
209*0Sstevel@tonic-gate 	    buf, di_minor_name(minor));
210*0Sstevel@tonic-gate 
211*0Sstevel@tonic-gate 	di_devfs_path_free(buf);
212*0Sstevel@tonic-gate 
213*0Sstevel@tonic-gate 	if (devfsadm_enumerate_int(path, 0, &buf, rules, 1)) {
214*0Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
215*0Sstevel@tonic-gate 	}
216*0Sstevel@tonic-gate 
217*0Sstevel@tonic-gate 	(void) snprintf(path, sizeof (path), "ecpp%s", buf);
218*0Sstevel@tonic-gate 	free(buf);
219*0Sstevel@tonic-gate 	(void) devfsadm_mklink(path, node, minor, 0);
220*0Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
221*0Sstevel@tonic-gate }
222*0Sstevel@tonic-gate 
223*0Sstevel@tonic-gate /*
224*0Sstevel@tonic-gate  * type=ddi_serial:mb;minor=a      tty00
225*0Sstevel@tonic-gate  * type=ddi_serial:mb;minor=b      tty01
226*0Sstevel@tonic-gate  * type=ddi_serial:mb;minor=c      tty02
227*0Sstevel@tonic-gate  * type=ddi_serial:mb;minor=d      tty03
228*0Sstevel@tonic-gate  */
229*0Sstevel@tonic-gate static int
230*0Sstevel@tonic-gate serial(di_minor_t minor, di_node_t node)
231*0Sstevel@tonic-gate {
232*0Sstevel@tonic-gate 
233*0Sstevel@tonic-gate 	char *mn = di_minor_name(minor);
234*0Sstevel@tonic-gate 	char link[PATH_MAX];
235*0Sstevel@tonic-gate 
236*0Sstevel@tonic-gate 	(void) strcpy(link, "tty");
237*0Sstevel@tonic-gate 	(void) strcat(link, mn);
238*0Sstevel@tonic-gate 	(void) devfsadm_mklink(link, node, minor, 0);
239*0Sstevel@tonic-gate 
240*0Sstevel@tonic-gate 	if (strcmp(mn, "a") == 0) {
241*0Sstevel@tonic-gate 		(void) devfsadm_mklink("tty00", node, minor, 0);
242*0Sstevel@tonic-gate 
243*0Sstevel@tonic-gate 	} else if (strcmp(mn, "b") == 0) {
244*0Sstevel@tonic-gate 		(void) devfsadm_mklink("tty01", node, minor, 0);
245*0Sstevel@tonic-gate 
246*0Sstevel@tonic-gate 	} else if (strcmp(mn, "c") == 0) {
247*0Sstevel@tonic-gate 		(void) devfsadm_mklink("tty02", node, minor, 0);
248*0Sstevel@tonic-gate 
249*0Sstevel@tonic-gate 	} else if (strcmp(mn, "d") == 0) {
250*0Sstevel@tonic-gate 		(void) devfsadm_mklink("tty03", node, minor, 0);
251*0Sstevel@tonic-gate 	}
252*0Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
253*0Sstevel@tonic-gate }
254*0Sstevel@tonic-gate 
255*0Sstevel@tonic-gate /*
256*0Sstevel@tonic-gate  * type=ddi_serial:dialout,mb;minor=a,cu   ttyd0
257*0Sstevel@tonic-gate  * type=ddi_serial:dialout,mb;minor=b,cu   ttyd1
258*0Sstevel@tonic-gate  * type=ddi_serial:dialout,mb;minor=c,cu   ttyd2
259*0Sstevel@tonic-gate  * type=ddi_serial:dialout,mb;minor=d,cu   ttyd3
260*0Sstevel@tonic-gate  */
261*0Sstevel@tonic-gate static int
262*0Sstevel@tonic-gate serial_dialout(di_minor_t minor, di_node_t node)
263*0Sstevel@tonic-gate {
264*0Sstevel@tonic-gate 	char *mn = di_minor_name(minor);
265*0Sstevel@tonic-gate 
266*0Sstevel@tonic-gate 	if (strcmp(mn, "a,cu") == 0) {
267*0Sstevel@tonic-gate 		(void) devfsadm_mklink("ttyd0", node, minor, 0);
268*0Sstevel@tonic-gate 		(void) devfsadm_mklink("cua0", node, minor, 0);
269*0Sstevel@tonic-gate 
270*0Sstevel@tonic-gate 	} else if (strcmp(mn, "b,cu") == 0) {
271*0Sstevel@tonic-gate 		(void) devfsadm_mklink("ttyd1", node, minor, 0);
272*0Sstevel@tonic-gate 		(void) devfsadm_mklink("cua1", node, minor, 0);
273*0Sstevel@tonic-gate 
274*0Sstevel@tonic-gate 	} else if (strcmp(mn, "c,cu") == 0) {
275*0Sstevel@tonic-gate 		(void) devfsadm_mklink("ttyd2", node, minor, 0);
276*0Sstevel@tonic-gate 		(void) devfsadm_mklink("cua2", node, minor, 0);
277*0Sstevel@tonic-gate 
278*0Sstevel@tonic-gate 	} else if (strcmp(mn, "d,cu") == 0) {
279*0Sstevel@tonic-gate 		(void) devfsadm_mklink("ttyd3", node, minor, 0);
280*0Sstevel@tonic-gate 		(void) devfsadm_mklink("cua3", node, minor, 0);
281*0Sstevel@tonic-gate 	}
282*0Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
283*0Sstevel@tonic-gate }
284*0Sstevel@tonic-gate 
285*0Sstevel@tonic-gate static int
286*0Sstevel@tonic-gate kdmouse(di_minor_t minor, di_node_t node)
287*0Sstevel@tonic-gate {
288*0Sstevel@tonic-gate 	(void) devfsadm_mklink("kdmouse", node, minor, 0);
289*0Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
290*0Sstevel@tonic-gate }
291*0Sstevel@tonic-gate 
292*0Sstevel@tonic-gate static int
293*0Sstevel@tonic-gate bmc(di_minor_t minor, di_node_t node)
294*0Sstevel@tonic-gate {
295*0Sstevel@tonic-gate 	(void) devfsadm_mklink("bmc", node, minor, 0);
296*0Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
297*0Sstevel@tonic-gate }
298*0Sstevel@tonic-gate static int
299*0Sstevel@tonic-gate agp_process(di_minor_t minor, di_node_t node)
300*0Sstevel@tonic-gate {
301*0Sstevel@tonic-gate 	char *minor_nm, *drv_nm;
302*0Sstevel@tonic-gate 	char *devfspath;
303*0Sstevel@tonic-gate 	char *I_path, *p_path, *buf;
304*0Sstevel@tonic-gate 	char *name = (char *)NULL;
305*0Sstevel@tonic-gate 	int i, index;
306*0Sstevel@tonic-gate 	devfsadm_enumerate_t rules[1];
307*0Sstevel@tonic-gate 
308*0Sstevel@tonic-gate 	minor_nm = di_minor_name(minor);
309*0Sstevel@tonic-gate 	drv_nm = di_driver_name(node);
310*0Sstevel@tonic-gate 
311*0Sstevel@tonic-gate 	if ((minor_nm == NULL) || (drv_nm == NULL)) {
312*0Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
313*0Sstevel@tonic-gate 	}
314*0Sstevel@tonic-gate 
315*0Sstevel@tonic-gate 	devfsadm_print(debug_mid, "agp_process: minor=%s node=%s\n",
316*0Sstevel@tonic-gate 		minor_nm, di_node_name(node));
317*0Sstevel@tonic-gate 
318*0Sstevel@tonic-gate 	devfspath = di_devfs_path(node);
319*0Sstevel@tonic-gate 	if (devfspath == NULL) {
320*0Sstevel@tonic-gate 		devfsadm_print(debug_mid, "agp_process: devfspath is NULL\n");
321*0Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
322*0Sstevel@tonic-gate 	}
323*0Sstevel@tonic-gate 
324*0Sstevel@tonic-gate 	I_path = (char *)malloc(PATH_MAX);
325*0Sstevel@tonic-gate 
326*0Sstevel@tonic-gate 	if (I_path == NULL) {
327*0Sstevel@tonic-gate 		di_devfs_path_free(devfspath);
328*0Sstevel@tonic-gate 		devfsadm_print(debug_mid,  "agp_process: malloc failed\n");
329*0Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
330*0Sstevel@tonic-gate 	}
331*0Sstevel@tonic-gate 
332*0Sstevel@tonic-gate 	p_path = (char *)malloc(PATH_MAX);
333*0Sstevel@tonic-gate 
334*0Sstevel@tonic-gate 	if (p_path == NULL) {
335*0Sstevel@tonic-gate 		devfsadm_print(debug_mid,  "agp_process: malloc failed\n");
336*0Sstevel@tonic-gate 		di_devfs_path_free(devfspath);
337*0Sstevel@tonic-gate 		free(I_path);
338*0Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
339*0Sstevel@tonic-gate 	}
340*0Sstevel@tonic-gate 
341*0Sstevel@tonic-gate 	(void) strlcpy(p_path, devfspath, PATH_MAX);
342*0Sstevel@tonic-gate 	(void) strlcat(p_path, ":", PATH_MAX);
343*0Sstevel@tonic-gate 	(void) strlcat(p_path, minor_nm, PATH_MAX);
344*0Sstevel@tonic-gate 	di_devfs_path_free(devfspath);
345*0Sstevel@tonic-gate 
346*0Sstevel@tonic-gate 	devfsadm_print(debug_mid, "agp_process: path %s\n", p_path);
347*0Sstevel@tonic-gate 
348*0Sstevel@tonic-gate 	for (i = 0; ; i++) {
349*0Sstevel@tonic-gate 		if ((driver_name_table[i].driver_name == NULL) ||
350*0Sstevel@tonic-gate 		    (strcmp(drv_nm, driver_name_table[i].driver_name) == 0)) {
351*0Sstevel@tonic-gate 			index = driver_name_table[i].index;
352*0Sstevel@tonic-gate 			break;
353*0Sstevel@tonic-gate 		}
354*0Sstevel@tonic-gate 	}
355*0Sstevel@tonic-gate 	switch (index) {
356*0Sstevel@tonic-gate 	case DRIVER_AGPPSEUDO:
357*0Sstevel@tonic-gate 		devfsadm_print(debug_mid,
358*0Sstevel@tonic-gate 			    "agp_process: psdeudo driver name\n");
359*0Sstevel@tonic-gate 		name = "agpgart";
360*0Sstevel@tonic-gate 		(void) snprintf(I_path, PATH_MAX, "%s", name);
361*0Sstevel@tonic-gate 		devfsadm_print(debug_mid,
362*0Sstevel@tonic-gate 		    "mklink %s -> %s\n", I_path, p_path);
363*0Sstevel@tonic-gate 
364*0Sstevel@tonic-gate 		(void) devfsadm_mklink(I_path, node, minor, 0);
365*0Sstevel@tonic-gate 
366*0Sstevel@tonic-gate 		free(I_path);
367*0Sstevel@tonic-gate 		free(p_path);
368*0Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
369*0Sstevel@tonic-gate 	case DRIVER_AGPTARGET:
370*0Sstevel@tonic-gate 		devfsadm_print(debug_mid,
371*0Sstevel@tonic-gate 			    "agp_process: target driver name\n");
372*0Sstevel@tonic-gate 		rules[0] = agptarget_rules[0];
373*0Sstevel@tonic-gate 		name = "agptarget";
374*0Sstevel@tonic-gate 		break;
375*0Sstevel@tonic-gate 	case DRIVER_CPUGART:
376*0Sstevel@tonic-gate 		devfsadm_print(debug_mid,
377*0Sstevel@tonic-gate 			    "agp_process: cpugart driver name\n");
378*0Sstevel@tonic-gate 		rules[0] = cpugart_rules[0];
379*0Sstevel@tonic-gate 		name = "cpugart";
380*0Sstevel@tonic-gate 		break;
381*0Sstevel@tonic-gate 	case DRIVER_AGPMASTER:
382*0Sstevel@tonic-gate 		devfsadm_print(debug_mid,
383*0Sstevel@tonic-gate 			    "agp_process: agpmaster driver name\n");
384*0Sstevel@tonic-gate 		rules[0] = agpmaster_rules[0];
385*0Sstevel@tonic-gate 		name = "agpmaster";
386*0Sstevel@tonic-gate 		break;
387*0Sstevel@tonic-gate 	case DRIVER_UNKNOWN:
388*0Sstevel@tonic-gate 		devfsadm_print(debug_mid,
389*0Sstevel@tonic-gate 			    "agp_process: unknown driver name=%s\n", drv_nm);
390*0Sstevel@tonic-gate 		free(I_path);
391*0Sstevel@tonic-gate 		free(p_path);
392*0Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
393*0Sstevel@tonic-gate 	}
394*0Sstevel@tonic-gate 
395*0Sstevel@tonic-gate 	if (devfsadm_enumerate_int(p_path, 0, &buf, rules, 1)) {
396*0Sstevel@tonic-gate 		devfsadm_print(debug_mid, "agp_process: exit/coninue\n");
397*0Sstevel@tonic-gate 		free(I_path);
398*0Sstevel@tonic-gate 		free(p_path);
399*0Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
400*0Sstevel@tonic-gate 	}
401*0Sstevel@tonic-gate 
402*0Sstevel@tonic-gate 
403*0Sstevel@tonic-gate 	(void) snprintf(I_path, PATH_MAX, "agp/%s%s", name, buf);
404*0Sstevel@tonic-gate 
405*0Sstevel@tonic-gate 	devfsadm_print(debug_mid, "agp_process: p_path=%s buf=%s\n",
406*0Sstevel@tonic-gate 		    p_path, buf);
407*0Sstevel@tonic-gate 
408*0Sstevel@tonic-gate 	free(buf);
409*0Sstevel@tonic-gate 
410*0Sstevel@tonic-gate 	devfsadm_print(debug_mid, "mklink %s -> %s\n", I_path, p_path);
411*0Sstevel@tonic-gate 
412*0Sstevel@tonic-gate 	(void) devfsadm_mklink(I_path, node, minor, 0);
413*0Sstevel@tonic-gate 
414*0Sstevel@tonic-gate 	free(p_path);
415*0Sstevel@tonic-gate 	free(I_path);
416*0Sstevel@tonic-gate 
417*0Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
418*0Sstevel@tonic-gate }
419