FreeBSD kernel sound device code
midi.c File Reference
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/queue.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/signalvar.h>
#include <sys/conf.h>
#include <sys/selinfo.h>
#include <sys/sysctl.h>
#include <sys/malloc.h>
#include <sys/sx.h>
#include <sys/fcntl.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <sys/poll.h>
#include <sys/sbuf.h>
#include <sys/kobj.h>
#include <sys/module.h>
#include <dev/sound/midi/midi.h>
#include "mpu_if.h"
#include <dev/sound/midi/midiq.h>
#include "synth_if.h"
Include dependency graph for midi.c:

Go to the source code of this file.

Data Structures

struct  snd_midi
 
struct  synth_midi
 

Macros

#define KOBJMETHOD_END   { NULL, NULL }
 
#define PCMMKMINOR(u, d, c)   ((((c) & 0xff) << 16) | (((u) & 0x0f) << 4) | ((d) & 0x0f))
 
#define MIDIMKMINOR(u, d, c)   PCMMKMINOR(u, d, c)
 
#define MIDI_DEV_RAW   2
 
#define MIDI_DEV_MIDICTL   12
 
#define MIDI_NAMELEN   16
 
#define MIDI_DEBUG(l, a)   if(midi_debug>=l) a
 
#define MIDI_LENGTH(d)   (midi_lengths[((d) >> 4) & 7])
 
#define MIDI_ACK   0xfe
 
#define MIDI_IS_STATUS(d)   ((d) >= 0x80)
 
#define MIDI_IS_COMMON(d)   ((d) >= 0xf0)
 
#define MIDI_SYSEX_START   0xF0
 
#define MIDI_SYSEX_END   0xF7
 
#define MIDI_RSIZE   32
 
#define MIDI_WSIZE   32
 

Enumerations

enum  midi_states { MIDI_IN_START , MIDI_IN_SYSEX , MIDI_IN_DATA }
 

Functions

 __FBSDID ("$FreeBSD$")
 
 MALLOC_DEFINE (M_MIDI, "midi buffers", "Midi data allocation area")
 
 DEFINE_CLASS (midisynth, midisynth_methods, 0)
 
 TAILQ_HEAD (snd_midi)
 
static int midi_destroy (struct snd_midi *, int)
 
static int midistat_prepare (struct sbuf *s)
 
static int midi_load (void)
 
static int midi_unload (void)
 
 SYSCTL_NODE (_hw, OID_AUTO, midi, CTLFLAG_RD|CTLFLAG_MPSAFE, 0, "Midi driver")
 
static SYSCTL_NODE (_hw_midi, OID_AUTO, stat, CTLFLAG_RD|CTLFLAG_MPSAFE, 0, "Status device")
 
 SYSCTL_INT (_hw_midi, OID_AUTO, debug, CTLFLAG_RW, &midi_debug, 0, "")
 
 SYSCTL_INT (_hw_midi, OID_AUTO, dumpraw, CTLFLAG_RW, &midi_dumpraw, 0, "")
 
 SYSCTL_INT (_hw_midi, OID_AUTO, instroff, CTLFLAG_RW, &midi_instroff, 0, "")
 
 SYSCTL_INT (_hw_midi_stat, OID_AUTO, verbose, CTLFLAG_RW, &midistat_verbose, 0, "")
 
struct snd_midimidi_init (kobj_class_t cls, int unit, int channel, void *cookie)
 
int midi_uninit (struct snd_midi *m)
 
int midi_in (struct snd_midi *m, MIDI_TYPE *buf, int size)
 
int midi_out (struct snd_midi *m, MIDI_TYPE *buf, int size)
 
int midi_open (struct cdev *i_dev, int flags, int mode, struct thread *td)
 
int midi_close (struct cdev *i_dev, int flags, int mode, struct thread *td)
 
int midi_read (struct cdev *i_dev, struct uio *uio, int ioflag)
 
int midi_write (struct cdev *i_dev, struct uio *uio, int ioflag)
 
int midi_ioctl (struct cdev *i_dev, u_long cmd, caddr_t arg, int mode, struct thread *td)
 
