From alex@kapran.bitmcnit.bryansk.su  Wed Mar 14 03:47:02 2001
Return-Path: <alex@kapran.bitmcnit.bryansk.su>
Received: from rbn-gw.bgtu.debryansk.ru (rbn-gw.bgtu.debryansk.ru [62.76.89.2])
	by hub.freebsd.org (Postfix) with ESMTP id 607BB37B718
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 14 Mar 2001 03:46:44 -0800 (PST)
	(envelope-from alex@kapran.bitmcnit.bryansk.su)
Received: from server.bitmcnit.bryansk.su (root@bitmcnit.bryansk.su [192.168.121.2])
	by rbn-gw.bgtu.debryansk.ru (8.11.2/8.11.2) with ESMTP id f2EBjFC03807
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 14 Mar 2001 14:45:18 +0300
Received: (from uucp@localhost)
	by server.bitmcnit.bryansk.su (8.9.3/8.9.3) with UUCP id OAA30336
	for FreeBSD-gnats-submit@freebsd.org; Wed, 14 Mar 2001 14:30:01 +0300
Received: (from alex@localhost)
	by kapran.bitmcnit.bryansk.su (8.11.3/8.11.3) id f2EBN3n00805;
	Wed, 14 Mar 2001 14:23:03 +0300 (MSK)
	(envelope-from alex)
Message-Id: <200103141123.f2EBN3n00805@kapran.bitmcnit.bryansk.su>
Date: Wed, 14 Mar 2001 14:23:03 +0300 (MSK)
From: Alex Kapranoff <alex@kapran.bitmcnit.bryansk.su>
Reply-To: alex@kapran.bitmcnit.bryansk.su
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: pcm doesn't always autocreate device aliases w/ DEVFS
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         25799
>Category:       kern
>Synopsis:       pcm doesn't always autocreate device aliases w/ DEVFS
>Confidential:   no
>Severity:       non-critical
>Priority:       high
>Responsible:    cg
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Mar 14 03:50:01 PST 2001
>Closed-Date:    Sun Apr 8 14:28:26 PDT 2001
>Last-Modified:  Sun Apr 08 14:29:11 PDT 2001
>Originator:     Alex Kapranoff
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
Internal Mongolia
>Environment:

System: FreeBSD kapran.bitmcnit.bryansk.su 5.0-CURRENT FreeBSD 5.0-CURRENT #2: Wed Mar 14 11:06:41 MSK 2001 root@kapran.bitmcnit.bryansk.su:/usr/src/sys/compile/KAPRAN i386

I have an old ISA non-PNP Sound Blaster 16 Vibra. It probes as
follows:

sbc0: <SoundBlaster 16> at port 0x220-0x22f irq 5 drq 1 flags 0x15 on isa0
pcm1: <SB16 DSP 4.13> on sbc0

using the following /boot/device.hints:

hint.pcm.0.at="isa"
hint.pcm.0.irq="5"
hint.pcm.0.drq="1"
hint.pcm.0.flags="0x15"
hint.sbc.0.at="isa"
hint.sbc.0.port="0x220"
hint.sbc.0.irq="5"
hint.sbc.0.drq="1"
hint.sbc.0.flags="0x15"

I use DEVFS.

>Description:

I have the following sound-related devices in /dev after boot:

crw-rw-rw-  1 root  wheel      30,  20 14  13:39 /dev/audio1.0
crw-rw-rw-  1 root  wheel      30, 0x00010014 14  13:39 /dev/audio1.1
crw-rw-rw-  1 root  wheel      30,  19 14  13:39 /dev/dsp1.0
crw-rw-rw-  1 root  wheel      30, 0x00010013 14  13:39 /dev/dsp1.1
crw-rw-rw-  1 root  wheel      30,  21 14  13:39 /dev/dspW1.0
crw-rw-rw-  1 root  wheel      30, 0x00010015 14  13:39 /dev/dspW1.1
crw-rw-rw-  1 root  wheel      30,  16 14  13:39 /dev/mixer1
cr--r--r--  1 root  wheel      30,   6 14  13:39 /dev/sndstat

And sysctl hw.snd.unit is (default value):
hw.snd.unit: 0

pcm driver does not create /dev/{audio,dsp,dspW,mixer} aliases because
it tries to use unit 0 (according to hw.snd.unit), whereas my box only
have unit 1. See /sys/dev/sound/pcm/sound.c:pcm_makelinks()

