Home | History | Annotate | Download | only in dev
History log of /src/sys/dev/sequencer.c
RevisionDateAuthorComments
 1.84  17-Oct-2023  riastradh sequencer.c: Nix trailing whitespace.

No functional change intended.
 1.83  16-Oct-2023  oster Redo previous by making the DPRINT macro always expand to something.
 1.82  15-Oct-2023  oster When building kernel=ALL, make gcc happy by addressing its warning of:
"suggest braces around empty body in an 'if' statement".
 1.81  01-Jul-2022  riastradh sequencer(4): Fix lock leak in ioctl(FIOASYNC).

Reported-by: syzbot+0bfe9054ab0e70ab02e6@syzkaller.appspotmail.com
Reported-by: syzbot+f2c5459483e60dd2c877@syzkaller.appspotmail.com
Reported-by: syzbot+d932ddf0ec7e30784ca8@syzkaller.appspotmail.com

Note: The evidence from
https://syzkaller.appspot.com/bug?id=19e1c8779bb0e020188ca80a586e470b59d7525d
suggests in the stack trace that the syscall was 16, which is chown.
This is not accurate; it happens because the x86 syscall logic sets
rax in the trapframe to the return value (in this case, 16 is EBUSY)
_before_ calling userret which does the lockdebug checks, and ddb
uses the trapframe's rax to show what the syscall number was when
printing its stack trace:

[ 104.0605877] Mutex error: lwp_exit,1084: sleep lock held
[ 104.0605877] lock address : 0xffffd9801269e050 type : sleep/adaptive
...
[ 104.5005727] syscall() at netbsd:syscall+0x323 sys/arch/x86/x86/syscall.c:92
[ 104.5115909] --- syscall (number 16) ---

XXX Maybe we should record the syscall number elsewhere so this is
not so confusing -- second time in 24h I've been bitten by this, and
in a different way.
 1.80  04-Jun-2022  pgoyette Combine the midi and sequencer modules into a single midi_seq module
to avoid a circular dependency as noted in kern/56772. Retain minimal
modules of the original names to accomodate auto-loading upon access
to the /dev/xxx nodes.
 1.79  16-Apr-2022  riastradh sequencer(4): VOP_CLOSE requires vnode lock.

Reported-by: syzbot+877c50d819fea9403247@syzkaller.appspotmail.com
 1.78  16-Apr-2022  riastradh sequencer(4): Convert some #if DIAGNOSTIC to assertions.
 1.77  16-Apr-2022  riastradh sequencer(4): Sprinkle KNF.

- Sort includes.
- Nix trailing whitespace.
- No parens for return.
- Blank line between declarations and statements.
- Note MP bug with unit allocation.

No functional change intended.
 1.76  31-Mar-2022  pgoyette For device modules that provide both auto-config and /dev/xxx
interfaces, make sure that initialization and destruction
follow the proper sequence. This is triggered by the recent
changes to the devsw stuff; per riastradh@ the required call
sequence is:

devsw_attach()
config_init_component() or config_cf*_attach()
...
config_fini_component() or config_cf*_detach()
devsw_detach()

While here, add a few missing calls to some of the detach
routines.

Testing of these changes has been limited to:
1. compile without build break
2. no related test failures from atf
3. modload/modunload work as well as
before.

No functional device testing done, since I don't have any
of these devices. Let me know of any damage I might cause
here!

XXX Some of the modules affected by this commit are already
XXX broken; see kern/56772. This commit does not break
any additional modules (as far as I know).
 1.75  29-Mar-2022  riastradh sequencer(4): Don't use mutex_spin_exit on an IPL_NONE lock.
 1.74  26-Sep-2021  thorpej Change the kqueue filterops::f_isfd field to filterops::f_flags, and
define a flag FILTEROP_ISFD that has the meaning of the prior f_isfd.
Field and flag name aligned with OpenBSD.

This does not constitute a functional or ABI change, as the field location
and size, and the value placed in that field, are the same as the previous
code, but we're bumping __NetBSD_Version__ so 3rd-party module source code
can adapt, as needed.

NetBSD 9.99.89
 1.73  19-Dec-2020  thorpej Use sel{record,remove}_knote().
 1.72  23-May-2020  ad branches: 1.72.2;
Move proc_lock into the data segment. It was dynamically allocated because
at the time we had mutex_obj_alloc() but not __cacheline_aligned.
 1.71  25-Aug-2019  maxv Fix the size passed to memcpy, we only want 8 bytes. Found by KASAN.
 1.70  29-Oct-2017  riastradh branches: 1.70.4;
Provisionally return to declaring midi_cd unconditionally.

Apparently this breaks compiling some kernels, although how they ever
managed to link if midi_cd is not declared in ioconf.h, and therefore
presumably not defined in ioconf.c, is beyond me.

Maybe someone who knows how sequencer is supposed to work, and/or
someone who knows how arm kernels are linked, can figure this out...
 1.69  28-Oct-2017  riastradh Back out extern struct cfdriver -> ioconf.h change to sequencer.c.

This broke the module build, because it needs midi_cd which is defined
in another module and not declared by the ioconf.h generated from
sequencer.ioconf.

