seq_clientmgr.c 63 KB

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