>How-To-Repeat:
	
>Fix:

First, you can set hw.snd.unit to 1 or whatever in your kernel
hints file or in /boot/device.hints.

Next, you can set hw.snd.unit to 1 by appending
'hw.snd.unit=1' to your /etc/rc.sysctl file.

And last. With proposed patch, hw.snd.unit defaults to '-1'
which now means 'autoselect the first existing unit for
making aliases in /dev'. This variant is prefered :)

This PR supercedes my old and rather lame kern/21308 so whoever cares
please close kern/21308 as soon as this one.

--- /sys/dev/sound/pcm/sound.c.orig	Wed Mar 14 10:57:40 2001
+++ sound.c	Wed Mar 14 13:46:23 2001
@@ -90,7 +90,7 @@
 
 #ifdef USING_DEVFS
 int snd_unit;
-TUNABLE_INT_DECL("hw.snd.unit", 0, snd_unit);
+TUNABLE_INT_DECL("hw.snd.unit", -1, snd_unit);
 #endif
 
 SYSCTL_NODE(_hw, OID_AUTO, snd, CTLFLAG_RD, 0, "Sound driver");
@@ -193,8 +193,16 @@
 	}
 
 	unit = snd_unit;
-	if (unit < 0 || unit > devclass_get_maxunit(pcm_devclass))
-		return;
+	if (unit == -1) {
+		/* find the first unit */
+		for(unit = 0;
+		    unit <= devclass_get_maxunit(pcm_devclass); ++unit)
+			if (devclass_get_softc(pcm_devclass, unit) != NULL)
+				break;
+	} else {
+		if (unit < 0 || unit > devclass_get_maxunit(pcm_devclass))
+			return;
+	}
 	if (devclass_get_softc(pcm_devclass, unit) == NULL)
 		return;
 
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->cg 
Responsible-Changed-By: kris 
Responsible-Changed-When: Fri Mar 23 21:51:15 PST 2001 
Responsible-Changed-Why:  
Cameron is the sound guy 

http://www.freebsd.org/cgi/query-pr.cgi?pr=25799 

From: "Cameron Grant" <gandalf@vilnya.demon.co.uk>
To: <freebsd-gnats-submit@FreeBSD.org>,
	<alex@kapran.bitmcnit.bryansk.su>
Cc:  
Subject: Re: kern/25799: pcm doesn't always autocreate device aliases w/ DEVFS
Date: Sat, 24 Mar 2001 17:13:09 -0000

 your hints for pcm0 are invalid.  for an sb16, pcm will attach to sbc
 automatically.  you are creating a phantom pcm0 device.
 
 on a correctly configured system, the first sound device will always be
 pcm0, so this patch is unnecessary.
 
     -cg
 
 

From: Alex Kapranoff <alex@kapran.bitmcnit.bryansk.su>
To: Cameron Grant <gandalf@vilnya.demon.co.uk>
Cc: freebsd-gnats-submit@freebsd.org
Subject: Re: kern/25799: pcm doesn't always autocreate device aliases w/ DEVFS
Date: Sun, 25 Mar 2001 09:54:51 +0400

 On Sat, Mar 24, 2001 at 05:13:09PM -0000, Cameron Grant wrote:
 > your hints for pcm0 are invalid.  for an sb16, pcm will attach to sbc
 > automatically.  you are creating a phantom pcm0 device.
 
   I've just cleared my hints file from old cruft generated by
 `gethints.pl' when I first ran it long long time ago. And indeed pcm1
 weirdness has gone away. I now have pretty straightforward sbc0 & pcm0
 pair. Thanks for your advice, Cameron!
 
 > on a correctly configured system, the first sound device will always be
 > pcm0, so this patch is unnecessary.
 
   Yes, and therefore PR should be closed now.
 
   Thanks again for the wonderful sound experience I have with FreeBSD :)
 
 -- 
 Alex Kapranoff,                              Voice: +7(0832)791845
 We've lived 11 weeks in the brand new millenium...
State-Changed-From-To: open->closed 
State-Changed-By: greid 
State-Changed-When: Sun Apr 8 14:28:26 PDT 2001 
State-Changed-Why:  
User error; submitter requests closure 

http://www.freebsd.org/cgi/query-pr.cgi?pr=25799 
>Unformatted:
