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.
This commit is contained in:
pgoyette 2022-06-04 03:31:10 +00:00
parent 7e1677552f
commit d2d4d4364b
14 changed files with 300 additions and 150 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: files.audio,v 1.14 2020/01/25 19:22:05 jmcneill Exp $
# $NetBSD: files.audio,v 1.15 2022/06/04 03:31:10 pgoyette Exp $
defparam opt_audio.h AUDIO_BLK_MS
@ -23,7 +23,11 @@ file dev/audio/linear.c audio
file dev/audio/audio.c audio needs-flag
file dev/audio/audiobell.c spkr_audio needs-flag
file dev/audio/mulaw.c audio
file dev/midi.c midi needs-flag
file dev/midi.c midi | sequencer needs-flag
file dev/midi_mod.c midi | sequencer needs-flag
file dev/midi_seq_mod.c midi | sequencer needs-flag
file dev/midictl.c midisyn
file dev/midisyn.c midisyn
file dev/sequencer.c midi | sequencer needs-flag
file dev/sequencer_mod.c midi | sequencer needs-flag
file dev/spkr_audio.c spkr_audio needs-flag

View File

@ -1,4 +1,4 @@
# $NetBSD: files.dev,v 1.8 2021/10/10 13:03:09 jmcneill Exp $
# $NetBSD: files.dev,v 1.9 2022/06/04 03:31:10 pgoyette Exp $
file dev/bio.c bio needs-flag
file dev/ccd.c ccd
@ -22,7 +22,6 @@ file dev/mm.c kern # XXX
file dev/nullcons_subr.c nullcons needs-flag
file dev/radio.c radio needs-flag
file dev/random.c rnd needs-flag
file dev/sequencer.c sequencer needs-flag
file dev/video.c video needs-flag
file dev/vnd.c vnd
file dev/ipmi.c ipmi needs-flag

View File

@ -1,4 +1,4 @@
/* $NetBSD: midi.c,v 1.97 2022/05/22 11:27:35 andvar Exp $ */
/* $NetBSD: midi.c,v 1.98 2022/06/04 03:31:10 pgoyette Exp $ */
/*
* Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@ -31,11 +31,10 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: midi.c,v 1.97 2022/05/22 11:27:35 andvar Exp $");
__KERNEL_RCSID(0, "$NetBSD: midi.c,v 1.98 2022/06/04 03:31:10 pgoyette Exp $");
#ifdef _KERNEL_OPT
#include "midi.h"
#include "sequencer.h"
#endif
#include <sys/param.h>
@ -1900,45 +1899,3 @@ midi_attach_mi(const struct midi_hw_if *mhwp, void *hdlp, device_t dev)
}
#endif /* NMIDI > 0 || NMIDIBUS > 0 */
#ifdef _MODULE
#include "ioconf.c"
devmajor_t midi_bmajor = -1, midi_cmajor = -1;
#endif
MODULE(MODULE_CLASS_DRIVER, midi, "audio");
static int
midi_modcmd(modcmd_t cmd, void *arg)
{
int error = 0;
#ifdef _MODULE
switch (cmd) {
case MODULE_CMD_INIT:
error = devsw_attach(midi_cd.cd_name, NULL, &midi_bmajor,
&midi_cdevsw, &midi_cmajor);
if (error)
break;
error = config_init_component(cfdriver_ioconf_midi,
cfattach_ioconf_midi, cfdata_ioconf_midi);
if (error) {
devsw_detach(NULL, &midi_cdevsw);
}
break;
case MODULE_CMD_FINI:
error = config_fini_component(cfdriver_ioconf_midi,
cfattach_ioconf_midi, cfdata_ioconf_midi);
if (error == 0)
devsw_detach(NULL, &midi_cdevsw);
break;
default:
error = ENOTTY;
break;
}
#endif
return error;
}

63
sys/dev/midi_mod.c Normal file
View File

