seq_clientmgr.c 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506
  1. /*
  2. * ALSA sequencer Client Manager
  3. * Copyright (c) 1998-2001 by Frank van de Pol <fvdpol@coil.demon.nl>
  4. * Jaroslav Kysela <perex@suse.cz>
  5. * Takashi Iwai <tiwai@suse.de>
  6. *
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. #include <sound/driver.h>
  24. #include <linux/init.h>
  25. #include <linux/smp_lock.h>
  26. #include <linux/slab.h>
  27. #include <sound/core.h>
  28. #include <sound/minors.h>
  29. #include <linux/kmod.h>
  30. #include <sound/seq_kernel.h>
  31. #include "seq_clientmgr.h"
  32. #include "seq_memory.h"
  33. #include "seq_queue.h"
  34. #include "seq_timer.h"
  35. #include "seq_info.h"
  36. #include "seq_system.h"
  37. #include <sound/seq_device.h>
  38. #ifdef CONFIG_COMPAT
  39. #include <linux/compat.h>
  40. #endif
  41. /* Client Manager
  42. * this module handles the connections of userland and kernel clients
  43. *
  44. */
  45. #define SNDRV_SEQ_LFLG_INPUT 0x0001
  46. #define SNDRV_SEQ_LFLG_OUTPUT 0x0002
  47. #define SNDRV_SEQ_LFLG_OPEN (SNDRV_SEQ_LFLG_INPUT|SNDRV_SEQ_LFLG_OUTPUT)
  48. static DEFINE_SPINLOCK(clients_lock);
  49. static DECLARE_MUTEX(register_mutex);
  50. /*
  51. * client table
  52. */
  53. static char clienttablock[SNDRV_SEQ_MAX_CLIENTS];
  54. static client_t *clienttab[SNDRV_SEQ_MAX_CLIENTS];
  55. static usage_t client_usage;
  56. /*
  57. * prototypes
  58. */
  59. static int bounce_error_event(client_t *client, snd_seq_event_t *event, int err, int atomic, int hop);
  60. static int snd_seq_deliver_single_event(client_t *client, snd_seq_event_t *event, int filter, int atomic, int hop);
  61. /*
  62. */
  63. static inline mm_segment_t snd_enter_user(void)
  64. {
  65. mm_segment_t fs = get_fs();
  66. set_fs(get_ds());
  67. return fs;
  68. }
  69. static inline void snd_leave_user(mm_segment_t fs)
  70. {
  71. set_fs(fs);
  72. }
  73. /*
  74. */
  75. static inline unsigned short snd_seq_file_flags(struct file *file)
  76. {
  77. switch (file->f_mode & (FMODE_READ | FMODE_WRITE)) {
  78. case FMODE_WRITE:
  79. return SNDRV_SEQ_LFLG_OUTPUT;
  80. case FMODE_READ:
  81. return SNDRV_SEQ_LFLG_INPUT;
  82. default:
  83. return SNDRV_SEQ_LFLG_OPEN;
  84. }
  85. }
  86. static inline int snd_seq_write_pool_allocated(client_t *client)
  87. {
  88. return snd_seq_total_cells(client->pool) > 0;
  89. }
  90. /* return pointer to client structure for specified id */
  91. static client_t *clientptr(int clientid)
  92. {
  93. if (clientid < 0 || clientid >= SNDRV_SEQ_MAX_CLIENTS) {
  94. snd_printd("Seq: oops. Trying to get pointer to client %d\n", clientid);
  95. return NULL;
  96. }
  97. return clienttab[clientid];
  98. }
  99. extern int seq_client_load[];
  100. client_t *snd_seq_client_use_ptr(int clientid)
  101. {
  102. unsigned long flags;
  103. client_t *client;
  104. if (clientid < 0 || clientid >= SNDRV_SEQ_MAX_CLIENTS) {
  105. snd_printd("Seq: oops. Trying to get pointer to client %d\n", clientid);
  106. return NULL;
  107. }
  108. spin_lock_irqsave(&clients_lock, flags);
  109. client = clientptr(clientid);
  110. if (client)
  111. goto __lock;
  112. if (clienttablock[clientid]) {
  113. spin_unlock_irqrestore(&clients_lock, flags);
  114. return NULL;
  115. }
  116. spin_unlock_irqrestore(&clients_lock, flags);
  117. #ifdef CONFIG_KMOD
  118. if (!in_interrupt() && current->fs->root) {
  119. static char client_requested[64];
  120. static char card_requested[SNDRV_CARDS];
  121. if (clientid < 64) {
  122. int idx;
  123. if (! client_requested[clientid] && current->fs->root) {
  124. client_requested[clientid] = 1;
  125. for (idx = 0; idx < 64; idx++) {
  126. if (seq_client_load[idx] < 0)
  127. break;
  128. if (seq_client_load[idx] == clientid) {
  129. request_module("snd-seq-client-%i", clientid);
  130. break;
  131. }
  132. }
  133. }
  134. } else if (clientid >= 64 && clientid < 128) {
  135. int card = (clientid - 64) / 8;
  136. if (card < snd_ecards_limit) {
  137. if (! card_requested[card]) {
  138. card_requested[card] = 1;
  139. snd_request_card(card);
  140. }
  141. snd_seq_device_load_drivers();
  142. }
  143. }
  144. spin_lock_irqsave(&clients_lock, flags);
  145. client = clientptr(clientid);
  146. if (client)
  147. goto __lock;
  148. spin_unlock_irqrestore(&clients_lock, flags);
  149. }
  150. #endif
  151. return NULL;
  152. __lock:
  153. snd_use_lock_use(&client->use_lock);
  154. spin_unlock_irqrestore(&clients_lock, flags);
  155. return client;
  156. }
  157. static void usage_alloc(usage_t * res, int num)
  158. {
  159. res->cur += num;
  160. if (res->cur > res->peak)
  161. res->peak = res->cur;
  162. }
  163. static void usage_free(usage_t * res, int num)
  164. {
  165. res->cur -= num;
  166. }
  167. /* initialise data structures */
  168. int __init client_init_data(void)
  169. {
  170. /* zap out the client table */
  171. memset(&clienttablock, 0, sizeof(clienttablock));
  172. memset(&clienttab, 0, sizeof(clienttab));
  173. return 0;
  174. }
  175. static client_t *seq_create_client1(int client_index, int poolsize)
  176. {
  177. unsigned long flags;
  178. int c;
  179. client_t *client;
  180. /* init client data */
  181. client = kzalloc(sizeof(*client), GFP_KERNEL);
  182. if (client == NULL)
  183. return NULL;
  184. client->pool = snd_seq_pool_new(poolsize);
  185. if (client->pool == NULL) {
  186. kfree(client);
  187. return NULL;
  188. }
  189. client->type = NO_CLIENT;
  190. snd_use_lock_init(&client->use_lock);
  191. rwlock_init(&client->ports_lock);
  192. init_MUTEX(&client->ports_mutex);
  193. INIT_LIST_HEAD(&client->ports_list_head);
  194. /* find free slot in the client table */
  195. spin_lock_irqsave(&clients_lock, flags);
  196. if (client_index < 0) {
  197. for (c = 128; c < SNDRV_SEQ_MAX_CLIENTS; c++) {
  198. if (clienttab[c] || clienttablock[c])
  199. continue;
  200. clienttab[client->number = c] = client;
  201. spin_unlock_irqrestore(&clients_lock, flags);
  202. return client;
  203. }
  204. } else {
  205. if (clienttab[client_index] == NULL && !clienttablock[client_index]) {
  206. clienttab[client->number = client_index] = client;
  207. spin_unlock_irqrestore(&clients_lock, flags);
  208. return client;
  209. }
  210. }
  211. spin_unlock_irqrestore(&clients_lock, flags);
  212. snd_seq_pool_delete(&client->pool);
  213. kfree(client);
  214. return NULL; /* no free slot found or busy, return failure code */
  215. }
  216. static int seq_free_client1(client_t *client)
  217. {
  218. unsigned long flags;
  219. snd_assert(client != NULL, return -EINVAL);
  220. snd_seq_delete_all_ports(client);
  221. snd_seq_queue_client_leave(client->number);
  222. spin_lock_irqsave(&clients_lock, flags);
  223. clienttablock[client->number] = 1;
  224. clienttab[client->number] = NULL;
  225. spin_unlock_irqrestore(&clients_lock, flags);
  226. snd_use_lock_sync(&client->use_lock);
  227. snd_seq_queue_client_termination(client->number);
  228. if (client->pool)
  229. snd_seq_pool_delete(&client->pool);
  230. spin_lock_irqsave(&clients_lock, flags);
  231. clienttablock[client->number] = 0;
  232. spin_unlock_irqrestore(&clients_lock, flags);
  233. return 0;
  234. }
  235. static void seq_free_client(client_t * client)
  236. {
  237. down(&register_mutex);
  238. switch (client->type) {
  239. case NO_CLIENT:
  240. snd_printk(KERN_WARNING "Seq: Trying to free unused client %d\n", client->number);
  241. break;
  242. case USER_CLIENT:
  243. case KERNEL_CLIENT:
  244. seq_free_client1(client);
  245. usage_free(&client_usage, 1);
  246. break;
  247. default:
  248. snd_printk(KERN_ERR "Seq: Trying to free client %d with undefined type = %d\n", client->number, client->type);
  249. }
  250. up(&register_mutex);
  251. snd_seq_system_client_ev_client_exit(client->number);
  252. }
  253. /* -------------------------------------------------------- */
  254. /* create a user client */
  255. static int snd_seq_open(struct inode *inode, struct file *file)
  256. {
  257. int c, mode; /* client id */
  258. client_t *client;
  259. user_client_t *user;
  260. if (down_interruptible(&register_mutex))
  261. return -ERESTARTSYS;
  262. client = seq_create_client1(-1, SNDRV_SEQ_DEFAULT_EVENTS);
  263. if (client == NULL) {
  264. up(&register_mutex);
  265. return -ENOMEM; /* failure code */
  266. }
  267. mode = snd_seq_file_flags(file);
  268. if (mode & SNDRV_SEQ_LFLG_INPUT)
  269. client->accept_input = 1;
  270. if (mode & SNDRV_SEQ_LFLG_OUTPUT)
  271. client->accept_output = 1;
  272. user = &client->data.user;
  273. user->fifo = NULL;
  274. user->fifo_pool_size = 0;
  275. if (mode & SNDRV_SEQ_LFLG_INPUT) {
  276. user->fifo_pool_size = SNDRV_SEQ_DEFAULT_CLIENT_EVENTS;
  277. user->fifo = snd_seq_fifo_new(user->fifo_pool_size);
  278. if (user->fifo == NULL) {
  279. seq_free_client1(client);
  280. kfree(client);
  281. up(&register_mutex);
  282. return -ENOMEM;
  283. }
  284. }
  285. usage_alloc(&client_usage, 1);
  286. client->type = USER_CLIENT;
  287. up(&register_mutex);
  288. c = client->number;
  289. file->private_data = client;
  290. /* fill client data */
  291. user->file = file;
  292. sprintf(client->name, "Client-%d", c);
  293. /* make others aware this new client */
  294. snd_seq_system_client_ev_client_start(c);
  295. return 0;
  296. }
  297. /* delete a user client */
  298. static int snd_seq_release(struct inode *inode, struct file *file)
  299. {
  300. client_t *client = (client_t *) file->private_data;
  301. if (client) {
  302. seq_free_client(client);
  303. if (client->data.user.fifo)
  304. snd_seq_fifo_delete(&client->data.user.fifo);
  305. kfree(client);
  306. }
  307. return 0;
  308. }
  309. /* handle client read() */
  310. /* possible error values:
  311. * -ENXIO invalid client or file open mode
  312. * -ENOSPC FIFO overflow (the flag is cleared after this error report)
  313. * -EINVAL no enough user-space buffer to write the whole event
  314. * -EFAULT seg. fault during copy to user space
  315. */
  316. static ssize_t snd_seq_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
  317. {
  318. client_t *client = (client_t *) file->private_data;
  319. fifo_t *fifo;
  320. int err;
  321. long result = 0;
  322. snd_seq_event_cell_t *cell;
  323. if (!(snd_seq_file_flags(file) & SNDRV_SEQ_LFLG_INPUT))
  324. return -ENXIO;
  325. if (!access_ok(VERIFY_WRITE, buf, count))
  326. return -EFAULT;
  327. /* check client structures are in place */
  328. snd_assert(client != NULL, return -ENXIO);
  329. if (!client->accept_input || (fifo = client->data.user.fifo) == NULL)
  330. return -ENXIO;
  331. if (atomic_read(&fifo->overflow) > 0) {
  332. /* buffer overflow is detected */
  333. snd_seq_fifo_clear(fifo);
  334. /* return error code */
  335. return -ENOSPC;
  336. }
  337. cell = NULL;
  338. err = 0;
  339. snd_seq_fifo_lock(fifo);
  340. /* while data available in queue */
  341. while (count >= sizeof(snd_seq_event_t)) {
  342. int nonblock;
  343. nonblock = (file->f_flags & O_NONBLOCK) || result > 0;
  344. if ((err = snd_seq_fifo_cell_out(fifo, &cell, nonblock)) < 0) {
  345. break;
  346. }
  347. if (snd_seq_ev_is_variable(&cell->event)) {
  348. snd_seq_event_t tmpev;
  349. tmpev = cell->event;
  350. tmpev.data.ext.len &= ~SNDRV_SEQ_EXT_MASK;
  351. if (copy_to_user(buf, &tmpev, sizeof(snd_seq_event_t))) {
  352. err = -EFAULT;
  353. break;
  354. }
  355. count -= sizeof(snd_seq_event_t);
  356. buf += sizeof(snd_seq_event_t);
  357. err = snd_seq_expand_var_event(&cell->event, count,
  358. (char __force *)buf, 0,
  359. sizeof(snd_seq_event_t));
  360. if (err < 0)
  361. break;
  362. result += err;
  363. count -= err;
  364. buf += err;
  365. } else {
  366. if (copy_to_user(buf, &cell->event, sizeof(snd_seq_event_t))) {
  367. err = -EFAULT;
  368. break;
  369. }
  370. count -= sizeof(snd_seq_event_t);
  371. buf += sizeof(snd_seq_event_t);
  372. }
  373. snd_seq_cell_free(cell);
  374. cell = NULL; /* to be sure */
  375. result += sizeof(snd_seq_event_t);
  376. }
  377. if (err < 0) {
  378. if (cell)
  379. snd_seq_fifo_cell_putback(fifo, cell);
  380. if (err == -EAGAIN && result > 0)
  381. err = 0;
  382. }
  383. snd_seq_fifo_unlock(fifo);
  384. return (err < 0) ? err : result;
  385. }
  386. /*
  387. * check access permission to the port
  388. */
  389. static int check_port_perm(client_port_t *port, unsigned int flags)
  390. {
  391. if ((port->capability & flags) != flags)
  392. return 0;
  393. return flags;
  394. }
  395. /*
  396. * check if the destination client is available, and return the pointer
  397. * if filter is non-zero, client filter bitmap is tested.
  398. */
  399. static client_t *get_event_dest_client(snd_seq_event_t *event, int filter)
  400. {
  401. client_t *dest;
  402. dest = snd_seq_client_use_ptr(event->dest.client);
  403. if (dest == NULL)
  404. return NULL;
  405. if (! dest->accept_input)
  406. goto __not_avail;
  407. if ((dest->filter & SNDRV_SEQ_FILTER_USE_EVENT) &&
  408. ! test_bit(event->type, dest->event_filter))
  409. goto __not_avail;
  410. if (filter && !(dest->filter & filter))
  411. goto __not_avail;
  412. return dest; /* ok - accessible */
  413. __not_avail:
  414. snd_seq_client_unlock(dest);
  415. return NULL;
  416. }
  417. /*
  418. * Return the error event.
  419. *
  420. * If the receiver client is a user client, the original event is
  421. * encapsulated in SNDRV_SEQ_EVENT_BOUNCE as variable length event. If
  422. * the original event is also variable length, the external data is
  423. * copied after the event record.
  424. * If the receiver client is a kernel client, the original event is
  425. * quoted in SNDRV_SEQ_EVENT_KERNEL_ERROR, since this requires no extra
  426. * kmalloc.
  427. */
  428. static int bounce_error_event(client_t *client, snd_seq_event_t *event,
  429. int err, int atomic, int hop)
  430. {
  431. snd_seq_event_t bounce_ev;
  432. int result;
  433. if (client == NULL ||
  434. ! (client->filter & SNDRV_SEQ_FILTER_BOUNCE) ||
  435. ! client->accept_input)
  436. return 0; /* ignored */
  437. /* set up quoted error */
  438. memset(&bounce_ev, 0, sizeof(bounce_ev));
  439. bounce_ev.type = SNDRV_SEQ_EVENT_KERNEL_ERROR;
  440. bounce_ev.flags = SNDRV_SEQ_EVENT_LENGTH_FIXED;
  441. bounce_ev.queue = SNDRV_SEQ_QUEUE_DIRECT;
  442. bounce_ev.source.client = SNDRV_SEQ_CLIENT_SYSTEM;
  443. bounce_ev.source.port = SNDRV_SEQ_PORT_SYSTEM_ANNOUNCE;
  444. bounce_ev.dest.client = client->number;
  445. bounce_ev.dest.port = event->source.port;
  446. bounce_ev.data.quote.origin = event->dest;
  447. bounce_ev.data.quote.event = event;
  448. bounce_ev.data.quote.value = -err; /* use positive value */
  449. result = snd_seq_deliver_single_event(NULL, &bounce_ev, 0, atomic, hop + 1);
  450. if (result < 0) {
  451. client->event_lost++;
  452. return result;
  453. }
  454. return result;
  455. }
  456. /*
  457. * rewrite the time-stamp of the event record with the curren time
  458. * of the given queue.
  459. * return non-zero if updated.
  460. */
  461. static int update_timestamp_of_queue(snd_seq_event_t *event, int queue, int real_time)
  462. {
  463. queue_t *q;
  464. q = queueptr(queue);
  465. if (! q)
  466. return 0;
  467. event->queue = queue;
  468. event->flags &= ~SNDRV_SEQ_TIME_STAMP_MASK;
  469. if (real_time) {
  470. event->time.time = snd_seq_timer_get_cur_time(q->timer);
  471. event->flags |= SNDRV_SEQ_TIME_STAMP_REAL;
  472. } else {
  473. event->time.tick = snd_seq_timer_get_cur_tick(q->timer);
  474. event->flags |= SNDRV_SEQ_TIME_STAMP_TICK;
  475. }
  476. queuefree(q);
  477. return 1;
  478. }
  479. /*
  480. * deliver an event to the specified destination.
  481. * if filter is non-zero, client filter bitmap is tested.
  482. *
  483. * RETURN VALUE: 0 : if succeeded
  484. * <0 : error
  485. */
  486. static int snd_seq_deliver_single_event(client_t *client,
  487. snd_seq_event_t *event,
  488. int filter, int atomic, int hop)
  489. {
  490. client_t *dest = NULL;
  491. client_port_t *dest_port = NULL;
  492. int result = -ENOENT;
  493. int direct;
  494. direct = snd_seq_ev_is_direct(event);
  495. dest = get_event_dest_client(event, filter);
  496. if (dest == NULL)
  497. goto __skip;
  498. dest_port = snd_seq_port_use_ptr(dest, event->dest.port);
  499. if (dest_port == NULL)
  500. goto __skip;
  501. /* check permission */
  502. if (! check_port_perm(dest_port, SNDRV_SEQ_PORT_CAP_WRITE)) {
  503. result = -EPERM;
  504. goto __skip;
  505. }
  506. if (dest_port->timestamping)
  507. update_timestamp_of_queue(event, dest_port->time_queue,
  508. dest_port->time_real);
  509. switch (dest->type) {
  510. case USER_CLIENT:
  511. if (dest->data.user.fifo)
  512. result = snd_seq_fifo_event_in(dest->data.user.fifo, event);
  513. break;
  514. case KERNEL_CLIENT:
  515. if (dest_port->event_input == NULL)
  516. break;
  517. result = dest_port->event_input(event, direct, dest_port->private_data, atomic, hop);
  518. break;
  519. default:
  520. break;
  521. }
  522. __skip:
  523. if (dest_port)
  524. snd_seq_port_unlock(dest_port);
  525. if (dest)
  526. snd_seq_client_unlock(dest);
  527. if (result < 0 && !direct) {
  528. result = bounce_error_event(client, event, result, atomic, hop);
  529. }
  530. return result;
  531. }
  532. /*
  533. * send the event to all subscribers:
  534. */
  535. static int deliver_to_subscribers(client_t *client,
  536. snd_seq_event_t *event,
  537. int atomic, int hop)
  538. {
  539. subscribers_t *subs;
  540. int err = 0, num_ev = 0;
  541. snd_seq_event_t event_saved;
  542. client_port_t *src_port;
  543. struct list_head *p;
  544. port_subs_info_t *grp;
  545. src_port = snd_seq_port_use_ptr(client, event->source.port);
  546. if (src_port == NULL)
  547. return -EINVAL; /* invalid source port */
  548. /* save original event record */
  549. event_saved = *event;
  550. grp = &src_port->c_src;
  551. /* lock list */
  552. if (atomic)
  553. read_lock(&grp->list_lock);
  554. else
  555. down_read(&grp->list_mutex);
  556. list_for_each(p, &grp->list_head) {
  557. subs = list_entry(p, subscribers_t, src_list);
  558. event->dest = subs->info.dest;
  559. if (subs->info.flags & SNDRV_SEQ_PORT_SUBS_TIMESTAMP)
  560. /* convert time according to flag with subscription */
  561. update_timestamp_of_queue(event, subs->info.queue,
  562. subs->info.flags & SNDRV_SEQ_PORT_SUBS_TIME_REAL);
  563. err = snd_seq_deliver_single_event(client, event,
  564. 0, atomic, hop);
  565. if (err < 0)
  566. break;
  567. num_ev++;
  568. /* restore original event record */
  569. *event = event_saved;
  570. }
  571. if (atomic)
  572. read_unlock(&grp->list_lock);
  573. else
  574. up_read(&grp->list_mutex);
  575. *event = event_saved; /* restore */
  576. snd_seq_port_unlock(src_port);
  577. return (err < 0) ? err : num_ev;
  578. }
  579. #ifdef SUPPORT_BROADCAST
  580. /*
  581. * broadcast to all ports:
  582. */
  583. static int port_broadcast_event(client_t *client,
  584. snd_seq_event_t *event,
  585. int atomic, int hop)
  586. {
  587. int num_ev = 0, err = 0;
  588. client_t *dest_client;
  589. struct list_head *p;
  590. dest_client = get_event_dest_client(event, SNDRV_SEQ_FILTER_BROADCAST);
  591. if (dest_client == NULL)
  592. return 0; /* no matching destination */
  593. read_lock(&dest_client->ports_lock);
  594. list_for_each(p, &dest_client->ports_list_head) {
  595. client_port_t *port = list_entry(p, client_port_t, list);
  596. event->dest.port = port->addr.port;
  597. /* pass NULL as source client to avoid error bounce */
  598. err = snd_seq_deliver_single_event(NULL, event,
  599. SNDRV_SEQ_FILTER_BROADCAST,
  600. atomic, hop);
  601. if (err < 0)
  602. break;
  603. num_ev++;
  604. }
  605. read_unlock(&dest_client->ports_lock);
  606. snd_seq_client_unlock(dest_client);
  607. event->dest.port = SNDRV_SEQ_ADDRESS_BROADCAST; /* restore */
  608. return (err < 0) ? err : num_ev;
  609. }
  610. /*
  611. * send the event to all clients:
  612. * if destination port is also ADDRESS_BROADCAST, deliver to all ports.
  613. */
  614. static int broadcast_event(client_t *client,
  615. snd_seq_event_t *event, int atomic, int hop)
  616. {
  617. int err = 0, num_ev = 0;
  618. int dest;
  619. snd_seq_addr_t addr;
  620. addr = event->dest; /* save */
  621. for (dest = 0; dest < SNDRV_SEQ_MAX_CLIENTS; dest++) {
  622. /* don't send to itself */
  623. if (dest == client->number)
  624. continue;
  625. event->dest.client = dest;
  626. event->dest.port = addr.port;
  627. if (addr.port == SNDRV_SEQ_ADDRESS_BROADCAST)
  628. err = port_broadcast_event(client, event, atomic, hop);
  629. else
  630. /* pass NULL as source client to avoid error bounce */
  631. err = snd_seq_deliver_single_event(NULL, event,
  632. SNDRV_SEQ_FILTER_BROADCAST,
  633. atomic, hop);
  634. if (err < 0)
  635. break;
  636. num_ev += err;
  637. }
  638. event->dest = addr; /* restore */
  639. return (err < 0) ? err : num_ev;
  640. }
  641. /* multicast - not supported yet */
  642. static int multicast_event(client_t *client, snd_seq_event_t *event,
  643. int atomic, int hop)
  644. {
  645. snd_printd("seq: multicast not supported yet.\n");
  646. return 0; /* ignored */
  647. }
  648. #endif /* SUPPORT_BROADCAST */
  649. /* deliver an event to the destination port(s).
  650. * if the event is to subscribers or broadcast, the event is dispatched
  651. * to multiple targets.
  652. *
  653. * RETURN VALUE: n > 0 : the number of delivered events.
  654. * n == 0 : the event was not passed to any client.
  655. * n < 0 : error - event was not processed.
  656. */
  657. static int snd_seq_deliver_event(client_t *client, snd_seq_event_t *event,
  658. int atomic, int hop)
  659. {
  660. int result;
  661. hop++;
  662. if (hop >= SNDRV_SEQ_MAX_HOPS) {
  663. snd_printd("too long delivery path (%d:%d->%d:%d)\n",
  664. event->source.client, event->source.port,
  665. event->dest.client, event->dest.port);
  666. return -EMLINK;
  667. }
  668. if (event->queue == SNDRV_SEQ_ADDRESS_SUBSCRIBERS ||
  669. event->dest.client == SNDRV_SEQ_ADDRESS_SUBSCRIBERS)
  670. result = deliver_to_subscribers(client, event, atomic, hop);
  671. #ifdef SUPPORT_BROADCAST
  672. else if (event->queue == SNDRV_SEQ_ADDRESS_BROADCAST ||
  673. event->dest.client == SNDRV_SEQ_ADDRESS_BROADCAST)
  674. result = broadcast_event(client, event, atomic, hop);
  675. else if (event->dest.client >= SNDRV_SEQ_MAX_CLIENTS)
  676. result = multicast_event(client, event, atomic, hop);
  677. else if (event->dest.port == SNDRV_SEQ_ADDRESS_BROADCAST)
  678. result = port_broadcast_event(client, event, atomic, hop);
  679. #endif
  680. else
  681. result = snd_seq_deliver_single_event(client, event, 0, atomic, hop);
  682. return result;
  683. }
  684. /*
  685. * dispatch an event cell:
  686. * This function is called only from queue check routines in timer
  687. * interrupts or after enqueued.
  688. * The event cell shall be released or re-queued in this function.
  689. *
  690. * RETURN VALUE: n > 0 : the number of delivered events.
  691. * n == 0 : the event was not passed to any client.
  692. * n < 0 : error - event was not processed.
  693. */
  694. int snd_seq_dispatch_event(snd_seq_event_cell_t *cell, int atomic, int hop)
  695. {
  696. client_t *client;
  697. int result;
  698. snd_assert(cell != NULL, return -EINVAL);
  699. client = snd_seq_client_use_ptr(cell->event.source.client);
  700. if (client == NULL) {
  701. snd_seq_cell_free(cell); /* release this cell */
  702. return -EINVAL;
  703. }
  704. if (cell->event.type == SNDRV_SEQ_EVENT_NOTE) {
  705. /* NOTE event:
  706. * the event cell is re-used as a NOTE-OFF event and
  707. * enqueued again.
  708. */
  709. snd_seq_event_t tmpev, *ev;
  710. /* reserve this event to enqueue note-off later */
  711. tmpev = cell->event;
  712. tmpev.type = SNDRV_SEQ_EVENT_NOTEON;
  713. result = snd_seq_deliver_event(client, &tmpev, atomic, hop);
  714. /*
  715. * This was originally a note event. We now re-use the
  716. * cell for the note-off event.
  717. */
  718. ev = &cell->event;
  719. ev->type = SNDRV_SEQ_EVENT_NOTEOFF;
  720. ev->flags |= SNDRV_SEQ_PRIORITY_HIGH;
  721. /* add the duration time */
  722. switch (ev->flags & SNDRV_SEQ_TIME_STAMP_MASK) {
  723. case SNDRV_SEQ_TIME_STAMP_TICK:
  724. ev->time.tick += ev->data.note.duration;
  725. break;
  726. case SNDRV_SEQ_TIME_STAMP_REAL:
  727. /* unit for duration is ms */
  728. ev->time.time.tv_nsec += 1000000 * (ev->data.note.duration % 1000);
  729. ev->time.time.tv_sec += ev->data.note.duration / 1000 +
  730. ev->time.time.tv_nsec / 1000000000;
  731. ev->time.time.tv_nsec %= 1000000000;
  732. break;
  733. }
  734. ev->data.note.velocity = ev->data.note.off_velocity;
  735. /* Now queue this cell as the note off event */
  736. if (snd_seq_enqueue_event(cell, atomic, hop) < 0)
  737. snd_seq_cell_free(cell); /* release this cell */
  738. } else {
  739. /* Normal events:
  740. * event cell is freed after processing the event
  741. */
  742. result = snd_seq_deliver_event(client, &cell->event, atomic, hop);
  743. snd_seq_cell_free(cell);
  744. }
  745. snd_seq_client_unlock(client);
  746. return result;
  747. }
  748. /* Allocate a cell from client pool and enqueue it to queue:
  749. * if pool is empty and blocking is TRUE, sleep until a new cell is
  750. * available.
  751. */
  752. static int snd_seq_client_enqueue_event(client_t *client,
  753. snd_seq_event_t *event,
  754. struct file *file, int blocking,
  755. int atomic, int hop)
  756. {
  757. snd_seq_event_cell_t *cell;
  758. int err;
  759. /* special queue values - force direct passing */
  760. if (event->queue == SNDRV_SEQ_ADDRESS_SUBSCRIBERS) {
  761. event->dest.client = SNDRV_SEQ_ADDRESS_SUBSCRIBERS;
  762. event->queue = SNDRV_SEQ_QUEUE_DIRECT;
  763. } else
  764. #ifdef SUPPORT_BROADCAST
  765. if (event->queue == SNDRV_SEQ_ADDRESS_BROADCAST) {
  766. event->dest.client = SNDRV_SEQ_ADDRESS_BROADCAST;
  767. event->queue = SNDRV_SEQ_QUEUE_DIRECT;
  768. }
  769. #endif
  770. if (event->dest.client == SNDRV_SEQ_ADDRESS_SUBSCRIBERS) {
  771. /* check presence of source port */
  772. client_port_t *src_port = snd_seq_port_use_ptr(client, event->source.port);
  773. if (src_port == NULL)
  774. return -EINVAL;
  775. snd_seq_port_unlock(src_port);
  776. }
  777. /* direct event processing without enqueued */
  778. if (snd_seq_ev_is_direct(event)) {
  779. if (event->type == SNDRV_SEQ_EVENT_NOTE)
  780. return -EINVAL; /* this event must be enqueued! */
  781. return snd_seq_deliver_event(client, event, atomic, hop);
  782. }
  783. /* Not direct, normal queuing */
  784. if (snd_seq_queue_is_used(event->queue, client->number) <= 0)
  785. return -EINVAL; /* invalid queue */
  786. if (! snd_seq_write_pool_allocated(client))
  787. return -ENXIO; /* queue is not allocated */
  788. /* allocate an event cell */
  789. err = snd_seq_event_dup(client->pool, event, &cell, !blocking || atomic, file);
  790. if (err < 0)
  791. return err;
  792. /* we got a cell. enqueue it. */
  793. if ((err = snd_seq_enqueue_event(cell, atomic, hop)) < 0) {
  794. snd_seq_cell_free(cell);
  795. return err;
  796. }
  797. return 0;
  798. }
  799. /*
  800. * check validity of event type and data length.
  801. * return non-zero if invalid.
  802. */
  803. static int check_event_type_and_length(snd_seq_event_t *ev)
  804. {
  805. switch (snd_seq_ev_length_type(ev)) {
  806. case SNDRV_SEQ_EVENT_LENGTH_FIXED:
  807. if (snd_seq_ev_is_variable_type(ev))
  808. return -EINVAL;
  809. break;
  810. case SNDRV_SEQ_EVENT_LENGTH_VARIABLE:
  811. if (! snd_seq_ev_is_variable_type(ev) ||
  812. (ev->data.ext.len & ~SNDRV_SEQ_EXT_MASK) >= SNDRV_SEQ_MAX_EVENT_LEN)
  813. return -EINVAL;
  814. break;
  815. case SNDRV_SEQ_EVENT_LENGTH_VARUSR:
  816. if (! snd_seq_ev_is_instr_type(ev) ||
  817. ! snd_seq_ev_is_direct(ev))
  818. return -EINVAL;
  819. break;
  820. }
  821. return 0;
  822. }
  823. /* handle write() */
  824. /* possible error values:
  825. * -ENXIO invalid client or file open mode
  826. * -ENOMEM malloc failed
  827. * -EFAULT seg. fault during copy from user space
  828. * -EINVAL invalid event
  829. * -EAGAIN no space in output pool
  830. * -EINTR interrupts while sleep
  831. * -EMLINK too many hops
  832. * others depends on return value from driver callback
  833. */
  834. static ssize_t snd_seq_write(struct file *file, const char __user *buf, size_t count, loff_t *offset)
  835. {
  836. client_t *client = (client_t *) file->private_data;
  837. int written = 0, len;
  838. int err = -EINVAL;
  839. snd_seq_event_t event;
  840. if (!(snd_seq_file_flags(file) & SNDRV_SEQ_LFLG_OUTPUT))
  841. return -ENXIO;
  842. /* check client structures are in place */
  843. snd_assert(client != NULL, return -ENXIO);
  844. if (!client->accept_output || client->pool == NULL)
  845. return -ENXIO;
  846. /* allocate the pool now if the pool is not allocated yet */
  847. if (client->pool->size > 0 && !snd_seq_write_pool_allocated(client)) {
  848. if (snd_seq_pool_init(client->pool) < 0)
  849. return -ENOMEM;
  850. }
  851. /* only process whole events */
  852. while (count >= sizeof(snd_seq_event_t)) {
  853. /* Read in the event header from the user */
  854. len = sizeof(event);
  855. if (copy_from_user(&event, buf, len)) {
  856. err = -EFAULT;
  857. break;
  858. }
  859. event.source.client = client->number; /* fill in client number */
  860. /* Check for extension data length */
  861. if (check_event_type_and_length(&event)) {
  862. err = -EINVAL;
  863. break;
  864. }
  865. /* check for special events */
  866. if (event.type == SNDRV_SEQ_EVENT_NONE)
  867. goto __skip_event;
  868. else if (snd_seq_ev_is_reserved(&event)) {
  869. err = -EINVAL;
  870. break;
  871. }
  872. if (snd_seq_ev_is_variable(&event)) {
  873. int extlen = event.data.ext.len & ~SNDRV_SEQ_EXT_MASK;
  874. if ((size_t)(extlen + len) > count) {
  875. /* back out, will get an error this time or next */
  876. err = -EINVAL;
  877. break;
  878. }
  879. /* set user space pointer */
  880. event.data.ext.len = extlen | SNDRV_SEQ_EXT_USRPTR;
  881. event.data.ext.ptr = (char __force *)buf
  882. + sizeof(snd_seq_event_t);
  883. len += extlen; /* increment data length */
  884. } else {
  885. #ifdef CONFIG_COMPAT
  886. if (client->convert32 && snd_seq_ev_is_varusr(&event)) {
  887. void *ptr = compat_ptr(event.data.raw32.d[1]);
  888. event.data.ext.ptr = ptr;
  889. }
  890. #endif
  891. }
  892. /* ok, enqueue it */
  893. err = snd_seq_client_enqueue_event(client, &event, file,
  894. !(file->f_flags & O_NONBLOCK),
  895. 0, 0);
  896. if (err < 0)
  897. break;
  898. __skip_event:
  899. /* Update pointers and counts */
  900. count -= len;
  901. buf += len;
  902. written += len;
  903. }
  904. return written ? written : err;
  905. }
  906. /*
  907. * handle polling
  908. */
  909. static unsigned int snd_seq_poll(struct file *file, poll_table * wait)
  910. {
  911. client_t *client = (client_t *) file->private_data;
  912. unsigned int mask = 0;
  913. /* check client structures are in place */
  914. snd_assert(client != NULL, return -ENXIO);
  915. if ((snd_seq_file_flags(file) & SNDRV_SEQ_LFLG_INPUT) &&
  916. client->data.user.fifo) {
  917. /* check if data is available in the outqueue */
  918. if (snd_seq_fifo_poll_wait(client->data.user.fifo, file, wait))
  919. mask |= POLLIN | POLLRDNORM;
  920. }
  921. if (snd_seq_file_flags(file) & SNDRV_SEQ_LFLG_OUTPUT) {
  922. /* check if data is available in the pool */
  923. if (!snd_seq_write_pool_allocated(client) ||
  924. snd_seq_pool_poll_wait(client->pool, file, wait))
  925. mask |= POLLOUT | POLLWRNORM;
  926. }
  927. return mask;
  928. }
  929. /*-----------------------------------------------------*/
  930. /* SYSTEM_INFO ioctl() */
  931. static int snd_seq_ioctl_system_info(client_t *client, void __user *arg)
  932. {
  933. snd_seq_system_info_t info;
  934. memset(&info, 0, sizeof(info));
  935. /* fill the info fields */
  936. info.queues = SNDRV_SEQ_MAX_QUEUES;
  937. info.clients = SNDRV_SEQ_MAX_CLIENTS;
  938. info.ports = 256; /* fixed limit */
  939. info.channels = 256; /* fixed limit */
  940. info.cur_clients = client_usage.cur;
  941. info.cur_queues = snd_seq_queue_get_cur_queues();
  942. if (copy_to_user(arg, &info, sizeof(info)))
  943. return -EFAULT;
  944. return 0;
  945. }
  946. /* RUNNING_MODE ioctl() */
  947. static int snd_seq_ioctl_running_mode(client_t *client, void __user *arg)
  948. {
  949. struct sndrv_seq_running_info info;
  950. client_t *cptr;
  951. int err = 0;
  952. if (copy_from_user(&info, arg, sizeof(info)))
  953. return -EFAULT;
  954. /* requested client number */
  955. cptr = snd_seq_client_use_ptr(info.client);
  956. if (cptr == NULL)
  957. return -ENOENT; /* don't change !!! */
  958. #ifdef SNDRV_BIG_ENDIAN
  959. if (! info.big_endian) {
  960. err = -EINVAL;
  961. goto __err;
  962. }
  963. #else
  964. if (info.big_endian) {
  965. err = -EINVAL;
  966. goto __err;
  967. }
  968. #endif
  969. if (info.cpu_mode > sizeof(long)) {
  970. err = -EINVAL;
  971. goto __err;
  972. }
  973. cptr->convert32 = (info.cpu_mode < sizeof(long));
  974. __err:
  975. snd_seq_client_unlock(cptr);
  976. return err;
  977. }
  978. /* CLIENT_INFO ioctl() */
  979. static void get_client_info(client_t *cptr, snd_seq_client_info_t *info)
  980. {
  981. info->client = cptr->number;
  982. /* fill the info fields */
  983. info->type = cptr->type;
  984. strcpy(info->name, cptr->name);
  985. info->filter = cptr->filter;
  986. info->event_lost = cptr->event_lost;
  987. memcpy(info->event_filter, cptr->event_filter, 32);
  988. info->num_ports = cptr->num_ports;
  989. memset(info->reserved, 0, sizeof(info->reserved));
  990. }
  991. static int snd_seq_ioctl_get_client_info(client_t * client, void __user *arg)
  992. {
  993. client_t *cptr;
  994. snd_seq_client_info_t client_info;
  995. if (copy_from_user(&client_info, arg, sizeof(client_info)))
  996. return -EFAULT;
  997. /* requested client number */
  998. cptr = snd_seq_client_use_ptr(client_info.client);
  999. if (cptr == NULL)
  1000. return -ENOENT; /* don't change !!! */
  1001. get_client_info(cptr, &client_info);
  1002. snd_seq_client_unlock(cptr);
  1003. if (copy_to_user(arg, &client_info, sizeof(client_info)))
  1004. return -EFAULT;
  1005. return 0;
  1006. }
  1007. /* CLIENT_INFO ioctl() */
  1008. static int snd_seq_ioctl_set_client_info(client_t * client, void __user *arg)
  1009. {
  1010. snd_seq_client_info_t client_info;
  1011. if (copy_from_user(&client_info, arg, sizeof(client_info)))
  1012. return -EFAULT;
  1013. /* it is not allowed to set the info fields for an another client */
  1014. if (client->number != client_info.client)
  1015. return -EPERM;
  1016. /* also client type must be set now */
  1017. if (client->type != client_info.type)
  1018. return -EINVAL;
  1019. /* fill the info fields */
  1020. if (client_info.name[0])
  1021. strlcpy(client->name, client_info.name, sizeof(client->name));
  1022. client->filter = client_info.filter;
  1023. client->event_lost = client_info.event_lost;
  1024. memcpy(client->event_filter, client_info.event_filter, 32);
  1025. return 0;
  1026. }
  1027. /*
  1028. * CREATE PORT ioctl()
  1029. */
  1030. static int snd_seq_ioctl_create_port(client_t * client, void __user *arg)
  1031. {
  1032. client_port_t *port;
  1033. snd_seq_port_info_t info;
  1034. snd_seq_port_callback_t *callback;
  1035. if (copy_from_user(&info, arg, sizeof(info)))
  1036. return -EFAULT;
  1037. /* it is not allowed to create the port for an another client */
  1038. if (info.addr.client != client->number)
  1039. return -EPERM;
  1040. port = snd_seq_create_port(client, (info.flags & SNDRV_SEQ_PORT_FLG_GIVEN_PORT) ? info.addr.port : -1);
  1041. if (port == NULL)
  1042. return -ENOMEM;
  1043. if (client->type == USER_CLIENT && info.kernel) {
  1044. snd_seq_delete_port(client, port->addr.port);
  1045. return -EINVAL;
  1046. }
  1047. if (client->type == KERNEL_CLIENT) {
  1048. if ((callback = info.kernel) != NULL) {
  1049. if (callback->owner)
  1050. port->owner = callback->owner;
  1051. port->private_data = callback->private_data;
  1052. port->private_free = callback->private_free;
  1053. port->callback_all = callback->callback_all;
  1054. port->event_input = callback->event_input;
  1055. port->c_src.open = callback->subscribe;
  1056. port->c_src.close = callback->unsubscribe;
  1057. port->c_dest.open = callback->use;
  1058. port->c_dest.close = callback->unuse;
  1059. }
  1060. }
  1061. info.addr = port->addr;
  1062. snd_seq_set_port_info(port, &info);
  1063. snd_seq_system_client_ev_port_start(port->addr.client, port->addr.port);
  1064. if (copy_to_user(arg, &info, sizeof(info)))
  1065. return -EFAULT;
  1066. return 0;
  1067. }
  1068. /*
  1069. * DELETE PORT ioctl()
  1070. */
  1071. static int snd_seq_ioctl_delete_port(client_t * client, void __user *arg)
  1072. {
  1073. snd_seq_port_info_t info;
  1074. int err;
  1075. /* set passed parameters */
  1076. if (copy_from_user(&info, arg, sizeof(info)))
  1077. return -EFAULT;
  1078. /* it is not allowed to remove the port for an another client */
  1079. if (info.addr.client != client->number)
  1080. return -EPERM;
  1081. err = snd_seq_delete_port(client, info.addr.port);
  1082. if (err >= 0)
  1083. snd_seq_system_client_ev_port_exit(client->number, info.addr.port);
  1084. return err;
  1085. }
  1086. /*
  1087. * GET_PORT_INFO ioctl() (on any client)
  1088. */
  1089. static int snd_seq_ioctl_get_port_info(client_t *client, void __user *arg)
  1090. {
  1091. client_t *cptr;
  1092. client_port_t *port;
  1093. snd_seq_port_info_t info;
  1094. if (copy_from_user(&info, arg, sizeof(info)))
  1095. return -EFAULT;
  1096. cptr = snd_seq_client_use_ptr(info.addr.client);
  1097. if (cptr == NULL)
  1098. return -ENXIO;
  1099. port = snd_seq_port_use_ptr(cptr, info.addr.port);
  1100. if (port == NULL) {
  1101. snd_seq_client_unlock(cptr);
  1102. return -ENOENT; /* don't change */
  1103. }
  1104. /* get port info */
  1105. snd_seq_get_port_info(port, &info);
  1106. snd_seq_port_unlock(port);
  1107. snd_seq_client_unlock(cptr);
  1108. if (copy_to_user(arg, &info, sizeof(info)))
  1109. return -EFAULT;
  1110. return 0;
  1111. }
  1112. /*
  1113. * SET_PORT_INFO ioctl() (only ports on this/own client)
  1114. */
  1115. static int snd_seq_ioctl_set_port_info(client_t * client, void __user *arg)
  1116. {
  1117. client_port_t *port;
  1118. snd_seq_port_info_t info;
  1119. if (copy_from_user(&info, arg, sizeof(info)))
  1120. return -EFAULT;
  1121. if (info.addr.client != client->number) /* only set our own ports ! */
  1122. return -EPERM;
  1123. port = snd_seq_port_use_ptr(client, info.addr.port);
  1124. if (port) {
  1125. snd_seq_set_port_info(port, &info);
  1126. snd_seq_port_unlock(port);
  1127. }
  1128. return 0;
  1129. }
  1130. /*
  1131. * port subscription (connection)
  1132. */
  1133. #define PERM_RD (SNDRV_SEQ_PORT_CAP_READ|SNDRV_SEQ_PORT_CAP_SUBS_READ)
  1134. #define PERM_WR (SNDRV_SEQ_PORT_CAP_WRITE|SNDRV_SEQ_PORT_CAP_SUBS_WRITE)
  1135. static int check_subscription_permission(client_t *client, client_port_t *sport,
  1136. client_port_t *dport,
  1137. snd_seq_port_subscribe_t *subs)
  1138. {
  1139. if (client->number != subs->sender.client &&
  1140. client->number != subs->dest.client) {
  1141. /* connection by third client - check export permission */
  1142. if (check_port_perm(sport, SNDRV_SEQ_PORT_CAP_NO_EXPORT))
  1143. return -EPERM;
  1144. if (check_port_perm(dport, SNDRV_SEQ_PORT_CAP_NO_EXPORT))
  1145. return -EPERM;
  1146. }
  1147. /* check read permission */
  1148. /* if sender or receiver is the subscribing client itself,
  1149. * no permission check is necessary
  1150. */
  1151. if (client->number != subs->sender.client) {
  1152. if (! check_port_perm(sport, PERM_RD))
  1153. return -EPERM;
  1154. }
  1155. /* check write permission */
  1156. if (client->number != subs->dest.client) {
  1157. if (! check_port_perm(dport, PERM_WR))
  1158. return -EPERM;
  1159. }
  1160. return 0;
  1161. }
  1162. /*
  1163. * send an subscription notify event to user client:
  1164. * client must be user client.
  1165. */
  1166. int snd_seq_client_notify_subscription(int client, int port,
  1167. snd_seq_port_subscribe_t *info, int evtype)
  1168. {
  1169. snd_seq_event_t event;
  1170. memset(&event, 0, sizeof(event));
  1171. event.type = evtype;
  1172. event.data.connect.dest = info->dest;
  1173. event.data.connect.sender = info->sender;
  1174. return snd_seq_system_notify(client, port, &event); /* non-atomic */
  1175. }
  1176. /*
  1177. * add to port's subscription list IOCTL interface
  1178. */
  1179. static int snd_seq_ioctl_subscribe_port(client_t * client, void __user *arg)
  1180. {
  1181. int result = -EINVAL;
  1182. client_t *receiver = NULL, *sender = NULL;
  1183. client_port_t *sport = NULL, *dport = NULL;
  1184. snd_seq_port_subscribe_t subs;
  1185. if (copy_from_user(&subs, arg, sizeof(subs)))
  1186. return -EFAULT;
  1187. if ((receiver = snd_seq_client_use_ptr(subs.dest.client)) == NULL)
  1188. goto __end;
  1189. if ((sender = snd_seq_client_use_ptr(subs.sender.client)) == NULL)
  1190. goto __end;
  1191. if ((sport = snd_seq_port_use_ptr(sender, subs.sender.port)) == NULL)
  1192. goto __end;
  1193. if ((dport = snd_seq_port_use_ptr(receiver, subs.dest.port)) == NULL)
  1194. goto __end;
  1195. result = check_subscription_permission(client, sport, dport, &subs);
  1196. if (result < 0)
  1197. goto __end;
  1198. /* connect them */
  1199. result = snd_seq_port_connect(client, sender, sport, receiver, dport, &subs);
  1200. if (! result) /* broadcast announce */
  1201. snd_seq_client_notify_subscription(SNDRV_SEQ_ADDRESS_SUBSCRIBERS, 0,
  1202. &subs, SNDRV_SEQ_EVENT_PORT_SUBSCRIBED);
  1203. __end:
  1204. if (sport)
  1205. snd_seq_port_unlock(sport);
  1206. if (dport)
  1207. snd_seq_port_unlock(dport);
  1208. if (sender)
  1209. snd_seq_client_unlock(sender);
  1210. if (receiver)
  1211. snd_seq_client_unlock(receiver);
  1212. return result;
  1213. }
  1214. /*
  1215. * remove from port's subscription list
  1216. */
  1217. static int snd_seq_ioctl_unsubscribe_port(client_t * client, void __user *arg)
  1218. {
  1219. int result = -ENXIO;
  1220. client_t *receiver = NULL, *sender = NULL;
  1221. client_port_t *sport = NULL, *dport = NULL;
  1222. snd_seq_port_subscribe_t subs;
  1223. if (copy_from_user(&subs, arg, sizeof(subs)))
  1224. return -EFAULT;
  1225. if ((receiver = snd_seq_client_use_ptr(subs.dest.client)) == NULL)
  1226. goto __end;
  1227. if ((sender = snd_seq_client_use_ptr(subs.sender.client)) == NULL)
  1228. goto __end;
  1229. if ((sport = snd_seq_port_use_ptr(sender, subs.sender.port)) == NULL)
  1230. goto __end;
  1231. if ((dport = snd_seq_port_use_ptr(receiver, subs.dest.port)) == NULL)
  1232. goto __end;
  1233. result = check_subscription_permission(client, sport, dport, &subs);
  1234. if (result < 0)
  1235. goto __end;
  1236. result = snd_seq_port_disconnect(client, sender, sport, receiver, dport, &subs);
  1237. if (! result) /* broadcast announce */
  1238. snd_seq_client_notify_subscription(SNDRV_SEQ_ADDRESS_SUBSCRIBERS, 0,
  1239. &subs, SNDRV_SEQ_EVENT_PORT_UNSUBSCRIBED);
  1240. __end:
  1241. if (sport)
  1242. snd_seq_port_unlock(sport);
  1243. if (dport)
  1244. snd_seq_port_unlock(dport);
  1245. if (sender)
  1246. snd_seq_client_unlock(sender);
  1247. if (receiver)
  1248. snd_seq_client_unlock(receiver);
  1249. return result;
  1250. }
  1251. /* CREATE_QUEUE ioctl() */
  1252. static int snd_seq_ioctl_create_queue(client_t *client, void __user *arg)
  1253. {
  1254. snd_seq_queue_info_t info;
  1255. int result;
  1256. queue_t *q;
  1257. if (copy_from_user(&info, arg, sizeof(info)))
  1258. return -EFAULT;
  1259. result = snd_seq_queue_alloc(client->number, info.locked, info.flags);
  1260. if (result < 0)
  1261. return result;
  1262. q = queueptr(result);
  1263. if (q == NULL)
  1264. return -EINVAL;
  1265. info.queue = q->queue;
  1266. info.locked = q->locked;
  1267. info.owner = q->owner;
  1268. /* set queue name */
  1269. if (! info.name[0])
  1270. snprintf(info.name, sizeof(info.name), "Queue-%d", q->queue);
  1271. strlcpy(q->name, info.name, sizeof(q->name));
  1272. queuefree(q);
  1273. if (copy_to_user(arg, &info, sizeof(info)))
  1274. return -EFAULT;
  1275. return 0;
  1276. }
  1277. /* DELETE_QUEUE ioctl() */
  1278. static int snd_seq_ioctl_delete_queue(client_t *client, void __user *arg)
  1279. {
  1280. snd_seq_queue_info_t info;
  1281. if (copy_from_user(&info, arg, sizeof(info)))
  1282. return -EFAULT;
  1283. return snd_seq_queue_delete(client->number, info.queue);
  1284. }
  1285. /* GET_QUEUE_INFO ioctl() */
  1286. static int snd_seq_ioctl_get_queue_info(client_t *client, void __user *arg)
  1287. {
  1288. snd_seq_queue_info_t info;
  1289. queue_t *q;
  1290. if (copy_from_user(&info, arg, sizeof(info)))
  1291. return -EFAULT;
  1292. q = queueptr(info.queue);
  1293. if (q == NULL)
  1294. return -EINVAL;
  1295. memset(&info, 0, sizeof(info));
  1296. info.queue = q->queue;
  1297. info.owner = q->owner;
  1298. info.locked = q->locked;
  1299. strlcpy(info.name, q->name, sizeof(info.name));
  1300. queuefree(q);
  1301. if (copy_to_user(arg, &info, sizeof(info)))
  1302. return -EFAULT;
  1303. return 0;
  1304. }
  1305. /* SET_QUEUE_INFO ioctl() */
  1306. static int snd_seq_ioctl_set_queue_info(client_t *client, void __user *arg)
  1307. {
  1308. snd_seq_queue_info_t info;
  1309. queue_t *q;
  1310. if (copy_from_user(&info, arg, sizeof(info)))
  1311. return -EFAULT;
  1312. if (info.owner != client->number)
  1313. return -EINVAL;
  1314. /* change owner/locked permission */
  1315. if (snd_seq_queue_check_access(info.queue, client->number)) {
  1316. if (snd_seq_queue_set_owner(info.queue, client->number, info.locked) < 0)
  1317. return -EPERM;
  1318. if (info.locked)
  1319. snd_seq_queue_use(info.queue, client->number, 1);
  1320. } else {
  1321. return -EPERM;
  1322. }
  1323. q = queueptr(info.queue);
  1324. if (! q)
  1325. return -EINVAL;
  1326. if (q->owner != client->number) {
  1327. queuefree(q);
  1328. return -EPERM;
  1329. }
  1330. strlcpy(q->name, info.name, sizeof(q->name));
  1331. queuefree(q);
  1332. return 0;
  1333. }
  1334. /* GET_NAMED_QUEUE ioctl() */
  1335. static int snd_seq_ioctl_get_named_queue(client_t *client, void __user *arg)
  1336. {
  1337. snd_seq_queue_info_t info;
  1338. queue_t *q;
  1339. if (copy_from_user(&info, arg, sizeof(info)))
  1340. return -EFAULT;
  1341. q = snd_seq_queue_find_name(info.name);
  1342. if (q == NULL)
  1343. return -EINVAL;
  1344. info.queue = q->queue;
  1345. info.owner = q->owner;
  1346. info.locked = q->locked;
  1347. queuefree(q);
  1348. if (copy_to_user(arg, &info, sizeof(info)))
  1349. return -EFAULT;
  1350. return 0;
  1351. }
  1352. /* GET_QUEUE_STATUS ioctl() */
  1353. static int snd_seq_ioctl_get_queue_status(client_t * client, void __user *arg)
  1354. {
  1355. snd_seq_queue_status_t status;
  1356. queue_t *queue;
  1357. seq_timer_t *tmr;
  1358. if (copy_from_user(&status, arg, sizeof(status)))
  1359. return -EFAULT;
  1360. queue = queueptr(status.queue);
  1361. if (queue == NULL)
  1362. return -EINVAL;
  1363. memset(&status, 0, sizeof(status));
  1364. status.queue = queue->queue;
  1365. tmr = queue->timer;
  1366. status.events = queue->tickq->cells + queue->timeq->cells;
  1367. status.time = snd_seq_timer_get_cur_time(tmr);
  1368. status.tick = snd_seq_timer_get_cur_tick(tmr);
  1369. status.running = tmr->running;
  1370. status.flags = queue->flags;
  1371. queuefree(queue);
  1372. if (copy_to_user(arg, &status, sizeof(status)))
  1373. return -EFAULT;
  1374. return 0;
  1375. }
  1376. /* GET_QUEUE_TEMPO ioctl() */
  1377. static int snd_seq_ioctl_get_queue_tempo(client_t * client, void __user *arg)
  1378. {
  1379. snd_seq_queue_tempo_t tempo;
  1380. queue_t *queue;
  1381. seq_timer_t *tmr;
  1382. if (copy_from_user(&tempo, arg, sizeof(tempo)))
  1383. return -EFAULT;
  1384. queue = queueptr(tempo.queue);
  1385. if (queue == NULL)
  1386. return -EINVAL;
  1387. memset(&tempo, 0, sizeof(tempo));
  1388. tempo.queue = queue->queue;
  1389. tmr = queue->timer;
  1390. tempo.tempo = tmr->tempo;
  1391. tempo.ppq = tmr->ppq;
  1392. tempo.skew_value = tmr->skew;
  1393. tempo.skew_base = tmr->skew_base;
  1394. queuefree(queue);
  1395. if (copy_to_user(arg, &tempo, sizeof(tempo)))
  1396. return -EFAULT;
  1397. return 0;
  1398. }
  1399. /* SET_QUEUE_TEMPO ioctl() */
  1400. int snd_seq_set_queue_tempo(int client, snd_seq_queue_tempo_t *tempo)
  1401. {
  1402. if (!snd_seq_queue_check_access(tempo->queue, client))
  1403. return -EPERM;
  1404. return snd_seq_queue_timer_set_tempo(tempo->queue, client, tempo);
  1405. }
  1406. static int snd_seq_ioctl_set_queue_tempo(client_t * client, void __user *arg)
  1407. {
  1408. int result;
  1409. snd_seq_queue_tempo_t tempo;
  1410. if (copy_from_user(&tempo, arg, sizeof(tempo)))
  1411. return -EFAULT;
  1412. result = snd_seq_set_queue_tempo(client->number, &tempo);
  1413. return result < 0 ? result : 0;
  1414. }
  1415. /* GET_QUEUE_TIMER ioctl() */
  1416. static int snd_seq_ioctl_get_queue_timer(client_t * client, void __user *arg)
  1417. {
  1418. snd_seq_queue_timer_t timer;
  1419. queue_t *queue;
  1420. seq_timer_t *tmr;
  1421. if (copy_from_user(&timer, arg, sizeof(timer)))
  1422. return -EFAULT;
  1423. queue = queueptr(timer.queue);
  1424. if (queue == NULL)
  1425. return -EINVAL;
  1426. if (down_interruptible(&queue->timer_mutex)) {
  1427. queuefree(queue);
  1428. return -ERESTARTSYS;
  1429. }
  1430. tmr = queue->timer;
  1431. memset(&timer, 0, sizeof(timer));
  1432. timer.queue = queue->queue;
  1433. timer.type = tmr->type;
  1434. if (tmr->type == SNDRV_SEQ_TIMER_ALSA) {
  1435. timer.u.alsa.id = tmr->alsa_id;
  1436. timer.u.alsa.resolution = tmr->preferred_resolution;
  1437. }
  1438. up(&queue->timer_mutex);
  1439. queuefree(queue);
  1440. if (copy_to_user(arg, &timer, sizeof(timer)))
  1441. return -EFAULT;
  1442. return 0;
  1443. }
  1444. /* SET_QUEUE_TIMER ioctl() */
  1445. static int snd_seq_ioctl_set_queue_timer(client_t * client, void __user *arg)
  1446. {
  1447. int result = 0;
  1448. snd_seq_queue_timer_t timer;
  1449. if (copy_from_user(&timer, arg, sizeof(timer)))
  1450. return -EFAULT;
  1451. if (timer.type != SNDRV_SEQ_TIMER_ALSA)
  1452. return -EINVAL;
  1453. if (snd_seq_queue_check_access(timer.queue, client->number)) {
  1454. queue_t *q;
  1455. seq_timer_t *tmr;
  1456. q = queueptr(timer.queue);
  1457. if (q == NULL)
  1458. return -ENXIO;
  1459. if (down_interruptible(&q->timer_mutex)) {
  1460. queuefree(q);
  1461. return -ERESTARTSYS;
  1462. }
  1463. tmr = q->timer;
  1464. snd_seq_queue_timer_close(timer.queue);
  1465. tmr->type = timer.type;
  1466. if (tmr->type == SNDRV_SEQ_TIMER_ALSA) {
  1467. tmr->alsa_id = timer.u.alsa.id;
  1468. tmr->preferred_resolution = timer.u.alsa.resolution;
  1469. }
  1470. result = snd_seq_queue_timer_open(timer.queue);
  1471. up(&q->timer_mutex);
  1472. queuefree(q);
  1473. } else {
  1474. return -EPERM;
  1475. }
  1476. return result;
  1477. }
  1478. /* GET_QUEUE_CLIENT ioctl() */
  1479. static int snd_seq_ioctl_get_queue_client(client_t * client, void __user *arg)
  1480. {
  1481. snd_seq_queue_client_t info;
  1482. int used;
  1483. if (copy_from_user(&info, arg, sizeof(info)))
  1484. return -EFAULT;
  1485. used = snd_seq_queue_is_used(info.queue, client->number);
  1486. if (used < 0)
  1487. return -EINVAL;
  1488. info.used = used;
  1489. info.client = client->number;
  1490. if (copy_to_user(arg, &info, sizeof(info)))
  1491. return -EFAULT;
  1492. return 0;
  1493. }
  1494. /* SET_QUEUE_CLIENT ioctl() */
  1495. static int snd_seq_ioctl_set_queue_client(client_t * client, void __user *arg)
  1496. {
  1497. int err;
  1498. snd_seq_queue_client_t info;
  1499. if (copy_from_user(&info, arg, sizeof(info)))
  1500. return -EFAULT;
  1501. if (info.used >= 0) {
  1502. err = snd_seq_queue_use(info.queue, client->number, info.used);
  1503. if (err < 0)
  1504. return err;
  1505. }
  1506. return snd_seq_ioctl_get_queue_client(client, arg);
  1507. }
  1508. /* GET_CLIENT_POOL ioctl() */
  1509. static int snd_seq_ioctl_get_client_pool(client_t * client, void __user *arg)
  1510. {
  1511. snd_seq_client_pool_t info;
  1512. client_t *cptr;
  1513. if (copy_from_user(&info, arg, sizeof(info)))
  1514. return -EFAULT;
  1515. cptr = snd_seq_client_use_ptr(info.client);
  1516. if (cptr == NULL)
  1517. return -ENOENT;
  1518. memset(&info, 0, sizeof(info));
  1519. info.output_pool = cptr->pool->size;
  1520. info.output_room = cptr->pool->room;
  1521. info.output_free = info.output_pool;
  1522. if (cptr->pool)
  1523. info.output_free = snd_seq_unused_cells(cptr->pool);
  1524. if (cptr->type == USER_CLIENT) {
  1525. info.input_pool = cptr->data.user.fifo_pool_size;
  1526. info.input_free = info.input_pool;
  1527. if (cptr->data.user.fifo)
  1528. info.input_free = snd_seq_unused_cells(cptr->data.user.fifo->pool);
  1529. } else {
  1530. info.input_pool = 0;
  1531. info.input_free = 0;
  1532. }
  1533. snd_seq_client_unlock(cptr);
  1534. if (copy_to_user(arg, &info, sizeof(info)))
  1535. return -EFAULT;
  1536. return 0;
  1537. }
  1538. /* SET_CLIENT_POOL ioctl() */
  1539. static int snd_seq_ioctl_set_client_pool(client_t * client, void __user *arg)
  1540. {
  1541. snd_seq_client_pool_t info;
  1542. int rc;
  1543. if (copy_from_user(&info, arg, sizeof(info)))
  1544. return -EFAULT;
  1545. if (client->number != info.client)
  1546. return -EINVAL; /* can't change other clients */
  1547. if (info.output_pool >= 1 && info.output_pool <= SNDRV_SEQ_MAX_EVENTS &&
  1548. (! snd_seq_write_pool_allocated(client) ||
  1549. info.output_pool != client->pool->size)) {
  1550. if (snd_seq_write_pool_allocated(client)) {
  1551. /* remove all existing cells */
  1552. snd_seq_queue_client_leave_cells(client->number);
  1553. snd_seq_pool_done(client->pool);
  1554. }
  1555. client->pool->size = info.output_pool;
  1556. rc = snd_seq_pool_init(client->pool);
  1557. if (rc < 0)
  1558. return rc;
  1559. }
  1560. if (client->type == USER_CLIENT && client->data.user.fifo != NULL &&
  1561. info.input_pool >= 1 &&
  1562. info.input_pool <= SNDRV_SEQ_MAX_CLIENT_EVENTS &&
  1563. info.input_pool != client->data.user.fifo_pool_size) {
  1564. /* change pool size */
  1565. rc = snd_seq_fifo_resize(client->data.user.fifo, info.input_pool);
  1566. if (rc < 0)
  1567. return rc;
  1568. client->data.user.fifo_pool_size = info.input_pool;
  1569. }
  1570. if (info.output_room >= 1 &&
  1571. info.output_room <= client->pool->size) {
  1572. client->pool->room = info.output_room;
  1573. }
  1574. return snd_seq_ioctl_get_client_pool(client, arg);
  1575. }
  1576. /* REMOVE_EVENTS ioctl() */
  1577. static int snd_seq_ioctl_remove_events(client_t * client, void __user *arg)
  1578. {
  1579. snd_seq_remove_events_t info;
  1580. if (copy_from_user(&info, arg, sizeof(info)))
  1581. return -EFAULT;
  1582. /*
  1583. * Input mostly not implemented XXX.
  1584. */
  1585. if (info.remove_mode & SNDRV_SEQ_REMOVE_INPUT) {
  1586. /*
  1587. * No restrictions so for a user client we can clear
  1588. * the whole fifo
  1589. */
  1590. if (client->type == USER_CLIENT)
  1591. snd_seq_fifo_clear(client->data.user.fifo);
  1592. }
  1593. if (info.remove_mode & SNDRV_SEQ_REMOVE_OUTPUT)
  1594. snd_seq_queue_remove_cells(client->number, &info);
  1595. return 0;
  1596. }
  1597. /*
  1598. * get subscription info
  1599. */
  1600. static int snd_seq_ioctl_get_subscription(client_t *client, void __user *arg)
  1601. {
  1602. int result;
  1603. client_t *sender = NULL;
  1604. client_port_t *sport = NULL;
  1605. snd_seq_port_subscribe_t subs;
  1606. subscribers_t *p;
  1607. if (copy_from_user(&subs, arg, sizeof(subs)))
  1608. return -EFAULT;
  1609. result = -EINVAL;
  1610. if ((sender = snd_seq_client_use_ptr(subs.sender.client)) == NULL)
  1611. goto __end;
  1612. if ((sport = snd_seq_port_use_ptr(sender, subs.sender.port)) == NULL)
  1613. goto __end;
  1614. p = snd_seq_port_get_subscription(&sport->c_src, &subs.dest);
  1615. if (p) {
  1616. result = 0;
  1617. subs = p->info;
  1618. } else
  1619. result = -ENOENT;
  1620. __end:
  1621. if (sport)
  1622. snd_seq_port_unlock(sport);
  1623. if (sender)
  1624. snd_seq_client_unlock(sender);
  1625. if (result >= 0) {
  1626. if (copy_to_user(arg, &subs, sizeof(subs)))
  1627. return -EFAULT;
  1628. }
  1629. return result;
  1630. }
  1631. /*
  1632. * get subscription info - check only its presence
  1633. */
  1634. static int snd_seq_ioctl_query_subs(client_t *client, void __user *arg)
  1635. {
  1636. int result = -ENXIO;
  1637. client_t *cptr = NULL;
  1638. client_port_t *port = NULL;
  1639. snd_seq_query_subs_t subs;
  1640. port_subs_info_t *group;
  1641. struct list_head *p;
  1642. int i;
  1643. if (copy_from_user(&subs, arg, sizeof(subs)))
  1644. return -EFAULT;
  1645. if ((cptr = snd_seq_client_use_ptr(subs.root.client)) == NULL)
  1646. goto __end;
  1647. if ((port = snd_seq_port_use_ptr(cptr, subs.root.port)) == NULL)
  1648. goto __end;
  1649. switch (subs.type) {
  1650. case SNDRV_SEQ_QUERY_SUBS_READ:
  1651. group = &port->c_src;
  1652. break;
  1653. case SNDRV_SEQ_QUERY_SUBS_WRITE:
  1654. group = &port->c_dest;
  1655. break;
  1656. default:
  1657. goto __end;
  1658. }
  1659. down_read(&group->list_mutex);
  1660. /* search for the subscriber */
  1661. subs.num_subs = group->count;
  1662. i = 0;
  1663. result = -ENOENT;
  1664. list_for_each(p, &group->list_head) {
  1665. if (i++ == subs.index) {
  1666. /* found! */
  1667. subscribers_t *s;
  1668. if (subs.type == SNDRV_SEQ_QUERY_SUBS_READ) {
  1669. s = list_entry(p, subscribers_t, src_list);
  1670. subs.addr = s->info.dest;
  1671. } else {
  1672. s = list_entry(p, subscribers_t, dest_list);
  1673. subs.addr = s->info.sender;
  1674. }
  1675. subs.flags = s->info.flags;
  1676. subs.queue = s->info.queue;
  1677. result = 0;
  1678. break;
  1679. }
  1680. }
  1681. up_read(&group->list_mutex);
  1682. __end:
  1683. if (port)
  1684. snd_seq_port_unlock(port);
  1685. if (cptr)
  1686. snd_seq_client_unlock(cptr);
  1687. if (result >= 0) {
  1688. if (copy_to_user(arg, &subs, sizeof(subs)))
  1689. return -EFAULT;
  1690. }
  1691. return result;
  1692. }
  1693. /*
  1694. * query next client
  1695. */
  1696. static int snd_seq_ioctl_query_next_client(client_t *client, void __user *arg)
  1697. {
  1698. client_t *cptr = NULL;
  1699. snd_seq_client_info_t info;
  1700. if (copy_from_user(&info, arg, sizeof(info)))
  1701. return -EFAULT;
  1702. /* search for next client */
  1703. info.client++;
  1704. if (info.client < 0)
  1705. info.client = 0;
  1706. for (; info.client < SNDRV_SEQ_MAX_CLIENTS; info.client++) {
  1707. cptr = snd_seq_client_use_ptr(info.client);
  1708. if (cptr)
  1709. break; /* found */
  1710. }
  1711. if (cptr == NULL)
  1712. return -ENOENT;
  1713. get_client_info(cptr, &info);
  1714. snd_seq_client_unlock(cptr);
  1715. if (copy_to_user(arg, &info, sizeof(info)))
  1716. return -EFAULT;
  1717. return 0;
  1718. }
  1719. /*
  1720. * query next port
  1721. */
  1722. static int snd_seq_ioctl_query_next_port(client_t *client, void __user *arg)
  1723. {
  1724. client_t *cptr;
  1725. client_port_t *port = NULL;
  1726. snd_seq_port_info_t info;
  1727. if (copy_from_user(&info, arg, sizeof(info)))
  1728. return -EFAULT;
  1729. cptr = snd_seq_client_use_ptr(info.addr.client);
  1730. if (cptr == NULL)
  1731. return -ENXIO;
  1732. /* search for next port */
  1733. info.addr.port++;
  1734. port = snd_seq_port_query_nearest(cptr, &info);
  1735. if (port == NULL) {
  1736. snd_seq_client_unlock(cptr);
  1737. return -ENOENT;
  1738. }
  1739. /* get port info */
  1740. info.addr = port->addr;
  1741. snd_seq_get_port_info(port, &info);
  1742. snd_seq_port_unlock(port);
  1743. snd_seq_client_unlock(cptr);
  1744. if (copy_to_user(arg, &info, sizeof(info)))
  1745. return -EFAULT;
  1746. return 0;
  1747. }
  1748. /* -------------------------------------------------------- */
  1749. static struct seq_ioctl_table {
  1750. unsigned int cmd;
  1751. int (*func)(client_t *client, void __user * arg);
  1752. } ioctl_tables[] = {
  1753. { SNDRV_SEQ_IOCTL_SYSTEM_INFO, snd_seq_ioctl_system_info },
  1754. { SNDRV_SEQ_IOCTL_RUNNING_MODE, snd_seq_ioctl_running_mode },
  1755. { SNDRV_SEQ_IOCTL_GET_CLIENT_INFO, snd_seq_ioctl_get_client_info },
  1756. { SNDRV_SEQ_IOCTL_SET_CLIENT_INFO, snd_seq_ioctl_set_client_info },
  1757. { SNDRV_SEQ_IOCTL_CREATE_PORT, snd_seq_ioctl_create_port },
  1758. { SNDRV_SEQ_IOCTL_DELETE_PORT, snd_seq_ioctl_delete_port },
  1759. { SNDRV_SEQ_IOCTL_GET_PORT_INFO, snd_seq_ioctl_get_port_info },
  1760. { SNDRV_SEQ_IOCTL_SET_PORT_INFO, snd_seq_ioctl_set_port_info },
  1761. { SNDRV_SEQ_IOCTL_SUBSCRIBE_PORT, snd_seq_ioctl_subscribe_port },
  1762. { SNDRV_SEQ_IOCTL_UNSUBSCRIBE_PORT, snd_seq_ioctl_unsubscribe_port },
  1763. { SNDRV_SEQ_IOCTL_CREATE_QUEUE, snd_seq_ioctl_create_queue },
  1764. { SNDRV_SEQ_IOCTL_DELETE_QUEUE, snd_seq_ioctl_delete_queue },
  1765. { SNDRV_SEQ_IOCTL_GET_QUEUE_INFO, snd_seq_ioctl_get_queue_info },
  1766. { SNDRV_SEQ_IOCTL_SET_QUEUE_INFO, snd_seq_ioctl_set_queue_info },
  1767. { SNDRV_SEQ_IOCTL_GET_NAMED_QUEUE, snd_seq_ioctl_get_named_queue },
  1768. { SNDRV_SEQ_IOCTL_GET_QUEUE_STATUS, snd_seq_ioctl_get_queue_status },
  1769. { SNDRV_SEQ_IOCTL_GET_QUEUE_TEMPO, snd_seq_ioctl_get_queue_tempo },
  1770. { SNDRV_SEQ_IOCTL_SET_QUEUE_TEMPO, snd_seq_ioctl_set_queue_tempo },
  1771. { SNDRV_SEQ_IOCTL_GET_QUEUE_TIMER, snd_seq_ioctl_get_queue_timer },
  1772. { SNDRV_SEQ_IOCTL_SET_QUEUE_TIMER, snd_seq_ioctl_set_queue_timer },
  1773. { SNDRV_SEQ_IOCTL_GET_QUEUE_CLIENT, snd_seq_ioctl_get_queue_client },
  1774. { SNDRV_SEQ_IOCTL_SET_QUEUE_CLIENT, snd_seq_ioctl_set_queue_client },
  1775. { SNDRV_SEQ_IOCTL_GET_CLIENT_POOL, snd_seq_ioctl_get_client_pool },
  1776. { SNDRV_SEQ_IOCTL_SET_CLIENT_POOL, snd_seq_ioctl_set_client_pool },
  1777. { SNDRV_SEQ_IOCTL_GET_SUBSCRIPTION, snd_seq_ioctl_get_subscription },
  1778. { SNDRV_SEQ_IOCTL_QUERY_NEXT_CLIENT, snd_seq_ioctl_query_next_client },
  1779. { SNDRV_SEQ_IOCTL_QUERY_NEXT_PORT, snd_seq_ioctl_query_next_port },
  1780. { SNDRV_SEQ_IOCTL_REMOVE_EVENTS, snd_seq_ioctl_remove_events },
  1781. { SNDRV_SEQ_IOCTL_QUERY_SUBS, snd_seq_ioctl_query_subs },
  1782. { 0, NULL },
  1783. };
  1784. static int snd_seq_do_ioctl(client_t *client, unsigned int cmd, void __user *arg)
  1785. {
  1786. struct seq_ioctl_table *p;
  1787. switch (cmd) {
  1788. case SNDRV_SEQ_IOCTL_PVERSION:
  1789. /* return sequencer version number */
  1790. return put_user(SNDRV_SEQ_VERSION, (int __user *)arg) ? -EFAULT : 0;
  1791. case SNDRV_SEQ_IOCTL_CLIENT_ID:
  1792. /* return the id of this client */
  1793. return put_user(client->number, (int __user *)arg) ? -EFAULT : 0;
  1794. }
  1795. if (! arg)
  1796. return -EFAULT;
  1797. for (p = ioctl_tables; p->cmd; p++) {
  1798. if (p->cmd == cmd)
  1799. return p->func(client, arg);
  1800. }
  1801. snd_printd("seq unknown ioctl() 0x%x (type='%c', number=0x%2x)\n",
  1802. cmd, _IOC_TYPE(cmd), _IOC_NR(cmd));
  1803. return -ENOTTY;
  1804. }
  1805. static long snd_seq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  1806. {
  1807. client_t *client = (client_t *) file->private_data;
  1808. snd_assert(client != NULL, return -ENXIO);
  1809. return snd_seq_do_ioctl(client, cmd, (void __user *) arg);
  1810. }
  1811. #ifdef CONFIG_COMPAT
  1812. #include "seq_compat.c"
  1813. #else
  1814. #define snd_seq_ioctl_compat NULL
  1815. #endif
  1816. /* -------------------------------------------------------- */
  1817. /* exported to kernel modules */
  1818. int snd_seq_create_kernel_client(snd_card_t *card, int client_index, snd_seq_client_callback_t * callback)
  1819. {
  1820. client_t *client;
  1821. snd_assert(! in_interrupt(), return -EBUSY);
  1822. if (callback == NULL)
  1823. return -EINVAL;
  1824. if (card && client_index > 7)
  1825. return -EINVAL;
  1826. if (card == NULL && client_index > 63)
  1827. return -EINVAL;
  1828. if (card)
  1829. client_index += 64 + (card->number << 3);
  1830. if (down_interruptible(&register_mutex))
  1831. return -ERESTARTSYS;
  1832. /* empty write queue as default */
  1833. client = seq_create_client1(client_index, 0);
  1834. if (client == NULL) {
  1835. up(&register_mutex);
  1836. return -EBUSY; /* failure code */
  1837. }
  1838. usage_alloc(&client_usage, 1);
  1839. client->accept_input = callback->allow_output;
  1840. client->accept_output = callback->allow_input;
  1841. /* fill client data */
  1842. client->data.kernel.card = card;
  1843. client->data.kernel.private_data = callback->private_data;
  1844. sprintf(client->name, "Client-%d", client->number);
  1845. client->type = KERNEL_CLIENT;
  1846. up(&register_mutex);
  1847. /* make others aware this new client */
  1848. snd_seq_system_client_ev_client_start(client->number);
  1849. /* return client number to caller */
  1850. return client->number;
  1851. }
  1852. /* exported to kernel modules */
  1853. int snd_seq_delete_kernel_client(int client)
  1854. {
  1855. client_t *ptr;
  1856. snd_assert(! in_interrupt(), return -EBUSY);
  1857. ptr = clientptr(client);
  1858. if (ptr == NULL)
  1859. return -EINVAL;
  1860. seq_free_client(ptr);
  1861. kfree(ptr);
  1862. return 0;
  1863. }
  1864. /* skeleton to enqueue event, called from snd_seq_kernel_client_enqueue
  1865. * and snd_seq_kernel_client_enqueue_blocking
  1866. */
  1867. static int kernel_client_enqueue(int client, snd_seq_event_t *ev,
  1868. struct file *file, int blocking,
  1869. int atomic, int hop)
  1870. {
  1871. client_t *cptr;
  1872. int result;
  1873. snd_assert(ev != NULL, return -EINVAL);
  1874. if (ev->type == SNDRV_SEQ_EVENT_NONE)
  1875. return 0; /* ignore this */
  1876. if (ev->type == SNDRV_SEQ_EVENT_KERNEL_ERROR)
  1877. return -EINVAL; /* quoted events can't be enqueued */
  1878. /* fill in client number */
  1879. ev->source.client = client;
  1880. if (check_event_type_and_length(ev))
  1881. return -EINVAL;
  1882. cptr = snd_seq_client_use_ptr(client);
  1883. if (cptr == NULL)
  1884. return -EINVAL;
  1885. if (! cptr->accept_output)
  1886. result = -EPERM;
  1887. else /* send it */
  1888. result = snd_seq_client_enqueue_event(cptr, ev, file, blocking, atomic, hop);
  1889. snd_seq_client_unlock(cptr);
  1890. return result;
  1891. }
  1892. /*
  1893. * exported, called by kernel clients to enqueue events (w/o blocking)
  1894. *
  1895. * RETURN VALUE: zero if succeed, negative if error
  1896. */
  1897. int snd_seq_kernel_client_enqueue(int client, snd_seq_event_t * ev,
  1898. int atomic, int hop)
  1899. {
  1900. return kernel_client_enqueue(client, ev, NULL, 0, atomic, hop);
  1901. }
  1902. /*
  1903. * exported, called by kernel clients to enqueue events (with blocking)
  1904. *
  1905. * RETURN VALUE: zero if succeed, negative if error
  1906. */
  1907. int snd_seq_kernel_client_enqueue_blocking(int client, snd_seq_event_t * ev,
  1908. struct file *file,
  1909. int atomic, int hop)
  1910. {
  1911. return kernel_client_enqueue(client, ev, file, 1, atomic, hop);
  1912. }
  1913. /*
  1914. * exported, called by kernel clients to dispatch events directly to other
  1915. * clients, bypassing the queues. Event time-stamp will be updated.
  1916. *
  1917. * RETURN VALUE: negative = delivery failed,
  1918. * zero, or positive: the number of delivered events
  1919. */
  1920. int snd_seq_kernel_client_dispatch(int client, snd_seq_event_t * ev,
  1921. int atomic, int hop)
  1922. {
  1923. client_t *cptr;
  1924. int result;
  1925. snd_assert(ev != NULL, return -EINVAL);
  1926. /* fill in client number */
  1927. ev->queue = SNDRV_SEQ_QUEUE_DIRECT;
  1928. ev->source.client = client;
  1929. if (check_event_type_and_length(ev))
  1930. return -EINVAL;
  1931. cptr = snd_seq_client_use_ptr(client);
  1932. if (cptr == NULL)
  1933. return -EINVAL;
  1934. if (!cptr->accept_output)
  1935. result = -EPERM;
  1936. else
  1937. result = snd_seq_deliver_event(cptr, ev, atomic, hop);
  1938. snd_seq_client_unlock(cptr);
  1939. return result;
  1940. }
  1941. /*
  1942. * exported, called by kernel clients to perform same functions as with
  1943. * userland ioctl()
  1944. */
  1945. int snd_seq_kernel_client_ctl(int clientid, unsigned int cmd, void *arg)
  1946. {
  1947. client_t *client;
  1948. mm_segment_t fs;
  1949. int result;
  1950. client = clientptr(clientid);
  1951. if (client == NULL)
  1952. return -ENXIO;
  1953. fs = snd_enter_user();
  1954. result = snd_seq_do_ioctl(client, cmd, (void __user *)arg);
  1955. snd_leave_user(fs);
  1956. return result;
  1957. }
  1958. /* exported (for OSS emulator) */
  1959. int snd_seq_kernel_client_write_poll(int clientid, struct file *file, poll_table *wait)
  1960. {
  1961. client_t *client;
  1962. client = clientptr(clientid);
  1963. if (client == NULL)
  1964. return -ENXIO;
  1965. if (! snd_seq_write_pool_allocated(client))
  1966. return 1;
  1967. if (snd_seq_pool_poll_wait(client->pool, file, wait))
  1968. return 1;
  1969. return 0;
  1970. }
  1971. /*---------------------------------------------------------------------------*/
  1972. /*
  1973. * /proc interface
  1974. */
  1975. static void snd_seq_info_dump_subscribers(snd_info_buffer_t *buffer, port_subs_info_t *group, int is_src, char *msg)
  1976. {
  1977. struct list_head *p;
  1978. subscribers_t *s;
  1979. int count = 0;
  1980. down_read(&group->list_mutex);
  1981. if (list_empty(&group->list_head)) {
  1982. up_read(&group->list_mutex);
  1983. return;
  1984. }
  1985. snd_iprintf(buffer, msg);
  1986. list_for_each(p, &group->list_head) {
  1987. if (is_src)
  1988. s = list_entry(p, subscribers_t, src_list);
  1989. else
  1990. s = list_entry(p, subscribers_t, dest_list);
  1991. if (count++)
  1992. snd_iprintf(buffer, ", ");
  1993. snd_iprintf(buffer, "%d:%d",
  1994. is_src ? s->info.dest.client : s->info.sender.client,
  1995. is_src ? s->info.dest.port : s->info.sender.port);
  1996. if (s->info.flags & SNDRV_SEQ_PORT_SUBS_TIMESTAMP)
  1997. snd_iprintf(buffer, "[%c:%d]", ((s->info.flags & SNDRV_SEQ_PORT_SUBS_TIME_REAL) ? 'r' : 't'), s->info.queue);
  1998. if (group->exclusive)
  1999. snd_iprintf(buffer, "[ex]");
  2000. }
  2001. up_read(&group->list_mutex);
  2002. snd_iprintf(buffer, "\n");
  2003. }
  2004. #define FLAG_PERM_RD(perm) ((perm) & SNDRV_SEQ_PORT_CAP_READ ? ((perm) & SNDRV_SEQ_PORT_CAP_SUBS_READ ? 'R' : 'r') : '-')
  2005. #define FLAG_PERM_WR(perm) ((perm) & SNDRV_SEQ_PORT_CAP_WRITE ? ((perm) & SNDRV_SEQ_PORT_CAP_SUBS_WRITE ? 'W' : 'w') : '-')
  2006. #define FLAG_PERM_EX(perm) ((perm) & SNDRV_SEQ_PORT_CAP_NO_EXPORT ? '-' : 'e')
  2007. #define FLAG_PERM_DUPLEX(perm) ((perm) & SNDRV_SEQ_PORT_CAP_DUPLEX ? 'X' : '-')
  2008. static void snd_seq_info_dump_ports(snd_info_buffer_t *buffer, client_t *client)
  2009. {
  2010. struct list_head *l;
  2011. down(&client->ports_mutex);
  2012. list_for_each(l, &client->ports_list_head) {
  2013. client_port_t *p = list_entry(l, client_port_t, list);
  2014. snd_iprintf(buffer, " Port %3d : \"%s\" (%c%c%c%c)\n",
  2015. p->addr.port, p->name,
  2016. FLAG_PERM_RD(p->capability),
  2017. FLAG_PERM_WR(p->capability),
  2018. FLAG_PERM_EX(p->capability),
  2019. FLAG_PERM_DUPLEX(p->capability));
  2020. snd_seq_info_dump_subscribers(buffer, &p->c_src, 1, " Connecting To: ");
  2021. snd_seq_info_dump_subscribers(buffer, &p->c_dest, 0, " Connected From: ");
  2022. }
  2023. up(&client->ports_mutex);
  2024. }
  2025. /* exported to seq_info.c */
  2026. void snd_seq_info_clients_read(snd_info_entry_t *entry,
  2027. snd_info_buffer_t * buffer)
  2028. {
  2029. extern void snd_seq_info_pool(snd_info_buffer_t * buffer, pool_t * pool, char *space);
  2030. int c;
  2031. client_t *client;
  2032. snd_iprintf(buffer, "Client info\n");
  2033. snd_iprintf(buffer, " cur clients : %d\n", client_usage.cur);
  2034. snd_iprintf(buffer, " peak clients : %d\n", client_usage.peak);
  2035. snd_iprintf(buffer, " max clients : %d\n", SNDRV_SEQ_MAX_CLIENTS);
  2036. snd_iprintf(buffer, "\n");
  2037. /* list the client table */
  2038. for (c = 0; c < SNDRV_SEQ_MAX_CLIENTS; c++) {
  2039. client = snd_seq_client_use_ptr(c);
  2040. if (client == NULL)
  2041. continue;
  2042. if (client->type == NO_CLIENT) {
  2043. snd_seq_client_unlock(client);
  2044. continue;
  2045. }
  2046. snd_iprintf(buffer, "Client %3d : \"%s\" [%s]\n",
  2047. c, client->name,
  2048. client->type == USER_CLIENT ? "User" : "Kernel");
  2049. snd_seq_info_dump_ports(buffer, client);
  2050. if (snd_seq_write_pool_allocated(client)) {
  2051. snd_iprintf(buffer, " Output pool :\n");
  2052. snd_seq_info_pool(buffer, client->pool, " ");
  2053. }
  2054. if (client->type == USER_CLIENT && client->data.user.fifo &&
  2055. client->data.user.fifo->pool) {
  2056. snd_iprintf(buffer, " Input pool :\n");
  2057. snd_seq_info_pool(buffer, client->data.user.fifo->pool, " ");
  2058. }
  2059. snd_seq_client_unlock(client);
  2060. }
  2061. }
  2062. /*---------------------------------------------------------------------------*/
  2063. /*
  2064. * REGISTRATION PART
  2065. */
  2066. static struct file_operations snd_seq_f_ops =
  2067. {
  2068. .owner = THIS_MODULE,
  2069. .read = snd_seq_read,
  2070. .write = snd_seq_write,
  2071. .open = snd_seq_open,
  2072. .release = snd_seq_release,
  2073. .poll = snd_seq_poll,
  2074. .unlocked_ioctl = snd_seq_ioctl,
  2075. .compat_ioctl = snd_seq_ioctl_compat,
  2076. };
  2077. static snd_minor_t snd_seq_reg =
  2078. {
  2079. .comment = "sequencer",
  2080. .f_ops = &snd_seq_f_ops,
  2081. };
  2082. /*
  2083. * register sequencer device
  2084. */
  2085. int __init snd_sequencer_device_init(void)
  2086. {
  2087. int err;
  2088. if (down_interruptible(&register_mutex))
  2089. return -ERESTARTSYS;
  2090. if ((err = snd_register_device(SNDRV_DEVICE_TYPE_SEQUENCER, NULL, 0, &snd_seq_reg, "seq")) < 0) {
  2091. up(&register_mutex);
  2092. return err;
  2093. }
  2094. up(&register_mutex);
  2095. return 0;
  2096. }
  2097. /*
  2098. * unregister sequencer device
  2099. */
  2100. void __exit snd_sequencer_device_done(void)
  2101. {
  2102. snd_unregister_device(SNDRV_DEVICE_TYPE_SEQUENCER, NULL, 0);
  2103. }