But... It also needs sequencer_cd, which is _also_ not declared by
the ioconf.h generated from sequencer.ioconf, nor defined in the
ioconf.c generated from sequencer.ioconf. Did this ever work???
 1.68  28-Oct-2017  riastradh Kill some more extern cfdriver xyz_cd in favour of #include "ioconf.h".
 1.67  25-Oct-2017  maya Use C99 initializer for filterops

Mostly done with spatch with touchups for indentation

@@
expression a;
identifier b,c,d;
identifier p;
@@
const struct filterops p =
- { a, b, c, d
+ {
+ .f_isfd = a,
+ .f_attach = b,
+ .f_detach = c,
+ .f_event = d,
};
 1.66  01-Jun-2017  pgoyette Add infrastructure for modularization of audio, midi, and sequencer
 1.65  01-Jun-2017  chs remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.
 1.64  20-Aug-2015  christos include "ioconf.h" to get the 'void <driver>attach(int count);' prototype.
 1.63  30-Dec-2014  mrg fix !AUDIO_DEBUG build.
 1.62  30-Dec-2014  mrg - fix a confusion between midi(4) unit and connected to sequencer
devices.
- minor comment/debug clean ups.

fixes problems attempting to read or write from the right midi(4)
device using the sequencer(4) device when one or more of the
non-final devices fails to open with midiseq_open().
 1.61  23-Dec-2014  mrg use __func__ in some debug messages.
 1.60  22-Dec-2014  mrg various clean ups for midi and sequencer:

midi specific:
- add reference counting for midi operations, and ensure that
detach waits for other threads to complete before tearing
down the device completely.
- in detach, halt midi callouts before destroying them
- re-check sc->dying after sleeping in midiread()
- in real_writebytes(), make sure we're open and not dying
- make sure we drop the interrupt lock before calling any code
that may want to check thread locks. this is now safe due to
the above changes.

sequencer specific:
- avoid caching the midi softc in the sequencer softc. instead,
every time we want to use it, look it up again and make sure
it still exists.


this fixes various crashes i've seen in the usb midi code when
detaching the umidi while it is active.
 1.59  25-Jul-2014  dholland branches: 1.59.2; 1.59.4;
Add d_discard to all struct cdevsw instances I could find.

All have been set to "nodiscard"; some should get a real implementation.
 1.58  16-Mar-2014  dholland branches: 1.58.2;
Change (mostly mechanically) every cdevsw/bdevsw I can find to use
designated initializers.

I have not built every extant kernel so I have probably broken at
least one build; however I've also found and fixed some wrong
cdevsw/bdevsw entries so even if so I think we come out ahead.
 1.57  17-Oct-2013  christos remove unused variables
 1.56  27-Apr-2013  christos branches: 1.56.4;
allocate dynamically
 1.55  09-Apr-2012  plunky branches: 1.55.2;
Tidy up a little, the way that midi attachment code works

- change midi_attach() to omit the 'parent' arg (there are
only two callers of this and it is not used)

- change midisyn_attach() to midisyn_init(), so not needing a midi_softc,
and fix the midi_pcppi driver to set hw_if and hw_hdl directly in
its midi_softc before calling midi_attach()

- add a device_t to opl_softc structure, change opl drivers to store
the device 'self' in opl_softc and fix opl_attach() to use this
opl_softc->dev field directly rather than a field in an otherwise
unused midi_softc

- remove unnecessary midi_softc from opl and cms drivers (child device
provides that)

reviewed by mrg
 1.54  13-Feb-2012  mrg call VOP_CLOSE() in the case we're bailing due to missing both read/write.
fixes vrelel() warnings when opening /dev/music on a device that doesn't
support the requested open flags.
 1.53  23-Nov-2011  jmcneill branches: 1.53.2;
Merge jmcneill-audiomp3 branch, which is derived from ad-audiomp2. From
the original ad-audiomp branch notes:

Add MP locking to the audio drivers.

Making the audio drivers MP safe is necessary before efforts
can be made to make the VM system MP safe.

The are two locks per device instance, an ISR lock and
a character device lock. The ISR lock replaces calls to
splaudio()/splx(), and will be held across calls to device
methods which were called at splaudio() before (e.g.
trigger_output). The character device lock is held across
calls to nearly all of the methods, excluding some only
used for initialization, e.g. get_locks.

Welcome to 5.99.57.
 1.52  18-Mar-2009  cegger branches: 1.52.12; 1.52.14;
Ansify function definitions w/o arguments. Generated with sed.
 1.51  11-Jan-2009  cegger branches: 1.51.2;
make this compile
 1.50  15-Jul-2008  christos branches: 1.50.2; 1.50.6;
Use more timespecs internally. From Alexander Shishkin and me.
Welcome to 4.99.70, 30 more to go for 100.
 1.49  12-Jun-2008  cegger branches: 1.49.2;
use device_lookup_private to get softc
 1.48  28-Apr-2008  martin branches: 1.48.2; 1.48.4;
Remove clause 3 and 4 from TNF licenses
 1.47  24-Apr-2008  ad branches: 1.47.2;
Network protocol interrupts can now block on locks, so merge the globals
proclist_mutex and proclist_lock into a single adaptive mutex (proc_lock).
Implications:

- Inspecting process state requires thread context, so signals can no longer
be sent from a hardware interrupt handler. Signal activity must be
deferred to a soft interrupt or kthread.

- As the proc state locking is simplified, it's now safe to take exit()
and wait() out from under kernel_lock.

- The system spends less time at IPL_SCHED, and there is less lock activity.
 1.46  21-Mar-2008  plunky branches: 1.46.2;
use devsw_name2chr() to look up the major number of the midi device as
it is a character device
 1.45  04-Mar-2008  cube Split device_t/softc for midi(4), and other related cosmetic changes.
 1.44  01-Mar-2008  rmind Welcome to 4.99.55:

- Add a lot of missing selinit() and seldestroy() calls.

- Merge selwakeup() and selnotify() calls into a single selnotify().

- Add an additional 'events' argument to selnotify() call. It will
indicate which event (POLL_IN, POLL_OUT, etc) happen. If unknown,
zero may be used.

Note: please pass appropriate value of 'events' where possible.
Proposed on: <tech-kern>
 1.43  05-Dec-2007  pooka branches: 1.43.8; 1.43.12;
Do not "return 1" from kqfilter for errors. That value is passed
directly to the userland caller and results in a mysterious EPERM.
Instead, return EINVAL or something else sensible depending on the
case.
 1.42  08-Oct-2007  ad branches: 1.42.4; 1.42.6;
Use the softint API.
 1.41  09-Jul-2007  ad branches: 1.41.6; 1.41.8; 1.41.10;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.40  04-Mar-2007  christos branches: 1.40.2; 1.40.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.39  09-Feb-2007  ad branches: 1.39.2;
Merge newlock2 to head.
 1.38  24-Nov-2006  christos fix spelling of accommodate; from Zapher.
 1.37  16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.36  22-Oct-2006  pooka make compile for NMIDI == 0
 1.35  12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.34  03-Sep-2006  christos branches: 1.34.2; 1.34.4;
- add missing initializer
- comment out impossible comparison
 1.33  17-Aug-2006  christos Fix all the -D*DEBUG* code that it was rotting away and did not even compile.
Mostly from Arnaud Lacombe, many thanks!
 1.32  30-Jun-2006  chap Ankh-Morpork, we have a MIDI driver....

Merge from chap-midi branch, after
~month for review
Comments by thorpej@ drochner@ and Alexandre Ratchov

Incorporated: points by thorpej@ drochner@; preliminary support for
a stats-collecting ioctl suggested by martin@ from comments by A.R.

PR kern/32441 kern/32442 kern/32567 kern/32588 kern/32694 kern/33590
kern/33614 and one instance of kern/32651

ok martin@
 1.31  28-Jun-2006  tron Actually initialize the "struct midi_info" in midi_getinfo().
Problem found by GCC 4.x.
 1.30  11-Dec-2005  christos branches: 1.30.4; 1.30.8; 1.30.14; 1.30.16;
merge ktrace-lwp.
 1.29  01-Jun-2005  drochner branches: 1.29.2;
more cast-qual and shadow fallout
 1.28  29-May-2005  christos - add const
- avoid variable shadowing.
 1.27  27-Feb-2005  perry nuke trailing whitespace
 1.26  04-Feb-2005  perry de-__P
 1.25  04-Dec-2003  keihan branches: 1.25.8; 1.25.10;
netbsd.org -> NetBSD.org

This was the last commit of this kind to src/sys, which is now totally
"NetBSD.org clean". Thanks for the patiance, and sorry for all the commits.
 1.24  29-Jun-2003  fvdl branches: 1.24.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.
 1.23  28-Jun-2003  darrenr Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V
 1.22  26-Nov-2002  christos si_ -> sel_
 1.21  23-Oct-2002  jdolecek merge kqueue branch into -current

kqueue provides a stateful and efficient event notification framework
currently supported events include socket, file, directory, fifo,
pipe, tty and device changes, and monitoring of processes and signals

kqueue is supported by all writable filesystems in NetBSD tree
(with exception of Coda) and all device drivers supporting poll(2)

based on work done by Jonathan Lemon for FreeBSD
initial NetBSD port done by Luke Mewburn and Jason Thorpe
 1.20  06-Sep-2002  gehenna Merge the gehenna-devsw branch into the trunk.

This merge changes the device switch tables from static array to
dynamically generated by config(8).

- All device switches is defined as a constant structure in device drivers.

- The new grammer ``device-major'' is introduced to ``files''.

device-major <prefix> char <num> [block <num>] [<rules>]

- All device major numbers must be listed up in port dependent majors.<arch>
by using this grammer.

- Added the new naming convention.
The name of the device switch must be <prefix>_[bc]devsw for auto-generation
of device switch tables.

- The backward compatibility of loading block/character device
switch by LKM framework is broken. This is necessary to convert
from block/character device major to device name in runtime and vice versa.

- The restriction to assign device major by LKM is completely removed.
We don't need to reserve LKM entries for dynamic loading of device switch.

- In compile time, device major numbers list is packed into the kernel and
the LKM framework will refer it to assign device major number dynamically.
 1.19  13-Jan-2002  tsutsui branches: 1.19.8;
Call malloc(9) with M_ZERO flag instead of memset() after malloc().
 1.18  13-Nov-2001  lukem remove superfluous NSEQUENCER > 0 test
 1.17  13-Nov-2001  lukem add RCSIDs
 1.16  03-Sep-2001  reinoud branches: 1.16.2;
Make it compile again when AUDIO_DEBUG is turned on ... in sequencesread
and sequencerwrite were two debug messages that had a type conflict in the
printf. I put in a (int) to solve it.
 1.15  23-Mar-2000  thorpej branches: 1.15.6; 1.15.8;
New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.14  11-Oct-1999  augustss branches: 1.14.2;
Allow larger timer variation.
 1.13  25-Nov-1998  augustss branches: 1.13.10;
Make the copyright header conform to the NetBSD template.
 1.12  20-Oct-1998  augustss Make seq_input_event() static to avoid a name clash with the (commercial)
OSS audio LKM.
 1.11  05-Oct-1998  augustss Make MIDI input work again.
Fix from Torsten Duwe <duwe@ns.lst.de>.
 1.10  24-Aug-1998  augustss Write MIDI data from the sequencer to the device in a more sane way.
 1.9  20-Aug-1998  augustss Provide a workaround for people who want a sequencer but have no MIDI devices.
 1.8  17-Aug-1998  augustss * Redo the way the way the MIDI driver attaches to audio devices.
* Improve the midisyn layer a little.
* Add a driver for the Yamaha OPL[23] FM synths.
The opl driver is not finished yet; it sounds pretty awful.

For some strange reason I cannot get any FM sound from my SB64 cards,
but a regular SB16 works fine.
 1.7  13-Aug-1998  augustss Make sure to turn off timeout flag when doing untimeout().
 1.6  13-Aug-1998  augustss Fix typo in SYSEX code.
 1.5  13-Aug-1998  augustss Remove some leftover fluff.
Make sure there is no outstanding timeout when the sequencer is closed.
 1.4  12-Aug-1998  augustss Handle SYSEX messages.
 1.3  12-Aug-1998  augustss Tidy up and rename some functions in the MIDI driver.
 1.2  07-Aug-1998  augustss Report a sensible MIDI device name.
 1.1  07-Aug-1998  augustss Add MIDI support. The MIDI devices can be accessed as ``raw'' through
the /dev/rmidiN devices, or with a sequencer interface via /dev/music.
So far the only supported MIDI device is the MPU401 port on SoundBlaster
(and only on SB on isapnp, since we do not have locators with multiple
values yet).
 1.13.10.1  27-Dec-1999  wrstuden Pull up to last week's -current.
 1.14.2.1  20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.15.8.6  10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.15.8.5  02-Oct-2002  jdolecek do not need the (void *) cast for kn_hook anymore
 1.15.8.4  11-Feb-2002  jdolecek Sync w/ -current.
 1.15.8.3  10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.15.8.2  13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.15.8.1  08-Sep-2001  thorpej Add kqueue support (someone who understands the sequencer code
should make sure I got this right).
 1.15.6.6  11-Dec-2002  thorpej Sync with HEAD.
 1.15.6.5  11-Nov-2002  nathanw Catch up to -current
 1.15.6.4  17-Sep-2002  nathanw Catch up to -current.
 1.15.6.3  28-Feb-2002  nathanw Catch up to -current.
 1.15.6.2  14-Nov-2001  nathanw Catch up to -current.
 1.15.6.1  21-Sep-2001  nathanw Catch up to -current.
 1.16.2.4  26-Sep-2001  fvdl * add a VCLONED vnode flag that indicates a vnode representing a cloned
device.
* rename REVOKEALL to REVOKEALIAS, and add a REVOKECLONE flag, to pass
to VOP_REVOKE
* the revoke system call will revoke all aliases, as before, but not the
clones
* vdevgone is called when detaching a device, so make it use REVOKECLONE
to get rid of all clones as well
* clean up all uses of VOP_OPEN wrt. locking.
* add a few VOPS to spec_vnops that need to do something when it's a
clone vnode (access and getattr)
* add a copy of the vnode vattr structure of the original 'master' vnode
to the specinfo of a cloned vnode. could possibly redirect getattr to
the 'master' vnode, but this has issues with revoke
* add a vdev_reassignvp function that disassociates a vnode from its
original device, and reassociates it with the specified dev_t. to be
used by cloning devices only, in case a new minor is allocated.
* change all direct references in drivers to v_devcookie and v_rdev
to vdev_privdata(vp) and vdev_rdev(vp). for diagnostic purposes
when debugging race conditions that still exist wrt. locking and
revoking vnodes.
* make the locking state of a vnode consistent when passed to
d_open and d_close (unlocked). locked would be better, but has
some deadlock issues
 1.16.2.3  21-Sep-2001  fvdl Attempt to clean up the sequencer code a bit, with only 50% success.
 1.16.2.2  18-Sep-2001  fvdl Various changes to make cloning devices possible:

* Add an extra argument (struct vnode **) to VOP_OPEN. If it is
not NULL, specfs will create a cloned (aliased) vnode during
the call, and return it there. The caller should release and
unlock the original vnode if a new vnode was returned. The
new vnode is returned locked.

* Add a flag field to the cdevsw and bdevsw structures.
DF_CLONING indicates that it wants a new vnode for each
open (XXX is there a better way? devprop?)

* If a device is cloning, always call the close entry
point for a VOP_CLOSE.


Also, rewrite cons.c to do the right thing with vnodes. Use VOPs
rather then direct device entry calls. Suggested by mycroft@

Light to moderate testing done an i386 system (arch doesn't matter
though, these are MI changes).
 1.16.2.1  07-Sep-2001  thorpej Commit my "devvp" changes to the thorpej-devvp branch. This
replaces the use of dev_t in most places with a struct vnode *.

This will form the basic infrastructure for real cloning device
support (besides being architecurally cleaner -- it'll be good
to get away from using numbers to represent objects).
 1.19.8.1  16-May-2002  gehenna Add the character device switch.
Replace the direct-access to devsw table with calling devsw API.
 1.24.2.7  10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.24.2.6  04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.24.2.5  04-Feb-2005  skrll Sync with HEAD.
 1.24.2.4  21-Sep-2004  skrll Fix the sync with head I botched.
 1.24.2.3  18-Sep-2004  skrll Sync with HEAD.
 1.24.2.2  03-Aug-2004  skrll Sync with HEAD
 1.24.2.1  02-Jul-2003  darrenr Apply the aborted ktrace-lwp changes to a specific branch. This is just for
others to review, I'm concerned that patch fuziness may have resulted in some
errant code being generated but I'll look at that later by comparing the diff
from the base to the branch with the file I attempt to apply to it. This will,
at the very least, put the changes in a better context for others to review
them and attempt to tinker with removing passing of 'struct lwp' through
the kernel.
 1.25.10.2  19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.25.10.1  12-Feb-2005  yamt sync with head.
 1.25.8.1  29-Apr-2005  kent sync with -current
 1.29.2.8  24-Mar-2008  yamt sync with head.
 1.29.2.7  17-Mar-2008  yamt sync with head.
 1.29.2.6  07-Dec-2007  yamt sync with head
 1.29.2.5  27-Oct-2007  yamt sync with head.
 1.29.2.4  03-Sep-2007  yamt sync with head.
 1.29.2.3  26-Feb-2007  yamt sync with head.
 1.29.2.2  30-Dec-2006  yamt sync with head.
 1.29.2.1  21-Jun-2006  yamt sync with head.
 1.30.16.1  13-Jul-2006  gdamore Merge from HEAD.
 1.30.14.21  01-Jun-2006  chap Updating midiplay(1) to support the SYSEX CONTINUATION and ESCAPED events
that may appear in MIDI files revealed that the /dev/music API still needs
to expose the MIDIPUTC event from /dev/sequencer (to support ESCAPED); I
also noticed the sequencer was keeping some state globally that should be
per device.
 1.30.14.20  31-May-2006  chap PR kern/33614.

Rework of midiplay(1) to use sequencer facilities for tempo change (rather
than setting the sequencer for one tempo and doing all its own scaling)
exposed a hitherto concealed bug in sequencer tempo change handling.

Also took the opportunity to clarify some field names and add spl calls
in the top half to avoid concurrent access with the bottom to the timer.
 1.30.14.19  25-May-2006  chap File-scope the functions that don't need to be global.
 1.30.14.18  25-May-2006  chap ANSI/KNF the sequencer function declarations.
 1.30.14.17  25-May-2006  chap Refactored sequencer to use the native API (now that there is one), and
updated the MIDI controller list in midiio.h.

It would be worth confirming that sequencer.c compiles on vax. It should.
 1.30.14.16  20-May-2006  chap Now for Phase Two. The patched files have been rolled forward again, with
a naive mechanical resolution of conflicts. Now to compare the diffs and
make sure the resolutions made sense. Sleep first.
 1.30.14.15  20-May-2006  chap Learned of two ugly corners in MIDI protocol that made the state machine
overly pedantic. Both have to do with the End SysEx byte, 0xf7. First, it
is allowed not only at the end of a SysEx message, but anywhere else any
status byte can appear (and in that case has no meaning). Second, it is
not even required at the end of a SysEx message - any subsequent status
byte implicitly ends the SysEx, and this is not considered an error.

I don't like these provisions because they make it even harder to detect
errors in a corrupted MIDI stream, but as MIDI gets sent increasingly over
error-correcting transports I suppose that is less of a concern. In any
case, though midi(4) will accept data (input from device or data from
write(2)) with stray or dropped End SysEx bytes, it will always ensure
that output to the device, and data for read(2), has End SysEx only and
always at the ends of SysEx messages.
 1.30.14.14  20-May-2006  chap Spotted a bug in a buffer condition. Never saw any symptom, but it's a
bug nonetheless.
 1.30.14.13  20-May-2006  chap The two choices CN_SEQ_GLOBAL and CN_SEQ_PER_EP cannot cover all devices,
some are wired arbitrarily oddly and need a CN_FIXED quirk to specify
the cable number mappings explicitly. But then as a result of those
mappings, the automatically bound mididevice unit numbers might not match
the order of the device's physical jacks or blinkenlights, so an MD_FIXED
quirk is needed to specify that order as well. It turns out the cn_base
field added earlier was neither necessary (at the time) nor sufficient
(to handle CN_FIXED), so it's gone now.

Q: How do you tell when you've got the cable number associations wrong on
a Midisport 2x4?
A: Everything works right except data-rate throttling - you'll be able to
send data to certain ports at rates far in excess of the MIDI data rate
(and lose most of it). If you never transmit that fast, you'll never
notice.

So testing for a sane data transfer rate (use dd to blast a stream of MIDI
data at the rmidi device, it'll report the rate on completion) is probably
a wise testing step when adding support for a new umidi device.
 1.30.14.12  20-May-2006  chap Patch to account explicitly for the prior inconsistency in the treatment of
cable numbers. Also contains a (functionally insignificant) change to the
declaration of endpoint buffers introduced in kern/32441, which will be
useful in a forthcoming patch. This patch should be fuzz-free on 2.0
source after the 32441 and 32442 patches.
 1.30.14.11  20-May-2006  chap Active Sense now handled for receive as well as for transmit. Following the
spec, if no Active Sense is seen on receive, no special behavior applies,
but if an Active Sense is seen then any absence of received data exceeding
300ms thereafter will be signalled as a read EOF on the rmidi device.
Receipt of any further data will clear the EOF condition, and operation
resumes as if no Active Sense has been seen.

Also moved some selnotify's out of locks so they don't deadlock against
the corresponding kevent filters.

This concludes this round of midi hacking (except for possibly improving
the safety of how pending callouts and interrupts are canceled on device
detach. Other fixes/enhancements to the midi subsystems will get their
own patches.
 1.30.14.10  20-May-2006  chap The FST now handles the equivalence between NoteOn (velocity 0) and a
NoteOff with velocity 64, both for canonicalizing (always produce NoteOff)
and compressing (produce whichever allows a current running status to be
exploited). The code from sequencer that attempted to model this behavior
and running status has been superseded and removed. Also removed the
EBADF checks I added to sequencer earlier, as they're handled in a layer
above.
 1.30.14.9  20-May-2006  chap umidi now uses hw_if_ext and no longer has its own approximate midi state
machine. This patch is relative to umidi.c and umidivar.h already patched
by midiman.pat (kern/32441).
 1.30.14.8  20-May-2006  chap Added hw_if_ext for hw drivers that want their messages intact rather than
byte by byte. Works with midisyn - must still integrate and test with
umidi.
 1.30.14.7  20-May-2006  chap The DFA (well, technically it's really a FST - a DFA with output) is now
used for transmit as well as receive; it's run at the upstream end of
each pipe (the receive interrupt for receive, the write call for transmit)
so that protocol errors can be detected as soon as possible, and erroneous
data won't fill the buffer. Implemented a guarantee that read(2) on the
raw device returns as many complete messages as will fit in the read
request, so the user program does not have to parse around read boundaries
(except for SysEx). Required a new buffer scheme that preserves message
boundaries. (A little like reinventing STREAMS, hmm...) Implemented
FIONREAD. New approach to sharing the cpu during output to interrupt-
challenged devices.

umidi happens to work now even in the presence of Active Sense, as the
transmit FST ensures the Active Sense doesn't appear in the midst of
another message, and right now the FST is always in canonicalizing mode
so there is no running status to disturb. That's half accident though, and
doesn't work for midisyn (which treats any System Common message as SysEx,
argh). The right solution will be to allow message-based drivers like umidi
and midisyn to get their data via a message-at-a-time interface, rather
than splitting the messages into bytes for lower drivers to reassemble
wrong.
 1.30.14.6  20-May-2006  chap Receive dfa factored out and made usable for both receive and transmit.
So far so good. Now to rewire transmit to use it.
 1.30.14.5  20-May-2006  chap Implement Active Sense on transmit. The same callout used by
midi_start_output for brief delays in output is now also scheduled
for 285 ms if there is nothing to transmit, and will send an Active Sense
at that time if there is nothing else to go; this will keep the receiving
equipment expecting our Active Sense and ensure that notes will stop
sounding when it ceases (either because we close normally, or we hang,
or someone trips over a cable). Sounds simple enough but involved a new
locking strategy, because we used to block out user_incurred start_output
whenever the device interrupt or callout was pending, but in the case of
the 285ms callout we /want/ to let a user write through and cancel the
callout (and avoid races, etc). Also moved the callout_init into
midi_attach because midiattach was not called in all cases, and added
a callout_stop in detach (though it is not yet quite up to all cases where
the callout may have been fired but not yet run at the time of detach -
nothing is easy.)

Surprisingly, the Active Sense works almost right over umidi: umidi's
state machine isn't smart enough to pass it through a packet being built,
and makes garbage instead, but a Yamaha keyboard at least is happy to
accept a bit of garbage within 300 ms as a sign we're still alive. :)

Now to go do a better state machine for output. :/ It shouldn't be in
umidi; it should be in midi, done once and done right; there should be
no need to have slightly different replicas of the midi state machine
all over the kernel ... I think there's one in sequencer too.
 1.30.14.4  20-May-2006  chap Take open modes seriously: do not write if not open for writing, or read
if not open for reading, or if the midi device cannot read. In sequencer,
open only the midi devices that support at least one of the open modes
wanted; so, if the sequencer is opened for reading only, do not bother
opening midi devices that cannot input. Do not write anything to the
midi devices if opened for reading only; seq_reset previously wrote a
bunch of initial settings, which could lead to long timeouts in seq_drain
on close because of data in the output buffer that could not go anywhere.

TODO: sending initial settings is the less important thing for seq_reset
to do; the most important is to reset the buffers so the playing stops!
At present, it doesn't do that at all.
 1.30.14.3  20-May-2006  chap Fixes a bug in midi_unit_count.

Dropped byte and message counters now use evcnt.

My state machine could treat an invalid SystemCommon message or out-of-
sequence EndSysex (all protocol errors anyway) as /mishandled/ protocol
errors if encountered in certain states. Fixed.
 1.30.14.2  20-May-2006  chap Replaces the state machine in midi.c with a full, pedantically correct,
error detecting one. Rearranges some DPRINTFN debug levels to make it
easier to get the level of debug information wanted. Applies to 2.0.
 1.30.14.1  20-May-2006  chap Now for Phase One. The patches to be applied in sequence were created
and tested against 2.0 sources. To begin, let CVS roll the affected files
back to that historic state. The reverse operation will be used (and
will involve some manual merging) after the patches have been applied.
Naturally, intermediate stages on this branch will not be directly
compilable (unless merged into a 2.0 checkout).
 1.30.8.2  03-Sep-2006  yamt sync with head.
 1.30.8.1  11-Aug-2006  yamt sync with head
 1.30.4.1  09-Sep-2006  rpaulo sync with head
 1.34.4.2  10-Dec-2006  yamt sync with head.
 1.34.4.1  22-Oct-2006  yamt sync with head
 1.34.2.4  27-Jan-2007  ad Don't call selnotify() or psignal() while above IPL_VM: defer them to a
soft interrupt.
 1.34.2.3  19-Jan-2007  ad Acquire proclist_mutex before sending signals.
 1.34.2.2  12-Jan-2007  ad Sync with head.
 1.34.2.1  18-Nov-2006  ad Sync with head.
 1.39.2.1  12-Mar-2007  rmind Sync with HEAD.
 1.40.4.1  11-Jul-2007  mjf Sync with head.
 1.40.2.3  01-Jul-2007  ad Adapt to callout API change.
 1.40.2.2  17-Jun-2007  ad - Increase the number of thread priorities from 128 to 256. How the space
is set up is to be revisited.
- Implement soft interrupts as kernel threads. A generic implementation
is provided, with hooks for fast-path MD code that can run the interrupt
threads over the top of other threads executing in the kernel.
- Split vnode::v_flag into three fields, depending on how the flag is
locked (by the interlock, by the vnode lock, by the file system).
- Miscellaneous locking fixes and improvements.
 1.40.2.1  13-May-2007  ad Catch up with the cdev/bdev changes.
 1.41.10.1  14-Oct-2007  yamt sync with head.
 1.41.8.3  23-Mar-2008  matt sync with HEAD
 1.41.8.2  09-Jan-2008  matt sync with HEAD
 1.41.8.1  06-Nov-2007  matt sync with HEAD
 1.41.6.2  09-Dec-2007  jmcneill Sync with HEAD.
 1.41.6.1  26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.42.6.1  08-Dec-2007  ad Sync with head.
 1.42.4.1  08-Dec-2007  mjf Sync with HEAD.
 1.43.12.6  17-Jan-2009  mjf Sync with HEAD.
 1.43.12.5  28-Sep-2008  mjf Sync with HEAD.
 1.43.12.4  29-Jun-2008  mjf Sync with HEAD.
 1.43.12.3  02-Jun-2008  mjf Sync with HEAD.
 1.43.12.2  05-Apr-2008  mjf - add "file-system DEVFS" and "pseudo-device devfsctl" to conf/std seeing
as these are always needed.

- convert many, many drivers over to the New Devfs World Order. For a
list of device drivers yet to be converted see,
http://www.netbsd.org/~mjf/devfs-todo.html.

- add a new device_unregister_all(device_t) function to remove all device
names associated with a device_t, which saves us having to construct
device names when the driver is detached.

- add a DEV_AUDIO type for devices.
 1.43.12.1  03-Apr-2008  mjf Sync with HEAD.
 1.43.8.1  24-Mar-2008  keiichi sync with head.
 1.46.2.2  17-Jun-2008  yamt sync with head.
 1.46.2.1  18-May-2008  yamt sync with head.
 1.47.2.2  04-May-2009  yamt sync with head.
 1.47.2.1  16-May-2008  yamt sync with head.
 1.48.4.2  18-Jul-2008  simonb Sync with head.
 1.48.4.1  18-Jun-2008  simonb Sync with head.
 1.48.2.2  18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.48.2.1  23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.49.2.1  19-Oct-2008  haad Sync with HEAD.
 1.50.6.2  12-Dec-2008  ad Checkpoint work in progress.
 1.50.6.1  09-Dec-2008  ad Checkpoint work on MIDI.
 1.50.2.2  28-Apr-2009  skrll Sync with HEAD.
 1.50.2.1  19-Jan-2009  skrll Sync with HEAD.
 1.51.2.1  13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.52.14.4  22-Nov-2011  mrg more steps towards making this work:
- avoid using uninitialised memory to get a pointer, this fixes
hangs in sequencerwrite() and general mayhem when it corrupts
random other memory.
- re-take sc->lock in sequencewrite() when continuing from the
main loop.
 1.52.14.3  22-Nov-2011  mrg adjust DPRINTF*() calls to actually build.
avoid a potential NULl pointer deref.
 1.52.14.2  20-Nov-2011  jmcneill avoid passing size 0 to kmem_alloc when the sequencer device is opened and
no midi devices are attached
 1.52.14.1  19-Nov-2011  jmcneill port ad-audiomp2 branch changes to 5.99.56
todo:
- port ad-audiomp2 pcppi changes
- these drivers need to be fixed:
- emuxki
- gcscaudio
- hdafg
- uaudio
- umidi
- MD audio drivers
 1.52.12.2  22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.52.12.1  17-Apr-2012  yamt sync with head
 1.53.2.2  29-Apr-2012  mrg sync to latest -current.
 1.53.2.1  18-Feb-2012  mrg merge to -current.
 1.55.2.3  03-Dec-2017  jdolecek update from HEAD
 1.55.2.2  20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.55.2.1  23-Jun-2013  tls resync from head
 1.56.4.1  18-May-2014  rmind sync with head
 1.58.2.1  10-Aug-2014  tls Rebase.
 1.59.4.3  28-Aug-2017  skrll Sync with HEAD
 1.59.4.2  22-Sep-2015  skrll Sync with HEAD
 1.59.4.1  06-Apr-2015  skrll Sync with HEAD
 1.59.2.1  11-Jan-2015  martin Pull up following revision(s) (requested by mrg in ticket #407):
sys/dev/midivar.h: revision 1.20
sys/dev/usb/umidivar.h: file removal
sys/dev/midi.c: revision 1.82
sys/dev/midi.c: revision 1.83
sys/dev/usb/FILES: revision 1.13
sys/dev/midi_if.h: revision 1.26
sys/dev/sequencer.c: revision 1.60
sys/dev/sequencer.c: revision 1.61
sys/dev/sequencer.c: revision 1.62
sys/dev/sequencer.c: revision 1.63
sys/dev/usb/umidi_quirks.c: revision 1.19
sys/dev/usb/umidi.c: revision 1.66
sys/dev/usb/umidi.c: revision 1.67
sys/dev/usb/umidi.c: revision 1.68
sys/dev/usb/umidireg.h: file removal
sys/dev/sequencervar.h: revision 1.17
fix the midi_if documentation to properly describe the locks that will
be held during various operations.
various umidi clean ups:
- move the contents of umidi{reg,var}.h into umidi.c directly as they
are not referenced by any other file.
- remove the useless include of umidi{reg,var}.h from umidi_quirks.c.
- add reference counting and wait/broadcast support to the IO paths.
- fix the error handling in midi_attach() and midi_open().
- sprinkle KASSERT() in several places.
- drop the local interrupt lock before calling into various parts of
the USB code. fixes lockdebug issues, and likely hangs.
- rename "binded" member as "bound".
with these most of the panics and problems i've seen are gone. there
is still one lockdebug panic to deal with that happens when unplugging
umidi while midiplay(1) is running.
various clean ups for midi and sequencer:
midi specific:
- add reference counting for midi operations, and ensure that
detach waits for other threads to complete before tearing
down the device completely.
- in detach, halt midi callouts before destroying them
- re-check sc->dying after sleeping in midiread()
- in real_writebytes(), make sure we're open and not dying
- make sure we drop the interrupt lock before calling any code
that may want to check thread locks. this is now safe due to
the above changes.
sequencer specific:
- avoid caching the midi softc in the sequencer softc. instead,
every time we want to use it, look it up again and make sure
it still exists.
this fixes various crashes i've seen in the usb midi code when
detaching the umidi while it is active.
use __func__ in some debug messages.
- check sc->dying after sleeping in several more places, and
convert it into EIO error where necessary.
- remove a wrong additional mutex_exit() call.
- make sure to check sc->dying under the device lock.
- fix a confusion between midi(4) unit and connected to sequencer
devices.
- minor comment/debug clean ups.
fixes problems attempting to read or write from the right midi(4)
device using the sequencer(4) device when one or more of the
non-final devices fails to open with midiseq_open().
fix !AUDIO_DEBUG build.
CID/1261465: Dereference after NULL check.
CID/1261467: Unreachable code
actually fix one of the previous: don't test for NULL after deref.
 1.70.4.1  13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.72.2.1  03-Jan-2021  thorpej Sync w/ HEAD.

RSS XML Feed