@ -0,0 +1,63 @@
/* $NetBSD: midi_mod.c,v 1.1 2022/06/04 03:31:10 pgoyette Exp $ */
/*
* Copyright (c) 2022 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Paul Goyette
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: midi_mod.c,v 1.1 2022/06/04 03:31:10 pgoyette Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/module.h>
/*
* The midi module itself doesn't do anything. It exists only to
* ensure that the combo-module for midi-plus-sequencer is loaded.
* This allows us to have both midi and sequencer code to refer
* to each other, avoiding a circular module dependency.
*/
MODULE(MODULE_CLASS_DRIVER, midi, "midi_seq");
static int
midi_modcmd(modcmd_t cmd, void *arg)
{
int error = 0;
switch (cmd) {
case MODULE_CMD_INIT:
case MODULE_CMD_FINI:
break;
default:
error = ENOTTY;
break;
}
return error;
}

123
sys/dev/midi_seq_mod.c Normal file
View File

@ -0,0 +1,123 @@
/* $NetBSD: midi_seq_mod.c,v 1.1 2022/06/04 03:31:10 pgoyette Exp $ */
/*
* Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Lennart Augustsson (augustss@NetBSD.org), (MIDI FST and Active
* Sense handling) Chapman Flack (chap@NetBSD.org), and Andrew Doran.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: midi_seq_mod.c,v 1.1 2022/06/04 03:31:10 pgoyette Exp $");
#ifdef _KERNEL_OPT
#include "midi.h"
#endif
#include <sys/param.h>
#include <sys/ioctl.h>
#include <sys/fcntl.h>
#include <sys/vnode.h>
#include <sys/select.h>
#include <sys/poll.h>
#include <sys/proc.h>
#include <sys/systm.h>
#include <sys/callout.h>
#include <sys/syslog.h>
#include <sys/kernel.h>
#include <sys/signalvar.h>
#include <sys/conf.h>
#include <sys/audioio.h>
#include <sys/midiio.h>
#include <sys/device.h>
#include <sys/intr.h>
#include <sys/module.h>
#include <dev/audio/audio_if.h>
#include <dev/midi_if.h>
#include <dev/midivar.h>
#include "ioconf.h"
extern struct cfdriver sequencer_cd;
extern struct cdevsw midi_cdevsw;
extern struct cdevsw sequencer_cdevsw;
#ifdef _MODULE
#include "ioconf.c"
CFDRIVER_DECL(sequencer, DV_DULL, NULL);
devmajor_t midi_bmajor = -1, midi_cmajor = -1;
devmajor_t sequencer_bmajor = -1, sequencer_cmajor = -1;
#endif
MODULE(MODULE_CLASS_DRIVER, midi_seq, "audio");
static int
midi_seq_modcmd(modcmd_t cmd, void *arg)
{
int error = 0;
#ifdef _MODULE
switch (cmd) {
case MODULE_CMD_INIT:
error = devsw_attach(midi_cd.cd_name, NULL, &midi_bmajor,
&midi_cdevsw, &midi_cmajor);
if (error)
break;
error = devsw_attach(sequencer_cd.cd_name,
NULL, &sequencer_bmajor,
&sequencer_cdevsw, &sequencer_cmajor);
if (error) {
devsw_detach(NULL, &midi_cdevsw);
break;
}
error = config_init_component(cfdriver_ioconf_midi_seq,
cfattach_ioconf_midi_seq, cfdata_ioconf_midi_seq);
if (error) {
devsw_detach(NULL, &sequencer_cdevsw);
devsw_detach(NULL, &midi_cdevsw);
}
break;
case MODULE_CMD_FINI:
error = config_fini_component(cfdriver_ioconf_midi_seq,
cfattach_ioconf_midi_seq, cfdata_ioconf_midi_seq);
if (error == 0) {
devsw_detach(NULL, &sequencer_cdevsw);
devsw_detach(NULL, &midi_cdevsw);
}
break;
default:
error = ENOTTY;
break;
}
#endif
return error;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: sequencer.c,v 1.79 2022/04/16 11:13:10 riastradh Exp $ */
/* $NetBSD: sequencer.c,v 1.80 2022/06/04 03:31:10 pgoyette Exp $ */
/*
* Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@ -55,10 +55,9 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sequencer.c,v 1.79 2022/04/16 11:13:10 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: sequencer.c,v 1.80 2022/06/04 03:31:10 pgoyette Exp $");
#ifdef _KERNEL_OPT
#include "sequencer.h"
#include "midi.h"
#endif
@ -76,7 +75,6 @@ __KERNEL_RCSID(0, "$NetBSD: sequencer.c,v 1.79 2022/04/16 11:13:10 riastradh Exp
#include <sys/kernel.h>
#include <sys/kmem.h>
#include <sys/midiio.h>
#include <sys/module.h>
#include <sys/pcq.h>
#include <sys/poll.h>
#include <sys/proc.h>
@ -1656,21 +1654,6 @@ midiseq_loadpatch(struct midi_dev *md,
static dev_type_open(midiopen);
static dev_type_close(midiclose);
const struct cdevsw midi_cdevsw = {
.d_open = midiopen,
.d_close = midiclose,
.d_read = noread,
.d_write = nowrite,
.d_ioctl = noioctl,
.d_stop = nostop,
.d_tty = notty,
.d_poll = nopoll,
.d_mmap = nommap,
.d_kqfilter = nokqfilter,
.d_discard = nodiscard,
.d_flag = D_OTHER | D_MPSAFE
};
/*
* If someone has a sequencer, but no midi devices there will
* be unresolved references, so we provide little stubs.
@ -1688,8 +1671,6 @@ midiopen(dev_t dev, int flags, int ifmt, struct lwp *l)
return ENXIO;
}
struct cfdriver midi_cd;
void
midi_getinfo(dev_t dev, struct midi_info *mi)
{
@ -1709,46 +1690,3 @@ midi_writebytes(int unit, u_char *bf, int cc)
return ENXIO;
}
#endif /* NMIDI == 0 */
#ifdef _MODULE
#include "ioconf.c"
devmajor_t sequencer_bmajor = -1, sequencer_cmajor = -1;
#endif
MODULE(MODULE_CLASS_DRIVER, sequencer, "midi");
static int
sequencer_modcmd(modcmd_t cmd, void *arg)
{
int error = 0;
#ifdef _MODULE
switch (cmd) {
case MODULE_CMD_INIT:
error = devsw_attach(sequencer_cd.cd_name,
NULL, &sequencer_bmajor,
&sequencer_cdevsw, &sequencer_cmajor);
if (error)
break;
error = config_init_component(cfdriver_ioconf_sequencer,
cfattach_ioconf_sequencer, cfdata_ioconf_sequencer);
if (error) {
devsw_detach(NULL, &sequencer_cdevsw);
}
break;
case MODULE_CMD_FINI:
error = config_fini_component(cfdriver_ioconf_sequencer,
cfattach_ioconf_sequencer, cfdata_ioconf_sequencer);
if (error == 0)
devsw_detach(NULL, &sequencer_cdevsw);
break;
default:
error = ENOTTY;
break;
}
#endif
return error;
}