int midi_poll (struct cdev *i_dev, int events, struct thread *td)
 
static int midistat_open (struct cdev *i_dev, int flags, int mode, struct thread *td)
 
static int midistat_close (struct cdev *i_dev, int flags, int mode, struct thread *td)
 
static int midistat_read (struct cdev *i_dev, struct uio *uio, int flag)
 
int midisynth_open (void *n, void *arg, int flags)
 
int midisynth_close (void *n)
 
int midisynth_writeraw (void *n, uint8_t *buf, size_t len)
 
static int midisynth_killnote (void *n, uint8_t chn, uint8_t note, uint8_t vel)
 
static int midisynth_setinstr (void *n, uint8_t chn, uint16_t instr)
 
static int midisynth_startnote (void *n, uint8_t chn, uint8_t note, uint8_t vel)
 
static int midisynth_alloc (void *n, uint8_t chan, uint8_t note)
 
static int midisynth_controller (void *n, uint8_t chn, uint8_t ctrlnum, uint16_t val)
 
static int midisynth_bender (void *n, uint8_t chn, uint16_t val)
 
int seq_modevent (module_t mod, int type, void *data)
 
static int midi_modevent (module_t mod, int type, void *data)
 
kobj_t midimapper_addseq (void *arg1, int *unit, void **cookie)
 
int midimapper_open (void *arg1, void **cookie)
 
int midimapper_close (void *arg1, void *cookie)
 
kobj_t midimapper_fetch_synth (void *arg, void *cookie, int unit)
 
 DEV_MODULE (midi, midi_modevent, NULL)
 
 MODULE_VERSION (midi, 1)
 

Variables

static synth_open_t midisynth_open
 
static synth_close_t midisynth_close
 
static synth_writeraw_t midisynth_writeraw
 
static synth_killnote_t midisynth_killnote
 
static synth_startnote_t midisynth_startnote
 
static synth_setinstr_t midisynth_setinstr
 
static synth_alloc_t midisynth_alloc
 
static synth_controller_t midisynth_controller
 
static synth_bender_t midisynth_bender
 
static kobj_method_t midisynth_methods []
 
static d_open_t midi_open
 
static d_close_t midi_close
 
static d_ioctl_t midi_ioctl
 
static d_read_t midi_read
 
static d_write_t midi_write
 
static d_poll_t midi_poll
 
static struct cdevsw midi_cdevsw
 
int midi_debug
 
int midi_dumpraw
 
int midi_instroff
 
int midistat_verbose
 

Macro Definition Documentation

◆ KOBJMETHOD_END

#define KOBJMETHOD_END   { NULL, NULL }

Definition at line 76 of file midi.c.

◆ MIDI_ACK

#define MIDI_ACK   0xfe

Definition at line 445 of file midi.c.

◆ MIDI_DEBUG

#define MIDI_DEBUG (   l,
 
)    if(midi_debug>=l) a

Definition at line 262 of file midi.c.

◆ MIDI_DEV_MIDICTL

#define MIDI_DEV_MIDICTL   12

Definition at line 83 of file midi.c.

◆ MIDI_DEV_RAW

#define MIDI_DEV_RAW   2

Definition at line 82 of file midi.c.

◆ MIDI_IS_COMMON

#define MIDI_IS_COMMON (   d)    ((d) >= 0xf0)

Definition at line 447 of file midi.c.

◆ MIDI_IS_STATUS

#define MIDI_IS_STATUS (   d)    ((d) >= 0x80)

Definition at line 446 of file midi.c.

◆ MIDI_LENGTH

#define MIDI_LENGTH (   d)    (midi_lengths[((d) >> 4) & 7])

Definition at line 444 of file midi.c.

◆ MIDI_NAMELEN

#define MIDI_NAMELEN   16

Definition at line 100 of file midi.c.

◆ MIDI_RSIZE

#define MIDI_RSIZE   32

◆ MIDI_SYSEX_END

#define MIDI_SYSEX_END   0xF7

Definition at line 450 of file midi.c.

