1 /* 2 * CDDL HEADER START 3 * 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. 7 * 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. 12 * 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] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. 23 * Copyright 2011 Nexenta Systems, Inc. All rights reserved. 24 * Copyright (c) 2015, Joyent, Inc. All rights reserved. 25 * Copyright 2022 Garrett D'Amore <garrett@damore.org> 26 * Copyright 2022 Oxide Computer Company 27 */ 28 29 #include <regex.h> 30 #include <devfsadm.h> 31 #include <stdio.h> 32 #include <strings.h> 33 #include <stdlib.h> 34 #include <limits.h> 35 #include <sys/zone.h> 36 #include <sys/zcons.h> 37 #include <sys/cpuid_drv.h> 38 39 static int display(di_minor_t minor, di_node_t node); 40 static int parallel(di_minor_t minor, di_node_t node); 41 static int node_slash_minor(di_minor_t minor, di_node_t node); 42 static int driver_minor(di_minor_t minor, di_node_t node); 43 static int node_name(di_minor_t minor, di_node_t node); 44 static int minor_name(di_minor_t minor, di_node_t node); 45 static int wifi_minor_name(di_minor_t minor, di_node_t node); 46 static int conskbd(di_minor_t minor, di_node_t node); 47 static int consms(di_minor_t minor, di_node_t node); 48 static int power_button(di_minor_t minor, di_node_t node); 49 static int fc_port(di_minor_t minor, di_node_t node); 50 static int printer_create(di_minor_t minor, di_node_t node); 51 static int se_hdlc_create(di_minor_t minor, di_node_t node); 52 static int ppm(di_minor_t minor, di_node_t node); 53 static int gpio(di_minor_t minor, di_node_t node); 54 static int av_create(di_minor_t minor, di_node_t node); 55 static int tsalarm_create(di_minor_t minor, di_node_t node); 56 static int ntwdt_create(di_minor_t minor, di_node_t node); 57 static int zcons_create(di_minor_t minor, di_node_t node); 58 static int cpuid(di_minor_t minor, di_node_t node); 59 static int glvc(di_minor_t minor, di_node_t node); 60 static int ses_callback(di_minor_t minor, di_node_t node); 61 static int kmdrv_create(di_minor_t minor, di_node_t node); 62 static int vio9p_create(di_minor_t minor, di_node_t node); 63 64 static devfsadm_create_t misc_cbt[] = { 65 { "pseudo", "ddi_pseudo", "(^sad$)", 66 TYPE_EXACT | DRV_RE, ILEVEL_0, node_slash_minor 67 }, 68 { "pseudo", "ddi_pseudo", "zsh", 69 TYPE_EXACT | DRV_EXACT, ILEVEL_0, driver_minor 70 }, 71 { "network", "ddi_network", NULL, 72 TYPE_EXACT, ILEVEL_0, minor_name 73 }, 74 { "wifi", "ddi_network:wifi", NULL, 75 TYPE_EXACT, ILEVEL_0, wifi_minor_name 76 }, 77 { "display", "ddi_display", NULL, 78 TYPE_EXACT, ILEVEL_0, display 79 }, 80 { "parallel", "ddi_parallel", NULL, 81 TYPE_EXACT, ILEVEL_0, parallel 82 }, 83 { "enclosure", DDI_NT_SCSI_ENCLOSURE, NULL, 84 TYPE_EXACT, ILEVEL_0, ses_callback 85 }, 86 { "pseudo", "ddi_pseudo", "(^winlock$)|(^pm$)", 87 TYPE_EXACT | DRV_RE, ILEVEL_0, node_name 88 }, 89 { "pseudo", "ddi_pseudo", "conskbd", 90 TYPE_EXACT | DRV_EXACT, ILEVEL_0, conskbd 91 }, 92 { "pseudo", "ddi_pseudo", "consms", 93 TYPE_EXACT | DRV_EXACT, ILEVEL_0, consms 94 }, 95 { "pseudo", "ddi_pseudo", "eventfd", 96 TYPE_EXACT | DRV_EXACT, ILEVEL_0, minor_name 97 }, 98 { "pseudo", "ddi_pseudo", "signalfd", 99 TYPE_EXACT | DRV_EXACT, ILEVEL_0, minor_name 100 }, 101 { "pseudo", "ddi_pseudo", "rsm", 102 TYPE_EXACT | DRV_EXACT, ILEVEL_0, minor_name 103 }, 104 { "pseudo", "ddi_pseudo", 105 "(^lockstat$)|(^SUNW,rtvc$)|(^vol$)|(^log$)|(^sy$)|" 106 "(^ksyms$)|(^clone$)|(^tl$)|(^tnf$)|(^kstat$)|(^mdesc$)|(^eeprom$)|" 107 "(^ptsl$)|(^mm$)|(^wc$)|(^dump$)|(^cn$)|(^svvslo$)|(^ptm$)|" 108 "(^ptc$)|(^openeepr$)|(^poll$)|(^sysmsg$)|(^random$)|(^trapstat$)|" 109 "(^cryptoadm$)|(^crypto$)|(^pool$)|(^poolctl$)|(^bl$)|(^kmdb$)|" 110 "(^sysevent$)|(^physmem$)", 111 TYPE_EXACT | DRV_RE, ILEVEL_1, minor_name 112 }, 113 { "pseudo", "ddi_pseudo", 114 "(^ip$)|(^tcp$)|(^udp$)|(^icmp$)|" 115 "(^ip6$)|(^tcp6$)|(^udp6$)|(^icmp6$)|" 116 "(^rts$)|(^arp$)|(^ipsecah$)|(^ipsecesp$)|(^keysock$)|(^spdsock$)|" 117 "(^rds$)|(^sdp$)|(^ipnet$)|(^dlpistub$)|(^bpf$)", 118 TYPE_EXACT | DRV_RE, ILEVEL_1, minor_name 119 }, 120 { "pseudo", "ddi_pseudo", "ipd", 121 TYPE_EXACT | DRV_EXACT, ILEVEL_0, minor_name 122 }, 123 { "pseudo", "ddi_pseudo", 124 "(^ipf$)|(^ipnat$)|(^ipstate$)|(^ipauth$)|" 125 "(^ipsync$)|(^ipscan$)|(^iplookup$)", 126 TYPE_EXACT | DRV_RE, ILEVEL_0, minor_name, 127 }, 128 { "pseudo", "ddi_pseudo", "dld", 129 TYPE_EXACT | DRV_EXACT, ILEVEL_0, node_name 130 }, 131 { "pseudo", "ddi_pseudo", 132 "(^kdmouse$)|(^rootprop$)", 133 TYPE_EXACT | DRV_RE, ILEVEL_0, node_name 134 }, 135 { "pseudo", "ddi_pseudo", "timerfd", 136 TYPE_EXACT | DRV_EXACT, ILEVEL_0, minor_name 137 }, 138 { "pseudo", "ddi_pseudo", "tod", 139 TYPE_EXACT | DRV_EXACT, ILEVEL_0, node_name 140 }, 141 { "pseudo", "ddi_pseudo", "envctrl(two)?", 142 TYPE_EXACT | DRV_RE, ILEVEL_1, minor_name, 143 }, 144 { "pseudo", "ddi_pseudo", "fcode", 145 TYPE_EXACT | DRV_RE, ILEVEL_0, minor_name, 146 }, 147 { "power_button", "ddi_power_button", NULL, 148 TYPE_EXACT, ILEVEL_0, power_button, 149 }, 150 { "FC port", "ddi_ctl:devctl", "fp", 151 TYPE_EXACT | DRV_EXACT, ILEVEL_0, fc_port 152 }, 153 { "printer", "ddi_printer", NULL, 154 TYPE_EXACT, ILEVEL_0, printer_create 155 }, 156 { "pseudo", "ddi_pseudo", "se", 157 TYPE_EXACT | DRV_EXACT, ILEVEL_0, se_hdlc_create 158 }, 159 { "ppm", "ddi_ppm", NULL, 160 TYPE_EXACT, ILEVEL_0, ppm 161 }, 162 { "pseudo", "ddi_pseudo", "gpio_87317", 163 TYPE_EXACT | DRV_EXACT, ILEVEL_0, gpio 164 }, 165 { "pseudo", "ddi_pseudo", "sckmdrv", 166 TYPE_EXACT | DRV_RE, ILEVEL_0, kmdrv_create, 167 }, 168 { "pseudo", "ddi_pseudo", "oplkmdrv", 169 TYPE_EXACT | DRV_RE, ILEVEL_0, kmdrv_create, 170 }, 171 { "av", "^ddi_av:(isoch|async)$", NULL, 172 TYPE_RE, ILEVEL_0, av_create, 173 }, 174 { "pseudo", "ddi_pseudo", "tsalarm", 175 TYPE_EXACT | DRV_RE, ILEVEL_0, tsalarm_create, 176 }, 177 { "pseudo", "ddi_pseudo", "ntwdt", 178 TYPE_EXACT | DRV_RE, ILEVEL_0, ntwdt_create, 179 }, 180 { "pseudo", "ddi_pseudo", "daplt", 181 TYPE_EXACT | DRV_EXACT, ILEVEL_0, minor_name 182 }, 183 { "pseudo", "ddi_pseudo", "zcons", 184 TYPE_EXACT | DRV_EXACT, ILEVEL_0, zcons_create, 185 }, 186 { "pseudo", "ddi_pseudo", CPUID_DRIVER_NAME, 187 TYPE_EXACT | DRV_EXACT, ILEVEL_0, cpuid, 188 }, 189 { "pseudo", "ddi_pseudo", "glvc", 190 TYPE_EXACT | DRV_EXACT, ILEVEL_0, glvc, 191 }, 192 { "pseudo", "ddi_pseudo", "dm2s", 193 TYPE_EXACT | DRV_EXACT, ILEVEL_0, minor_name, 194 }, 195 { "pseudo", "ddi_pseudo", "nsmb", 196 TYPE_EXACT | DRV_EXACT, ILEVEL_1, minor_name, 197 }, 198 { "pseudo", "ddi_pseudo", "mem_cache", 199 TYPE_EXACT | DRV_RE, ILEVEL_1, minor_name, 200 }, 201 { "pseudo", "ddi_pseudo", "fm", 202 TYPE_EXACT | DRV_RE, ILEVEL_1, minor_name, 203 }, 204 { "pseudo", "ddi_pseudo", "smbsrv", 205 TYPE_EXACT | DRV_EXACT, ILEVEL_1, minor_name, 206 }, 207 { "pseudo", "ddi_pseudo", "tpm", 208 TYPE_EXACT | DRV_EXACT, ILEVEL_0, minor_name 209 }, 210 { "pseudo", "ddi_pseudo", "overlay", 211 TYPE_EXACT | DRV_EXACT, ILEVEL_0, minor_name 212 }, 213 { "9p", "ddi_pseudo", "vio9p", 214 TYPE_EXACT | DRV_EXACT, ILEVEL_0, vio9p_create, 215 }, 216 }; 217 218 DEVFSADM_CREATE_INIT_V0(misc_cbt); 219 220 static devfsadm_remove_t misc_remove_cbt[] = { 221 { "pseudo", "^profile$", 222 RM_PRE | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all 223 }, 224 { "pseudo", "^rsm$", 225 RM_PRE | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all 226 }, 227 { "printer", "^printers/[0-9]+$", 228 RM_PRE | RM_HOT | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all 229 }, 230 { "av", "^av/[0-9]+/(async|isoch)$", 231 RM_PRE | RM_HOT | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all 232 }, 233 { "pseudo", "^daplt$", 234 RM_PRE | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all 235 }, 236 { "pseudo", "^zcons/" ZONENAME_REGEXP "/(" ZCONS_MANAGER_NAME "|" 237 ZCONS_SUBSIDIARY_NAME ")$", 238 RM_PRE | RM_HOT | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all 239 }, 240 { "pseudo", "^" CPUID_SELF_NAME "$", RM_ALWAYS | RM_PRE | RM_HOT, 241 ILEVEL_0, devfsadm_rm_all 242 }, 243 { "enclosure", "^es/ses[0-9]+$", RM_POST, 244 ILEVEL_0, devfsadm_rm_all 245 }, 246 { "pseudo", "^pfil$", 247 RM_PRE | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all 248 }, 249 { "pseudo", "^tpm$", 250 RM_PRE | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all 251 }, 252 { "pseudo", "^sctp|sctp6$", 253 RM_PRE | RM_ALWAYS, ILEVEL_0, devfsadm_rm_link 254 }, 255 { "9p", "^9p/[0-9]+$", 256 RM_PRE | RM_HOT | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all 257 }, 258 }; 259 260 /* Rules for gpio devices */ 261 static devfsadm_enumerate_t gpio_rules[1] = 262 {"^gpio([0-9]+)$", 1, MATCH_ALL}; 263 264 DEVFSADM_REMOVE_INIT_V0(misc_remove_cbt); 265 266 /* 267 * Handles minor node type "ddi_display". 268 * 269 * type=ddi_display fbs/\M0 fb\N0 270 */ 271 static int 272 display(di_minor_t minor, di_node_t node) 273 { 274 char l_path[PATH_MAX + 1], contents[PATH_MAX + 1], *buf; 275 devfsadm_enumerate_t rules[1] = {"^fb([0-9]+)$", 1, MATCH_ALL}; 276 char *mn = di_minor_name(minor); 277 278 /* create fbs/\M0 primary link */ 279 (void) strcpy(l_path, "fbs/"); 280 (void) strcat(l_path, mn); 281 (void) devfsadm_mklink(l_path, node, minor, 0); 282 283 /* create fb\N0 which links to fbs/\M0 */ 284 if (devfsadm_enumerate_int(l_path, 0, &buf, rules, 1)) { 285 return (DEVFSADM_CONTINUE); 286 } 287 (void) strcpy(contents, l_path); 288 (void) strcpy(l_path, "fb"); 289 (void) strcat(l_path, buf); 290 free(buf); 291 (void) devfsadm_secondary_link(l_path, contents, 0); 292 return (DEVFSADM_CONTINUE); 293 } 294 295 /* 296 * Handles minor node type "ddi_parallel". 297 * type=ddi_parallel;name=mcpp mcpp\N0 298 */ 299 static int 300 parallel(di_minor_t minor, di_node_t node) 301 { 302 char path[PATH_MAX + 1], *buf; 303 devfsadm_enumerate_t rules[1] = {"mcpp([0-9]+)$", 1, MATCH_ALL}; 304 305 306 if (strcmp(di_node_name(node), "mcpp") != 0) { 307 return (DEVFSADM_CONTINUE); 308 } 309 310 if (NULL == (buf = di_devfs_path(node))) { 311 return (DEVFSADM_CONTINUE); 312 } 313 314 (void) snprintf(path, sizeof (path), "%s:%s", 315 buf, di_minor_name(minor)); 316 317 di_devfs_path_free(buf); 318 319 if (devfsadm_enumerate_int(path, 0, &buf, rules, 1)) { 320 return (DEVFSADM_CONTINUE); 321 } 322 (void) snprintf(path, sizeof (path), "mcpp%s", buf); 323 free(buf); 324 325 (void) devfsadm_mklink(path, node, minor, 0); 326 return (DEVFSADM_CONTINUE); 327 } 328 329 static int 330 ses_callback(di_minor_t minor, di_node_t node) 331 { 332 char l_path[PATH_MAX]; 333 char *buf; 334 char *devfspath; 335 char p_path[PATH_MAX]; 336 devfsadm_enumerate_t re[] = {"^es$/^ses([0-9]+)$", 1, MATCH_ALL}; 337 338 /* find devices path -- need to free mem */ 339 if (NULL == (devfspath = di_devfs_path(node))) { 340 return (DEVFSADM_CONTINUE); 341 } 342 343 (void) snprintf(p_path, sizeof (p_path), "%s:%s", devfspath, 344 di_minor_name(minor)); 345 346 347 /* find next number to use; buf is an ascii number */ 348 if (devfsadm_enumerate_int(p_path, 0, &buf, re, 1)) { 349 /* free memory */ 350 di_devfs_path_free(devfspath); 351 return (DEVFSADM_CONTINUE); 352 } 353 354 (void) snprintf(l_path, sizeof (l_path), "es/ses%s", buf); 355 356 (void) devfsadm_mklink(l_path, node, minor, 0); 357 /* free memory */ 358 free(buf); 359 di_devfs_path_free(devfspath); 360 return (DEVFSADM_CONTINUE); 361 362 } 363 364 static int 365 node_slash_minor(di_minor_t minor, di_node_t node) 366 { 367 368 char path[PATH_MAX + 1]; 369 370 (void) strcpy(path, di_node_name(node)); 371 (void) strcat(path, "/"); 372 (void) strcat(path, di_minor_name(minor)); 373 (void) devfsadm_mklink(path, node, minor, 0); 374 return (DEVFSADM_CONTINUE); 375 } 376 377 static int 378 driver_minor(di_minor_t minor, di_node_t node) 379 { 380 char path[PATH_MAX + 1]; 381 382 (void) strcpy(path, di_driver_name(node)); 383 (void) strcat(path, di_minor_name(minor)); 384 (void) devfsadm_mklink(path, node, minor, 0); 385 return (DEVFSADM_CONTINUE); 386 } 387 388 /* 389 * Handles links of the form: 390 * type=ddi_pseudo;name=xyz \D 391 */ 392 static int 393 node_name(di_minor_t minor, di_node_t node) 394 { 395 (void) devfsadm_mklink(di_node_name(node), node, minor, 0); 396 return (DEVFSADM_CONTINUE); 397 } 398 399 /* 400 * Handles links of the form: 401 * type=ddi_pseudo;name=xyz \M0 402 */ 403 static int 404 minor_name(di_minor_t minor, di_node_t node) 405 { 406 char *mn = di_minor_name(minor); 407 408 (void) devfsadm_mklink(mn, node, minor, 0); 409 if (strcmp(mn, "icmp") == 0) { 410 (void) devfsadm_mklink("rawip", node, minor, 0); 411 } 412 if (strcmp(mn, "icmp6") == 0) { 413 (void) devfsadm_mklink("rawip6", node, minor, 0); 414 } 415 if (strcmp(mn, "ipf") == 0) { 416 (void) devfsadm_mklink("ipl", node, minor, 0); 417 } 418 return (DEVFSADM_CONTINUE); 419 } 420 421 /* 422 * create links at /dev/wifi for wifi minor node 423 */ 424 static int 425 wifi_minor_name(di_minor_t minor, di_node_t node) 426 { 427 char buf[256]; 428 char *mn = di_minor_name(minor); 429 430 (void) snprintf(buf, sizeof (buf), "%s%s", "wifi/", mn); 431 (void) devfsadm_mklink(buf, node, minor, 0); 432 433 return (DEVFSADM_CONTINUE); 434 } 435 436 static int 437 conskbd(di_minor_t minor, di_node_t node) 438 { 439 (void) devfsadm_mklink("kbd", node, minor, 0); 440 return (DEVFSADM_CONTINUE); 441 } 442 443 static int 444 consms(di_minor_t minor, di_node_t node) 445 { 446 (void) devfsadm_mklink("mouse", node, minor, 0); 447 return (DEVFSADM_CONTINUE); 448 } 449 450 static int 451 power_button(di_minor_t minor, di_node_t node) 452 { 453 (void) devfsadm_mklink("power_button", node, minor, 0); 454 return (DEVFSADM_CONTINUE); 455 } 456 457 static int 458 fc_port(di_minor_t minor, di_node_t node) 459 { 460 devfsadm_enumerate_t rules[1] = {"fc/fp([0-9]+)$", 1, MATCH_ALL}; 461 char *buf, path[PATH_MAX + 1]; 462 char *ptr; 463 464 if (NULL == (ptr = di_devfs_path(node))) { 465 return (DEVFSADM_CONTINUE); 466 } 467 468 (void) strcpy(path, ptr); 469 (void) strcat(path, ":"); 470 (void) strcat(path, di_minor_name(minor)); 471 472 di_devfs_path_free(ptr); 473 474 if (devfsadm_enumerate_int(path, 0, &buf, rules, 1) != 0) { 475 return (DEVFSADM_CONTINUE); 476 } 477 478 (void) strcpy(path, "fc/fp"); 479 (void) strcat(path, buf); 480 free(buf); 481 482 (void) devfsadm_mklink(path, node, minor, 0); 483 return (DEVFSADM_CONTINUE); 484 } 485 486 /* 487 * Handles: 488 * minor node type "ddi_printer". 489 * rules of the form: type=ddi_printer;name=bpp \M0 490 */ 491 static int 492 printer_create(di_minor_t minor, di_node_t node) 493 { 494 char *mn; 495 char path[PATH_MAX + 1], *buf; 496 devfsadm_enumerate_t rules[1] = {"^printers$/^([0-9]+)$", 1, MATCH_ALL}; 497 498 mn = di_minor_name(minor); 499 500 if (strcmp(di_driver_name(node), "bpp") == 0) { 501 (void) devfsadm_mklink(mn, node, minor, 0); 502 } 503 504 if (NULL == (buf = di_devfs_path(node))) { 505 return (DEVFSADM_CONTINUE); 506 } 507 508 (void) snprintf(path, sizeof (path), "%s:%s", buf, mn); 509 di_devfs_path_free(buf); 510 511 if (devfsadm_enumerate_int(path, 0, &buf, rules, 1)) { 512 return (DEVFSADM_CONTINUE); 513 } 514 515 (void) snprintf(path, sizeof (path), "printers/%s", buf); 516 free(buf); 517 518 (void) devfsadm_mklink(path, node, minor, 0); 519 520 return (DEVFSADM_CONTINUE); 521 } 522 523 /* 524 * Handles links of the form: 525 * type=ddi_pseudo;name=se;minor2=hdlc se_hdlc\N0 526 * type=ddi_pseudo;name=serial;minor2=hdlc se_hdlc\N0 527 */ 528 static int 529 se_hdlc_create(di_minor_t minor, di_node_t node) 530 { 531 devfsadm_enumerate_t rules[1] = {"^se_hdlc([0-9]+)$", 1, MATCH_ALL}; 532 char *buf, path[PATH_MAX + 1]; 533 char *ptr; 534 char *mn; 535 536 mn = di_minor_name(minor); 537 538 /* minor node should be of the form: "?,hdlc" */ 539 if (strcmp(mn + 1, ",hdlc") != 0) { 540 return (DEVFSADM_CONTINUE); 541 } 542 543 if (NULL == (ptr = di_devfs_path(node))) { 544 return (DEVFSADM_CONTINUE); 545 } 546 547 (void) strcpy(path, ptr); 548 (void) strcat(path, ":"); 549 (void) strcat(path, mn); 550 551 di_devfs_path_free(ptr); 552 553 if (devfsadm_enumerate_int(path, 0, &buf, rules, 1) != 0) { 554 return (DEVFSADM_CONTINUE); 555 } 556 557 (void) strcpy(path, "se_hdlc"); 558 (void) strcat(path, buf); 559 free(buf); 560 561 (void) devfsadm_mklink(path, node, minor, 0); 562 563 return (DEVFSADM_CONTINUE); 564 } 565 566 static int 567 gpio(di_minor_t minor, di_node_t node) 568 { 569 char l_path[PATH_MAX], p_path[PATH_MAX], *buf, *devfspath; 570 char *minor_nm, *drvr_nm; 571 572 573 minor_nm = di_minor_name(minor); 574 drvr_nm = di_driver_name(node); 575 if ((minor_nm == NULL) || (drvr_nm == NULL)) { 576 return (DEVFSADM_CONTINUE); 577 } 578 579 devfspath = di_devfs_path(node); 580 581 (void) strcpy(p_path, devfspath); 582 (void) strcat(p_path, ":"); 583 (void) strcat(p_path, minor_nm); 584 di_devfs_path_free(devfspath); 585 586 /* build the physical path from the components */ 587 if (devfsadm_enumerate_int(p_path, 0, &buf, gpio_rules, 1)) { 588 return (DEVFSADM_CONTINUE); 589 } 590 591 (void) snprintf(l_path, sizeof (l_path), "%s%s", "gpio", buf); 592 593 free(buf); 594 595 (void) devfsadm_mklink(l_path, node, minor, 0); 596 597 return (DEVFSADM_CONTINUE); 598 } 599 600 /* 601 * Creates /dev/ppm nodes for Platform Specific PM module 602 */ 603 static int 604 ppm(di_minor_t minor, di_node_t node) 605 { 606 (void) devfsadm_mklink("ppm", node, minor, 0); 607 return (DEVFSADM_CONTINUE); 608 } 609 610 /* 611 * Handles: 612 * /dev/av/[0-9]+/(async|isoch) 613 */ 614 static int 615 av_create(di_minor_t minor, di_node_t node) 616 { 617 devfsadm_enumerate_t rules[1] = {"^av$/^([0-9]+)$", 1, MATCH_ADDR}; 618 char *minor_str; 619 char path[PATH_MAX + 1]; 620 char *buf; 621 622 if ((buf = di_devfs_path(node)) == NULL) { 623 return (DEVFSADM_CONTINUE); 624 } 625 626 minor_str = di_minor_name(minor); 627 (void) snprintf(path, sizeof (path), "%s:%s", buf, minor_str); 628 di_devfs_path_free(buf); 629 630 if (devfsadm_enumerate_int(path, 0, &buf, rules, 1)) { 631 return (DEVFSADM_CONTINUE); 632 } 633 634 (void) snprintf(path, sizeof (path), "av/%s/%s", buf, minor_str); 635 free(buf); 636 637 (void) devfsadm_mklink(path, node, minor, 0); 638 639 return (DEVFSADM_CONTINUE); 640 } 641 642 /* 643 * Create device nodes for Virtio 9P channels: 644 * /dev/9p/[0-9]+ 645 */ 646 static int 647 vio9p_create(di_minor_t minor, di_node_t node) 648 { 649 char *minor_name = di_minor_name(minor); 650 char path[PATH_MAX + 1]; 651 652 if (minor_name == NULL || strcmp(minor_name, "9p") != 0) { 653 return (DEVFSADM_CONTINUE); 654 } 655 656 (void) snprintf(path, sizeof (path), "9p/%d", di_instance(node)); 657 (void) devfsadm_mklink(path, node, minor, 0); 658 659 return (DEVFSADM_CONTINUE); 660 } 661 662 /* 663 * Creates /dev/lom and /dev/tsalarm:ctl for tsalarm node 664 */ 665 static int 666 tsalarm_create(di_minor_t minor, di_node_t node) 667 { 668 char buf[PATH_MAX + 1]; 669 char *mn = di_minor_name(minor); 670 671 (void) snprintf(buf, sizeof (buf), "%s%s", di_node_name(node), ":ctl"); 672 673 (void) devfsadm_mklink(mn, node, minor, 0); 674 (void) devfsadm_mklink(buf, node, minor, 0); 675 676 return (DEVFSADM_CONTINUE); 677 } 678 679 /* 680 * Creates /dev/ntwdt for ntwdt node 681 */ 682 static int 683 ntwdt_create(di_minor_t minor, di_node_t node) 684 { 685 (void) devfsadm_mklink("ntwdt", node, minor, 0); 686 return (DEVFSADM_CONTINUE); 687 } 688 689 static int 690 zcons_create(di_minor_t minor, di_node_t node) 691 { 692 char *minor_str; 693 char *zonename; 694 char path[MAXPATHLEN]; 695 696 minor_str = di_minor_name(minor); 697 698 if (di_prop_lookup_strings(DDI_DEV_T_ANY, node, "zonename", 699 &zonename) == -1) { 700 return (DEVFSADM_CONTINUE); 701 } 702 703 (void) snprintf(path, sizeof (path), "zcons/%s/%s", zonename, 704 minor_str); 705 (void) devfsadm_mklink(path, node, minor, 0); 706 707 return (DEVFSADM_CONTINUE); 708 } 709 710 /* 711 * /dev/cpu/self/cpuid -> /devices/pseudo/cpuid@0:self 712 */ 713 static int 714 cpuid(di_minor_t minor, di_node_t node) 715 { 716 (void) devfsadm_mklink(CPUID_SELF_NAME, node, minor, 0); 717 return (DEVFSADM_CONTINUE); 718 } 719 720 /* 721 * For device 722 * /dev/spfma -> /devices/virtual-devices/fma@5:glvc 723 */ 724 static int 725 glvc(di_minor_t minor, di_node_t node) 726 { 727 char node_name[MAXNAMELEN + 1]; 728 729 (void) strcpy(node_name, di_node_name(node)); 730 731 if (strncmp(node_name, "fma", 3) == 0) { 732 /* Only one fma channel */ 733 (void) devfsadm_mklink("spfma", node, minor, 0); 734 } 735 return (DEVFSADM_CONTINUE); 736 } 737 738 /* 739 * Handles links of the form: 740 * type=ddi_pseudo;name=sckmdrv kmdrv\M0 741 * type=ddi_pseudo;name=oplkmdrv kmdrv\M0 742 */ 743 static int 744 kmdrv_create(di_minor_t minor, di_node_t node) 745 { 746 747 (void) devfsadm_mklink("kmdrv", node, minor, 0); 748 return (DEVFSADM_CONTINUE); 749 } 750