10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*1676Sjpk  * Common Development and Distribution License (the "License").
6*1676Sjpk  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
221414Scindi  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #include <regex.h>
290Sstevel@tonic-gate #include <devfsadm.h>
300Sstevel@tonic-gate #include <stdio.h>
310Sstevel@tonic-gate #include <strings.h>
320Sstevel@tonic-gate #include <stdlib.h>
330Sstevel@tonic-gate #include <limits.h>
340Sstevel@tonic-gate #include <ctype.h>
351414Scindi #include <sys/mc.h>
36*1676Sjpk #include <bsm/devalloc.h>
37*1676Sjpk 
38*1676Sjpk extern int system_labeled;
390Sstevel@tonic-gate 
400Sstevel@tonic-gate static int lp(di_minor_t minor, di_node_t node);
410Sstevel@tonic-gate static int serial_dialout(di_minor_t minor, di_node_t node);
420Sstevel@tonic-gate static int serial(di_minor_t minor, di_node_t node);
430Sstevel@tonic-gate static int diskette(di_minor_t minor, di_node_t node);
440Sstevel@tonic-gate static int vt00(di_minor_t minor, di_node_t node);
450Sstevel@tonic-gate static int kdmouse(di_minor_t minor, di_node_t node);
460Sstevel@tonic-gate static int bmc(di_minor_t minor, di_node_t node);
47437Smws static int smbios(di_minor_t minor, di_node_t node);
480Sstevel@tonic-gate static int agp_process(di_minor_t minor, di_node_t node);
491414Scindi static int mc_node(di_minor_t minor, di_node_t node);
500Sstevel@tonic-gate 
510Sstevel@tonic-gate static devfsadm_create_t misc_cbt[] = {
520Sstevel@tonic-gate 	{ "vt00", "ddi_display", NULL,
530Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_0,	vt00
540Sstevel@tonic-gate 	},
550Sstevel@tonic-gate 	{ "mouse", "ddi_mouse", "mouse8042",
560Sstevel@tonic-gate 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, kdmouse
570Sstevel@tonic-gate 	},
580Sstevel@tonic-gate 	{ "pseudo", "ddi_pseudo", "bmc",
590Sstevel@tonic-gate 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, bmc,
600Sstevel@tonic-gate 	},
61437Smws 	{ "pseudo", "ddi_pseudo", "smbios",
62437Smws 	    TYPE_EXACT | DRV_EXACT, ILEVEL_1, smbios,
63437Smws 	},
640Sstevel@tonic-gate 	{ "disk",  "ddi_block:diskette", NULL,
650Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_1, diskette
660Sstevel@tonic-gate 	},
670Sstevel@tonic-gate 	{ "parallel",  "ddi_printer", NULL,
680Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_1, lp
690Sstevel@tonic-gate 	},
700Sstevel@tonic-gate 	{ "serial", "ddi_serial:mb", NULL,
710Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_1, serial
720Sstevel@tonic-gate 	},
730Sstevel@tonic-gate 	{ "serial",  "ddi_serial:dialout,mb", NULL,
740Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_1, serial_dialout
750Sstevel@tonic-gate 	},
761414Scindi 	{ "agp", "ddi_agp:pseudo", NULL,
770Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_0, agp_process
780Sstevel@tonic-gate 	},
791414Scindi 	{ "agp", "ddi_agp:target", NULL,
800Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_0, agp_process
810Sstevel@tonic-gate 	},
821414Scindi 	{ "agp", "ddi_agp:cpugart", NULL,
830Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_0, agp_process
840Sstevel@tonic-gate 	},
851414Scindi 	{ "agp", "ddi_agp:master", NULL,
860Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_0, agp_process
871414Scindi 	},
881414Scindi 	{ "memory-controller", "ddi_mem_ctrl", NULL,
891414Scindi 	    TYPE_EXACT, ILEVEL_0, mc_node
900Sstevel@tonic-gate 	}
910Sstevel@tonic-gate };
920Sstevel@tonic-gate 
930Sstevel@tonic-gate DEVFSADM_CREATE_INIT_V0(misc_cbt);
940Sstevel@tonic-gate 
950Sstevel@tonic-gate static char *debug_mid = "agp_mid";
960Sstevel@tonic-gate 
970Sstevel@tonic-gate typedef enum {
980Sstevel@tonic-gate 	DRIVER_AGPPSEUDO = 0,
990Sstevel@tonic-gate 	DRIVER_AGPTARGET,
1000Sstevel@tonic-gate 	DRIVER_CPUGART,
1010Sstevel@tonic-gate 	DRIVER_AGPMASTER,
1020Sstevel@tonic-gate 	DRIVER_UNKNOWN
1030Sstevel@tonic-gate } driver_defs_t;
1040Sstevel@tonic-gate 
1050Sstevel@tonic-gate typedef struct {
1060Sstevel@tonic-gate 	char	*driver_name;
1070Sstevel@tonic-gate 	int	index;
1080Sstevel@tonic-gate } driver_name_table_entry_t;
1090Sstevel@tonic-gate 
1100Sstevel@tonic-gate static driver_name_table_entry_t driver_name_table[] = {
1110Sstevel@tonic-gate 	{ "agpgart",		DRIVER_AGPPSEUDO },
1120Sstevel@tonic-gate 	{ "agptarget",		DRIVER_AGPTARGET },
1130Sstevel@tonic-gate 	{ "amd64_gart",		DRIVER_CPUGART },
1140Sstevel@tonic-gate 	{ "vgatext",		DRIVER_AGPMASTER },
1150Sstevel@tonic-gate 	{ NULL,			DRIVER_UNKNOWN }
1160Sstevel@tonic-gate };
1170Sstevel@tonic-gate 
1180Sstevel@tonic-gate static devfsadm_enumerate_t agptarget_rules[1] =
1190Sstevel@tonic-gate 	{ "^agp$/^agptarget([0-9]+)$", 1, MATCH_ALL };
1200Sstevel@tonic-gate static devfsadm_enumerate_t cpugart_rules[1] =
1210Sstevel@tonic-gate 	{ "^agp$/^cpugart([0-9]+)$", 1, MATCH_ALL };
1220Sstevel@tonic-gate static devfsadm_enumerate_t agpmaster_rules[1] =
1230Sstevel@tonic-gate 	{  "^agp$/^agpmaster([0-9]+)$", 1, MATCH_ALL };
1240Sstevel@tonic-gate 
1250Sstevel@tonic-gate static devfsadm_remove_t misc_remove_cbt[] = {
1260Sstevel@tonic-gate 	{ "vt", "vt[0-9][0-9]", RM_PRE|RM_ALWAYS,
1270Sstevel@tonic-gate 		ILEVEL_0, devfsadm_rm_all
1280Sstevel@tonic-gate 	}
1290Sstevel@tonic-gate };
1300Sstevel@tonic-gate 
1310Sstevel@tonic-gate DEVFSADM_REMOVE_INIT_V0(misc_remove_cbt);
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate /*
1340Sstevel@tonic-gate  * Handles minor node type "ddi_display", in addition to generic processing
1350Sstevel@tonic-gate  * done by display().
1360Sstevel@tonic-gate  *
1370Sstevel@tonic-gate  * This creates a /dev/vt00 link to /dev/fb, for backwards compatibility.
1380Sstevel@tonic-gate  */
1390Sstevel@tonic-gate /* ARGSUSED */
1400Sstevel@tonic-gate int
1410Sstevel@tonic-gate vt00(di_minor_t minor, di_node_t node)
1420Sstevel@tonic-gate {
1430Sstevel@tonic-gate 	(void) devfsadm_secondary_link("vt00", "fb", 0);
1440Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
1450Sstevel@tonic-gate }
1460Sstevel@tonic-gate 
1470Sstevel@tonic-gate /*
1480Sstevel@tonic-gate  * type=ddi_block:diskette;addr=0,0;minor=c        diskette
1490Sstevel@tonic-gate  * type=ddi_block:diskette;addr=0,0;minor=c,raw    rdiskette
1500Sstevel@tonic-gate  * type=ddi_block:diskette;addr1=0;minor=c diskette\A2
1510Sstevel@tonic-gate  * type=ddi_block:diskette;addr1=0;minor=c,raw     rdiskette\A2
1520Sstevel@tonic-gate  */
1530Sstevel@tonic-gate static int
1540Sstevel@tonic-gate diskette(di_minor_t minor, di_node_t node)
1550Sstevel@tonic-gate {
156*1676Sjpk 	int flags = 0;
1570Sstevel@tonic-gate 	char *a2;
1580Sstevel@tonic-gate 	char link[PATH_MAX];
1590Sstevel@tonic-gate 	char *addr = di_bus_addr(node);
1600Sstevel@tonic-gate 	char *mn = di_minor_name(minor);
1610Sstevel@tonic-gate 
162*1676Sjpk 	if (system_labeled)
163*1676Sjpk 		flags = DA_ADD|DA_FLOPPY;
164*1676Sjpk 
1650Sstevel@tonic-gate 	if (strcmp(addr, "0,0") == 0) {
1660Sstevel@tonic-gate 		if (strcmp(mn, "c") == 0) {
167*1676Sjpk 			(void) devfsadm_mklink("diskette", node, minor, flags);
1680Sstevel@tonic-gate 		} else if (strcmp(mn, "c,raw") == 0) {
169*1676Sjpk 			(void) devfsadm_mklink("rdiskette", node, minor, flags);
1700Sstevel@tonic-gate 		}
1710Sstevel@tonic-gate 
1720Sstevel@tonic-gate 	}
1730Sstevel@tonic-gate 
1740Sstevel@tonic-gate 	if (addr[0] == '0') {
1750Sstevel@tonic-gate 		if ((a2 = strchr(addr, ',')) != NULL) {
1760Sstevel@tonic-gate 			a2++;
1770Sstevel@tonic-gate 			if (strcmp(mn, "c") == 0) {
1780Sstevel@tonic-gate 				(void) strcpy(link, "diskette");
1790Sstevel@tonic-gate 				(void) strcat(link, a2);
180*1676Sjpk 				(void) devfsadm_mklink(link, node, minor,
181*1676Sjpk 				    flags);
1820Sstevel@tonic-gate 			} else if (strcmp(mn, "c,raw") == 0) {
1830Sstevel@tonic-gate 				(void) strcpy(link, "rdiskette");
1840Sstevel@tonic-gate 				(void) strcat(link, a2);
185*1676Sjpk 				(void) devfsadm_mklink(link, node, minor,
186*1676Sjpk 				    flags);
1870Sstevel@tonic-gate 			}
1880Sstevel@tonic-gate 		}
1890Sstevel@tonic-gate 	}
1900Sstevel@tonic-gate 
1910Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
1920Sstevel@tonic-gate }
1930Sstevel@tonic-gate 
1940Sstevel@tonic-gate /*
1950Sstevel@tonic-gate  * type=ddi_printer;name=lp;addr=1,3bc      lp0
1960Sstevel@tonic-gate  * type=ddi_printer;name=lp;addr=1,378      lp1
1970Sstevel@tonic-gate  * type=ddi_printer;name=lp;addr=1,278      lp2
1980Sstevel@tonic-gate  */
1990Sstevel@tonic-gate static int
2000Sstevel@tonic-gate lp(di_minor_t minor, di_node_t node)
2010Sstevel@tonic-gate {
2020Sstevel@tonic-gate 	char *addr = di_bus_addr(node);
2030Sstevel@tonic-gate 	char *buf;
2040Sstevel@tonic-gate 	char path[PATH_MAX + 1];
2050Sstevel@tonic-gate 	devfsadm_enumerate_t rules[1] = {"^ecpp([0-9]+)$", 1, MATCH_ALL};
2060Sstevel@tonic-gate 
2070Sstevel@tonic-gate 	if (strcmp(addr, "1,3bc") == 0) {
2080Sstevel@tonic-gate 		(void) devfsadm_mklink("lp0", node, minor, 0);
2090Sstevel@tonic-gate 
2100Sstevel@tonic-gate 	} else if (strcmp(addr, "1,378") == 0) {
2110Sstevel@tonic-gate 		(void) devfsadm_mklink("lp1", node, minor, 0);
2120Sstevel@tonic-gate 
2130Sstevel@tonic-gate 	} else if (strcmp(addr, "1,278") == 0) {
2140Sstevel@tonic-gate 		(void) devfsadm_mklink("lp2", node, minor, 0);
2150Sstevel@tonic-gate 	}
2160Sstevel@tonic-gate 
2170Sstevel@tonic-gate 	if (strcmp(di_driver_name(node), "ecpp") != 0) {
2180Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
2190Sstevel@tonic-gate 	}
2200Sstevel@tonic-gate 
2210Sstevel@tonic-gate 	if ((buf = di_devfs_path(node)) == NULL) {
2220Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
2230Sstevel@tonic-gate 	}
2240Sstevel@tonic-gate 
2250Sstevel@tonic-gate 	(void) snprintf(path, sizeof (path), "%s:%s",
2260Sstevel@tonic-gate 	    buf, di_minor_name(minor));
2270Sstevel@tonic-gate 
2280Sstevel@tonic-gate 	di_devfs_path_free(buf);
2290Sstevel@tonic-gate 
2300Sstevel@tonic-gate 	if (devfsadm_enumerate_int(path, 0, &buf, rules, 1)) {
2310Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
2320Sstevel@tonic-gate 	}
2330Sstevel@tonic-gate 
2340Sstevel@tonic-gate 	(void) snprintf(path, sizeof (path), "ecpp%s", buf);
2350Sstevel@tonic-gate 	free(buf);
2360Sstevel@tonic-gate 	(void) devfsadm_mklink(path, node, minor, 0);
2370Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
2380Sstevel@tonic-gate }
2390Sstevel@tonic-gate 
2400Sstevel@tonic-gate /*
2410Sstevel@tonic-gate  * type=ddi_serial:mb;minor=a      tty00
2420Sstevel@tonic-gate  * type=ddi_serial:mb;minor=b      tty01
2430Sstevel@tonic-gate  * type=ddi_serial:mb;minor=c      tty02
2440Sstevel@tonic-gate  * type=ddi_serial:mb;minor=d      tty03
2450Sstevel@tonic-gate  */
2460Sstevel@tonic-gate static int
2470Sstevel@tonic-gate serial(di_minor_t minor, di_node_t node)
2480Sstevel@tonic-gate {
2490Sstevel@tonic-gate 
2500Sstevel@tonic-gate 	char *mn = di_minor_name(minor);
2510Sstevel@tonic-gate 	char link[PATH_MAX];
2520Sstevel@tonic-gate 
2530Sstevel@tonic-gate 	(void) strcpy(link, "tty");
2540Sstevel@tonic-gate 	(void) strcat(link, mn);
2550Sstevel@tonic-gate 	(void) devfsadm_mklink(link, node, minor, 0);
2560Sstevel@tonic-gate 
2570Sstevel@tonic-gate 	if (strcmp(mn, "a") == 0) {
2580Sstevel@tonic-gate 		(void) devfsadm_mklink("tty00", node, minor, 0);
2590Sstevel@tonic-gate 
2600Sstevel@tonic-gate 	} else if (strcmp(mn, "b") == 0) {
2610Sstevel@tonic-gate 		(void) devfsadm_mklink("tty01", node, minor, 0);
2620Sstevel@tonic-gate 
2630Sstevel@tonic-gate 	} else if (strcmp(mn, "c") == 0) {
2640Sstevel@tonic-gate 		(void) devfsadm_mklink("tty02", node, minor, 0);
2650Sstevel@tonic-gate 
2660Sstevel@tonic-gate 	} else if (strcmp(mn, "d") == 0) {
2670Sstevel@tonic-gate 		(void) devfsadm_mklink("tty03", node, minor, 0);
2680Sstevel@tonic-gate 	}
2690Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
2700Sstevel@tonic-gate }
2710Sstevel@tonic-gate 
2720Sstevel@tonic-gate /*
2730Sstevel@tonic-gate  * type=ddi_serial:dialout,mb;minor=a,cu   ttyd0
2740Sstevel@tonic-gate  * type=ddi_serial:dialout,mb;minor=b,cu   ttyd1
2750Sstevel@tonic-gate  * type=ddi_serial:dialout,mb;minor=c,cu   ttyd2
2760Sstevel@tonic-gate  * type=ddi_serial:dialout,mb;minor=d,cu   ttyd3
2770Sstevel@tonic-gate  */
2780Sstevel@tonic-gate static int
2790Sstevel@tonic-gate serial_dialout(di_minor_t minor, di_node_t node)
2800Sstevel@tonic-gate {
2810Sstevel@tonic-gate 	char *mn = di_minor_name(minor);
2820Sstevel@tonic-gate 
2830Sstevel@tonic-gate 	if (strcmp(mn, "a,cu") == 0) {
2840Sstevel@tonic-gate 		(void) devfsadm_mklink("ttyd0", node, minor, 0);
2850Sstevel@tonic-gate 		(void) devfsadm_mklink("cua0", node, minor, 0);
2860Sstevel@tonic-gate 
2870Sstevel@tonic-gate 	} else if (strcmp(mn, "b,cu") == 0) {
2880Sstevel@tonic-gate 		(void) devfsadm_mklink("ttyd1", node, minor, 0);
2890Sstevel@tonic-gate 		(void) devfsadm_mklink("cua1", node, minor, 0);
2900Sstevel@tonic-gate 
2910Sstevel@tonic-gate 	} else if (strcmp(mn, "c,cu") == 0) {
2920Sstevel@tonic-gate 		(void) devfsadm_mklink("ttyd2", node, minor, 0);
2930Sstevel@tonic-gate 		(void) devfsadm_mklink("cua2", node, minor, 0);
2940Sstevel@tonic-gate 
2950Sstevel@tonic-gate 	} else if (strcmp(mn, "d,cu") == 0) {
2960Sstevel@tonic-gate 		(void) devfsadm_mklink("ttyd3", node, minor, 0);
2970Sstevel@tonic-gate 		(void) devfsadm_mklink("cua3", node, minor, 0);
2980Sstevel@tonic-gate 	}
2990Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
3000Sstevel@tonic-gate }
3010Sstevel@tonic-gate 
3020Sstevel@tonic-gate static int
3030Sstevel@tonic-gate kdmouse(di_minor_t minor, di_node_t node)
3040Sstevel@tonic-gate {
3050Sstevel@tonic-gate 	(void) devfsadm_mklink("kdmouse", node, minor, 0);
3060Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
3070Sstevel@tonic-gate }
3080Sstevel@tonic-gate 
3090Sstevel@tonic-gate static int
3100Sstevel@tonic-gate bmc(di_minor_t minor, di_node_t node)
3110Sstevel@tonic-gate {
3120Sstevel@tonic-gate 	(void) devfsadm_mklink("bmc", node, minor, 0);
3130Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
3140Sstevel@tonic-gate }
315437Smws 
316437Smws static int
317437Smws smbios(di_minor_t minor, di_node_t node)
318437Smws {
319437Smws 	(void) devfsadm_mklink("smbios", node, minor, 0);
320437Smws 	return (DEVFSADM_CONTINUE);
321437Smws }
322437Smws 
3230Sstevel@tonic-gate static int
3240Sstevel@tonic-gate agp_process(di_minor_t minor, di_node_t node)
3250Sstevel@tonic-gate {
3260Sstevel@tonic-gate 	char *minor_nm, *drv_nm;
3270Sstevel@tonic-gate 	char *devfspath;
3280Sstevel@tonic-gate 	char *I_path, *p_path, *buf;
3290Sstevel@tonic-gate 	char *name = (char *)NULL;
3300Sstevel@tonic-gate 	int i, index;
3310Sstevel@tonic-gate 	devfsadm_enumerate_t rules[1];
3320Sstevel@tonic-gate 
3330Sstevel@tonic-gate 	minor_nm = di_minor_name(minor);
3340Sstevel@tonic-gate 	drv_nm = di_driver_name(node);
3350Sstevel@tonic-gate 
3360Sstevel@tonic-gate 	if ((minor_nm == NULL) || (drv_nm == NULL)) {
3370Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
3380Sstevel@tonic-gate 	}
3390Sstevel@tonic-gate 
3400Sstevel@tonic-gate 	devfsadm_print(debug_mid, "agp_process: minor=%s node=%s\n",
3410Sstevel@tonic-gate 		minor_nm, di_node_name(node));
3420Sstevel@tonic-gate 
3430Sstevel@tonic-gate 	devfspath = di_devfs_path(node);
3440Sstevel@tonic-gate 	if (devfspath == NULL) {
3450Sstevel@tonic-gate 		devfsadm_print(debug_mid, "agp_process: devfspath is NULL\n");
3460Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
3470Sstevel@tonic-gate 	}
3480Sstevel@tonic-gate 
3490Sstevel@tonic-gate 	I_path = (char *)malloc(PATH_MAX);
3500Sstevel@tonic-gate 
3510Sstevel@tonic-gate 	if (I_path == NULL) {
3520Sstevel@tonic-gate 		di_devfs_path_free(devfspath);
3530Sstevel@tonic-gate 		devfsadm_print(debug_mid,  "agp_process: malloc failed\n");
3540Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
3550Sstevel@tonic-gate 	}
3560Sstevel@tonic-gate 
3570Sstevel@tonic-gate 	p_path = (char *)malloc(PATH_MAX);
3580Sstevel@tonic-gate 
3590Sstevel@tonic-gate 	if (p_path == NULL) {
3600Sstevel@tonic-gate 		devfsadm_print(debug_mid,  "agp_process: malloc failed\n");
3610Sstevel@tonic-gate 		di_devfs_path_free(devfspath);
3620Sstevel@tonic-gate 		free(I_path);
3630Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
3640Sstevel@tonic-gate 	}
3650Sstevel@tonic-gate 
3660Sstevel@tonic-gate 	(void) strlcpy(p_path, devfspath, PATH_MAX);
3670Sstevel@tonic-gate 	(void) strlcat(p_path, ":", PATH_MAX);
3680Sstevel@tonic-gate 	(void) strlcat(p_path, minor_nm, PATH_MAX);
3690Sstevel@tonic-gate 	di_devfs_path_free(devfspath);
3700Sstevel@tonic-gate 
3710Sstevel@tonic-gate 	devfsadm_print(debug_mid, "agp_process: path %s\n", p_path);
3720Sstevel@tonic-gate 
3730Sstevel@tonic-gate 	for (i = 0; ; i++) {
3740Sstevel@tonic-gate 		if ((driver_name_table[i].driver_name == NULL) ||
3750Sstevel@tonic-gate 		    (strcmp(drv_nm, driver_name_table[i].driver_name) == 0)) {
3760Sstevel@tonic-gate 			index = driver_name_table[i].index;
3770Sstevel@tonic-gate 			break;
3780Sstevel@tonic-gate 		}
3790Sstevel@tonic-gate 	}
3800Sstevel@tonic-gate 	switch (index) {
3810Sstevel@tonic-gate 	case DRIVER_AGPPSEUDO:
3820Sstevel@tonic-gate 		devfsadm_print(debug_mid,
3830Sstevel@tonic-gate 			    "agp_process: psdeudo driver name\n");
3840Sstevel@tonic-gate 		name = "agpgart";
3850Sstevel@tonic-gate 		(void) snprintf(I_path, PATH_MAX, "%s", name);
3860Sstevel@tonic-gate 		devfsadm_print(debug_mid,
3870Sstevel@tonic-gate 		    "mklink %s -> %s\n", I_path, p_path);
3880Sstevel@tonic-gate 
3890Sstevel@tonic-gate 		(void) devfsadm_mklink(I_path, node, minor, 0);
3900Sstevel@tonic-gate 
3910Sstevel@tonic-gate 		free(I_path);
3920Sstevel@tonic-gate 		free(p_path);
3930Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
3940Sstevel@tonic-gate 	case DRIVER_AGPTARGET:
3950Sstevel@tonic-gate 		devfsadm_print(debug_mid,
3960Sstevel@tonic-gate 			    "agp_process: target driver name\n");
3970Sstevel@tonic-gate 		rules[0] = agptarget_rules[0];
3980Sstevel@tonic-gate 		name = "agptarget";
3990Sstevel@tonic-gate 		break;
4000Sstevel@tonic-gate 	case DRIVER_CPUGART:
4010Sstevel@tonic-gate 		devfsadm_print(debug_mid,
4020Sstevel@tonic-gate 			    "agp_process: cpugart driver name\n");
4030Sstevel@tonic-gate 		rules[0] = cpugart_rules[0];
4040Sstevel@tonic-gate 		name = "cpugart";
4050Sstevel@tonic-gate 		break;
4060Sstevel@tonic-gate 	case DRIVER_AGPMASTER:
4070Sstevel@tonic-gate 		devfsadm_print(debug_mid,
4080Sstevel@tonic-gate 			    "agp_process: agpmaster driver name\n");
4090Sstevel@tonic-gate 		rules[0] = agpmaster_rules[0];
4100Sstevel@tonic-gate 		name = "agpmaster";
4110Sstevel@tonic-gate 		break;
4120Sstevel@tonic-gate 	case DRIVER_UNKNOWN:
4130Sstevel@tonic-gate 		devfsadm_print(debug_mid,
4140Sstevel@tonic-gate 			    "agp_process: unknown driver name=%s\n", drv_nm);
4150Sstevel@tonic-gate 		free(I_path);
4160Sstevel@tonic-gate 		free(p_path);
4170Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
4180Sstevel@tonic-gate 	}
4190Sstevel@tonic-gate 
4200Sstevel@tonic-gate 	if (devfsadm_enumerate_int(p_path, 0, &buf, rules, 1)) {
4210Sstevel@tonic-gate 		devfsadm_print(debug_mid, "agp_process: exit/coninue\n");
4220Sstevel@tonic-gate 		free(I_path);
4230Sstevel@tonic-gate 		free(p_path);
4240Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
4250Sstevel@tonic-gate 	}
4260Sstevel@tonic-gate 
4270Sstevel@tonic-gate 
4280Sstevel@tonic-gate 	(void) snprintf(I_path, PATH_MAX, "agp/%s%s", name, buf);
4290Sstevel@tonic-gate 
4300Sstevel@tonic-gate 	devfsadm_print(debug_mid, "agp_process: p_path=%s buf=%s\n",
4310Sstevel@tonic-gate 		    p_path, buf);
4320Sstevel@tonic-gate 
4330Sstevel@tonic-gate 	free(buf);
4340Sstevel@tonic-gate 
4350Sstevel@tonic-gate 	devfsadm_print(debug_mid, "mklink %s -> %s\n", I_path, p_path);
4360Sstevel@tonic-gate 
4370Sstevel@tonic-gate 	(void) devfsadm_mklink(I_path, node, minor, 0);
4380Sstevel@tonic-gate 
4390Sstevel@tonic-gate 	free(p_path);
4400Sstevel@tonic-gate 	free(I_path);
4410Sstevel@tonic-gate 
4420Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
4430Sstevel@tonic-gate }
4441414Scindi 
4451414Scindi /*
4461414Scindi  * /dev/mc/mc<chipid> -> /devices/.../pci1022,1102@<chipid+24>,2:mc-amd
4471414Scindi  */
4481414Scindi static int
4491414Scindi mc_node(di_minor_t minor, di_node_t node)
4501414Scindi {
4511414Scindi 	const char *minorname = di_minor_name(minor);
4521414Scindi 	const char *busaddr = di_bus_addr(node);
4531414Scindi 	char linkpath[PATH_MAX];
4541414Scindi 	int unitaddr;
4551414Scindi 	char *c;
4561414Scindi 
4571414Scindi 	if (minorname == NULL || busaddr == NULL)
4581414Scindi 		return (DEVFSADM_CONTINUE);
4591414Scindi 
4601414Scindi 	errno = 0;
4611414Scindi 	unitaddr = strtol(busaddr, &c, 16);
4621414Scindi 
4631414Scindi 	if (errno != 0 || unitaddr < MC_AMD_DEV_OFFSET)
4641414Scindi 		return (DEVFSADM_CONTINUE);
4651414Scindi 
4661414Scindi 	(void) snprintf(linkpath, sizeof (linkpath), "mc/mc%u",
4671414Scindi 	    unitaddr - MC_AMD_DEV_OFFSET);
4681414Scindi 	(void) devfsadm_mklink(linkpath, node, minor, 0);
4691414Scindi 	return (DEVFSADM_CONTINUE);
4701414Scindi }
471