seq_ports.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. /*
  2. * ALSA sequencer Ports
  3. * Copyright (c) 1998 by Frank van de Pol <fvdpol@coil.demon.nl>
  4. * Jaroslav Kysela <perex@perex.cz>
  5. *
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. *
  21. */
  22. #include <sound/core.h>
  23. #include <linux/slab.h>
  24. #include <linux/module.h>
  25. #include "seq_system.h"
  26. #include "seq_ports.h"
  27. #include "seq_clientmgr.h"
  28. /*
  29. registration of client ports
  30. */
  31. /*
  32. NOTE: the current implementation of the port structure as a linked list is
  33. not optimal for clients that have many ports. For sending messages to all
  34. subscribers of a port we first need to find the address of the port
  35. structure, which means we have to traverse the list. A direct access table
  36. (array) would be better, but big preallocated arrays waste memory.
  37. Possible actions:
  38. 1) leave it this way, a client does normaly does not have more than a few
  39. ports
  40. 2) replace the linked list of ports by a array of pointers which is
  41. dynamicly kmalloced. When a port is added or deleted we can simply allocate
  42. a new array, copy the corresponding pointers, and delete the old one. We
  43. then only need a pointer to this array, and an integer that tells us how
  44. much elements are in array.
  45. */
  46. /* return pointer to port structure - port is locked if found */
  47. struct snd_seq_client_port *snd_seq_port_use_ptr(struct snd_seq_client *client,
  48. int num)
  49. {
  50. struct snd_seq_client_port *port;
  51. if (client == NULL)
  52. return NULL;
  53. read_lock(&client->ports_lock);
  54. list_for_each_entry(port, &client->ports_list_head, list) {
  55. if (port->addr.port == num) {
  56. if (port->closing)
  57. break; /* deleting now */
  58. snd_use_lock_use(&port->use_lock);
  59. read_unlock(&client->ports_lock);
  60. return port;
  61. }
  62. }
  63. read_unlock(&client->ports_lock);
  64. return NULL; /* not found */
  65. }
  66. /* search for the next port - port is locked if found */
  67. struct snd_seq_client_port *snd_seq_port_query_nearest(struct snd_seq_client *client,
  68. struct snd_seq_port_info *pinfo)
  69. {
  70. int num;
  71. struct snd_seq_client_port *port, *found;
  72. num = pinfo->addr.port;
  73. found = NULL;
  74. read_lock(&client->ports_lock);
  75. list_for_each_entry(port, &client->ports_list_head, list) {
  76. if (port->addr.port < num)
  77. continue;
  78. if (port->addr.port == num) {
  79. found = port;
  80. break;
  81. }
  82. if (found == NULL || port->addr.port < found->addr.port)
  83. found = port;
  84. }
  85. if (found) {
  86. if (found->closing)
  87. found = NULL;
  88. else
  89. snd_use_lock_use(&found->use_lock);
  90. }
  91. read_unlock(&client->ports_lock);
  92. return found;
  93. }
  94. /* initialize snd_seq_port_subs_info */
  95. static void port_subs_info_init(struct snd_seq_port_subs_info *grp)
  96. {
  97. INIT_LIST_HEAD(&grp->list_head);
  98. grp->count = 0;
  99. grp->exclusive = 0;
  100. rwlock_init(&grp->list_lock);
  101. init_rwsem(&grp->list_mutex);
  102. grp->open = NULL;
  103. grp->close = NULL;
  104. }
  105. /* create a port, port number is returned (-1 on failure) */
  106. struct snd_seq_client_port *snd_seq_create_port(struct snd_seq_client *client,
  107. int port)
  108. {
  109. unsigned long flags;
  110. struct snd_seq_client_port *new_port, *p;
  111. int num = -1;
  112. /* sanity check */
  113. if (snd_BUG_ON(!client))
  114. return NULL;
  115. if (client->num_ports >= SNDRV_SEQ_MAX_PORTS) {
  116. pr_warn("ALSA: seq: too many ports for client %d\n", client->number);
  117. return NULL;
  118. }
  119. /* create a new port */
  120. new_port = kzalloc(sizeof(*new_port), GFP_KERNEL);
  121. if (!new_port)
  122. return NULL; /* failure, out of memory */
  123. /* init port data */
  124. new_port->addr.client = client->number;
  125. new_port->addr.port = -1;
  126. new_port->owner = THIS_MODULE;
  127. sprintf(new_port->name, "port-%d", num);
  128. snd_use_lock_init(&new_port->use_lock);
  129. port_subs_info_init(&new_port->c_src);
  130. port_subs_info_init(&new_port->c_dest);
  131. num = port >= 0 ? port : 0;
  132. mutex_lock(&client->ports_mutex);
  133. write_lock_irqsave(&client->ports_lock, flags);
  134. list_for_each_entry(p, &client->ports_list_head, list) {
  135. if (p->addr.port > num)
  136. break;
  137. if (port < 0) /* auto-probe mode */
  138. num = p->addr.port + 1;
  139. }
  140. /* insert the new port */
  141. list_add_tail(&new_port->list, &p->list);
  142. client->num_ports++;
  143. new_port->addr.port = num; /* store the port number in the port */
  144. write_unlock_irqrestore(&client->ports_lock, flags);
  145. mutex_unlock(&client->ports_mutex);
  146. sprintf(new_port->name, "port-%d", num);
  147. return new_port;
  148. }
  149. /* */
  150. static int subscribe_port(struct snd_seq_client *client,
  151. struct snd_seq_client_port *port,
  152. struct snd_seq_port_subs_info *grp,
  153. struct snd_seq_port_subscribe *info, int send_ack);
  154. static int unsubscribe_port(struct snd_seq_client *client,
  155. struct snd_seq_client_port *port,
  156. struct snd_seq_port_subs_info *grp,
  157. struct snd_seq_port_subscribe *info, int send_ack);
  158. static struct snd_seq_client_port *get_client_port(struct snd_seq_addr *addr,
  159. struct snd_seq_client **cp)
  160. {
  161. struct snd_seq_client_port *p;
  162. *cp = snd_seq_client_use_ptr(addr->client);
  163. if (*cp) {
  164. p = snd_seq_port_use_ptr(*cp, addr->port);
  165. if (! p) {
  166. snd_seq_client_unlock(*cp);
  167. *cp = NULL;
  168. }
  169. return p;
  170. }
  171. return NULL;
  172. }
  173. static void delete_and_unsubscribe_port(struct snd_seq_client *client,
  174. struct snd_seq_client_port *port,
  175. struct snd_seq_subscribers *subs,
  176. bool is_src, bool ack);
  177. static inline struct snd_seq_subscribers *
  178. get_subscriber(struct list_head *p, bool is_src)
  179. {
  180. if (is_src)
  181. return list_entry(p, struct snd_seq_subscribers, src_list);
  182. else
  183. return list_entry(p, struct snd_seq_subscribers, dest_list);
  184. }
  185. /*
  186. * remove all subscribers on the list
  187. * this is called from port_delete, for each src and dest list.
  188. */
  189. static void clear_subscriber_list(struct snd_seq_client *client,
  190. struct snd_seq_client_port *port,
  191. struct snd_seq_port_subs_info *grp,
  192. int is_src)
  193. {
  194. struct list_head *p, *n;
  195. list_for_each_safe(p, n, &grp->list_head) {
  196. struct snd_seq_subscribers *subs;
  197. struct snd_seq_client *c;
  198. struct snd_seq_client_port *aport;
  199. subs = get_subscriber(p, is_src);
  200. if (is_src)
  201. aport = get_client_port(&subs->info.dest, &c);
  202. else
  203. aport = get_client_port(&subs->info.sender, &c);
  204. delete_and_unsubscribe_port(client, port, subs, is_src, false);
  205. if (!aport) {
  206. /* looks like the connected port is being deleted.
  207. * we decrease the counter, and when both ports are deleted
  208. * remove the subscriber info
  209. */
  210. if (atomic_dec_and_test(&subs->ref_count))
  211. kfree(subs);
  212. continue;
  213. }
  214. /* ok we got the connected port */
  215. delete_and_unsubscribe_port(c, aport, subs, !is_src, true);
  216. kfree(subs);
  217. snd_seq_port_unlock(aport);
  218. snd_seq_client_unlock(c);
  219. }
  220. }
  221. /* delete port data */
  222. static int port_delete(struct snd_seq_client *client,
  223. struct snd_seq_client_port *port)
  224. {
  225. /* set closing flag and wait for all port access are gone */
  226. port->closing = 1;
  227. snd_use_lock_sync(&port->use_lock);
  228. /* clear subscribers info */
  229. clear_subscriber_list(client, port, &port->c_src, true);
  230. clear_subscriber_list(client, port, &port->c_dest, false);
  231. if (port->private_free)
  232. port->private_free(port->private_data);
  233. snd_BUG_ON(port->c_src.count != 0);
  234. snd_BUG_ON(port->c_dest.count != 0);
  235. kfree(port);
  236. return 0;
  237. }
  238. /* delete a port with the given port id */
  239. int snd_seq_delete_port(struct snd_seq_client *client, int port)
  240. {
  241. unsigned long flags;
  242. struct snd_seq_client_port *found = NULL, *p;
  243. mutex_lock(&client->ports_mutex);
  244. write_lock_irqsave(&client->ports_lock, flags);
  245. list_for_each_entry(p, &client->ports_list_head, list) {
  246. if (p->addr.port == port) {
  247. /* ok found. delete from the list at first */
  248. list_del(&p->list);
  249. client->num_ports--;
  250. found = p;
  251. break;
  252. }
  253. }
  254. write_unlock_irqrestore(&client->ports_lock, flags);
  255. mutex_unlock(&client->ports_mutex);
  256. if (found)
  257. return port_delete(client, found);
  258. else
  259. return -ENOENT;
  260. }
  261. /* delete the all ports belonging to the given client */
  262. int snd_seq_delete_all_ports(struct snd_seq_client *client)
  263. {
  264. unsigned long flags;
  265. struct list_head deleted_list;
  266. struct snd_seq_client_port *port, *tmp;
  267. /* move the port list to deleted_list, and
  268. * clear the port list in the client data.
  269. */
  270. mutex_lock(&client->ports_mutex);
  271. write_lock_irqsave(&client->ports_lock, flags);
  272. if (! list_empty(&client->ports_list_head)) {
  273. list_add(&deleted_list, &client->ports_list_head);
  274. list_del_init(&client->ports_list_head);
  275. } else {
  276. INIT_LIST_HEAD(&deleted_list);
  277. }
  278. client->num_ports = 0;
  279. write_unlock_irqrestore(&client->ports_lock, flags);
  280. /* remove each port in deleted_list */
  281. list_for_each_entry_safe(port, tmp, &deleted_list, list) {
  282. list_del(&port->list);
  283. snd_seq_system_client_ev_port_exit(port->addr.client, port->addr.port);
  284. port_delete(client, port);
  285. }
  286. mutex_unlock(&client->ports_mutex);
  287. return 0;
  288. }
  289. /* set port info fields */
  290. int snd_seq_set_port_info(struct snd_seq_client_port * port,
  291. struct snd_seq_port_info * info)
  292. {
  293. if (snd_BUG_ON(!port || !info))
  294. return -EINVAL;
  295. /* set port name */
  296. if (info->name[0])
  297. strlcpy(port->name, info->name, sizeof(port->name));
  298. /* set capabilities */
  299. port->capability = info->capability;
  300. /* get port type */
  301. port->type = info->type;
  302. /* information about supported channels/voices */
  303. port->midi_channels = info->midi_channels;
  304. port->midi_voices = info->midi_voices;
  305. port->synth_voices = info->synth_voices;
  306. /* timestamping */
  307. port->timestamping = (info->flags & SNDRV_SEQ_PORT_FLG_TIMESTAMP) ? 1 : 0;
  308. port->time_real = (info->flags & SNDRV_SEQ_PORT_FLG_TIME_REAL) ? 1 : 0;
  309. port->time_queue = info->time_queue;
  310. return 0;
  311. }
  312. /* get port info fields */
  313. int snd_seq_get_port_info(struct snd_seq_client_port * port,
  314. struct snd_seq_port_info * info)
  315. {
  316. if (snd_BUG_ON(!port || !info))
  317. return -EINVAL;
  318. /* get port name */
  319. strlcpy(info->name, port->name, sizeof(info->name));
  320. /* get capabilities */
  321. info->capability = port->capability;
  322. /* get port type */
  323. info->type = port->type;
  324. /* information about supported channels/voices */
  325. info->midi_channels = port->midi_channels;
  326. info->midi_voices = port->midi_voices;
  327. info->synth_voices = port->synth_voices;
  328. /* get subscriber counts */
  329. info->read_use = port->c_src.count;
  330. info->write_use = port->c_dest.count;
  331. /* timestamping */
  332. info->flags = 0;
  333. if (port->timestamping) {
  334. info->flags |= SNDRV_SEQ_PORT_FLG_TIMESTAMP;
  335. if (port->time_real)
  336. info->flags |= SNDRV_SEQ_PORT_FLG_TIME_REAL;
  337. info->time_queue = port->time_queue;
  338. }
  339. return 0;
  340. }
  341. /*
  342. * call callback functions (if any):
  343. * the callbacks are invoked only when the first (for connection) or
  344. * the last subscription (for disconnection) is done. Second or later
  345. * subscription results in increment of counter, but no callback is
  346. * invoked.
  347. * This feature is useful if these callbacks are associated with
  348. * initialization or termination of devices (see seq_midi.c).
  349. */
  350. static int subscribe_port(struct snd_seq_client *client,
  351. struct snd_seq_client_port *port,
  352. struct snd_seq_port_subs_info *grp,
  353. struct snd_seq_port_subscribe *info,
  354. int send_ack)
  355. {
  356. int err = 0;
  357. if (!try_module_get(port->owner))
  358. return -EFAULT;
  359. grp->count++;
  360. if (grp->open && grp->count == 1) {
  361. err = grp->open(port->private_data, info);
  362. if (err < 0) {
  363. module_put(port->owner);
  364. grp->count--;
  365. }
  366. }
  367. if (err >= 0 && send_ack && client->type == USER_CLIENT)
  368. snd_seq_client_notify_subscription(port->addr.client, port->addr.port,
  369. info, SNDRV_SEQ_EVENT_PORT_SUBSCRIBED);
  370. return err;
  371. }
  372. static int unsubscribe_port(struct snd_seq_client *client,
  373. struct snd_seq_client_port *port,
  374. struct snd_seq_port_subs_info *grp,
  375. struct snd_seq_port_subscribe *info,
  376. int send_ack)
  377. {
  378. int err = 0;
  379. if (! grp->count)
  380. return -EINVAL;
  381. grp->count--;
  382. if (grp->close && grp->count == 0)
  383. err = grp->close(port->private_data, info);
  384. if (send_ack && client->type == USER_CLIENT)
  385. snd_seq_client_notify_subscription(port->addr.client, port->addr.port,
  386. info, SNDRV_SEQ_EVENT_PORT_UNSUBSCRIBED);
  387. module_put(port->owner);
  388. return err;
  389. }
  390. /* check if both addresses are identical */
  391. static inline int addr_match(struct snd_seq_addr *r, struct snd_seq_addr *s)
  392. {
  393. return (r->client == s->client) && (r->port == s->port);
  394. }
  395. /* check the two subscribe info match */
  396. /* if flags is zero, checks only sender and destination addresses */
  397. static int match_subs_info(struct snd_seq_port_subscribe *r,
  398. struct snd_seq_port_subscribe *s)
  399. {
  400. if (addr_match(&r->sender, &s->sender) &&
  401. addr_match(&r->dest, &s->dest)) {
  402. if (r->flags && r->flags == s->flags)
  403. return r->queue == s->queue;
  404. else if (! r->flags)
  405. return 1;
  406. }
  407. return 0;
  408. }
  409. static int check_and_subscribe_port(struct snd_seq_client *client,
  410. struct snd_seq_client_port *port,
  411. struct snd_seq_subscribers *subs,
  412. bool is_src, bool exclusive, bool ack)
  413. {
  414. struct snd_seq_port_subs_info *grp;
  415. struct list_head *p;
  416. struct snd_seq_subscribers *s;
  417. int err;
  418. grp = is_src ? &port->c_src : &port->c_dest;
  419. err = -EBUSY;
  420. down_write(&grp->list_mutex);
  421. if (exclusive) {
  422. if (!list_empty(&grp->list_head))
  423. goto __error;
  424. } else {
  425. if (grp->exclusive)
  426. goto __error;
  427. /* check whether already exists */
  428. list_for_each(p, &grp->list_head) {
  429. s = get_subscriber(p, is_src);
  430. if (match_subs_info(&subs->info, &s->info))
  431. goto __error;
  432. }
  433. }
  434. err = subscribe_port(client, port, grp, &subs->info, ack);
  435. if (err < 0) {
  436. grp->exclusive = 0;
  437. goto __error;
  438. }
  439. /* add to list */
  440. write_lock_irq(&grp->list_lock);
  441. if (is_src)
  442. list_add_tail(&subs->src_list, &grp->list_head);
  443. else
  444. list_add_tail(&subs->dest_list, &grp->list_head);
  445. grp->exclusive = exclusive;
  446. atomic_inc(&subs->ref_count);
  447. write_unlock_irq(&grp->list_lock);
  448. err = 0;
  449. __error:
  450. up_write(&grp->list_mutex);
  451. return err;
  452. }
  453. static void delete_and_unsubscribe_port(struct snd_seq_client *client,
  454. struct snd_seq_client_port *port,
  455. struct snd_seq_subscribers *subs,
  456. bool is_src, bool ack)
  457. {
  458. struct snd_seq_port_subs_info *grp;
  459. struct list_head *list;
  460. bool empty;
  461. grp = is_src ? &port->c_src : &port->c_dest;
  462. list = is_src ? &subs->src_list : &subs->dest_list;
  463. down_write(&grp->list_mutex);
  464. write_lock_irq(&grp->list_lock);
  465. empty = list_empty(list);
  466. if (!empty)
  467. list_del_init(list);
  468. grp->exclusive = 0;
  469. write_unlock_irq(&grp->list_lock);
  470. up_write(&grp->list_mutex);
  471. if (!empty)
  472. unsubscribe_port(client, port, grp, &subs->info, ack);
  473. }
  474. /* connect two ports */
  475. int snd_seq_port_connect(struct snd_seq_client *connector,
  476. struct snd_seq_client *src_client,
  477. struct snd_seq_client_port *src_port,
  478. struct snd_seq_client *dest_client,
  479. struct snd_seq_client_port *dest_port,
  480. struct snd_seq_port_subscribe *info)
  481. {
  482. struct snd_seq_subscribers *subs;
  483. bool exclusive;
  484. int err;
  485. subs = kzalloc(sizeof(*subs), GFP_KERNEL);
  486. if (!subs)
  487. return -ENOMEM;
  488. subs->info = *info;
  489. atomic_set(&subs->ref_count, 0);
  490. INIT_LIST_HEAD(&subs->src_list);
  491. INIT_LIST_HEAD(&subs->dest_list);
  492. exclusive = !!(info->flags & SNDRV_SEQ_PORT_SUBS_EXCLUSIVE);
  493. err = check_and_subscribe_port(src_client, src_port, subs, true,
  494. exclusive,
  495. connector->number != src_client->number);
  496. if (err < 0)
  497. goto error;
  498. err = check_and_subscribe_port(dest_client, dest_port, subs, false,
  499. exclusive,
  500. connector->number != dest_client->number);
  501. if (err < 0)
  502. goto error_dest;
  503. return 0;
  504. error_dest:
  505. delete_and_unsubscribe_port(src_client, src_port, subs, true,
  506. connector->number != src_client->number);
  507. error:
  508. kfree(subs);
  509. return err;
  510. }
  511. /* remove the connection */
  512. int snd_seq_port_disconnect(struct snd_seq_client *connector,
  513. struct snd_seq_client *src_client,
  514. struct snd_seq_client_port *src_port,
  515. struct snd_seq_client *dest_client,
  516. struct snd_seq_client_port *dest_port,
  517. struct snd_seq_port_subscribe *info)
  518. {
  519. struct snd_seq_port_subs_info *src = &src_port->c_src;
  520. struct snd_seq_subscribers *subs;
  521. int err = -ENOENT;
  522. down_write(&src->list_mutex);
  523. /* look for the connection */
  524. list_for_each_entry(subs, &src->list_head, src_list) {
  525. if (match_subs_info(info, &subs->info)) {
  526. atomic_dec(&subs->ref_count); /* mark as not ready */
  527. err = 0;
  528. break;
  529. }
  530. }
  531. up_write(&src->list_mutex);
  532. if (err < 0)
  533. return err;
  534. delete_and_unsubscribe_port(src_client, src_port, subs, true,
  535. connector->number != src_client->number);
  536. delete_and_unsubscribe_port(dest_client, dest_port, subs, false,
  537. connector->number != dest_client->number);
  538. kfree(subs);
  539. return 0;
  540. }
  541. /* get matched subscriber */
  542. struct snd_seq_subscribers *snd_seq_port_get_subscription(struct snd_seq_port_subs_info *src_grp,
  543. struct snd_seq_addr *dest_addr)
  544. {
  545. struct snd_seq_subscribers *s, *found = NULL;
  546. down_read(&src_grp->list_mutex);
  547. list_for_each_entry(s, &src_grp->list_head, src_list) {
  548. if (addr_match(dest_addr, &s->info.dest)) {
  549. found = s;
  550. break;
  551. }
  552. }
  553. up_read(&src_grp->list_mutex);
  554. return found;
  555. }
  556. /*
  557. * Attach a device driver that wants to receive events from the
  558. * sequencer. Returns the new port number on success.
  559. * A driver that wants to receive the events converted to midi, will
  560. * use snd_seq_midisynth_register_port().
  561. */
  562. /* exported */
  563. int snd_seq_event_port_attach(int client,
  564. struct snd_seq_port_callback *pcbp,
  565. int cap, int type, int midi_channels,
  566. int midi_voices, char *portname)
  567. {
  568. struct snd_seq_port_info portinfo;
  569. int ret;
  570. /* Set up the port */
  571. memset(&portinfo, 0, sizeof(portinfo));
  572. portinfo.addr.client = client;
  573. strlcpy(portinfo.name, portname ? portname : "Unamed port",
  574. sizeof(portinfo.name));
  575. portinfo.capability = cap;
  576. portinfo.type = type;
  577. portinfo.kernel = pcbp;
  578. portinfo.midi_channels = midi_channels;
  579. portinfo.midi_voices = midi_voices;
  580. /* Create it */
  581. ret = snd_seq_kernel_client_ctl(client,
  582. SNDRV_SEQ_IOCTL_CREATE_PORT,
  583. &portinfo);
  584. if (ret >= 0)
  585. ret = portinfo.addr.port;
  586. return ret;
  587. }
  588. EXPORT_SYMBOL(snd_seq_event_port_attach);
  589. /*
  590. * Detach the driver from a port.
  591. */
  592. /* exported */
  593. int snd_seq_event_port_detach(int client, int port)
  594. {
  595. struct snd_seq_port_info portinfo;
  596. int err;
  597. memset(&portinfo, 0, sizeof(portinfo));
  598. portinfo.addr.client = client;
  599. portinfo.addr.port = port;
  600. err = snd_seq_kernel_client_ctl(client,
  601. SNDRV_SEQ_IOCTL_DELETE_PORT,
  602. &portinfo);
  603. return err;
  604. }
  605. EXPORT_SYMBOL(snd_seq_event_port_detach);