PageRenderTime 51ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/usr/src/cmd/devfsadm/sparc/misc_link_sparc.c

https://bitbucket.org/illumos/illumos-gate/
C | 244 lines | 151 code | 41 blank | 52 comment | 21 complexity | 2a4fcb9b6e10ffb13d2c314037e70139 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.0, BSD-3-Clause-No-Nuclear-License-2014, AGPL-1.0, AGPL-3.0, BSD-3-Clause, GPL-3.0, LGPL-2.1, BSD-2-Clause, MPL-2.0-no-copyleft-exception, GPL-2.0, 0BSD
  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 2009 Sun Microsystems, Inc. All rights reserved.
  23. * Use is subject to license terms.
  24. */
  25. #include <regex.h>
  26. #include <devfsadm.h>
  27. #include <stdio.h>
  28. #include <strings.h>
  29. #include <stdlib.h>
  30. #include <limits.h>
  31. #include <sys/mkdev.h>
  32. #include <bsm/devalloc.h>
  33. extern int system_labeled;
  34. static int ddi_other(di_minor_t minor, di_node_t node);
  35. static int diskette(di_minor_t minor, di_node_t node);
  36. static int ecpp_create(di_minor_t minor, di_node_t node);
  37. static int mc_node(di_minor_t minor, di_node_t node);
  38. static int starcat_sbbc_node(di_minor_t minor, di_node_t node);
  39. static int lom(di_minor_t minor, di_node_t node);
  40. static int ntwdt_create(di_minor_t minor, di_node_t node);
  41. static int bmc(di_minor_t minor, di_node_t node);
  42. static devfsadm_create_t misc_cbt[] = {
  43. { "other", "ddi_other", NULL,
  44. TYPE_EXACT, ILEVEL_0, ddi_other
  45. },
  46. { "memory-controller", "ddi_mem_ctrl", NULL,
  47. TYPE_EXACT, ILEVEL_0, mc_node
  48. },
  49. { "pseudo", "ddi_pseudo", "sbbc",
  50. TYPE_EXACT | DRV_EXACT, ILEVEL_1, starcat_sbbc_node
  51. },
  52. { "disk", "ddi_block:diskette", NULL,
  53. TYPE_EXACT, ILEVEL_1, diskette
  54. },
  55. { "printer", "ddi_printer", NULL,
  56. TYPE_EXACT, ILEVEL_1, ecpp_create
  57. },
  58. { "pseudo", "ddi_pseudo", "lw8",
  59. TYPE_EXACT | DRV_EXACT, ILEVEL_0, lom
  60. },
  61. { "pseudo", "ddi_pseudo", "ntwdt",
  62. TYPE_EXACT | DRV_EXACT, ILEVEL_0, ntwdt_create
  63. },
  64. { "pseudo", "ddi_pseudo", "bmc",
  65. TYPE_EXACT | DRV_EXACT, ILEVEL_0, bmc
  66. }
  67. };
  68. DEVFSADM_CREATE_INIT_V0(misc_cbt);
  69. /*
  70. * Handles minor node type "ddi_other"
  71. * type=ddi_other;name=SUNW,pmc pmc
  72. * type=ddi_other;name=SUNW,mic mic\M0
  73. */
  74. static int
  75. ddi_other(di_minor_t minor, di_node_t node)
  76. {
  77. char path[PATH_MAX + 1];
  78. char *nn = di_node_name(node);
  79. char *mn = di_minor_name(minor);
  80. if (strcmp(nn, "SUNW,pmc") == 0) {
  81. (void) devfsadm_mklink("pcm", node, minor, 0);
  82. } else if (strcmp(nn, "SUNW,mic") == 0) {
  83. (void) strcpy(path, "mic");
  84. (void) strcat(path, mn);
  85. (void) devfsadm_mklink(path, node, minor, 0);
  86. }
  87. return (DEVFSADM_CONTINUE);
  88. }
  89. /*
  90. * This function is called for diskette nodes
  91. */
  92. static int
  93. diskette(di_minor_t minor, di_node_t node)
  94. {
  95. int flags = 0;
  96. char *mn = di_minor_name(minor);
  97. if (system_labeled)
  98. flags = DA_ADD|DA_FLOPPY;
  99. if (strcmp(mn, "c") == 0) {
  100. (void) devfsadm_mklink("diskette", node, minor, flags);
  101. (void) devfsadm_mklink("diskette0", node, minor, flags);
  102. } else if (strcmp(mn, "c,raw") == 0) {
  103. (void) devfsadm_mklink("rdiskette", node, minor, flags);
  104. (void) devfsadm_mklink("rdiskette0", node, minor, flags);
  105. }
  106. return (DEVFSADM_CONTINUE);
  107. }
  108. /*
  109. * Handles links of the form:
  110. * type=ddi_printer;name=ecpp ecpp\N0
  111. */
  112. static int
  113. ecpp_create(di_minor_t minor, di_node_t node)
  114. {
  115. char *buf;
  116. char path[PATH_MAX + 1];
  117. devfsadm_enumerate_t rules[1] = {"^ecpp([0-9]+)$", 1, MATCH_ALL};
  118. if (strcmp(di_driver_name(node), "ecpp") != 0) {
  119. return (DEVFSADM_CONTINUE);
  120. }
  121. if ((buf = di_devfs_path(node)) == NULL) {
  122. return (DEVFSADM_CONTINUE);
  123. }
  124. (void) snprintf(path, sizeof (path), "%s:%s",
  125. buf, di_minor_name(minor));
  126. di_devfs_path_free(buf);
  127. if (devfsadm_enumerate_int(path, 0, &buf, rules, 1)) {
  128. return (DEVFSADM_CONTINUE);
  129. }
  130. (void) snprintf(path, sizeof (path), "ecpp%s", buf);
  131. free(buf);
  132. (void) devfsadm_mklink(path, node, minor, 0);
  133. return (DEVFSADM_CONTINUE);
  134. }
  135. /* Rules for memory controller */
  136. static devfsadm_enumerate_t mc_rules[1] =
  137. {"^mc$/^mc([0-9]+)$", 1, MATCH_ALL};
  138. static int
  139. mc_node(di_minor_t minor, di_node_t node)
  140. {
  141. char path[PATH_MAX], l_path[PATH_MAX], *buf, *devfspath;
  142. char *minor_nm;
  143. minor_nm = di_minor_name(minor);
  144. if (minor_nm == NULL) {
  145. return (DEVFSADM_CONTINUE);
  146. }
  147. devfspath = di_devfs_path(node);
  148. (void) strcpy(path, devfspath);
  149. (void) strcat(path, ":");
  150. (void) strcat(path, minor_nm);
  151. di_devfs_path_free(devfspath);
  152. /* build the physical path from the components */
  153. if (devfsadm_enumerate_int(path, 0, &buf, mc_rules, 1)) {
  154. return (DEVFSADM_CONTINUE);
  155. }
  156. (void) strcpy(l_path, "mc/mc");
  157. (void) strcat(l_path, buf);
  158. free(buf);
  159. (void) devfsadm_mklink(l_path, node, minor, 0);
  160. return (DEVFSADM_CONTINUE);
  161. }
  162. /*
  163. * Starcat sbbc node. We only really care about generating a /dev
  164. * link for the lone sbbc on the SC (as opposed to the potentially
  165. * numerous sbbcs on the domain), so only operate on instance 0.
  166. */
  167. static int
  168. starcat_sbbc_node(di_minor_t minor, di_node_t node)
  169. {
  170. char *mn;
  171. if (di_instance(node) == 0) {
  172. mn = di_minor_name(minor);
  173. (void) devfsadm_mklink(mn, node, minor, 0);
  174. }
  175. return (DEVFSADM_CONTINUE);
  176. }
  177. /*
  178. * Creates /dev/lom nodes for Platform Specific lom driver
  179. */
  180. static int
  181. lom(di_minor_t minor, di_node_t node)
  182. {
  183. (void) devfsadm_mklink("lom", node, minor, 0);
  184. return (DEVFSADM_CONTINUE);
  185. }
  186. /*
  187. * Creates /dev/ntwdt nodes for Platform Specific ntwdt driver
  188. */
  189. static int
  190. ntwdt_create(di_minor_t minor, di_node_t node)
  191. {
  192. (void) devfsadm_mklink("ntwdt", node, minor, 0);
  193. return (DEVFSADM_CONTINUE);
  194. }
  195. /*
  196. * Creates /dev/bmc node.
  197. */
  198. static int
  199. bmc(di_minor_t minor, di_node_t node)
  200. {
  201. (void) devfsadm_mklink("bmc", node, minor, 0);
  202. return (DEVFSADM_CONTINUE);
  203. }