63
sys/dev/sequencer_mod.c Normal file
View File

@ -0,0 +1,63 @@
/* $NetBSD: sequencer_mod.c,v 1.1 2022/06/04 03:31:10 pgoyette Exp $ */
/*
* Copyright (c) 2022 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Paul Goyette
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sequencer_mod.c,v 1.1 2022/06/04 03:31:10 pgoyette Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/module.h>
/*
* The sequencer module itself doesn't do anything. It exists only to
* ensure that the combo-module for midi-plus-sequencer is loaded. This
* allows us to have both midi and sequencer code to refer to each other,
* avoiding a circular module dependency.
*/
MODULE(MODULE_CLASS_DRIVER, sequencer, "midi_seq");
static int
sequencer_modcmd(modcmd_t cmd, void *arg)
{
int error = 0;
switch (cmd) {
case MODULE_CMD_INIT:
case MODULE_CMD_FINI:
break;
default:
error = ENOTTY;
break;
}
return error;
}

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.265 2022/04/14 16:50:26 pgoyette Exp $
# $NetBSD: Makefile,v 1.266 2022/06/04 03:31:10 pgoyette Exp $
.include <bsd.own.mk>
@ -115,6 +115,7 @@ SUBDIR+= luasystm
SUBDIR+= luapmf
SUBDIR+= mfs
SUBDIR+= midi
SUBDIR+= midi_seq
SUBDIR+= miiverbose
SUBDIR+= miniroot
SUBDIR+= mqueue