◆ MIDI_SYSEX_START

#define MIDI_SYSEX_START   0xF0

Definition at line 449 of file midi.c.

◆ MIDI_WSIZE

#define MIDI_WSIZE   32

◆ MIDIMKMINOR

#define MIDIMKMINOR (   u,
  d,
  c 
)    PCMMKMINOR(u, d, c)

Definition at line 80 of file midi.c.

◆ PCMMKMINOR

#define PCMMKMINOR (   u,
  d,
  c 
)    ((((c) & 0xff) << 16) | (((u) & 0x0f) << 4) | ((d) & 0x0f))

Definition at line 79 of file midi.c.

Enumeration Type Documentation

◆ midi_states

Enumerator
MIDI_IN_START 
MIDI_IN_SYSEX 
MIDI_IN_DATA 

Definition at line 85 of file midi.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ DEFINE_CLASS()

DEFINE_CLASS ( midisynth  ,
midisynth_methods  ,
 
)

◆ DEV_MODULE()

DEV_MODULE ( midi  ,
midi_modevent  ,
NULL   
)

◆ MALLOC_DEFINE()

MALLOC_DEFINE ( M_MIDI  ,
"midi buffers"  ,
"Midi data allocation area"   
)

◆ midi_close()

int midi_close ( struct cdev *  i_dev,
int  flags,
int  mode,
struct thread *  td 
)

Definition at line 682 of file midi.c.

References snd_midi::flags, m, M_RX, M_RXEN, M_TX, M_TXEN, and MIDI_DEBUG.

◆ midi_destroy()

static int midi_destroy ( struct snd_midi m,
int  midiuninit 
)
static

Definition at line 1361 of file midi.c.

References free, m, MIDI_DEBUG, and MIDIQ_BUF.

Referenced by midi_uninit(), and midi_unload().

Here is the caller graph for this function:

◆ midi_in()

int midi_in ( struct snd_midi m,
MIDI_TYPE buf,
int  size 
)

Definition at line 453 of file midi.c.

References buf, data, m, M_RX, MIDI_ACK, MIDI_DEBUG, MIDI_IN_DATA, MIDI_IN_START, MIDI_IN_SYSEX, MIDI_IS_COMMON, MIDI_IS_STATUS, MIDI_LENGTH, MIDI_SYSEX_END, MIDIQ_AVAIL, MIDIQ_ENQ, MIDIQ_FULL, MIDIQ_LEN, and size.

Referenced by mpu401_intr().

Here is the caller graph for this function:

◆ midi_init()

struct snd_midi * midi_init ( kobj_class_t  cls,
int  unit,
int  channel,
void *  cookie 
)

Definition at line 281 of file midi.c.

References buf, channel, snd_midi::cookie, free, inqsize, m, midi_cdevsw, MIDI_DEBUG, MIDI_DEV_RAW, MIDI_TYPE, MIDIMKMINOR, MIDIQ_BUF, MIDIQ_INIT, outqsize, and snd_midi::unit.

Referenced by mpu401_init().

Here is the caller graph for this function:

◆ midi_ioctl()

int midi_ioctl ( struct cdev *  i_dev,
u_long  cmd,
caddr_t  arg,
int  mode,
struct thread *  td 
)

Definition at line 884 of file midi.c.

Referenced by mseq_ioctl().

Here is the caller graph for this function:

◆ midi_load()

static int midi_load ( void  )
static

Definition at line 1387 of file midi.c.

References MIDI_DEV_MIDICTL, and MIDIMKMINOR.

Referenced by midi_modevent().

Here is the caller graph for this function:

◆ midi_modevent()

static int midi_modevent ( module_t  mod,
int  type,
void *  data 
)
static

Definition at line 1441 of file midi.c.

References data, midi_load(), midi_unload(), seq_modevent(), and type.

Referenced by sound_modevent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ midi_open()

int midi_open ( struct cdev *  i_dev,
int  flags,
int  mode,
struct thread *  td 
)

Definition at line 623 of file midi.c.

