dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / devfsadm / i386 / misc_link_i386.c
blob9742fe54dd9b673414384ba9ece1816693854747
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 * Copyright 2012 Joyent, Inc. All rights reserved.
27 #include <regex.h>
28 #include <devfsadm.h>
29 #include <stdio.h>
30 #include <strings.h>
31 #include <stdlib.h>
32 #include <limits.h>
33 #include <ctype.h>
34 #include <sys/mc_amd.h>
35 #include <bsm/devalloc.h>
37 static int lp(di_minor_t minor, di_node_t node);
38 static int serial_dialout(di_minor_t minor, di_node_t node);
39 static int serial(di_minor_t minor, di_node_t node);
40 static int diskette(di_minor_t minor, di_node_t node);
41 static int vt00(di_minor_t minor, di_node_t node);
42 static int kdmouse(di_minor_t minor, di_node_t node);
43 static int ipmi(di_minor_t minor, di_node_t node);
44 static int smbios(di_minor_t minor, di_node_t node);
45 static int mc_node(di_minor_t minor, di_node_t node);
46 static int xsvc(di_minor_t minor, di_node_t node);
47 static int srn(di_minor_t minor, di_node_t node);
48 static int ucode(di_minor_t minor, di_node_t node);
51 static devfsadm_create_t misc_cbt[] = {
52 { "vt00", "ddi_display", NULL,
53 TYPE_EXACT, ILEVEL_0, vt00
55 { "mouse", "ddi_mouse", "mouse8042",
56 TYPE_EXACT | DRV_EXACT, ILEVEL_0, kdmouse
58 { "pseudo", "ddi_pseudo", "ipmi",
59 TYPE_EXACT | DRV_EXACT, ILEVEL_0, ipmi,
61 { "pseudo", "ddi_pseudo", "smbios",
62 TYPE_EXACT | DRV_EXACT, ILEVEL_1, smbios,
64 /* floppies share the same class, but not link regex, as hard disks */
65 { "disk", "ddi_block:diskette", NULL,
66 TYPE_EXACT, ILEVEL_1, diskette
68 { "parallel", "ddi_printer", NULL,
69 TYPE_EXACT, ILEVEL_1, lp
71 { "serial", "ddi_serial:mb", NULL,
72 TYPE_EXACT, ILEVEL_1, serial
74 { "serial", "ddi_serial:dialout,mb", NULL,
75 TYPE_EXACT, ILEVEL_1, serial_dialout
77 { "pseudo", "ddi_pseudo", NULL,
78 TYPE_EXACT, ILEVEL_0, xsvc
80 { "pseudo", "ddi_pseudo", NULL,
81 TYPE_EXACT, ILEVEL_0, srn
83 { "memory-controller", "ddi_mem_ctrl", NULL,
84 TYPE_EXACT, ILEVEL_0, mc_node
86 { "pseudo", "ddi_pseudo", "ucode",
87 TYPE_EXACT | DRV_EXACT, ILEVEL_0, ucode,
91 DEVFSADM_CREATE_INIT_V0(misc_cbt);
93 static devfsadm_remove_t misc_remove_cbt[] = {
94 { "vt", "vt[0-9][0-9]", RM_PRE|RM_ALWAYS,
95 ILEVEL_0, devfsadm_rm_all
97 { "pseudo", "^ucode$", RM_ALWAYS | RM_PRE | RM_HOT,
98 ILEVEL_0, devfsadm_rm_all
100 { "mouse", "^kdmouse$", RM_ALWAYS | RM_PRE,
101 ILEVEL_0, devfsadm_rm_all
103 { "disk", "^(diskette|rdiskette)([0-9]*)$",
104 RM_ALWAYS | RM_PRE, ILEVEL_1, devfsadm_rm_all
106 { "parallel", "^(lp|ecpp)([0-9]+)$", RM_ALWAYS | RM_PRE,
107 ILEVEL_1, devfsadm_rm_all
109 { "serial", "^(tty|ttyd)([0-9]+)$", RM_ALWAYS | RM_PRE,
110 ILEVEL_1, devfsadm_rm_all
112 { "serial", "^tty[a-z]$", RM_ALWAYS | RM_PRE,
113 ILEVEL_1, devfsadm_rm_all
117 DEVFSADM_REMOVE_INIT_V0(misc_remove_cbt);
120 * Handles minor node type "ddi_display", in addition to generic processing
121 * done by display().
123 * This creates a /dev/vt00 link to /dev/fb, for backwards compatibility.
125 /* ARGSUSED */
127 vt00(di_minor_t minor, di_node_t node)
129 (void) devfsadm_secondary_link("vt00", "fb", 0);
130 return (DEVFSADM_CONTINUE);
134 * type=ddi_block:diskette;addr=0,0;minor=c diskette
135 * type=ddi_block:diskette;addr=0,0;minor=c,raw rdiskette
136 * type=ddi_block:diskette;addr1=0;minor=c diskette\A2
137 * type=ddi_block:diskette;addr1=0;minor=c,raw rdiskette\A2
139 static int
140 diskette(di_minor_t minor, di_node_t node)
142 int flags = 0;
143 char *a2;
144 char link[PATH_MAX];
145 char *addr = di_bus_addr(node);
146 char *mn = di_minor_name(minor);
148 if (strcmp(addr, "0,0") == 0) {
149 if (strcmp(mn, "c") == 0) {
150 (void) devfsadm_mklink("diskette", node, minor, flags);
151 } else if (strcmp(mn, "c,raw") == 0) {
152 (void) devfsadm_mklink("rdiskette", node, minor, flags);
157 if (addr[0] == '0') {
158 if ((a2 = strchr(addr, ',')) != NULL) {
159 a2++;
160 if (strcmp(mn, "c") == 0) {
161 (void) strcpy(link, "diskette");
162 (void) strcat(link, a2);
163 (void) devfsadm_mklink(link, node, minor,
164 flags);
165 } else if (strcmp(mn, "c,raw") == 0) {
166 (void) strcpy(link, "rdiskette");
167 (void) strcat(link, a2);
168 (void) devfsadm_mklink(link, node, minor,
169 flags);
174 return (DEVFSADM_CONTINUE);
178 * type=ddi_printer;name=lp;addr=1,3bc lp0
179 * type=ddi_printer;name=lp;addr=1,378 lp1
180 * type=ddi_printer;name=lp;addr=1,278 lp2
182 static int
183 lp(di_minor_t minor, di_node_t node)
185 char *addr = di_bus_addr(node);
186 char *buf;
187 char path[PATH_MAX + 1];
188 devfsadm_enumerate_t rules[1] = {"^ecpp([0-9]+)$", 1, MATCH_ALL};
190 if (strcmp(addr, "1,3bc") == 0) {
191 (void) devfsadm_mklink("lp0", node, minor, 0);
193 } else if (strcmp(addr, "1,378") == 0) {
194 (void) devfsadm_mklink("lp1", node, minor, 0);
196 } else if (strcmp(addr, "1,278") == 0) {
197 (void) devfsadm_mklink("lp2", node, minor, 0);
200 if (strcmp(di_driver_name(node), "ecpp") != 0) {
201 return (DEVFSADM_CONTINUE);
204 if ((buf = di_devfs_path(node)) == NULL) {
205 return (DEVFSADM_CONTINUE);
208 (void) snprintf(path, sizeof (path), "%s:%s",
209 buf, di_minor_name(minor));
211 di_devfs_path_free(buf);
213 if (devfsadm_enumerate_int(path, 0, &buf, rules, 1)) {
214 return (DEVFSADM_CONTINUE);
217 (void) snprintf(path, sizeof (path), "ecpp%s", buf);
218 free(buf);
219 (void) devfsadm_mklink(path, node, minor, 0);
220 return (DEVFSADM_CONTINUE);
224 * type=ddi_serial:mb;minor=a tty00
225 * type=ddi_serial:mb;minor=b tty01
226 * type=ddi_serial:mb;minor=c tty02
227 * type=ddi_serial:mb;minor=d tty03
229 static int
230 serial(di_minor_t minor, di_node_t node)
233 char *mn = di_minor_name(minor);
234 char link[PATH_MAX];
236 (void) strcpy(link, "tty");
237 (void) strcat(link, mn);
238 (void) devfsadm_mklink(link, node, minor, 0);
240 if (strcmp(mn, "a") == 0) {
241 (void) devfsadm_mklink("tty00", node, minor, 0);
243 } else if (strcmp(mn, "b") == 0) {
244 (void) devfsadm_mklink("tty01", node, minor, 0);
246 } else if (strcmp(mn, "c") == 0) {
247 (void) devfsadm_mklink("tty02", node, minor, 0);
249 } else if (strcmp(mn, "d") == 0) {
250 (void) devfsadm_mklink("tty03", node, minor, 0);
252 return (DEVFSADM_CONTINUE);
256 * type=ddi_serial:dialout,mb;minor=a,cu ttyd0
257 * type=ddi_serial:dialout,mb;minor=b,cu ttyd1
258 * type=ddi_serial:dialout,mb;minor=c,cu ttyd2
259 * type=ddi_serial:dialout,mb;minor=d,cu ttyd3
261 static int
262 serial_dialout(di_minor_t minor, di_node_t node)
264 char *mn = di_minor_name(minor);
266 if (strcmp(mn, "a,cu") == 0) {
267 (void) devfsadm_mklink("ttyd0", node, minor, 0);
268 (void) devfsadm_mklink("cua0", node, minor, 0);
270 } else if (strcmp(mn, "b,cu") == 0) {
271 (void) devfsadm_mklink("ttyd1", node, minor, 0);
272 (void) devfsadm_mklink("cua1", node, minor, 0);
274 } else if (strcmp(mn, "c,cu") == 0) {
275 (void) devfsadm_mklink("ttyd2", node, minor, 0);
276 (void) devfsadm_mklink("cua2", node, minor, 0);
278 } else if (strcmp(mn, "d,cu") == 0) {
279 (void) devfsadm_mklink("ttyd3", node, minor, 0);
280 (void) devfsadm_mklink("cua3", node, minor, 0);
282 return (DEVFSADM_CONTINUE);
285 static int
286 kdmouse(di_minor_t minor, di_node_t node)
288 (void) devfsadm_mklink("kdmouse", node, minor, 0);
289 return (DEVFSADM_CONTINUE);
292 static int
293 ipmi(di_minor_t minor, di_node_t node)
296 * Follow convention from other systems, and include an instance#,
297 * even though there will only be one.
299 (void) devfsadm_mklink("ipmi0", node, minor, 0);
300 return (DEVFSADM_CONTINUE);
303 static int
304 smbios(di_minor_t minor, di_node_t node)
306 (void) devfsadm_mklink("smbios", node, minor, 0);
307 return (DEVFSADM_CONTINUE);
311 * /dev/mc/mc<chipid> -> /devices/.../pci1022,1102@<chipid+24>,2:mc-amd
313 static int
314 mc_node(di_minor_t minor, di_node_t node)
316 const char *minorname = di_minor_name(minor);
317 const char *busaddr = di_bus_addr(node);
318 char linkpath[PATH_MAX];
319 int unitaddr;
320 char *c;
322 if (minorname == NULL || busaddr == NULL)
323 return (DEVFSADM_CONTINUE);
325 errno = 0;
326 unitaddr = strtol(busaddr, &c, 16);
328 if (errno != 0)
329 return (DEVFSADM_CONTINUE);
331 if (unitaddr == 0) {
332 (void) snprintf(linkpath, sizeof (linkpath), "mc/mc");
333 } else if (unitaddr >= MC_AMD_DEV_OFFSET) {
334 (void) snprintf(linkpath, sizeof (linkpath), "mc/mc%u",
335 unitaddr - MC_AMD_DEV_OFFSET);
336 } else {
337 (void) snprintf(linkpath, sizeof (linkpath), "mc/mc%u",
338 minor->dev_minor);
340 (void) devfsadm_mklink(linkpath, node, minor, 0);
341 return (DEVFSADM_CONTINUE);
345 * Creates \M0 devlink for xsvc node
347 static int
348 xsvc(di_minor_t minor, di_node_t node)
350 char *mn;
352 if (strcmp(di_node_name(node), "xsvc") != 0)
353 return (DEVFSADM_CONTINUE);
355 mn = di_minor_name(minor);
356 if (mn == NULL)
357 return (DEVFSADM_CONTINUE);
359 (void) devfsadm_mklink(mn, node, minor, 0);
360 return (DEVFSADM_CONTINUE);
364 * Creates \M0 devlink for srn device
366 static int
367 srn(di_minor_t minor, di_node_t node)
369 char *mn;
371 if (strcmp(di_node_name(node), "srn") != 0)
372 return (DEVFSADM_CONTINUE);
374 mn = di_minor_name(minor);
375 if (mn == NULL)
376 return (DEVFSADM_CONTINUE);
378 (void) devfsadm_mklink(mn, node, minor, 0);
379 return (DEVFSADM_CONTINUE);
383 * /dev/ucode -> /devices/pseudo/ucode@0:ucode
385 static int
386 ucode(di_minor_t minor, di_node_t node)
388 (void) devfsadm_mklink("ucode", node, minor, 0);
389 return (DEVFSADM_CONTINUE);