View File

@ -1,20 +1,12 @@
# $NetBSD: Makefile,v 1.2 2019/02/17 04:05:54 rin Exp $
# $NetBSD: Makefile,v 1.3 2022/06/04 03:31:10 pgoyette Exp $ */
.include "../Makefile.inc"
.PATH: ${S}/dev
KMOD= midi
IOCONF= midi.ioconf
SRCS= midi.c \
midictl.c \
midisyn.c
SRCS= midi_mod.c
CPPFLAGS+= -DNMIDI=1 -DNSEQUENCER=1
# Rather than our usual WARNS=5, we need to use 3, since there are a
# lot of signed-vs-unsigned compares
WARNS= 3
.include <bsd.kmodule.mk>

View File

@ -1,9 +0,0 @@
# $NetBSD: midi.ioconf,v 1.1 2017/06/01 09:58:27 pgoyette Exp $
ioconf midi
include "conf/files"
pseudo-root midibus*
midi* at midibus?

View File

@ -0,0 +1,23 @@
# $NetBSD: Makefile,v 1.1 2022/06/04 03:31:10 pgoyette Exp $
.include "../Makefile.inc"
.PATH: ${S}/dev
KMOD= midi_seq
IOCONF= midi_seq.ioconf
SRCS= midi_seq_mod.c
SRCS+= midi.c \
midictl.c \
midisyn.c
SRCS+= sequencer.c
CPPFLAGS+= -DNMIDI=1 -DNSEQUENCER=1
# Rather than our usual WARNS=5, we need to use 3, since there are a
# lot of signed-vs-unsigned compares
WARNS= 3
.include <bsd.kmodule.mk>

View File

@ -0,0 +1,11 @@
# $NetBSD: midi_seq.ioconf,v 1.1 2022/06/04 03:31:10 pgoyette Exp $
ioconf midi_seq
include "conf/files"
pseudo-root midibus*
midi* at midibus?
pseudo-device sequencer

View File

@ -1,18 +1,12 @@
# $NetBSD: Makefile,v 1.2 2019/02/17 04:05:57 rin Exp $
# $NetBSD: Makefile,v 1.3 2022/06/04 03:31:10 pgoyette Exp $
.include "../Makefile.inc"
.PATH: ${S}/dev
KMOD= sequencer
IOCONF= sequencer.ioconf
SRCS= sequencer.c
SRCS= sequencer_mod.c
CPPFLAGS+= -DNSEQUENCER=1 -DNMIDI=1
# Rather than our usual WARNS=5, we need to use 3, since there are a
# lot of signed-vs-unsigned compares
WARNS= 3
.include <bsd.kmodule.mk>

View File

@ -1,9 +0,0 @@
# $NetBSD: sequencer.ioconf,v 1.1 2017/06/01 09:58:27 pgoyette Exp $
ioconf sequencer
include "conf/files"
pseudo-root midi*
pseudo-device sequencer