References snd_midi::flags, m, M_RX, M_RXEN, M_TX, MIDI_DEBUG, MIDIQ_CLEAR, and MIDIQ_SIZE.

◆ midi_out()

int midi_out ( struct snd_midi m,
MIDI_TYPE buf,
int  size 
)

Definition at line 583 of file midi.c.

References buf, m, M_TXEN, MIDI_DEBUG, MIDIQ_AVAIL, MIDIQ_DEQ, MIDIQ_EMPTY, MIDIQ_LEN, and size.

Referenced by mpu401_intr().

Here is the caller graph for this function:

◆ midi_poll()

int midi_poll ( struct cdev *  i_dev,
int  events,
struct thread *  td 
)

Definition at line 891 of file midi.c.

References m, MIDIQ_AVAIL, and MIDIQ_EMPTY.

◆ midi_read()

int midi_read ( struct cdev *  i_dev,
struct uio *  uio,
int  ioflag 
)

Definition at line 727 of file midi.c.

References buf, m, M_RX, MIDI_DEBUG, MIDI_RSIZE, MIDIQ_DEQ, MIDIQ_EMPTY, and MIDIQ_LEN.

◆ midi_uninit()

int midi_uninit ( struct snd_midi m)

Definition at line 401 of file midi.c.

References m, and midi_destroy().

Referenced by mpu401_uninit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ midi_unload()

static int midi_unload ( void  )
static

Definition at line 1400 of file midi.c.

References m, MIDI_DEBUG, and midi_destroy().

Referenced by midi_modevent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ midi_write()

int midi_write ( struct cdev *  i_dev,
struct uio *  uio,
int  ioflag 
)

Definition at line 805 of file midi.c.

References buf, m, M_TX, M_TXEN, MIDI_DEBUG, MIDI_WSIZE, MIDIQ_AVAIL, MIDIQ_ENQ, and MIDIQ_LEN.

◆ midimapper_addseq()

kobj_t midimapper_addseq ( void *  arg1,
int *  unit,
void **  cookie 
)

Definition at line 1468 of file midi.c.

References snd_midi::unit.

Referenced by seq_addunit().

Here is the caller graph for this function:

◆ midimapper_close()

int midimapper_close ( void *  arg1,
void *  cookie 
)

Definition at line 1490 of file midi.c.

Referenced by mseq_close().

Here is the caller graph for this function:

◆ midimapper_fetch_synth()

kobj_t midimapper_fetch_synth ( void *  arg,
void *  cookie,
int  unit 
)

Definition at line 1496 of file midi.c.

References m, and snd_midi::unit.

Referenced by mseq_open().

Here is the caller graph for this function:

◆ midimapper_open()

int midimapper_open ( void *  arg1,
void **  cookie 
)

Definition at line 1476 of file midi.c.

References m.

Referenced by mseq_open().

Here is the caller graph for this function:

◆ midistat_close()

static int midistat_close ( struct cdev *  i_dev,
int  flags,
int  mode,
struct thread *  td 
)
static

Definition at line 955 of file midi.c.

References MIDI_DEBUG.

◆ midistat_open()

static int midistat_open ( struct cdev *  i_dev,
int  flags,
int  mode,
struct thread *  td 
)
static

Definition at line 930 of file midi.c.

References error, MIDI_DEBUG, and midistat_prepare().

Here is the call graph for this function:

◆ midistat_prepare()

static int midistat_prepare ( struct sbuf *  s)
static

Definition at line 1000 of file midi.c.

References m, and midistat_verbose.

Referenced by midistat_open().

Here is the caller graph for this function:

◆ midistat_read()

static int midistat_read ( struct cdev *  i_dev,
struct uio *  uio,
int  flag 
)
static

Definition at line 970 of file midi.c.

References MIDI_DEBUG.

◆ midisynth_alloc()

static int midisynth_alloc ( void *  n,
uint8_t  chan,
uint8_t  note 
)
static

Definition at line 1323 of file midi.c.

References chan.

◆ midisynth_bender()

static int midisynth_bender ( void *  n,
uint8_t  chn,
uint16_t  val 
)
static

Definition at line 1343 of file midi.c.

