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]
22 * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
33 #include <bsm/devalloc.h>
34 #include <sys/audio.h>
35 #include <sys/soundcard.h>
38 #define MAX_AUDIO_LINK 100
41 extern int system_labeled
;
43 static void check_audio_link(di_node_t anynode
, char *secondary_link
,
44 const char *primary_link_format
);
46 static int audio_process(di_minor_t minor
, di_node_t node
);
47 static int sndstat_process(di_minor_t minor
, di_node_t node
);
49 static devfsadm_create_t audio_cbt
[] = {
50 { "audio", "ddi_audio", NULL
,
51 TYPE_EXACT
, ILEVEL_0
, audio_process
53 { "pseudo", "ddi_pseudo", "audio",
54 TYPE_EXACT
|DRV_EXACT
, ILEVEL_0
, sndstat_process
58 DEVFSADM_CREATE_INIT_V0(audio_cbt
);
61 * the following can't be one big RE with a bunch of alterations "|"
62 * because recurse_dev_re() would not work.
64 static devfsadm_remove_t audio_remove_cbt
[] = {
69 /* /dev/audio, /dev/audioctl, /dev/dsp */
71 RM_POST
|RM_HOT
|RM_ALWAYS
, ILEVEL_0
, devfsadm_rm_all
73 { "audio", "^audioctl$",
74 RM_POST
|RM_HOT
|RM_ALWAYS
, ILEVEL_0
, devfsadm_rm_all
77 RM_POST
|RM_HOT
|RM_ALWAYS
, ILEVEL_0
, devfsadm_rm_all
80 RM_POST
|RM_HOT
|RM_ALWAYS
, ILEVEL_0
, devfsadm_rm_all
82 { "audio", "^sndstat$",
83 RM_PRE
|RM_HOT
|RM_ALWAYS
, ILEVEL_0
, devfsadm_rm_all
85 { "audio", "^mixer[0-9]+$",
86 RM_POST
|RM_HOT
|RM_ALWAYS
, ILEVEL_0
, devfsadm_rm_all
88 { "audio", "^dsp[0-9]+$",
89 RM_POST
|RM_HOT
|RM_ALWAYS
, ILEVEL_0
, devfsadm_rm_all
91 { "audio", "^sound/[0-9]+$",
92 RM_POST
|RM_HOT
|RM_ALWAYS
, ILEVEL_0
, devfsadm_rm_all
94 { "audio", "^sound/[0-9]+ctl$",
95 RM_POST
|RM_HOT
|RM_ALWAYS
, ILEVEL_0
, devfsadm_rm_all
99 DEVFSADM_REMOVE_INIT_V0(audio_remove_cbt
);
101 static di_node_t anynode
;
106 anynode
= DI_NODE_NIL
;
107 return (DEVFSADM_SUCCESS
);
113 check_audio_link(anynode
, "audio", "sound/%d");
114 check_audio_link(anynode
, "audioctl", "sound/%dctl");
115 check_audio_link(anynode
, "dsp", "dsp%d");
116 anynode
= DI_NODE_NIL
;
117 return (DEVFSADM_SUCCESS
);
121 #define COPYSUB(to, from, pm, pos) (void) strncpy(to, &from[pm[pos].rm_so], \
122 pm[pos].rm_eo - pm[pos].rm_so); \
123 to[pm[pos].rm_eo - pm[pos].rm_so] = 0;
126 send_number(long num
)
128 char buf
[PATH_MAX
+1];
131 * This is not safe with -r.
133 if (strcmp(devfsadm_root_path(), "/") != 0)
136 (void) snprintf(buf
, sizeof (buf
), "/dev/mixer%ld", num
);
137 if (device_exists(buf
)) {
140 if ((fd
= open(buf
, O_RDWR
)) < 0)
143 (void) ioctl(fd
, SNDCTL_SUN_SEND_NUMBER
, &num
);
145 devfsadm_print(CHATTY_MID
,
146 "sent devnum audio %ld to %s\n", num
, buf
);
151 sndstat_process(di_minor_t minor
, di_node_t node
)
155 mn
= di_minor_name(minor
);
159 * "Special" handling for /dev/sndstat and /dev/mixer.
161 if (strcmp(mn
, "sound,sndstat0") == 0) {
162 (void) devfsadm_mklink("sndstat", node
, minor
, 0);
163 (void) devfsadm_secondary_link("mixer", "sndstat", 0);
166 return (DEVFSADM_CONTINUE
);
170 * This function is called for every audio node.
171 * Calls enumerate to assign a logical unit id, and then
172 * devfsadm_mklink to make the link.
175 audio_process(di_minor_t minor
, di_node_t node
)
178 char devpath
[PATH_MAX
+ 1];
179 char newpath
[PATH_MAX
+ 1];
184 char re_string
[RE_SIZE
+1];
185 devfsadm_enumerate_t rules
[1] = {NULL
};
186 char base
[PATH_MAX
+ 1];
187 char linksrc
[PATH_MAX
+ 1];
188 char linkdst
[PATH_MAX
+ 1];
195 flags
= DA_ADD
|DA_AUDIO
;
198 mn
= di_minor_name(minor
);
200 if ((tmp
= di_devfs_path(node
)) == NULL
) {
201 return (DEVFSADM_CONTINUE
);
203 (void) snprintf(devpath
, sizeof (devpath
), "%s:%s", tmp
, mn
);
204 di_devfs_path_free(tmp
);
206 if (strncmp(mn
, "sound,", sizeof ("sound,") - 1) != 0) {
207 devfsadm_errprint("SUNW_audio_link: "
208 "can't find match for'%s'\n", mn
);
209 return (DEVFSADM_CONTINUE
);
212 /* strlen("sound,") */
213 (void) strlcpy(base
, mn
+ 6, sizeof (base
));
216 driver
= di_driver_name(node
);
218 /* if driver name override in minor name */
219 if ((tmp
= strchr(mn
, ',')) != NULL
) {
225 /* skip past "audio" portion of the minor name */
226 if (strncmp(mn
, "audio", sizeof ("audio") - 1) == 0) {
227 mn
+= sizeof ("audio") - 1;
230 /* parse the instance number */
231 for (i
= strlen(mn
); i
; i
--) {
232 if (!isdigit(mn
[i
- 1]))
235 inst
= strtol(mn
+ i
, &ep
, 10);
236 mn
[i
] = 0; /* lop off the instance number */
239 * First we create a node with the driver under /dev/sound.
240 * Note that "instance numbers" used by the audio framework
241 * are guaranteed to be unique for each driver.
243 (void) snprintf(newpath
, sizeof (newpath
), "sound/%s:%d%s",
245 (void) devfsadm_mklink(newpath
, node
, minor
, flags
);
248 * The rest of this logic is a gross simplification that is
249 * made possible by the fact that each audio node will have
250 * several different minors associated with it. Rather than
251 * processing each node separately, we just create the links
254 * This reduces the chances of the various links being out of
255 * sync with each other.
257 if (strcmp(mn
, "mixer") != 0) {
258 return (DEVFSADM_CONTINUE
);
262 * Its the control node, so create the various
267 * We want a match against the physical path
268 * without the minor name component.
270 (void) snprintf(re_string
, RE_SIZE
, "%s", "^mixer([0-9]+)");
271 rules
[0].re
= re_string
;
273 rules
[0].flags
= MATCH_ALL
;
276 * enumerate finds the logical audio id, and stuffs
279 (void) strlcpy(devpath
, newpath
, sizeof (devpath
));
280 if (devfsadm_enumerate_int(devpath
, 0, &buf
, rules
, 1)) {
281 return (DEVFSADM_CONTINUE
);
283 num
= strtol(buf
, &ep
, 10);
287 (void) snprintf(linksrc
, sizeof (linksrc
), "sound/%s:%ld",
289 (void) snprintf(linkdst
, sizeof (linkdst
), "sound/%ld", num
);
290 (void) devfsadm_secondary_link(linkdst
, linksrc
, flags
);
292 (void) snprintf(linksrc
, sizeof (linksrc
), "sound/%s:%ldctl",
294 (void) snprintf(linkdst
, sizeof (linkdst
), "sound/%ldctl", num
);
295 (void) devfsadm_secondary_link(linkdst
, linksrc
, flags
);
297 (void) snprintf(linksrc
, sizeof (linksrc
), "sound/%s:%lddsp",
299 (void) snprintf(linkdst
, sizeof (linkdst
), "dsp%ld", num
);
300 (void) devfsadm_secondary_link(linkdst
, linksrc
, flags
);
302 (void) snprintf(linksrc
, sizeof (linksrc
), "sound/%s:%ldmixer",
304 (void) snprintf(linkdst
, sizeof (linkdst
), "mixer%ld", num
);
305 (void) devfsadm_secondary_link(linkdst
, linksrc
, flags
);
307 /* Send control number */
310 return (DEVFSADM_CONTINUE
);
314 check_audio_link(di_node_t anynode
, char *secondary
, const char *primary_format
)
316 char primary
[PATH_MAX
+ 1];
320 /* if link is present, return */
321 if (devfsadm_link_valid(anynode
, secondary
) == DEVFSADM_TRUE
) {
326 flags
= DA_ADD
|DA_AUDIO
;
328 for (i
= 0; i
< MAX_AUDIO_LINK
; i
++) {
329 (void) sprintf(primary
, primary_format
, i
);
330 if (devfsadm_link_valid(anynode
, primary
) == DEVFSADM_TRUE
) {
331 /* we read link to get it to the master "real" link */
332 (void) devfsadm_secondary_link(secondary
,