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
51676Sjpk  * Common Development and Distribution License (the "License").
61676Sjpk  * 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>
361676Sjpk #include <bsm/devalloc.h>
371676Sjpk 
381676Sjpk 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);
49*2820Skz151634 static int drm_node(di_minor_t minor, di_node_t node);
501414Scindi static int mc_node(di_minor_t minor, di_node_t node);
510Sstevel@tonic-gate 
520Sstevel@tonic-gate static devfsadm_create_t misc_cbt[] = {
530Sstevel@tonic-gate 	{ "vt00", "ddi_display", NULL,
540Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_0,	vt00
550Sstevel@tonic-gate 	},
56*2820Skz151634 	{ "drm", "ddi_display:drm", NULL,
57*2820Skz151634 	    TYPE_EXACT, ILEVEL_0,	drm_node
58*2820Skz151634 	},
590Sstevel@tonic-gate 	{ "mouse", "ddi_mouse", "mouse8042",
600Sstevel@tonic-gate 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, kdmouse
610Sstevel@tonic-gate 	},
620Sstevel@tonic-gate 	{ "pseudo", "ddi_pseudo", "bmc",
630Sstevel@tonic-gate 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, bmc,
640Sstevel@tonic-gate 	},
65437Smws 	{ "pseudo", "ddi_pseudo", "smbios",
66437Smws 	    TYPE_EXACT | DRV_EXACT, ILEVEL_1, smbios,
67437Smws 	},
680Sstevel@tonic-gate 	{ "disk",  "ddi_block:diskette", NULL,
690Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_1, diskette
700Sstevel@tonic-gate 	},
710Sstevel@tonic-gate 	{ "parallel",  "ddi_printer", NULL,
720Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_1, lp
730Sstevel@tonic-gate 	},
740Sstevel@tonic-gate 	{ "serial", "ddi_serial:mb", NULL,
750Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_1, serial
760Sstevel@tonic-gate 	},
770Sstevel@tonic-gate 	{ "serial",  "ddi_serial:dialout,mb", NULL,
780Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_1, serial_dialout
790Sstevel@tonic-gate 	},
801414Scindi 	{ "agp", "ddi_agp:pseudo", NULL,
810Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_0, agp_process
820Sstevel@tonic-gate 	},
831414Scindi 	{ "agp", "ddi_agp:target", NULL,
840Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_0, agp_process
850Sstevel@tonic-gate 	},
861414Scindi 	{ "agp", "ddi_agp:cpugart", NULL,
870Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_0, agp_process
880Sstevel@tonic-gate 	},
891414Scindi 	{ "agp", "ddi_agp:master", NULL,
900Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_0, agp_process
911414Scindi 	},
921414Scindi 	{ "memory-controller", "ddi_mem_ctrl", NULL,
931414Scindi 	    TYPE_EXACT, ILEVEL_0, mc_node
940Sstevel@tonic-gate 	}
950Sstevel@tonic-gate };
960Sstevel@tonic-gate 
970Sstevel@tonic-gate DEVFSADM_CREATE_INIT_V0(misc_cbt);
980Sstevel@tonic-gate 
99*2820Skz151634 static char *debug_mid = "misc_mid";
1000Sstevel@tonic-gate 
1010Sstevel@tonic-gate typedef enum {
1020Sstevel@tonic-gate 	DRIVER_AGPPSEUDO = 0,
1030Sstevel@tonic-gate 	DRIVER_AGPTARGET,
1040Sstevel@tonic-gate 	DRIVER_CPUGART,
105*2820Skz151634 	DRIVER_AGPMASTER_DRM,
106*2820Skz151634 	DRIVER_AGPMASTER_VGATEXT,
1070Sstevel@tonic-gate 	DRIVER_UNKNOWN
1080Sstevel@tonic-gate } driver_defs_t;
1090Sstevel@tonic-gate 
1100Sstevel@tonic-gate typedef struct {
1110Sstevel@tonic-gate 	char	*driver_name;
1120Sstevel@tonic-gate 	int	index;
1130Sstevel@tonic-gate } driver_name_table_entry_t;
1140Sstevel@tonic-gate 
1150Sstevel@tonic-gate static driver_name_table_entry_t driver_name_table[] = {
1160Sstevel@tonic-gate 	{ "agpgart",		DRIVER_AGPPSEUDO },
1170Sstevel@tonic-gate 	{ "agptarget",		DRIVER_AGPTARGET },
1180Sstevel@tonic-gate 	{ "amd64_gart",		DRIVER_CPUGART },
119*2820Skz151634 	/* AGP master device managed by drm driver */
120*2820Skz151634 	{ "i915",		DRIVER_AGPMASTER_DRM },
121*2820Skz151634 	{ "vgatext",		DRIVER_AGPMASTER_VGATEXT },
1220Sstevel@tonic-gate 	{ NULL,			DRIVER_UNKNOWN }
1230Sstevel@tonic-gate };
1240Sstevel@tonic-gate 
1250Sstevel@tonic-gate static devfsadm_enumerate_t agptarget_rules[1] =
1260Sstevel@tonic-gate 	{ "^agp$/^agptarget([0-9]+)$", 1, MATCH_ALL };
1270Sstevel@tonic-gate static devfsadm_enumerate_t cpugart_rules[1] =
1280Sstevel@tonic-gate 	{ "^agp$/^cpugart([0-9]+)$", 1, MATCH_ALL };
1290Sstevel@tonic-gate static devfsadm_enumerate_t agpmaster_rules[1] =
1300Sstevel@tonic-gate 	{  "^agp$/^agpmaster([0-9]+)$", 1, MATCH_ALL };
1310Sstevel@tonic-gate 
1320Sstevel@tonic-gate static devfsadm_remove_t misc_remove_cbt[] = {
1330Sstevel@tonic-gate 	{ "vt", "vt[0-9][0-9]", RM_PRE|RM_ALWAYS,
1340Sstevel@tonic-gate 		ILEVEL_0, devfsadm_rm_all
1350Sstevel@tonic-gate 	}
1360Sstevel@tonic-gate };
1370Sstevel@tonic-gate 
1380Sstevel@tonic-gate DEVFSADM_REMOVE_INIT_V0(misc_remove_cbt);
1390Sstevel@tonic-gate 
1400Sstevel@tonic-gate /*
1410Sstevel@tonic-gate  * Handles minor node type "ddi_display", in addition to generic processing
1420Sstevel@tonic-gate  * done by display().
1430Sstevel@tonic-gate  *
1440Sstevel@tonic-gate  * This creates a /dev/vt00 link to /dev/fb, for backwards compatibility.
1450Sstevel@tonic-gate  */
1460Sstevel@tonic-gate /* ARGSUSED */
1470Sstevel@tonic-gate int
1480Sstevel@tonic-gate vt00(di_minor_t minor, di_node_t node)
1490Sstevel@tonic-gate {
1500Sstevel@tonic-gate 	(void) devfsadm_secondary_link("vt00", "fb", 0);
1510Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
1520Sstevel@tonic-gate }
1530Sstevel@tonic-gate 
1540Sstevel@tonic-gate /*
1550Sstevel@tonic-gate  * type=ddi_block:diskette;addr=0,0;minor=c        diskette
1560Sstevel@tonic-gate  * type=ddi_block:diskette;addr=0,0;minor=c,raw    rdiskette
1570Sstevel@tonic-gate  * type=ddi_block:diskette;addr1=0;minor=c diskette\A2
1580Sstevel@tonic-gate  * type=ddi_block:diskette;addr1=0;minor=c,raw     rdiskette\A2
1590Sstevel@tonic-gate  */
1600Sstevel@tonic-gate static int
1610Sstevel@tonic-gate diskette(di_minor_t minor, di_node_t node)
1620Sstevel@tonic-gate {
1631676Sjpk 	int flags = 0;
1640Sstevel@tonic-gate 	char *a2;
1650Sstevel@tonic-gate 	char link[PATH_MAX];
1660Sstevel@tonic-gate 	char *addr = di_bus_addr(node);
1670Sstevel@tonic-gate 	char *mn = di_minor_name(minor);
1680Sstevel@tonic-gate 
1691676Sjpk 	if (system_labeled)
1701676Sjpk 		flags = DA_ADD|DA_FLOPPY;
1711676Sjpk 
1720Sstevel@tonic-gate 	if (strcmp(addr, "0,0") == 0) {
1730Sstevel@tonic-gate 		if (strcmp(mn, "c") == 0) {
1741676Sjpk 			(void) devfsadm_mklink("diskette", node, minor, flags);
1750Sstevel@tonic-gate 		} else if (strcmp(mn, "c,raw") == 0) {
1761676Sjpk 			(void) devfsadm_mklink("rdiskette", node, minor, flags);
1770Sstevel@tonic-gate 		}
1780Sstevel@tonic-gate 
1790Sstevel@tonic-gate 	}
1800Sstevel@tonic-gate 
1810Sstevel@tonic-gate 	if (addr[0] == '0') {
1820Sstevel@tonic-gate 		if ((a2 = strchr(addr, ',')) != NULL) {
1830Sstevel@tonic-gate 			a2++;
1840Sstevel@tonic-gate 			if (strcmp(mn, "c") == 0) {
1850Sstevel@tonic-gate 				(void) strcpy(link, "diskette");
1860Sstevel@tonic-gate 				(void) strcat(link, a2);
1871676Sjpk 				(void) devfsadm_mklink(link, node, minor,
1881676Sjpk 				    flags);
1890Sstevel@tonic-gate 			} else if (strcmp(mn, "c,raw") == 0) {
1900Sstevel@tonic-gate 				(void) strcpy(link, "rdiskette");
1910Sstevel@tonic-gate 				(void) strcat(link, a2);
1921676Sjpk 				(void) devfsadm_mklink(link, node, minor,
1931676Sjpk 				    flags);
1940Sstevel@tonic-gate 			}
1950Sstevel@tonic-gate 		}
1960Sstevel@tonic-gate 	}
1970Sstevel@tonic-gate 
1980Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
1990Sstevel@tonic-gate }
2000Sstevel@tonic-gate 
2010Sstevel@tonic-gate /*
2020Sstevel@tonic-gate  * type=ddi_printer;name=lp;addr=1,3bc      lp0
2030Sstevel@tonic-gate  * type=ddi_printer;name=lp;addr=1,378      lp1
2040Sstevel@tonic-gate  * type=ddi_printer;name=lp;addr=1,278      lp2
2050Sstevel@tonic-gate  */
2060Sstevel@tonic-gate static int
2070Sstevel@tonic-gate lp(di_minor_t minor, di_node_t node)
2080Sstevel@tonic-gate {
2090Sstevel@tonic-gate 	char *addr = di_bus_addr(node);
2100Sstevel@tonic-gate 	char *buf;
2110Sstevel@tonic-gate 	char path[PATH_MAX + 1];
2120Sstevel@tonic-gate 	devfsadm_enumerate_t rules[1] = {"^ecpp([0-9]+)$", 1, MATCH_ALL};
2130Sstevel@tonic-gate 
2140Sstevel@tonic-gate 	if (strcmp(addr, "1,3bc") == 0) {
2150Sstevel@tonic-gate 		(void) devfsadm_mklink("lp0", node, minor, 0);
2160Sstevel@tonic-gate 
2170Sstevel@tonic-gate 	} else if (strcmp(addr, "1,378") == 0) {
2180Sstevel@tonic-gate 		(void) devfsadm_mklink("lp1", node, minor, 0);
2190Sstevel@tonic-gate 
2200Sstevel@tonic-gate 	} else if (strcmp(addr, "1,278") == 0) {
2210Sstevel@tonic-gate 		(void) devfsadm_mklink("lp2", node, minor, 0);
2220Sstevel@tonic-gate 	}
2230Sstevel@tonic-gate 
2240Sstevel@tonic-gate 	if (strcmp(di_driver_name(node), "ecpp") != 0) {
2250Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
2260Sstevel@tonic-gate 	}
2270Sstevel@tonic-gate 
2280Sstevel@tonic-gate 	if ((buf = di_devfs_path(node)) == NULL) {
2290Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
2300Sstevel@tonic-gate 	}
2310Sstevel@tonic-gate 
2320Sstevel@tonic-gate 	(void) snprintf(path, sizeof (path), "%s:%s",
2330Sstevel@tonic-gate 	    buf, di_minor_name(minor));
2340Sstevel@tonic-gate 
2350Sstevel@tonic-gate 	di_devfs_path_free(buf);
2360Sstevel@tonic-gate 
2370Sstevel@tonic-gate 	if (devfsadm_enumerate_int(path, 0, &buf, rules, 1)) {
2380Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
2390Sstevel@tonic-gate 	}
2400Sstevel@tonic-gate 
2410Sstevel@tonic-gate 	(void) snprintf(path, sizeof (path), "ecpp%s", buf);
2420Sstevel@tonic-gate 	free(buf);
2430Sstevel@tonic-gate 	(void) devfsadm_mklink(path, node, minor, 0);
2440Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
2450Sstevel@tonic-gate }
2460Sstevel@tonic-gate 
2470Sstevel@tonic-gate /*
2480Sstevel@tonic-gate  * type=ddi_serial:mb;minor=a      tty00
2490Sstevel@tonic-gate  * type=ddi_serial:mb;minor=b      tty01
2500Sstevel@tonic-gate  * type=ddi_serial:mb;minor=c      tty02
2510Sstevel@tonic-gate  * type=ddi_serial:mb;minor=d      tty03
2520Sstevel@tonic-gate  */
2530Sstevel@tonic-gate static int
2540Sstevel@tonic-gate serial(di_minor_t minor, di_node_t node)
2550Sstevel@tonic-gate {
2560Sstevel@tonic-gate 
2570Sstevel@tonic-gate 	char *mn = di_minor_name(minor);
2580Sstevel@tonic-gate 	char link[PATH_MAX];
2590Sstevel@tonic-gate 
2600Sstevel@tonic-gate 	(void) strcpy(link, "tty");
2610Sstevel@tonic-gate 	(void) strcat(link, mn);
2620Sstevel@tonic-gate 	(void) devfsadm_mklink(link, node, minor, 0);
2630Sstevel@tonic-gate 
2640Sstevel@tonic-gate 	if (strcmp(mn, "a") == 0) {
2650Sstevel@tonic-gate 		(void) devfsadm_mklink("tty00", node, minor, 0);
2660Sstevel@tonic-gate 
2670Sstevel@tonic-gate 	} else if (strcmp(mn, "b") == 0) {
2680Sstevel@tonic-gate 		(void) devfsadm_mklink("tty01", node, minor, 0);
2690Sstevel@tonic-gate 
2700Sstevel@tonic-gate 	} else if (strcmp(mn, "c") == 0) {
2710Sstevel@tonic-gate 		(void) devfsadm_mklink("tty02", node, minor, 0);
2720Sstevel@tonic-gate 
2730Sstevel@tonic-gate 	} else if (strcmp(mn, "d") == 0) {
2740Sstevel@tonic-gate 		(void) devfsadm_mklink("tty03", node, minor, 0);
2750Sstevel@tonic-gate 	}
2760Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
2770Sstevel@tonic-gate }
2780Sstevel@tonic-gate 
2790Sstevel@tonic-gate /*
2800Sstevel@tonic-gate  * type=ddi_serial:dialout,mb;minor=a,cu   ttyd0
2810Sstevel@tonic-gate  * type=ddi_serial:dialout,mb;minor=b,cu   ttyd1
2820Sstevel@tonic-gate  * type=ddi_serial:dialout,mb;minor=c,cu   ttyd2
2830Sstevel@tonic-gate  * type=ddi_serial:dialout,mb;minor=d,cu   ttyd3
2840Sstevel@tonic-gate  */
2850Sstevel@tonic-gate static int
2860Sstevel@tonic-gate serial_dialout(di_minor_t minor, di_node_t node)
2870Sstevel@tonic-gate {
2880Sstevel@tonic-gate 	char *mn = di_minor_name(minor);
2890Sstevel@tonic-gate 
2900Sstevel@tonic-gate 	if (strcmp(mn, "a,cu") == 0) {
2910Sstevel@tonic-gate 		(void) devfsadm_mklink("ttyd0", node, minor, 0);
2920Sstevel@tonic-gate 		(void) devfsadm_mklink("cua0", node, minor, 0);
2930Sstevel@tonic-gate 
2940Sstevel@tonic-gate 	} else if (strcmp(mn, "b,cu") == 0) {
2950Sstevel@tonic-gate 		(void) devfsadm_mklink("ttyd1", node, minor, 0);
2960Sstevel@tonic-gate 		(void) devfsadm_mklink("cua1", node, minor, 0);
2970Sstevel@tonic-gate 
2980Sstevel@tonic-gate 	} else if (strcmp(mn, "c,cu") == 0) {
2990Sstevel@tonic-gate 		(void) devfsadm_mklink("ttyd2", node, minor, 0);
3000Sstevel@tonic-gate 		(void) devfsadm_mklink("cua2", node, minor, 0);
3010Sstevel@tonic-gate 
3020Sstevel@tonic-gate 	} else if (strcmp(mn, "d,cu") == 0) {
3030Sstevel@tonic-gate 		(void) devfsadm_mklink("ttyd3", node, minor, 0);
3040Sstevel@tonic-gate 		(void) devfsadm_mklink("cua3", node, minor, 0);
3050Sstevel@tonic-gate 	}
3060Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
3070Sstevel@tonic-gate }
3080Sstevel@tonic-gate 
3090Sstevel@tonic-gate static int
3100Sstevel@tonic-gate kdmouse(di_minor_t minor, di_node_t node)
3110Sstevel@tonic-gate {
3120Sstevel@tonic-gate 	(void) devfsadm_mklink("kdmouse", node, minor, 0);
3130Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
3140Sstevel@tonic-gate }
3150Sstevel@tonic-gate 
3160Sstevel@tonic-gate static int
3170Sstevel@tonic-gate bmc(di_minor_t minor, di_node_t node)
3180Sstevel@tonic-gate {
3190Sstevel@tonic-gate 	(void) devfsadm_mklink("bmc", node, minor, 0);
3200Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
3210Sstevel@tonic-gate }
322437Smws 
323437Smws static int
324437Smws smbios(di_minor_t minor, di_node_t node)
325437Smws {
326437Smws 	(void) devfsadm_mklink("smbios", node, minor, 0);
327437Smws 	return (DEVFSADM_CONTINUE);
328437Smws }
329437Smws 
3300Sstevel@tonic-gate static int
3310Sstevel@tonic-gate agp_process(di_minor_t minor, di_node_t node)
3320Sstevel@tonic-gate {
3330Sstevel@tonic-gate 	char *minor_nm, *drv_nm;
3340Sstevel@tonic-gate 	char *devfspath;
3350Sstevel@tonic-gate 	char *I_path, *p_path, *buf;
3360Sstevel@tonic-gate 	char *name = (char *)NULL;
3370Sstevel@tonic-gate 	int i, index;
3380Sstevel@tonic-gate 	devfsadm_enumerate_t rules[1];
3390Sstevel@tonic-gate 
3400Sstevel@tonic-gate 	minor_nm = di_minor_name(minor);
3410Sstevel@tonic-gate 	drv_nm = di_driver_name(node);
3420Sstevel@tonic-gate 
3430Sstevel@tonic-gate 	if ((minor_nm == NULL) || (drv_nm == NULL)) {
3440Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
3450Sstevel@tonic-gate 	}
3460Sstevel@tonic-gate 
3470Sstevel@tonic-gate 	devfsadm_print(debug_mid, "agp_process: minor=%s node=%s\n",
3480Sstevel@tonic-gate 		minor_nm, di_node_name(node));
3490Sstevel@tonic-gate 
3500Sstevel@tonic-gate 	devfspath = di_devfs_path(node);
3510Sstevel@tonic-gate 	if (devfspath == NULL) {
3520Sstevel@tonic-gate 		devfsadm_print(debug_mid, "agp_process: devfspath is NULL\n");
3530Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
3540Sstevel@tonic-gate 	}
3550Sstevel@tonic-gate 
3560Sstevel@tonic-gate 	I_path = (char *)malloc(PATH_MAX);
3570Sstevel@tonic-gate 
3580Sstevel@tonic-gate 	if (I_path == NULL) {
3590Sstevel@tonic-gate 		di_devfs_path_free(devfspath);
3600Sstevel@tonic-gate 		devfsadm_print(debug_mid,  "agp_process: malloc failed\n");
3610Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
3620Sstevel@tonic-gate 	}
3630Sstevel@tonic-gate 
3640Sstevel@tonic-gate 	p_path = (char *)malloc(PATH_MAX);
3650Sstevel@tonic-gate 
3660Sstevel@tonic-gate 	if (p_path == NULL) {
3670Sstevel@tonic-gate 		devfsadm_print(debug_mid,  "agp_process: malloc failed\n");
3680Sstevel@tonic-gate 		di_devfs_path_free(devfspath);
3690Sstevel@tonic-gate 		free(I_path);
3700Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
3710Sstevel@tonic-gate 	}
3720Sstevel@tonic-gate 
3730Sstevel@tonic-gate 	(void) strlcpy(p_path, devfspath, PATH_MAX);
3740Sstevel@tonic-gate 	(void) strlcat(p_path, ":", PATH_MAX);
3750Sstevel@tonic-gate 	(void) strlcat(p_path, minor_nm, PATH_MAX);
3760Sstevel@tonic-gate 	di_devfs_path_free(devfspath);
3770Sstevel@tonic-gate 
3780Sstevel@tonic-gate 	devfsadm_print(debug_mid, "agp_process: path %s\n", p_path);
3790Sstevel@tonic-gate 
3800Sstevel@tonic-gate 	for (i = 0; ; i++) {
3810Sstevel@tonic-gate 		if ((driver_name_table[i].driver_name == NULL) ||
3820Sstevel@tonic-gate 		    (strcmp(drv_nm, driver_name_table[i].driver_name) == 0)) {
3830Sstevel@tonic-gate 			index = driver_name_table[i].index;
3840Sstevel@tonic-gate 			break;
3850Sstevel@tonic-gate 		}
3860Sstevel@tonic-gate 	}
3870Sstevel@tonic-gate 	switch (index) {
3880Sstevel@tonic-gate 	case DRIVER_AGPPSEUDO:
3890Sstevel@tonic-gate 		devfsadm_print(debug_mid,
3900Sstevel@tonic-gate 			    "agp_process: psdeudo driver name\n");
3910Sstevel@tonic-gate 		name = "agpgart";
3920Sstevel@tonic-gate 		(void) snprintf(I_path, PATH_MAX, "%s", name);
3930Sstevel@tonic-gate 		devfsadm_print(debug_mid,
3940Sstevel@tonic-gate 		    "mklink %s -> %s\n", I_path, p_path);
3950Sstevel@tonic-gate 
3960Sstevel@tonic-gate 		(void) devfsadm_mklink(I_path, node, minor, 0);
3970Sstevel@tonic-gate 
3980Sstevel@tonic-gate 		free(I_path);
3990Sstevel@tonic-gate 		free(p_path);
4000Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
4010Sstevel@tonic-gate 	case DRIVER_AGPTARGET:
4020Sstevel@tonic-gate 		devfsadm_print(debug_mid,
4030Sstevel@tonic-gate 			    "agp_process: target driver name\n");
4040Sstevel@tonic-gate 		rules[0] = agptarget_rules[0];
4050Sstevel@tonic-gate 		name = "agptarget";
4060Sstevel@tonic-gate 		break;
4070Sstevel@tonic-gate 	case DRIVER_CPUGART:
4080Sstevel@tonic-gate 		devfsadm_print(debug_mid,
4090Sstevel@tonic-gate 			    "agp_process: cpugart driver name\n");
4100Sstevel@tonic-gate 		rules[0] = cpugart_rules[0];
4110Sstevel@tonic-gate 		name = "cpugart";
4120Sstevel@tonic-gate 		break;
413*2820Skz151634 	case DRIVER_AGPMASTER_DRM:
414*2820Skz151634 	case DRIVER_AGPMASTER_VGATEXT:
4150Sstevel@tonic-gate 		devfsadm_print(debug_mid,
4160Sstevel@tonic-gate 			    "agp_process: agpmaster driver name\n");
4170Sstevel@tonic-gate 		rules[0] = agpmaster_rules[0];
4180Sstevel@tonic-gate 		name = "agpmaster";
4190Sstevel@tonic-gate 		break;
4200Sstevel@tonic-gate 	case DRIVER_UNKNOWN:
4210Sstevel@tonic-gate 		devfsadm_print(debug_mid,
4220Sstevel@tonic-gate 			    "agp_process: unknown driver name=%s\n", drv_nm);
4230Sstevel@tonic-gate 		free(I_path);
4240Sstevel@tonic-gate 		free(p_path);
4250Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
4260Sstevel@tonic-gate 	}
4270Sstevel@tonic-gate 
4280Sstevel@tonic-gate 	if (devfsadm_enumerate_int(p_path, 0, &buf, rules, 1)) {
4290Sstevel@tonic-gate 		devfsadm_print(debug_mid, "agp_process: exit/coninue\n");
4300Sstevel@tonic-gate 		free(I_path);
4310Sstevel@tonic-gate 		free(p_path);
4320Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
4330Sstevel@tonic-gate 	}
4340Sstevel@tonic-gate 
4350Sstevel@tonic-gate 
4360Sstevel@tonic-gate 	(void) snprintf(I_path, PATH_MAX, "agp/%s%s", name, buf);
4370Sstevel@tonic-gate 
4380Sstevel@tonic-gate 	devfsadm_print(debug_mid, "agp_process: p_path=%s buf=%s\n",
4390Sstevel@tonic-gate 		    p_path, buf);
4400Sstevel@tonic-gate 
4410Sstevel@tonic-gate 	free(buf);
4420Sstevel@tonic-gate 
4430Sstevel@tonic-gate 	devfsadm_print(debug_mid, "mklink %s -> %s\n", I_path, p_path);
4440Sstevel@tonic-gate 
4450Sstevel@tonic-gate 	(void) devfsadm_mklink(I_path, node, minor, 0);
4460Sstevel@tonic-gate 
4470Sstevel@tonic-gate 	free(p_path);
4480Sstevel@tonic-gate 	free(I_path);
4490Sstevel@tonic-gate 
4500Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
4510Sstevel@tonic-gate }
4521414Scindi 
453*2820Skz151634 static int
454*2820Skz151634 drm_node(di_minor_t minor, di_node_t node)
455*2820Skz151634 {
456*2820Skz151634 	char *minor_nm, *drv_nm;
457*2820Skz151634 	char *devfspath;
458*2820Skz151634 	char *I_path, *p_path, *buf;
459*2820Skz151634 	char *name = "card";
460*2820Skz151634 
461*2820Skz151634 	devfsadm_enumerate_t drm_rules[1] = {"^dri$/^card([0-9]+)$", 1,
462*2820Skz151634 		MATCH_ALL };
463*2820Skz151634 
464*2820Skz151634 
465*2820Skz151634 	minor_nm = di_minor_name(minor);
466*2820Skz151634 	drv_nm = di_driver_name(node);
467*2820Skz151634 	if ((minor_nm == NULL) || (drv_nm == NULL)) {
468*2820Skz151634 		return (DEVFSADM_CONTINUE);
469*2820Skz151634 	}
470*2820Skz151634 
471*2820Skz151634 	devfsadm_print(debug_mid, "drm_node: minor=%s node=%s type=%s\n",
472*2820Skz151634 	    minor_nm, di_node_name(node), di_minor_nodetype(minor));
473*2820Skz151634 
474*2820Skz151634 	devfspath = di_devfs_path(node);
475*2820Skz151634 	if (devfspath == NULL) {
476*2820Skz151634 		devfsadm_print(debug_mid, "drm_node: devfspath is NULL\n");
477*2820Skz151634 		return (DEVFSADM_CONTINUE);
478*2820Skz151634 	}
479*2820Skz151634 
480*2820Skz151634 	I_path = (char *)malloc(PATH_MAX);
481*2820Skz151634 
482*2820Skz151634 	if (I_path == NULL) {
483*2820Skz151634 		di_devfs_path_free(devfspath);
484*2820Skz151634 		devfsadm_print(debug_mid,  "drm_node: malloc failed\n");
485*2820Skz151634 		return (DEVFSADM_CONTINUE);
486*2820Skz151634 	}
487*2820Skz151634 
488*2820Skz151634 	p_path = (char *)malloc(PATH_MAX);
489*2820Skz151634 
490*2820Skz151634 	if (p_path == NULL) {
491*2820Skz151634 		devfsadm_print(debug_mid,  "drm_node: malloc failed\n");
492*2820Skz151634 		di_devfs_path_free(devfspath);
493*2820Skz151634 		free(I_path);
494*2820Skz151634 		return (DEVFSADM_CONTINUE);
495*2820Skz151634 	}
496*2820Skz151634 
497*2820Skz151634 	(void) strlcpy(p_path, devfspath, PATH_MAX);
498*2820Skz151634 	(void) strlcat(p_path, ":", PATH_MAX);
499*2820Skz151634 	(void) strlcat(p_path, minor_nm, PATH_MAX);
500*2820Skz151634 	di_devfs_path_free(devfspath);
501*2820Skz151634 
502*2820Skz151634 	devfsadm_print(debug_mid, "drm_node: p_path %s\n", p_path);
503*2820Skz151634 
504*2820Skz151634 	if (devfsadm_enumerate_int(p_path, 0, &buf, drm_rules, 1)) {
505*2820Skz151634 		free(p_path);
506*2820Skz151634 		devfsadm_print(debug_mid, "drm_node: exit/coninue\n");
507*2820Skz151634 		return (DEVFSADM_CONTINUE);
508*2820Skz151634 	}
509*2820Skz151634 	(void) snprintf(I_path, PATH_MAX, "dri/%s%s", name, buf);
510*2820Skz151634 
511*2820Skz151634 	devfsadm_print(debug_mid, "drm_node: p_path=%s buf=%s\n",
512*2820Skz151634 		    p_path, buf);
513*2820Skz151634 
514*2820Skz151634 	free(buf);
515*2820Skz151634 
516*2820Skz151634 	devfsadm_print(debug_mid, "mklink %s -> %s\n", I_path, p_path);
517*2820Skz151634 	(void) devfsadm_mklink(I_path, node, minor, 0);
518*2820Skz151634 
519*2820Skz151634 	free(p_path);
520*2820Skz151634 	free(I_path);
521*2820Skz151634 
522*2820Skz151634 	return (0);
523*2820Skz151634 }
524*2820Skz151634 
5251414Scindi /*
5261414Scindi  * /dev/mc/mc<chipid> -> /devices/.../pci1022,1102@<chipid+24>,2:mc-amd
5271414Scindi  */
5281414Scindi static int
5291414Scindi mc_node(di_minor_t minor, di_node_t node)
5301414Scindi {
5311414Scindi 	const char *minorname = di_minor_name(minor);
5321414Scindi 	const char *busaddr = di_bus_addr(node);
5331414Scindi 	char linkpath[PATH_MAX];
5341414Scindi 	int unitaddr;
5351414Scindi 	char *c;
5361414Scindi 
5371414Scindi 	if (minorname == NULL || busaddr == NULL)
5381414Scindi 		return (DEVFSADM_CONTINUE);
5391414Scindi 
5401414Scindi 	errno = 0;
5411414Scindi 	unitaddr = strtol(busaddr, &c, 16);
5421414Scindi 
5431414Scindi 	if (errno != 0 || unitaddr < MC_AMD_DEV_OFFSET)
5441414Scindi 		return (DEVFSADM_CONTINUE);
5451414Scindi 
5461414Scindi 	(void) snprintf(linkpath, sizeof (linkpath), "mc/mc%u",
5471414Scindi 	    unitaddr - MC_AMD_DEV_OFFSET);
5481414Scindi 	(void) devfsadm_mklink(linkpath, node, minor, 0);
5491414Scindi 	return (DEVFSADM_CONTINUE);
5501414Scindi }
551