References c, midisynth_writeraw, n, and val.

◆ midisynth_close()

int midisynth_close ( void *  n)

Definition at line 1133 of file midi.c.

References m, M_RX, M_RXEN, M_TX, M_TXEN, MIDI_DEBUG, and n.

◆ midisynth_controller()

static int midisynth_controller ( void *  n,
uint8_t  chn,
uint8_t  ctrlnum,
uint16_t  val 
)
static

Definition at line 1329 of file midi.c.

References c, midisynth_writeraw, n, and val.

◆ midisynth_killnote()

static int midisynth_killnote ( void *  n,
uint8_t  chn,
uint8_t  note,
uint8_t  vel 
)
static

Definition at line 1268 of file midi.c.

References c, midisynth_writeraw, and n.

◆ midisynth_open()

int midisynth_open ( void *  n,
void *  arg,
int  flags 
)

Definition at line 1070 of file midi.c.

References m, M_RX, M_RXEN, M_TX, MIDI_DEBUG, MIDIQ_CLEAR, MIDIQ_SIZE, and n.

◆ midisynth_setinstr()

static int midisynth_setinstr ( void *  n,
uint8_t  chn,
uint16_t  instr 
)
static

Definition at line 1292 of file midi.c.

References c, midi_instroff, midisynth_writeraw, and n.

◆ midisynth_startnote()

static int midisynth_startnote ( void *  n,
uint8_t  chn,
uint8_t  note,
uint8_t  vel 
)
static

Definition at line 1306 of file midi.c.

References c, midisynth_writeraw, and n.

◆ midisynth_writeraw()

int midisynth_writeraw ( void *  n,
uint8_t *  buf,
size_t  len 
)

Definition at line 1179 of file midi.c.

References buf, len, m, M_TX, M_TXEN, MIDI_DEBUG, midi_dumpraw, MIDI_WSIZE, MIDIQ_AVAIL, MIDIQ_ENQ, MIDIQ_LEN, and n.

◆ MODULE_VERSION()

MODULE_VERSION ( midi  ,
 
)

◆ seq_modevent()

int seq_modevent ( module_t  mod,
int  type,
void *  data 
)

Definition at line 695 of file sequencer.c.

References nseq, r, seq_addunit(), seq_delunit(), seqinfo_mtx, and type.

Referenced by midi_modevent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SYSCTL_INT() [1/4]

SYSCTL_INT ( _hw_midi  ,
OID_AUTO  ,
debug  ,
CTLFLAG_RW  ,
midi_debug,
,
""   
)

◆ SYSCTL_INT() [2/4]

SYSCTL_INT ( _hw_midi  ,
OID_AUTO  ,
dumpraw  ,
CTLFLAG_RW  ,
midi_dumpraw,
,
""   
)

◆ SYSCTL_INT() [3/4]

SYSCTL_INT ( _hw_midi  ,
OID_AUTO  ,
instroff  ,
CTLFLAG_RW  ,
midi_instroff,
,
""   
)

◆ SYSCTL_INT() [4/4]

SYSCTL_INT ( _hw_midi_stat  ,
OID_AUTO  ,
verbose  ,
CTLFLAG_RW  ,
midistat_verbose,
,
""   
)

◆ SYSCTL_NODE() [1/2]

SYSCTL_NODE ( _hw  ,
OID_AUTO  ,
midi  ,
CTLFLAG_RD|  CTLFLAG_MPSAFE,
,
"Midi driver"   
)

◆ SYSCTL_NODE() [2/2]

static SYSCTL_NODE ( _hw_midi  ,
OID_AUTO  ,
stat  ,
CTLFLAG_RD|  CTLFLAG_MPSAFE,
,
"Status device"   
)
static

◆ TAILQ_HEAD()

TAILQ_HEAD ( snd_midi  )

Definition at line 181 of file midi.c.

Variable Documentation

◆ midi_cdevsw

