xref: /onnv-gate/usr/src/cmd/devfsadm/i386/misc_link_i386.c (revision 9203:3ebffd0a1b10)
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 /*
22*9203SMark.Logan@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #include <regex.h>
270Sstevel@tonic-gate #include <devfsadm.h>
280Sstevel@tonic-gate #include <stdio.h>
290Sstevel@tonic-gate #include <strings.h>
300Sstevel@tonic-gate #include <stdlib.h>
310Sstevel@tonic-gate #include <limits.h>
320Sstevel@tonic-gate #include <ctype.h>
335254Sgavinm #include <sys/mc_amd.h>
341676Sjpk #include <bsm/devalloc.h>
351676Sjpk 
361676Sjpk extern int system_labeled;
370Sstevel@tonic-gate 
380Sstevel@tonic-gate static int lp(di_minor_t minor, di_node_t node);
390Sstevel@tonic-gate static int serial_dialout(di_minor_t minor, di_node_t node);
400Sstevel@tonic-gate static int serial(di_minor_t minor, di_node_t node);
410Sstevel@tonic-gate static int diskette(di_minor_t minor, di_node_t node);
420Sstevel@tonic-gate static int vt00(di_minor_t minor, di_node_t node);
430Sstevel@tonic-gate static int kdmouse(di_minor_t minor, di_node_t node);
440Sstevel@tonic-gate static int bmc(di_minor_t minor, di_node_t node);
45437Smws static int smbios(di_minor_t minor, di_node_t node);
460Sstevel@tonic-gate static int agp_process(di_minor_t minor, di_node_t node);
472820Skz151634 static int drm_node(di_minor_t minor, di_node_t node);
481414Scindi static int mc_node(di_minor_t minor, di_node_t node);
493446Smrj static int xsvc(di_minor_t minor, di_node_t node);
505295Srandyf static int srn(di_minor_t minor, di_node_t node);
514581Ssherrym static int ucode(di_minor_t minor, di_node_t node);
52*9203SMark.Logan@Sun.COM static int heci(di_minor_t minor, di_node_t node);
53*9203SMark.Logan@Sun.COM 
540Sstevel@tonic-gate 
550Sstevel@tonic-gate static devfsadm_create_t misc_cbt[] = {
560Sstevel@tonic-gate 	{ "vt00", "ddi_display", NULL,
570Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_0,	vt00
580Sstevel@tonic-gate 	},
592820Skz151634 	{ "drm", "ddi_display:drm", NULL,
602820Skz151634 	    TYPE_EXACT, ILEVEL_0,	drm_node
612820Skz151634 	},
620Sstevel@tonic-gate 	{ "mouse", "ddi_mouse", "mouse8042",
630Sstevel@tonic-gate 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, kdmouse
640Sstevel@tonic-gate 	},
650Sstevel@tonic-gate 	{ "pseudo", "ddi_pseudo", "bmc",
660Sstevel@tonic-gate 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, bmc,
670Sstevel@tonic-gate 	},
68437Smws 	{ "pseudo", "ddi_pseudo", "smbios",
69437Smws 	    TYPE_EXACT | DRV_EXACT, ILEVEL_1, smbios,
70437Smws 	},
710Sstevel@tonic-gate 	{ "disk",  "ddi_block:diskette", NULL,
720Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_1, diskette
730Sstevel@tonic-gate 	},
740Sstevel@tonic-gate 	{ "parallel",  "ddi_printer", NULL,
750Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_1, lp
760Sstevel@tonic-gate 	},
770Sstevel@tonic-gate 	{ "serial", "ddi_serial:mb", NULL,
780Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_1, serial
790Sstevel@tonic-gate 	},
800Sstevel@tonic-gate 	{ "serial",  "ddi_serial:dialout,mb", NULL,
810Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_1, serial_dialout
820Sstevel@tonic-gate 	},
831414Scindi 	{ "agp", "ddi_agp:pseudo", NULL,
840Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_0, agp_process
850Sstevel@tonic-gate 	},
861414Scindi 	{ "agp", "ddi_agp:target", NULL,
870Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_0, agp_process
880Sstevel@tonic-gate 	},
891414Scindi 	{ "agp", "ddi_agp:cpugart", NULL,
900Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_0, agp_process
910Sstevel@tonic-gate 	},
921414Scindi 	{ "agp", "ddi_agp:master", NULL,
930Sstevel@tonic-gate 	    TYPE_EXACT, ILEVEL_0, agp_process
941414Scindi 	},
953446Smrj 	{ "pseudo", "ddi_pseudo", NULL,
963446Smrj 	    TYPE_EXACT, ILEVEL_0, xsvc
973446Smrj 	},
985295Srandyf 	{ "pseudo", "ddi_pseudo", NULL,
995295Srandyf 	    TYPE_EXACT, ILEVEL_0, srn
1005295Srandyf 	},
1011414Scindi 	{ "memory-controller", "ddi_mem_ctrl", NULL,
1021414Scindi 	    TYPE_EXACT, ILEVEL_0, mc_node
1034581Ssherrym 	},
1044581Ssherrym 	{ "pseudo", "ddi_pseudo", "ucode",
1054581Ssherrym 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, ucode,
106*9203SMark.Logan@Sun.COM 	},
107*9203SMark.Logan@Sun.COM 	{ "pseudo", "ddi_pseudo", "heci",
108*9203SMark.Logan@Sun.COM 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, heci,
1090Sstevel@tonic-gate 	}
1100Sstevel@tonic-gate };
1110Sstevel@tonic-gate 
1120Sstevel@tonic-gate DEVFSADM_CREATE_INIT_V0(misc_cbt);
1130Sstevel@tonic-gate 
1142820Skz151634 static char *debug_mid = "misc_mid";
1150Sstevel@tonic-gate 
1160Sstevel@tonic-gate typedef enum {
1170Sstevel@tonic-gate 	DRIVER_AGPPSEUDO = 0,
1180Sstevel@tonic-gate 	DRIVER_AGPTARGET,
1190Sstevel@tonic-gate 	DRIVER_CPUGART,
1206393Scg149915 	DRIVER_AGPMASTER_DRM_I915,
1216393Scg149915 	DRIVER_AGPMASTER_DRM_RADEON,
1222820Skz151634 	DRIVER_AGPMASTER_VGATEXT,
1230Sstevel@tonic-gate 	DRIVER_UNKNOWN
1240Sstevel@tonic-gate } driver_defs_t;
1250Sstevel@tonic-gate 
1260Sstevel@tonic-gate typedef struct {
1270Sstevel@tonic-gate 	char	*driver_name;
1280Sstevel@tonic-gate 	int	index;
1290Sstevel@tonic-gate } driver_name_table_entry_t;
1300Sstevel@tonic-gate 
1310Sstevel@tonic-gate static driver_name_table_entry_t driver_name_table[] = {
1320Sstevel@tonic-gate 	{ "agpgart",		DRIVER_AGPPSEUDO },
1330Sstevel@tonic-gate 	{ "agptarget",		DRIVER_AGPTARGET },
1340Sstevel@tonic-gate 	{ "amd64_gart",		DRIVER_CPUGART },
1352820Skz151634 	/* AGP master device managed by drm driver */
1366393Scg149915 	{ "i915",		DRIVER_AGPMASTER_DRM_I915 },
1376393Scg149915 	{ "radeon",		DRIVER_AGPMASTER_DRM_RADEON },
1382820Skz151634 	{ "vgatext",		DRIVER_AGPMASTER_VGATEXT },
1390Sstevel@tonic-gate 	{ NULL,			DRIVER_UNKNOWN }
1400Sstevel@tonic-gate };
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate static devfsadm_enumerate_t agptarget_rules[1] =
1430Sstevel@tonic-gate 	{ "^agp$/^agptarget([0-9]+)$", 1, MATCH_ALL };
1440Sstevel@tonic-gate static devfsadm_enumerate_t cpugart_rules[1] =
1450Sstevel@tonic-gate 	{ "^agp$/^cpugart([0-9]+)$", 1, MATCH_ALL };
1460Sstevel@tonic-gate static devfsadm_enumerate_t agpmaster_rules[1] =
1470Sstevel@tonic-gate 	{  "^agp$/^agpmaster([0-9]+)$", 1, MATCH_ALL };
1480Sstevel@tonic-gate 
1490Sstevel@tonic-gate static devfsadm_remove_t misc_remove_cbt[] = {
1500Sstevel@tonic-gate 	{ "vt", "vt[0-9][0-9]", RM_PRE|RM_ALWAYS,
1510Sstevel@tonic-gate 		ILEVEL_0, devfsadm_rm_all
1524581Ssherrym 	},
1534581Ssherrym 	{ "pseudo", "^ucode$", RM_ALWAYS | RM_PRE | RM_HOT,
1544581Ssherrym 		ILEVEL_0, devfsadm_rm_all
1550Sstevel@tonic-gate 	}
1560Sstevel@tonic-gate };
1570Sstevel@tonic-gate 
1580Sstevel@tonic-gate DEVFSADM_REMOVE_INIT_V0(misc_remove_cbt);
1590Sstevel@tonic-gate 
1600Sstevel@tonic-gate /*
1610Sstevel@tonic-gate  * Handles minor node type "ddi_display", in addition to generic processing
1620Sstevel@tonic-gate  * done by display().
1630Sstevel@tonic-gate  *
1640Sstevel@tonic-gate  * This creates a /dev/vt00 link to /dev/fb, for backwards compatibility.
1650Sstevel@tonic-gate  */
1660Sstevel@tonic-gate /* ARGSUSED */
1670Sstevel@tonic-gate int
1680Sstevel@tonic-gate vt00(di_minor_t minor, di_node_t node)
1690Sstevel@tonic-gate {
1700Sstevel@tonic-gate 	(void) devfsadm_secondary_link("vt00", "fb", 0);
1710Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
1720Sstevel@tonic-gate }
1730Sstevel@tonic-gate 
1740Sstevel@tonic-gate /*
1750Sstevel@tonic-gate  * type=ddi_block:diskette;addr=0,0;minor=c        diskette
1760Sstevel@tonic-gate  * type=ddi_block:diskette;addr=0,0;minor=c,raw    rdiskette
1770Sstevel@tonic-gate  * type=ddi_block:diskette;addr1=0;minor=c diskette\A2
1780Sstevel@tonic-gate  * type=ddi_block:diskette;addr1=0;minor=c,raw     rdiskette\A2
1790Sstevel@tonic-gate  */
1800Sstevel@tonic-gate static int
1810Sstevel@tonic-gate diskette(di_minor_t minor, di_node_t node)
1820Sstevel@tonic-gate {
1831676Sjpk 	int flags = 0;
1840Sstevel@tonic-gate 	char *a2;
1850Sstevel@tonic-gate 	char link[PATH_MAX];
1860Sstevel@tonic-gate 	char *addr = di_bus_addr(node);
1870Sstevel@tonic-gate 	char *mn = di_minor_name(minor);
1880Sstevel@tonic-gate 
1891676Sjpk 	if (system_labeled)
1901676Sjpk 		flags = DA_ADD|DA_FLOPPY;
1911676Sjpk 
1920Sstevel@tonic-gate 	if (strcmp(addr, "0,0") == 0) {
1930Sstevel@tonic-gate 		if (strcmp(mn, "c") == 0) {
1941676Sjpk 			(void) devfsadm_mklink("diskette", node, minor, flags);
1950Sstevel@tonic-gate 		} else if (strcmp(mn, "c,raw") == 0) {
1961676Sjpk 			(void) devfsadm_mklink("rdiskette", node, minor, flags);
1970Sstevel@tonic-gate 		}
1980Sstevel@tonic-gate 
1990Sstevel@tonic-gate 	}
2000Sstevel@tonic-gate 
2010Sstevel@tonic-gate 	if (addr[0] == '0') {
2020Sstevel@tonic-gate 		if ((a2 = strchr(addr, ',')) != NULL) {
2030Sstevel@tonic-gate 			a2++;
2040Sstevel@tonic-gate 			if (strcmp(mn, "c") == 0) {
2050Sstevel@tonic-gate 				(void) strcpy(link, "diskette");
2060Sstevel@tonic-gate 				(void) strcat(link, a2);
2071676Sjpk 				(void) devfsadm_mklink(link, node, minor,
2081676Sjpk 				    flags);
2090Sstevel@tonic-gate 			} else if (strcmp(mn, "c,raw") == 0) {
2100Sstevel@tonic-gate 				(void) strcpy(link, "rdiskette");
2110Sstevel@tonic-gate 				(void) strcat(link, a2);
2121676Sjpk 				(void) devfsadm_mklink(link, node, minor,
2131676Sjpk 				    flags);
2140Sstevel@tonic-gate 			}
2150Sstevel@tonic-gate 		}
2160Sstevel@tonic-gate 	}
2170Sstevel@tonic-gate 
2180Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
2190Sstevel@tonic-gate }
2200Sstevel@tonic-gate 
2210Sstevel@tonic-gate /*
2220Sstevel@tonic-gate  * type=ddi_printer;name=lp;addr=1,3bc      lp0
2230Sstevel@tonic-gate  * type=ddi_printer;name=lp;addr=1,378      lp1
2240Sstevel@tonic-gate  * type=ddi_printer;name=lp;addr=1,278      lp2
2250Sstevel@tonic-gate  */
2260Sstevel@tonic-gate static int
2270Sstevel@tonic-gate lp(di_minor_t minor, di_node_t node)
2280Sstevel@tonic-gate {
2290Sstevel@tonic-gate 	char *addr = di_bus_addr(node);
2300Sstevel@tonic-gate 	char *buf;
2310Sstevel@tonic-gate 	char path[PATH_MAX + 1];
2320Sstevel@tonic-gate 	devfsadm_enumerate_t rules[1] = {"^ecpp([0-9]+)$", 1, MATCH_ALL};
2330Sstevel@tonic-gate 
2340Sstevel@tonic-gate 	if (strcmp(addr, "1,3bc") == 0) {
2350Sstevel@tonic-gate 		(void) devfsadm_mklink("lp0", node, minor, 0);
2360Sstevel@tonic-gate 
2370Sstevel@tonic-gate 	} else if (strcmp(addr, "1,378") == 0) {
2380Sstevel@tonic-gate 		(void) devfsadm_mklink("lp1", node, minor, 0);
2390Sstevel@tonic-gate 
2400Sstevel@tonic-gate 	} else if (strcmp(addr, "1,278") == 0) {
2410Sstevel@tonic-gate 		(void) devfsadm_mklink("lp2", node, minor, 0);
2420Sstevel@tonic-gate 	}
2430Sstevel@tonic-gate 
2440Sstevel@tonic-gate 	if (strcmp(di_driver_name(node), "ecpp") != 0) {
2450Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
2460Sstevel@tonic-gate 	}
2470Sstevel@tonic-gate 
2480Sstevel@tonic-gate 	if ((buf = di_devfs_path(node)) == NULL) {
2490Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
2500Sstevel@tonic-gate 	}
2510Sstevel@tonic-gate 
2520Sstevel@tonic-gate 	(void) snprintf(path, sizeof (path), "%s:%s",
2530Sstevel@tonic-gate 	    buf, di_minor_name(minor));
2540Sstevel@tonic-gate 
2550Sstevel@tonic-gate 	di_devfs_path_free(buf);
2560Sstevel@tonic-gate 
2570Sstevel@tonic-gate 	if (devfsadm_enumerate_int(path, 0, &buf, rules, 1)) {
2580Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
2590Sstevel@tonic-gate 	}
2600Sstevel@tonic-gate 
2610Sstevel@tonic-gate 	(void) snprintf(path, sizeof (path), "ecpp%s", buf);
2620Sstevel@tonic-gate 	free(buf);
2630Sstevel@tonic-gate 	(void) devfsadm_mklink(path, node, minor, 0);
2640Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
2650Sstevel@tonic-gate }
2660Sstevel@tonic-gate 
2670Sstevel@tonic-gate /*
2680Sstevel@tonic-gate  * type=ddi_serial:mb;minor=a      tty00
2690Sstevel@tonic-gate  * type=ddi_serial:mb;minor=b      tty01
2700Sstevel@tonic-gate  * type=ddi_serial:mb;minor=c      tty02
2710Sstevel@tonic-gate  * type=ddi_serial:mb;minor=d      tty03
2720Sstevel@tonic-gate  */
2730Sstevel@tonic-gate static int
2740Sstevel@tonic-gate serial(di_minor_t minor, di_node_t node)
2750Sstevel@tonic-gate {
2760Sstevel@tonic-gate 
2770Sstevel@tonic-gate 	char *mn = di_minor_name(minor);
2780Sstevel@tonic-gate 	char link[PATH_MAX];
2790Sstevel@tonic-gate 
2800Sstevel@tonic-gate 	(void) strcpy(link, "tty");
2810Sstevel@tonic-gate 	(void) strcat(link, mn);
2820Sstevel@tonic-gate 	(void) devfsadm_mklink(link, node, minor, 0);
2830Sstevel@tonic-gate 
2840Sstevel@tonic-gate 	if (strcmp(mn, "a") == 0) {
2850Sstevel@tonic-gate 		(void) devfsadm_mklink("tty00", node, minor, 0);
2860Sstevel@tonic-gate 
2870Sstevel@tonic-gate 	} else if (strcmp(mn, "b") == 0) {
2880Sstevel@tonic-gate 		(void) devfsadm_mklink("tty01", node, minor, 0);
2890Sstevel@tonic-gate 
2900Sstevel@tonic-gate 	} else if (strcmp(mn, "c") == 0) {
2910Sstevel@tonic-gate 		(void) devfsadm_mklink("tty02", node, minor, 0);
2920Sstevel@tonic-gate 
2930Sstevel@tonic-gate 	} else if (strcmp(mn, "d") == 0) {
2940Sstevel@tonic-gate 		(void) devfsadm_mklink("tty03", node, minor, 0);
2950Sstevel@tonic-gate 	}
2960Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
2970Sstevel@tonic-gate }
2980Sstevel@tonic-gate 
2990Sstevel@tonic-gate /*
3000Sstevel@tonic-gate  * type=ddi_serial:dialout,mb;minor=a,cu   ttyd0
3010Sstevel@tonic-gate  * type=ddi_serial:dialout,mb;minor=b,cu   ttyd1
3020Sstevel@tonic-gate  * type=ddi_serial:dialout,mb;minor=c,cu   ttyd2
3030Sstevel@tonic-gate  * type=ddi_serial:dialout,mb;minor=d,cu   ttyd3
3040Sstevel@tonic-gate  */
3050Sstevel@tonic-gate static int
3060Sstevel@tonic-gate serial_dialout(di_minor_t minor, di_node_t node)
3070Sstevel@tonic-gate {
3080Sstevel@tonic-gate 	char *mn = di_minor_name(minor);
3090Sstevel@tonic-gate 
3100Sstevel@tonic-gate 	if (strcmp(mn, "a,cu") == 0) {
3110Sstevel@tonic-gate 		(void) devfsadm_mklink("ttyd0", node, minor, 0);
3120Sstevel@tonic-gate 		(void) devfsadm_mklink("cua0", node, minor, 0);
3130Sstevel@tonic-gate 
3140Sstevel@tonic-gate 	} else if (strcmp(mn, "b,cu") == 0) {
3150Sstevel@tonic-gate 		(void) devfsadm_mklink("ttyd1", node, minor, 0);
3160Sstevel@tonic-gate 		(void) devfsadm_mklink("cua1", node, minor, 0);
3170Sstevel@tonic-gate 
3180Sstevel@tonic-gate 	} else if (strcmp(mn, "c,cu") == 0) {
3190Sstevel@tonic-gate 		(void) devfsadm_mklink("ttyd2", node, minor, 0);
3200Sstevel@tonic-gate 		(void) devfsadm_mklink("cua2", node, minor, 0);
3210Sstevel@tonic-gate 
3220Sstevel@tonic-gate 	} else if (strcmp(mn, "d,cu") == 0) {
3230Sstevel@tonic-gate 		(void) devfsadm_mklink("ttyd3", node, minor, 0);
3240Sstevel@tonic-gate 		(void) devfsadm_mklink("cua3", node, minor, 0);
3250Sstevel@tonic-gate 	}
3260Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
3270Sstevel@tonic-gate }
3280Sstevel@tonic-gate 
3290Sstevel@tonic-gate static int
3300Sstevel@tonic-gate kdmouse(di_minor_t minor, di_node_t node)
3310Sstevel@tonic-gate {
3320Sstevel@tonic-gate 	(void) devfsadm_mklink("kdmouse", node, minor, 0);
3330Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
3340Sstevel@tonic-gate }
3350Sstevel@tonic-gate 
3360Sstevel@tonic-gate static int
3370Sstevel@tonic-gate bmc(di_minor_t minor, di_node_t node)
3380Sstevel@tonic-gate {
3390Sstevel@tonic-gate 	(void) devfsadm_mklink("bmc", node, minor, 0);
3400Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
3410Sstevel@tonic-gate }
342437Smws 
343437Smws static int
344437Smws smbios(di_minor_t minor, di_node_t node)
345437Smws {
346437Smws 	(void) devfsadm_mklink("smbios", node, minor, 0);
347437Smws 	return (DEVFSADM_CONTINUE);
348437Smws }
349437Smws 
3500Sstevel@tonic-gate static int
3510Sstevel@tonic-gate agp_process(di_minor_t minor, di_node_t node)
3520Sstevel@tonic-gate {
3530Sstevel@tonic-gate 	char *minor_nm, *drv_nm;
3540Sstevel@tonic-gate 	char *devfspath;
3550Sstevel@tonic-gate 	char *I_path, *p_path, *buf;
3560Sstevel@tonic-gate 	char *name = (char *)NULL;
3570Sstevel@tonic-gate 	int i, index;
3580Sstevel@tonic-gate 	devfsadm_enumerate_t rules[1];
3590Sstevel@tonic-gate 
3600Sstevel@tonic-gate 	minor_nm = di_minor_name(minor);
3610Sstevel@tonic-gate 	drv_nm = di_driver_name(node);
3620Sstevel@tonic-gate 
3630Sstevel@tonic-gate 	if ((minor_nm == NULL) || (drv_nm == NULL)) {
3640Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
3650Sstevel@tonic-gate 	}
3660Sstevel@tonic-gate 
3670Sstevel@tonic-gate 	devfsadm_print(debug_mid, "agp_process: minor=%s node=%s\n",
3684581Ssherrym 	    minor_nm, di_node_name(node));
3690Sstevel@tonic-gate 
3700Sstevel@tonic-gate 	devfspath = di_devfs_path(node);
3710Sstevel@tonic-gate 	if (devfspath == NULL) {
3720Sstevel@tonic-gate 		devfsadm_print(debug_mid, "agp_process: devfspath is NULL\n");
3730Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
3740Sstevel@tonic-gate 	}
3750Sstevel@tonic-gate 
3760Sstevel@tonic-gate 	I_path = (char *)malloc(PATH_MAX);
3770Sstevel@tonic-gate 
3780Sstevel@tonic-gate 	if (I_path == NULL) {
3790Sstevel@tonic-gate 		di_devfs_path_free(devfspath);
3800Sstevel@tonic-gate 		devfsadm_print(debug_mid,  "agp_process: malloc failed\n");
3810Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
3820Sstevel@tonic-gate 	}
3830Sstevel@tonic-gate 
3840Sstevel@tonic-gate 	p_path = (char *)malloc(PATH_MAX);
3850Sstevel@tonic-gate 
3860Sstevel@tonic-gate 	if (p_path == NULL) {
3870Sstevel@tonic-gate 		devfsadm_print(debug_mid,  "agp_process: malloc failed\n");
3880Sstevel@tonic-gate 		di_devfs_path_free(devfspath);
3890Sstevel@tonic-gate 		free(I_path);
3900Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
3910Sstevel@tonic-gate 	}
3920Sstevel@tonic-gate 
3930Sstevel@tonic-gate 	(void) strlcpy(p_path, devfspath, PATH_MAX);
3940Sstevel@tonic-gate 	(void) strlcat(p_path, ":", PATH_MAX);
3950Sstevel@tonic-gate 	(void) strlcat(p_path, minor_nm, PATH_MAX);
3960Sstevel@tonic-gate 	di_devfs_path_free(devfspath);
3970Sstevel@tonic-gate 
3980Sstevel@tonic-gate 	devfsadm_print(debug_mid, "agp_process: path %s\n", p_path);
3990Sstevel@tonic-gate 
4000Sstevel@tonic-gate 	for (i = 0; ; i++) {
4010Sstevel@tonic-gate 		if ((driver_name_table[i].driver_name == NULL) ||
4020Sstevel@tonic-gate 		    (strcmp(drv_nm, driver_name_table[i].driver_name) == 0)) {
4030Sstevel@tonic-gate 			index = driver_name_table[i].index;
4040Sstevel@tonic-gate 			break;
4050Sstevel@tonic-gate 		}
4060Sstevel@tonic-gate 	}
4070Sstevel@tonic-gate 	switch (index) {
4080Sstevel@tonic-gate 	case DRIVER_AGPPSEUDO:
4090Sstevel@tonic-gate 		devfsadm_print(debug_mid,
4104581Ssherrym 		    "agp_process: psdeudo driver name\n");
4110Sstevel@tonic-gate 		name = "agpgart";
4120Sstevel@tonic-gate 		(void) snprintf(I_path, PATH_MAX, "%s", name);
4130Sstevel@tonic-gate 		devfsadm_print(debug_mid,
4140Sstevel@tonic-gate 		    "mklink %s -> %s\n", I_path, p_path);
4150Sstevel@tonic-gate 
4160Sstevel@tonic-gate 		(void) devfsadm_mklink(I_path, node, minor, 0);
4170Sstevel@tonic-gate 
4180Sstevel@tonic-gate 		free(I_path);
4190Sstevel@tonic-gate 		free(p_path);
4200Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
4210Sstevel@tonic-gate 	case DRIVER_AGPTARGET:
4220Sstevel@tonic-gate 		devfsadm_print(debug_mid,
4234581Ssherrym 		    "agp_process: target driver name\n");
4240Sstevel@tonic-gate 		rules[0] = agptarget_rules[0];
4250Sstevel@tonic-gate 		name = "agptarget";
4260Sstevel@tonic-gate 		break;
4270Sstevel@tonic-gate 	case DRIVER_CPUGART:
4280Sstevel@tonic-gate 		devfsadm_print(debug_mid,
4294581Ssherrym 		    "agp_process: cpugart driver name\n");
4300Sstevel@tonic-gate 		rules[0] = cpugart_rules[0];
4310Sstevel@tonic-gate 		name = "cpugart";
4320Sstevel@tonic-gate 		break;
4336393Scg149915 	case DRIVER_AGPMASTER_DRM_I915:
4346393Scg149915 	case DRIVER_AGPMASTER_DRM_RADEON:
4352820Skz151634 	case DRIVER_AGPMASTER_VGATEXT:
4360Sstevel@tonic-gate 		devfsadm_print(debug_mid,
4374581Ssherrym 		    "agp_process: agpmaster driver name\n");
4380Sstevel@tonic-gate 		rules[0] = agpmaster_rules[0];
4390Sstevel@tonic-gate 		name = "agpmaster";
4400Sstevel@tonic-gate 		break;
4410Sstevel@tonic-gate 	case DRIVER_UNKNOWN:
4420Sstevel@tonic-gate 		devfsadm_print(debug_mid,
4434581Ssherrym 		    "agp_process: unknown driver name=%s\n", drv_nm);
4440Sstevel@tonic-gate 		free(I_path);
4450Sstevel@tonic-gate 		free(p_path);
4460Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
4470Sstevel@tonic-gate 	}
4480Sstevel@tonic-gate 
4490Sstevel@tonic-gate 	if (devfsadm_enumerate_int(p_path, 0, &buf, rules, 1)) {
4500Sstevel@tonic-gate 		devfsadm_print(debug_mid, "agp_process: exit/coninue\n");
4510Sstevel@tonic-gate 		free(I_path);
4520Sstevel@tonic-gate 		free(p_path);
4530Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
4540Sstevel@tonic-gate 	}
4550Sstevel@tonic-gate 
4560Sstevel@tonic-gate 
4570Sstevel@tonic-gate 	(void) snprintf(I_path, PATH_MAX, "agp/%s%s", name, buf);
4580Sstevel@tonic-gate 
4590Sstevel@tonic-gate 	devfsadm_print(debug_mid, "agp_process: p_path=%s buf=%s\n",
4604581Ssherrym 	    p_path, buf);
4610Sstevel@tonic-gate 
4620Sstevel@tonic-gate 	free(buf);
4630Sstevel@tonic-gate 
4640Sstevel@tonic-gate 	devfsadm_print(debug_mid, "mklink %s -> %s\n", I_path, p_path);
4650Sstevel@tonic-gate 
4660Sstevel@tonic-gate 	(void) devfsadm_mklink(I_path, node, minor, 0);
4670Sstevel@tonic-gate 
4680Sstevel@tonic-gate 	free(p_path);
4690Sstevel@tonic-gate 	free(I_path);
4700Sstevel@tonic-gate 
4710Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
4720Sstevel@tonic-gate }
4731414Scindi 
4742820Skz151634 static int
4752820Skz151634 drm_node(di_minor_t minor, di_node_t node)
4762820Skz151634 {
4772820Skz151634 	char *minor_nm, *drv_nm;
4782820Skz151634 	char *devfspath;
4792820Skz151634 	char *I_path, *p_path, *buf;
4802820Skz151634 	char *name = "card";
4812820Skz151634 
4822820Skz151634 	devfsadm_enumerate_t drm_rules[1] = {"^dri$/^card([0-9]+)$", 1,
4832820Skz151634 		MATCH_ALL };
4842820Skz151634 
4852820Skz151634 
4862820Skz151634 	minor_nm = di_minor_name(minor);
4872820Skz151634 	drv_nm = di_driver_name(node);
4882820Skz151634 	if ((minor_nm == NULL) || (drv_nm == NULL)) {
4892820Skz151634 		return (DEVFSADM_CONTINUE);
4902820Skz151634 	}
4912820Skz151634 
4922820Skz151634 	devfsadm_print(debug_mid, "drm_node: minor=%s node=%s type=%s\n",
4932820Skz151634 	    minor_nm, di_node_name(node), di_minor_nodetype(minor));
4942820Skz151634 
4952820Skz151634 	devfspath = di_devfs_path(node);
4962820Skz151634 	if (devfspath == NULL) {
4972820Skz151634 		devfsadm_print(debug_mid, "drm_node: devfspath is NULL\n");
4982820Skz151634 		return (DEVFSADM_CONTINUE);
4992820Skz151634 	}
5002820Skz151634 
5012820Skz151634 	I_path = (char *)malloc(PATH_MAX);
5022820Skz151634 
5032820Skz151634 	if (I_path == NULL) {
5042820Skz151634 		di_devfs_path_free(devfspath);
5052820Skz151634 		devfsadm_print(debug_mid,  "drm_node: malloc failed\n");
5062820Skz151634 		return (DEVFSADM_CONTINUE);
5072820Skz151634 	}
5082820Skz151634 
5092820Skz151634 	p_path = (char *)malloc(PATH_MAX);
5102820Skz151634 
5112820Skz151634 	if (p_path == NULL) {
5122820Skz151634 		devfsadm_print(debug_mid,  "drm_node: malloc failed\n");
5132820Skz151634 		di_devfs_path_free(devfspath);
5142820Skz151634 		free(I_path);
5152820Skz151634 		return (DEVFSADM_CONTINUE);
5162820Skz151634 	}
5172820Skz151634 
5182820Skz151634 	(void) strlcpy(p_path, devfspath, PATH_MAX);
5192820Skz151634 	(void) strlcat(p_path, ":", PATH_MAX);
5202820Skz151634 	(void) strlcat(p_path, minor_nm, PATH_MAX);
5212820Skz151634 	di_devfs_path_free(devfspath);
5222820Skz151634 
5232820Skz151634 	devfsadm_print(debug_mid, "drm_node: p_path %s\n", p_path);
5242820Skz151634 
5252820Skz151634 	if (devfsadm_enumerate_int(p_path, 0, &buf, drm_rules, 1)) {
5262820Skz151634 		free(p_path);
5272820Skz151634 		devfsadm_print(debug_mid, "drm_node: exit/coninue\n");
5282820Skz151634 		return (DEVFSADM_CONTINUE);
5292820Skz151634 	}
5302820Skz151634 	(void) snprintf(I_path, PATH_MAX, "dri/%s%s", name, buf);
5312820Skz151634 
5322820Skz151634 	devfsadm_print(debug_mid, "drm_node: p_path=%s buf=%s\n",
5334581Ssherrym 	    p_path, buf);
5342820Skz151634 
5352820Skz151634 	free(buf);
5362820Skz151634 
5372820Skz151634 	devfsadm_print(debug_mid, "mklink %s -> %s\n", I_path, p_path);
5382820Skz151634 	(void) devfsadm_mklink(I_path, node, minor, 0);
5392820Skz151634 
5402820Skz151634 	free(p_path);
5412820Skz151634 	free(I_path);
5422820Skz151634 
5432820Skz151634 	return (0);
5442820Skz151634 }
5452820Skz151634 
5461414Scindi /*
5471414Scindi  * /dev/mc/mc<chipid> -> /devices/.../pci1022,1102@<chipid+24>,2:mc-amd
5481414Scindi  */
5491414Scindi static int
5501414Scindi mc_node(di_minor_t minor, di_node_t node)
5511414Scindi {
5521414Scindi 	const char *minorname = di_minor_name(minor);
5531414Scindi 	const char *busaddr = di_bus_addr(node);
5541414Scindi 	char linkpath[PATH_MAX];
5551414Scindi 	int unitaddr;
5561414Scindi 	char *c;
5571414Scindi 
5581414Scindi 	if (minorname == NULL || busaddr == NULL)
5591414Scindi 		return (DEVFSADM_CONTINUE);
5601414Scindi 
5611414Scindi 	errno = 0;
5621414Scindi 	unitaddr = strtol(busaddr, &c, 16);
5631414Scindi 
5645254Sgavinm 	if (errno != 0)
5651414Scindi 		return (DEVFSADM_CONTINUE);
5661414Scindi 
5675254Sgavinm 	if (unitaddr == 0) {
5685254Sgavinm 		(void) snprintf(linkpath, sizeof (linkpath), "mc/mc");
5695254Sgavinm 	} else if (unitaddr >= MC_AMD_DEV_OFFSET) {
5705254Sgavinm 		(void) snprintf(linkpath, sizeof (linkpath), "mc/mc%u",
5715254Sgavinm 		    unitaddr - MC_AMD_DEV_OFFSET);
5725254Sgavinm 	} else {
5737349SAdrian.Frost@Sun.COM 		(void) snprintf(linkpath, sizeof (linkpath), "mc/mc%u",
5747349SAdrian.Frost@Sun.COM 		    minor->dev_minor);
5755254Sgavinm 	}
5761414Scindi 	(void) devfsadm_mklink(linkpath, node, minor, 0);
5771414Scindi 	return (DEVFSADM_CONTINUE);
5781414Scindi }
5793446Smrj 
5803446Smrj /*
5813446Smrj  * Creates \M0 devlink for xsvc node
5823446Smrj  */
5833446Smrj static int
5843446Smrj xsvc(di_minor_t minor, di_node_t node)
5853446Smrj {
5863446Smrj 	char *mn;
5873446Smrj 
5883446Smrj 	if (strcmp(di_node_name(node), "xsvc") != 0)
5893446Smrj 		return (DEVFSADM_CONTINUE);
5903446Smrj 
5913446Smrj 	mn = di_minor_name(minor);
5923446Smrj 	if (mn == NULL)
5933446Smrj 		return (DEVFSADM_CONTINUE);
5943446Smrj 
5953446Smrj 	(void) devfsadm_mklink(mn, node, minor, 0);
5963446Smrj 	return (DEVFSADM_CONTINUE);
5973446Smrj }
5984581Ssherrym 
5994581Ssherrym /*
6005295Srandyf  * Creates \M0 devlink for srn device
6015295Srandyf  */
6025295Srandyf static int
6035295Srandyf srn(di_minor_t minor, di_node_t node)
6045295Srandyf {
6055295Srandyf 	char *mn;
6065295Srandyf 
6075295Srandyf 	if (strcmp(di_node_name(node), "srn") != 0)
6085295Srandyf 		return (DEVFSADM_CONTINUE);
6095295Srandyf 
6105295Srandyf 	mn = di_minor_name(minor);
6115295Srandyf 	if (mn == NULL)
6125295Srandyf 		return (DEVFSADM_CONTINUE);
6135295Srandyf 
6145295Srandyf 	(void) devfsadm_mklink(mn, node, minor, 0);
6155295Srandyf 	return (DEVFSADM_CONTINUE);
6165295Srandyf }
6175295Srandyf 
6185295Srandyf /*
6194581Ssherrym  *	/dev/ucode	->	/devices/pseudo/ucode@0:ucode
6204581Ssherrym  */
6214581Ssherrym static int
6224581Ssherrym ucode(di_minor_t minor, di_node_t node)
6234581Ssherrym {
6244581Ssherrym 	(void) devfsadm_mklink("ucode", node, minor, 0);
6254581Ssherrym 	return (DEVFSADM_CONTINUE);
6264581Ssherrym }
627*9203SMark.Logan@Sun.COM 
628*9203SMark.Logan@Sun.COM static int
629*9203SMark.Logan@Sun.COM heci(di_minor_t minor, di_node_t node)
630*9203SMark.Logan@Sun.COM {
631*9203SMark.Logan@Sun.COM 	if (strcmp(di_minor_name(minor), "AMT") == 0) {
632*9203SMark.Logan@Sun.COM 		(void) devfsadm_mklink("heci", node, minor, 0);
633*9203SMark.Logan@Sun.COM 	}
634*9203SMark.Logan@Sun.COM 	return (DEVFSADM_CONTINUE);
635*9203SMark.Logan@Sun.COM }
636