struct cdevsw midi_cdevsw
static
Initial value:
= {
.d_version = D_VERSION,
.d_open = midi_open,
.d_close = midi_close,
.d_read = midi_read,
.d_write = midi_write,
.d_ioctl = midi_ioctl,
.d_poll = midi_poll,
.d_name = "rmidi",
}
static d_write_t midi_write
Definition: midi.c:217
static d_ioctl_t midi_ioctl
Definition: midi.c:215
static d_open_t midi_open
Definition: midi.c:206
static d_read_t midi_read
Definition: midi.c:216
static d_poll_t midi_poll
Definition: midi.c:218
static d_close_t midi_close
Definition: midi.c:214

Definition at line 220 of file midi.c.

Referenced by midi_init().

◆ midi_close

d_close_t midi_close
static

Definition at line 214 of file midi.c.

◆ midi_debug

int midi_debug

Definition at line 248 of file midi.c.

◆ midi_dumpraw

int midi_dumpraw

Definition at line 252 of file midi.c.

Referenced by midisynth_writeraw().

◆ midi_instroff

int midi_instroff

Definition at line 255 of file midi.c.

Referenced by midisynth_setinstr().

◆ midi_ioctl

d_ioctl_t midi_ioctl
static

Definition at line 215 of file midi.c.

◆ midi_open

d_open_t midi_open
static

Definition at line 213 of file midi.c.

◆ midi_poll

d_poll_t midi_poll
static

Definition at line 218 of file midi.c.

◆ midi_read

d_read_t midi_read
static

Definition at line 216 of file midi.c.

◆ midi_write

d_write_t midi_write
static

Definition at line 217 of file midi.c.

◆ midistat_verbose

int midistat_verbose

Definition at line 258 of file midi.c.

Referenced by midistat_prepare().

◆ midisynth_alloc

synth_alloc_t midisynth_alloc
static

Definition at line 141 of file midi.c.

◆ midisynth_bender

synth_bender_t midisynth_bender
static

Definition at line 143 of file midi.c.

◆ midisynth_close

synth_close_t midisynth_close
static

Definition at line 136 of file midi.c.

◆ midisynth_controller

synth_controller_t midisynth_controller
static

Definition at line 142 of file midi.c.

◆ midisynth_killnote

synth_killnote_t midisynth_killnote
static

Definition at line 138 of file midi.c.

◆ midisynth_methods

kobj_method_t midisynth_methods[]
static
Initial value:
= {
KOBJMETHOD(synth_open, midisynth_open),
KOBJMETHOD(synth_close, midisynth_close),
KOBJMETHOD(synth_writeraw, midisynth_writeraw),
KOBJMETHOD(synth_setinstr, midisynth_setinstr),
KOBJMETHOD(synth_startnote, midisynth_startnote),
KOBJMETHOD(synth_killnote, midisynth_killnote),
KOBJMETHOD(synth_alloc, midisynth_alloc),
KOBJMETHOD(synth_controller, midisynth_controller),
KOBJMETHOD(synth_bender, midisynth_bender),
}
static synth_alloc_t midisynth_alloc
Definition: midi.c:141
static synth_setinstr_t midisynth_setinstr
Definition: midi.c:140
static synth_writeraw_t midisynth_writeraw
Definition: midi.c:137
static synth_controller_t midisynth_controller
Definition: midi.c:142
static synth_killnote_t midisynth_killnote
Definition: midi.c:138
static synth_startnote_t midisynth_startnote
Definition: midi.c:139
static synth_close_t midisynth_close
Definition: midi.c:136
#define KOBJMETHOD_END
Definition: midi.c:76
static synth_bender_t midisynth_bender
Definition: midi.c:143
static synth_open_t midisynth_open
Definition: midi.c:135

Definition at line 145 of file midi.c.

◆ midisynth_open

synth_open_t midisynth_open
static

Definition at line 135 of file midi.c.

◆ midisynth_setinstr

synth_setinstr_t midisynth_setinstr
static

Definition at line 140 of file midi.c.

◆ midisynth_startnote

synth_startnote_t midisynth_startnote
static

Definition at line 139 of file midi.c.

◆ midisynth_writeraw

synth_writeraw_t midisynth_writeraw
static