fw-cdev.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420
  1. /*
  2. * Char device for device raw access
  3. *
  4. * Copyright (C) 2005-2007 Kristian Hoegsberg <krh@bitplanet.net>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. */
  20. #include <linux/compat.h>
  21. #include <linux/delay.h>
  22. #include <linux/device.h>
  23. #include <linux/errno.h>
  24. #include <linux/firewire-cdev.h>
  25. #include <linux/idr.h>
  26. #include <linux/jiffies.h>
  27. #include <linux/kernel.h>
  28. #include <linux/kref.h>
  29. #include <linux/mm.h>
  30. #include <linux/module.h>
  31. #include <linux/mutex.h>
  32. #include <linux/poll.h>
  33. #include <linux/preempt.h>
  34. #include <linux/spinlock.h>
  35. #include <linux/time.h>
  36. #include <linux/vmalloc.h>
  37. #include <linux/wait.h>
  38. #include <linux/workqueue.h>
  39. #include <asm/system.h>
  40. #include <asm/uaccess.h>
  41. #include "fw-device.h"
  42. #include "fw-topology.h"
  43. #include "fw-transaction.h"
  44. struct client {
  45. u32 version;
  46. struct fw_device *device;
  47. spinlock_t lock;
  48. bool in_shutdown;
  49. struct idr resource_idr;
  50. struct list_head event_list;
  51. wait_queue_head_t wait;
  52. u64 bus_reset_closure;
  53. struct fw_iso_context *iso_context;
  54. u64 iso_closure;
  55. struct fw_iso_buffer buffer;
  56. unsigned long vm_start;
  57. struct list_head link;
  58. struct kref kref;
  59. };
  60. static inline void client_get(struct client *client)
  61. {
  62. kref_get(&client->kref);
  63. }
  64. static void client_release(struct kref *kref)
  65. {
  66. struct client *client = container_of(kref, struct client, kref);
  67. fw_device_put(client->device);
  68. kfree(client);
  69. }
  70. static void client_put(struct client *client)
  71. {
  72. kref_put(&client->kref, client_release);
  73. }
  74. struct client_resource;
  75. typedef void (*client_resource_release_fn_t)(struct client *,
  76. struct client_resource *);
  77. struct client_resource {
  78. client_resource_release_fn_t release;
  79. int handle;
  80. };
  81. struct address_handler_resource {
  82. struct client_resource resource;
  83. struct fw_address_handler handler;
  84. __u64 closure;
  85. struct client *client;
  86. };
  87. struct outbound_transaction_resource {
  88. struct client_resource resource;
  89. struct fw_transaction transaction;
  90. };
  91. struct inbound_transaction_resource {
  92. struct client_resource resource;
  93. struct fw_request *request;
  94. void *data;
  95. size_t length;
  96. };
  97. struct descriptor_resource {
  98. struct client_resource resource;
  99. struct fw_descriptor descriptor;
  100. u32 data[0];
  101. };
  102. struct iso_resource {
  103. struct client_resource resource;
  104. struct client *client;
  105. /* Schedule work and access todo only with client->lock held. */
  106. struct delayed_work work;
  107. enum {ISO_RES_ALLOC, ISO_RES_REALLOC, ISO_RES_DEALLOC,
  108. ISO_RES_ALLOC_ONCE, ISO_RES_DEALLOC_ONCE,} todo;
  109. int generation;
  110. u64 channels;
  111. s32 bandwidth;
  112. struct iso_resource_event *e_alloc, *e_dealloc;
  113. };
  114. static int schedule_iso_resource(struct iso_resource *);
  115. static void release_iso_resource(struct client *, struct client_resource *);
  116. /*
  117. * dequeue_event() just kfree()'s the event, so the event has to be
  118. * the first field in a struct XYZ_event.
  119. */
  120. struct event {
  121. struct { void *data; size_t size; } v[2];
  122. struct list_head link;
  123. };
  124. struct bus_reset_event {
  125. struct event event;
  126. struct fw_cdev_event_bus_reset reset;
  127. };
  128. struct outbound_transaction_event {
  129. struct event event;
  130. struct client *client;
  131. struct outbound_transaction_resource r;
  132. struct fw_cdev_event_response response;
  133. };
  134. struct inbound_transaction_event {
  135. struct event event;
  136. struct fw_cdev_event_request request;
  137. };
  138. struct iso_interrupt_event {
  139. struct event event;
  140. struct fw_cdev_event_iso_interrupt interrupt;
  141. };
  142. struct iso_resource_event {
  143. struct event event;
  144. struct fw_cdev_event_iso_resource resource;
  145. };
  146. static inline void __user *u64_to_uptr(__u64 value)
  147. {
  148. return (void __user *)(unsigned long)value;
  149. }
  150. static inline __u64 uptr_to_u64(void __user *ptr)
  151. {
  152. return (__u64)(unsigned long)ptr;
  153. }
  154. static int fw_device_op_open(struct inode *inode, struct file *file)
  155. {
  156. struct fw_device *device;
  157. struct client *client;
  158. device = fw_device_get_by_devt(inode->i_rdev);
  159. if (device == NULL)
  160. return -ENODEV;
  161. if (fw_device_is_shutdown(device)) {
  162. fw_device_put(device);
  163. return -ENODEV;
  164. }
  165. client = kzalloc(sizeof(*client), GFP_KERNEL);
  166. if (client == NULL) {
  167. fw_device_put(device);
  168. return -ENOMEM;
  169. }
  170. client->device = device;
  171. spin_lock_init(&client->lock);
  172. idr_init(&client->resource_idr);
  173. INIT_LIST_HEAD(&client->event_list);
  174. init_waitqueue_head(&client->wait);
  175. kref_init(&client->kref);
  176. file->private_data = client;
  177. mutex_lock(&device->client_list_mutex);
  178. list_add_tail(&client->link, &device->client_list);
  179. mutex_unlock(&device->client_list_mutex);
  180. return 0;
  181. }
  182. static void queue_event(struct client *client, struct event *event,
  183. void *data0, size_t size0, void *data1, size_t size1)
  184. {
  185. unsigned long flags;
  186. event->v[0].data = data0;
  187. event->v[0].size = size0;
  188. event->v[1].data = data1;
  189. event->v[1].size = size1;
  190. spin_lock_irqsave(&client->lock, flags);
  191. if (client->in_shutdown)
  192. kfree(event);
  193. else
  194. list_add_tail(&event->link, &client->event_list);
  195. spin_unlock_irqrestore(&client->lock, flags);
  196. wake_up_interruptible(&client->wait);
  197. }
  198. static int dequeue_event(struct client *client,
  199. char __user *buffer, size_t count)
  200. {
  201. unsigned long flags;
  202. struct event *event;
  203. size_t size, total;
  204. int i, ret;
  205. ret = wait_event_interruptible(client->wait,
  206. !list_empty(&client->event_list) ||
  207. fw_device_is_shutdown(client->device));
  208. if (ret < 0)
  209. return ret;
  210. if (list_empty(&client->event_list) &&
  211. fw_device_is_shutdown(client->device))
  212. return -ENODEV;
  213. spin_lock_irqsave(&client->lock, flags);
  214. event = list_first_entry(&client->event_list, struct event, link);
  215. list_del(&event->link);
  216. spin_unlock_irqrestore(&client->lock, flags);
  217. total = 0;
  218. for (i = 0; i < ARRAY_SIZE(event->v) && total < count; i++) {
  219. size = min(event->v[i].size, count - total);
  220. if (copy_to_user(buffer + total, event->v[i].data, size)) {
  221. ret = -EFAULT;
  222. goto out;
  223. }
  224. total += size;
  225. }
  226. ret = total;
  227. out:
  228. kfree(event);
  229. return ret;
  230. }
  231. static ssize_t fw_device_op_read(struct file *file, char __user *buffer,
  232. size_t count, loff_t *offset)
  233. {
  234. struct client *client = file->private_data;
  235. return dequeue_event(client, buffer, count);
  236. }
  237. static void fill_bus_reset_event(struct fw_cdev_event_bus_reset *event,
  238. struct client *client)
  239. {
  240. struct fw_card *card = client->device->card;
  241. unsigned long flags;
  242. spin_lock_irqsave(&card->lock, flags);
  243. event->closure = client->bus_reset_closure;
  244. event->type = FW_CDEV_EVENT_BUS_RESET;
  245. event->generation = client->device->generation;
  246. event->node_id = client->device->node_id;
  247. event->local_node_id = card->local_node->node_id;
  248. event->bm_node_id = 0; /* FIXME: We don't track the BM. */
  249. event->irm_node_id = card->irm_node->node_id;
  250. event->root_node_id = card->root_node->node_id;
  251. spin_unlock_irqrestore(&card->lock, flags);
  252. }
  253. static void for_each_client(struct fw_device *device,
  254. void (*callback)(struct client *client))
  255. {
  256. struct client *c;
  257. mutex_lock(&device->client_list_mutex);
  258. list_for_each_entry(c, &device->client_list, link)
  259. callback(c);
  260. mutex_unlock(&device->client_list_mutex);
  261. }
  262. static int schedule_reallocations(int id, void *p, void *data)
  263. {
  264. struct client_resource *r = p;
  265. if (r->release == release_iso_resource)
  266. schedule_iso_resource(container_of(r,
  267. struct iso_resource, resource));
  268. return 0;
  269. }
  270. static void queue_bus_reset_event(struct client *client)
  271. {
  272. struct bus_reset_event *e;
  273. e = kzalloc(sizeof(*e), GFP_KERNEL);
  274. if (e == NULL) {
  275. fw_notify("Out of memory when allocating bus reset event\n");
  276. return;
  277. }
  278. fill_bus_reset_event(&e->reset, client);
  279. queue_event(client, &e->event,
  280. &e->reset, sizeof(e->reset), NULL, 0);
  281. spin_lock_irq(&client->lock);
  282. idr_for_each(&client->resource_idr, schedule_reallocations, client);
  283. spin_unlock_irq(&client->lock);
  284. }
  285. void fw_device_cdev_update(struct fw_device *device)
  286. {
  287. for_each_client(device, queue_bus_reset_event);
  288. }
  289. static void wake_up_client(struct client *client)
  290. {
  291. wake_up_interruptible(&client->wait);
  292. }
  293. void fw_device_cdev_remove(struct fw_device *device)
  294. {
  295. for_each_client(device, wake_up_client);
  296. }
  297. static int ioctl_get_info(struct client *client, void *buffer)
  298. {
  299. struct fw_cdev_get_info *get_info = buffer;
  300. struct fw_cdev_event_bus_reset bus_reset;
  301. unsigned long ret = 0;
  302. client->version = get_info->version;
  303. get_info->version = FW_CDEV_VERSION;
  304. get_info->card = client->device->card->index;
  305. down_read(&fw_device_rwsem);
  306. if (get_info->rom != 0) {
  307. void __user *uptr = u64_to_uptr(get_info->rom);
  308. size_t want = get_info->rom_length;
  309. size_t have = client->device->config_rom_length * 4;
  310. ret = copy_to_user(uptr, client->device->config_rom,
  311. min(want, have));
  312. }
  313. get_info->rom_length = client->device->config_rom_length * 4;
  314. up_read(&fw_device_rwsem);
  315. if (ret != 0)
  316. return -EFAULT;
  317. client->bus_reset_closure = get_info->bus_reset_closure;
  318. if (get_info->bus_reset != 0) {
  319. void __user *uptr = u64_to_uptr(get_info->bus_reset);
  320. fill_bus_reset_event(&bus_reset, client);
  321. if (copy_to_user(uptr, &bus_reset, sizeof(bus_reset)))
  322. return -EFAULT;
  323. }
  324. return 0;
  325. }
  326. static int add_client_resource(struct client *client,
  327. struct client_resource *resource, gfp_t gfp_mask)
  328. {
  329. unsigned long flags;
  330. int ret;
  331. retry:
  332. if (idr_pre_get(&client->resource_idr, gfp_mask) == 0)
  333. return -ENOMEM;
  334. spin_lock_irqsave(&client->lock, flags);
  335. if (client->in_shutdown)
  336. ret = -ECANCELED;
  337. else
  338. ret = idr_get_new(&client->resource_idr, resource,
  339. &resource->handle);
  340. if (ret >= 0) {
  341. client_get(client);
  342. if (resource->release == release_iso_resource)
  343. schedule_iso_resource(container_of(resource,
  344. struct iso_resource, resource));
  345. }
  346. spin_unlock_irqrestore(&client->lock, flags);
  347. if (ret == -EAGAIN)
  348. goto retry;
  349. return ret < 0 ? ret : 0;
  350. }
  351. static int release_client_resource(struct client *client, u32 handle,
  352. client_resource_release_fn_t release,
  353. struct client_resource **resource)
  354. {
  355. struct client_resource *r;
  356. unsigned long flags;
  357. spin_lock_irqsave(&client->lock, flags);
  358. if (client->in_shutdown)
  359. r = NULL;
  360. else
  361. r = idr_find(&client->resource_idr, handle);
  362. if (r && r->release == release)
  363. idr_remove(&client->resource_idr, handle);
  364. spin_unlock_irqrestore(&client->lock, flags);
  365. if (!(r && r->release == release))
  366. return -EINVAL;
  367. if (resource)
  368. *resource = r;
  369. else
  370. r->release(client, r);
  371. client_put(client);
  372. return 0;
  373. }
  374. static void release_transaction(struct client *client,
  375. struct client_resource *resource)
  376. {
  377. struct outbound_transaction_resource *r = container_of(resource,
  378. struct outbound_transaction_resource, resource);
  379. fw_cancel_transaction(client->device->card, &r->transaction);
  380. }
  381. static void complete_transaction(struct fw_card *card, int rcode,
  382. void *payload, size_t length, void *data)
  383. {
  384. struct outbound_transaction_event *e = data;
  385. struct fw_cdev_event_response *rsp = &e->response;
  386. struct client *client = e->client;
  387. unsigned long flags;
  388. if (length < rsp->length)
  389. rsp->length = length;
  390. if (rcode == RCODE_COMPLETE)
  391. memcpy(rsp->data, payload, rsp->length);
  392. spin_lock_irqsave(&client->lock, flags);
  393. /*
  394. * 1. If called while in shutdown, the idr tree must be left untouched.
  395. * The idr handle will be removed and the client reference will be
  396. * dropped later.
  397. * 2. If the call chain was release_client_resource ->
  398. * release_transaction -> complete_transaction (instead of a normal
  399. * conclusion of the transaction), i.e. if this resource was already
  400. * unregistered from the idr, the client reference will be dropped
  401. * by release_client_resource and we must not drop it here.
  402. */
  403. if (!client->in_shutdown &&
  404. idr_find(&client->resource_idr, e->r.resource.handle)) {
  405. idr_remove(&client->resource_idr, e->r.resource.handle);
  406. /* Drop the idr's reference */
  407. client_put(client);
  408. }
  409. spin_unlock_irqrestore(&client->lock, flags);
  410. rsp->type = FW_CDEV_EVENT_RESPONSE;
  411. rsp->rcode = rcode;
  412. /*
  413. * In the case that sizeof(*rsp) doesn't align with the position of the
  414. * data, and the read is short, preserve an extra copy of the data
  415. * to stay compatible with a pre-2.6.27 bug. Since the bug is harmless
  416. * for short reads and some apps depended on it, this is both safe
  417. * and prudent for compatibility.
  418. */
  419. if (rsp->length <= sizeof(*rsp) - offsetof(typeof(*rsp), data))
  420. queue_event(client, &e->event, rsp, sizeof(*rsp),
  421. rsp->data, rsp->length);
  422. else
  423. queue_event(client, &e->event, rsp, sizeof(*rsp) + rsp->length,
  424. NULL, 0);
  425. /* Drop the transaction callback's reference */
  426. client_put(client);
  427. }
  428. static int ioctl_send_request(struct client *client, void *buffer)
  429. {
  430. struct fw_device *device = client->device;
  431. struct fw_cdev_send_request *request = buffer;
  432. struct outbound_transaction_event *e;
  433. int ret;
  434. /* What is the biggest size we'll accept, really? */
  435. if (request->length > 4096)
  436. return -EINVAL;
  437. e = kmalloc(sizeof(*e) + request->length, GFP_KERNEL);
  438. if (e == NULL)
  439. return -ENOMEM;
  440. e->client = client;
  441. e->response.length = request->length;
  442. e->response.closure = request->closure;
  443. if (request->data &&
  444. copy_from_user(e->response.data,
  445. u64_to_uptr(request->data), request->length)) {
  446. ret = -EFAULT;
  447. goto failed;
  448. }
  449. switch (request->tcode) {
  450. case TCODE_WRITE_QUADLET_REQUEST:
  451. case TCODE_WRITE_BLOCK_REQUEST:
  452. case TCODE_READ_QUADLET_REQUEST:
  453. case TCODE_READ_BLOCK_REQUEST:
  454. case TCODE_LOCK_MASK_SWAP:
  455. case TCODE_LOCK_COMPARE_SWAP:
  456. case TCODE_LOCK_FETCH_ADD:
  457. case TCODE_LOCK_LITTLE_ADD:
  458. case TCODE_LOCK_BOUNDED_ADD:
  459. case TCODE_LOCK_WRAP_ADD:
  460. case TCODE_LOCK_VENDOR_DEPENDENT:
  461. break;
  462. default:
  463. ret = -EINVAL;
  464. goto failed;
  465. }
  466. e->r.resource.release = release_transaction;
  467. ret = add_client_resource(client, &e->r.resource, GFP_KERNEL);
  468. if (ret < 0)
  469. goto failed;
  470. /* Get a reference for the transaction callback */
  471. client_get(client);
  472. fw_send_request(device->card, &e->r.transaction,
  473. request->tcode & 0x1f,
  474. device->node->node_id,
  475. request->generation,
  476. device->max_speed,
  477. request->offset,
  478. e->response.data, request->length,
  479. complete_transaction, e);
  480. if (request->data)
  481. return sizeof(request) + request->length;
  482. else
  483. return sizeof(request);
  484. failed:
  485. kfree(e);
  486. return ret;
  487. }
  488. static void release_request(struct client *client,
  489. struct client_resource *resource)
  490. {
  491. struct inbound_transaction_resource *r = container_of(resource,
  492. struct inbound_transaction_resource, resource);
  493. fw_send_response(client->device->card, r->request,
  494. RCODE_CONFLICT_ERROR);
  495. kfree(r);
  496. }
  497. static void handle_request(struct fw_card *card, struct fw_request *request,
  498. int tcode, int destination, int source,
  499. int generation, int speed,
  500. unsigned long long offset,
  501. void *payload, size_t length, void *callback_data)
  502. {
  503. struct address_handler_resource *handler = callback_data;
  504. struct inbound_transaction_resource *r;
  505. struct inbound_transaction_event *e;
  506. int ret;
  507. r = kmalloc(sizeof(*r), GFP_ATOMIC);
  508. e = kmalloc(sizeof(*e), GFP_ATOMIC);
  509. if (r == NULL || e == NULL)
  510. goto failed;
  511. r->request = request;
  512. r->data = payload;
  513. r->length = length;
  514. r->resource.release = release_request;
  515. ret = add_client_resource(handler->client, &r->resource, GFP_ATOMIC);
  516. if (ret < 0)
  517. goto failed;
  518. e->request.type = FW_CDEV_EVENT_REQUEST;
  519. e->request.tcode = tcode;
  520. e->request.offset = offset;
  521. e->request.length = length;
  522. e->request.handle = r->resource.handle;
  523. e->request.closure = handler->closure;
  524. queue_event(handler->client, &e->event,
  525. &e->request, sizeof(e->request), payload, length);
  526. return;
  527. failed:
  528. kfree(r);
  529. kfree(e);
  530. fw_send_response(card, request, RCODE_CONFLICT_ERROR);
  531. }
  532. static void release_address_handler(struct client *client,
  533. struct client_resource *resource)
  534. {
  535. struct address_handler_resource *r =
  536. container_of(resource, struct address_handler_resource, resource);
  537. fw_core_remove_address_handler(&r->handler);
  538. kfree(r);
  539. }
  540. static int ioctl_allocate(struct client *client, void *buffer)
  541. {
  542. struct fw_cdev_allocate *request = buffer;
  543. struct address_handler_resource *r;
  544. struct fw_address_region region;
  545. int ret;
  546. r = kmalloc(sizeof(*r), GFP_KERNEL);
  547. if (r == NULL)
  548. return -ENOMEM;
  549. region.start = request->offset;
  550. region.end = request->offset + request->length;
  551. r->handler.length = request->length;
  552. r->handler.address_callback = handle_request;
  553. r->handler.callback_data = r;
  554. r->closure = request->closure;
  555. r->client = client;
  556. ret = fw_core_add_address_handler(&r->handler, &region);
  557. if (ret < 0) {
  558. kfree(r);
  559. return ret;
  560. }
  561. r->resource.release = release_address_handler;
  562. ret = add_client_resource(client, &r->resource, GFP_KERNEL);
  563. if (ret < 0) {
  564. release_address_handler(client, &r->resource);
  565. return ret;
  566. }
  567. request->handle = r->resource.handle;
  568. return 0;
  569. }
  570. static int ioctl_deallocate(struct client *client, void *buffer)
  571. {
  572. struct fw_cdev_deallocate *request = buffer;
  573. return release_client_resource(client, request->handle,
  574. release_address_handler, NULL);
  575. }
  576. static int ioctl_send_response(struct client *client, void *buffer)
  577. {
  578. struct fw_cdev_send_response *request = buffer;
  579. struct client_resource *resource;
  580. struct inbound_transaction_resource *r;
  581. if (release_client_resource(client, request->handle,
  582. release_request, &resource) < 0)
  583. return -EINVAL;
  584. r = container_of(resource, struct inbound_transaction_resource,
  585. resource);
  586. if (request->length < r->length)
  587. r->length = request->length;
  588. if (copy_from_user(r->data, u64_to_uptr(request->data), r->length))
  589. return -EFAULT;
  590. fw_send_response(client->device->card, r->request, request->rcode);
  591. kfree(r);
  592. return 0;
  593. }
  594. static int ioctl_initiate_bus_reset(struct client *client, void *buffer)
  595. {
  596. struct fw_cdev_initiate_bus_reset *request = buffer;
  597. int short_reset;
  598. short_reset = (request->type == FW_CDEV_SHORT_RESET);
  599. return fw_core_initiate_bus_reset(client->device->card, short_reset);
  600. }
  601. static void release_descriptor(struct client *client,
  602. struct client_resource *resource)
  603. {
  604. struct descriptor_resource *r =
  605. container_of(resource, struct descriptor_resource, resource);
  606. fw_core_remove_descriptor(&r->descriptor);
  607. kfree(r);
  608. }
  609. static int ioctl_add_descriptor(struct client *client, void *buffer)
  610. {
  611. struct fw_cdev_add_descriptor *request = buffer;
  612. struct descriptor_resource *r;
  613. int ret;
  614. if (request->length > 256)
  615. return -EINVAL;
  616. r = kmalloc(sizeof(*r) + request->length * 4, GFP_KERNEL);
  617. if (r == NULL)
  618. return -ENOMEM;
  619. if (copy_from_user(r->data,
  620. u64_to_uptr(request->data), request->length * 4)) {
  621. ret = -EFAULT;
  622. goto failed;
  623. }
  624. r->descriptor.length = request->length;
  625. r->descriptor.immediate = request->immediate;
  626. r->descriptor.key = request->key;
  627. r->descriptor.data = r->data;
  628. ret = fw_core_add_descriptor(&r->descriptor);
  629. if (ret < 0)
  630. goto failed;
  631. r->resource.release = release_descriptor;
  632. ret = add_client_resource(client, &r->resource, GFP_KERNEL);
  633. if (ret < 0) {
  634. fw_core_remove_descriptor(&r->descriptor);
  635. goto failed;
  636. }
  637. request->handle = r->resource.handle;
  638. return 0;
  639. failed:
  640. kfree(r);
  641. return ret;
  642. }
  643. static int ioctl_remove_descriptor(struct client *client, void *buffer)
  644. {
  645. struct fw_cdev_remove_descriptor *request = buffer;
  646. return release_client_resource(client, request->handle,
  647. release_descriptor, NULL);
  648. }
  649. static void iso_callback(struct fw_iso_context *context, u32 cycle,
  650. size_t header_length, void *header, void *data)
  651. {
  652. struct client *client = data;
  653. struct iso_interrupt_event *e;
  654. e = kzalloc(sizeof(*e) + header_length, GFP_ATOMIC);
  655. if (e == NULL)
  656. return;
  657. e->interrupt.type = FW_CDEV_EVENT_ISO_INTERRUPT;
  658. e->interrupt.closure = client->iso_closure;
  659. e->interrupt.cycle = cycle;
  660. e->interrupt.header_length = header_length;
  661. memcpy(e->interrupt.header, header, header_length);
  662. queue_event(client, &e->event, &e->interrupt,
  663. sizeof(e->interrupt) + header_length, NULL, 0);
  664. }
  665. static int ioctl_create_iso_context(struct client *client, void *buffer)
  666. {
  667. struct fw_cdev_create_iso_context *request = buffer;
  668. struct fw_iso_context *context;
  669. /* We only support one context at this time. */
  670. if (client->iso_context != NULL)
  671. return -EBUSY;
  672. if (request->channel > 63)
  673. return -EINVAL;
  674. switch (request->type) {
  675. case FW_ISO_CONTEXT_RECEIVE:
  676. if (request->header_size < 4 || (request->header_size & 3))
  677. return -EINVAL;
  678. break;
  679. case FW_ISO_CONTEXT_TRANSMIT:
  680. if (request->speed > SCODE_3200)
  681. return -EINVAL;
  682. break;
  683. default:
  684. return -EINVAL;
  685. }
  686. context = fw_iso_context_create(client->device->card,
  687. request->type,
  688. request->channel,
  689. request->speed,
  690. request->header_size,
  691. iso_callback, client);
  692. if (IS_ERR(context))
  693. return PTR_ERR(context);
  694. client->iso_closure = request->closure;
  695. client->iso_context = context;
  696. /* We only support one context at this time. */
  697. request->handle = 0;
  698. return 0;
  699. }
  700. /* Macros for decoding the iso packet control header. */
  701. #define GET_PAYLOAD_LENGTH(v) ((v) & 0xffff)
  702. #define GET_INTERRUPT(v) (((v) >> 16) & 0x01)
  703. #define GET_SKIP(v) (((v) >> 17) & 0x01)
  704. #define GET_TAG(v) (((v) >> 18) & 0x03)
  705. #define GET_SY(v) (((v) >> 20) & 0x0f)
  706. #define GET_HEADER_LENGTH(v) (((v) >> 24) & 0xff)
  707. static int ioctl_queue_iso(struct client *client, void *buffer)
  708. {
  709. struct fw_cdev_queue_iso *request = buffer;
  710. struct fw_cdev_iso_packet __user *p, *end, *next;
  711. struct fw_iso_context *ctx = client->iso_context;
  712. unsigned long payload, buffer_end, header_length;
  713. u32 control;
  714. int count;
  715. struct {
  716. struct fw_iso_packet packet;
  717. u8 header[256];
  718. } u;
  719. if (ctx == NULL || request->handle != 0)
  720. return -EINVAL;
  721. /*
  722. * If the user passes a non-NULL data pointer, has mmap()'ed
  723. * the iso buffer, and the pointer points inside the buffer,
  724. * we setup the payload pointers accordingly. Otherwise we
  725. * set them both to 0, which will still let packets with
  726. * payload_length == 0 through. In other words, if no packets
  727. * use the indirect payload, the iso buffer need not be mapped
  728. * and the request->data pointer is ignored.
  729. */
  730. payload = (unsigned long)request->data - client->vm_start;
  731. buffer_end = client->buffer.page_count << PAGE_SHIFT;
  732. if (request->data == 0 || client->buffer.pages == NULL ||
  733. payload >= buffer_end) {
  734. payload = 0;
  735. buffer_end = 0;
  736. }
  737. p = (struct fw_cdev_iso_packet __user *)u64_to_uptr(request->packets);
  738. if (!access_ok(VERIFY_READ, p, request->size))
  739. return -EFAULT;
  740. end = (void __user *)p + request->size;
  741. count = 0;
  742. while (p < end) {
  743. if (get_user(control, &p->control))
  744. return -EFAULT;
  745. u.packet.payload_length = GET_PAYLOAD_LENGTH(control);
  746. u.packet.interrupt = GET_INTERRUPT(control);
  747. u.packet.skip = GET_SKIP(control);
  748. u.packet.tag = GET_TAG(control);
  749. u.packet.sy = GET_SY(control);
  750. u.packet.header_length = GET_HEADER_LENGTH(control);
  751. if (ctx->type == FW_ISO_CONTEXT_TRANSMIT) {
  752. header_length = u.packet.header_length;
  753. } else {
  754. /*
  755. * We require that header_length is a multiple of
  756. * the fixed header size, ctx->header_size.
  757. */
  758. if (ctx->header_size == 0) {
  759. if (u.packet.header_length > 0)
  760. return -EINVAL;
  761. } else if (u.packet.header_length % ctx->header_size != 0) {
  762. return -EINVAL;
  763. }
  764. header_length = 0;
  765. }
  766. next = (struct fw_cdev_iso_packet __user *)
  767. &p->header[header_length / 4];
  768. if (next > end)
  769. return -EINVAL;
  770. if (__copy_from_user
  771. (u.packet.header, p->header, header_length))
  772. return -EFAULT;
  773. if (u.packet.skip && ctx->type == FW_ISO_CONTEXT_TRANSMIT &&
  774. u.packet.header_length + u.packet.payload_length > 0)
  775. return -EINVAL;
  776. if (payload + u.packet.payload_length > buffer_end)
  777. return -EINVAL;
  778. if (fw_iso_context_queue(ctx, &u.packet,
  779. &client->buffer, payload))
  780. break;
  781. p = next;
  782. payload += u.packet.payload_length;
  783. count++;
  784. }
  785. request->size -= uptr_to_u64(p) - request->packets;
  786. request->packets = uptr_to_u64(p);
  787. request->data = client->vm_start + payload;
  788. return count;
  789. }
  790. static int ioctl_start_iso(struct client *client, void *buffer)
  791. {
  792. struct fw_cdev_start_iso *request = buffer;
  793. if (client->iso_context == NULL || request->handle != 0)
  794. return -EINVAL;
  795. if (client->iso_context->type == FW_ISO_CONTEXT_RECEIVE) {
  796. if (request->tags == 0 || request->tags > 15)
  797. return -EINVAL;
  798. if (request->sync > 15)
  799. return -EINVAL;
  800. }
  801. return fw_iso_context_start(client->iso_context, request->cycle,
  802. request->sync, request->tags);
  803. }
  804. static int ioctl_stop_iso(struct client *client, void *buffer)
  805. {
  806. struct fw_cdev_stop_iso *request = buffer;
  807. if (client->iso_context == NULL || request->handle != 0)
  808. return -EINVAL;
  809. return fw_iso_context_stop(client->iso_context);
  810. }
  811. static int ioctl_get_cycle_timer(struct client *client, void *buffer)
  812. {
  813. struct fw_cdev_get_cycle_timer *request = buffer;
  814. struct fw_card *card = client->device->card;
  815. unsigned long long bus_time;
  816. struct timeval tv;
  817. unsigned long flags;
  818. preempt_disable();
  819. local_irq_save(flags);
  820. bus_time = card->driver->get_bus_time(card);
  821. do_gettimeofday(&tv);
  822. local_irq_restore(flags);
  823. preempt_enable();
  824. request->local_time = tv.tv_sec * 1000000ULL + tv.tv_usec;
  825. request->cycle_timer = bus_time & 0xffffffff;
  826. return 0;
  827. }
  828. static void iso_resource_work(struct work_struct *work)
  829. {
  830. struct iso_resource_event *e;
  831. struct iso_resource *r =
  832. container_of(work, struct iso_resource, work.work);
  833. struct client *client = r->client;
  834. int generation, channel, bandwidth, todo;
  835. bool skip, free, success;
  836. spin_lock_irq(&client->lock);
  837. generation = client->device->generation;
  838. todo = r->todo;
  839. /* Allow 1000ms grace period for other reallocations. */
  840. if (todo == ISO_RES_ALLOC &&
  841. time_is_after_jiffies(client->device->card->reset_jiffies + HZ)) {
  842. if (schedule_delayed_work(&r->work, DIV_ROUND_UP(HZ, 3)))
  843. client_get(client);
  844. skip = true;
  845. } else {
  846. /* We could be called twice within the same generation. */
  847. skip = todo == ISO_RES_REALLOC &&
  848. r->generation == generation;
  849. }
  850. free = todo == ISO_RES_DEALLOC ||
  851. todo == ISO_RES_ALLOC_ONCE ||
  852. todo == ISO_RES_DEALLOC_ONCE;
  853. r->generation = generation;
  854. spin_unlock_irq(&client->lock);
  855. if (skip)
  856. goto out;
  857. bandwidth = r->bandwidth;
  858. fw_iso_resource_manage(client->device->card, generation,
  859. r->channels, &channel, &bandwidth,
  860. todo == ISO_RES_ALLOC ||
  861. todo == ISO_RES_REALLOC ||
  862. todo == ISO_RES_ALLOC_ONCE);
  863. /*
  864. * Is this generation outdated already? As long as this resource sticks
  865. * in the idr, it will be scheduled again for a newer generation or at
  866. * shutdown.
  867. */
  868. if (channel == -EAGAIN &&
  869. (todo == ISO_RES_ALLOC || todo == ISO_RES_REALLOC))
  870. goto out;
  871. success = channel >= 0 || bandwidth > 0;
  872. spin_lock_irq(&client->lock);
  873. /*
  874. * Transit from allocation to reallocation, except if the client
  875. * requested deallocation in the meantime.
  876. */
  877. if (r->todo == ISO_RES_ALLOC)
  878. r->todo = ISO_RES_REALLOC;
  879. /*
  880. * Allocation or reallocation failure? Pull this resource out of the
  881. * idr and prepare for deletion, unless the client is shutting down.
  882. */
  883. if (r->todo == ISO_RES_REALLOC && !success &&
  884. !client->in_shutdown &&
  885. idr_find(&client->resource_idr, r->resource.handle)) {
  886. idr_remove(&client->resource_idr, r->resource.handle);
  887. client_put(client);
  888. free = true;
  889. }
  890. spin_unlock_irq(&client->lock);
  891. if (todo == ISO_RES_ALLOC && channel >= 0)
  892. r->channels = 1ULL << (63 - channel);
  893. if (todo == ISO_RES_REALLOC && success)
  894. goto out;
  895. if (todo == ISO_RES_ALLOC || todo == ISO_RES_ALLOC_ONCE) {
  896. e = r->e_alloc;
  897. r->e_alloc = NULL;
  898. } else {
  899. e = r->e_dealloc;
  900. r->e_dealloc = NULL;
  901. }
  902. e->resource.handle = r->resource.handle;
  903. e->resource.channel = channel;
  904. e->resource.bandwidth = bandwidth;
  905. queue_event(client, &e->event,
  906. &e->resource, sizeof(e->resource), NULL, 0);
  907. if (free) {
  908. cancel_delayed_work(&r->work);
  909. kfree(r->e_alloc);
  910. kfree(r->e_dealloc);
  911. kfree(r);
  912. }
  913. out:
  914. client_put(client);
  915. }
  916. static int schedule_iso_resource(struct iso_resource *r)
  917. {
  918. int scheduled;
  919. client_get(r->client);
  920. scheduled = schedule_delayed_work(&r->work, 0);
  921. if (!scheduled)
  922. client_put(r->client);
  923. return scheduled;
  924. }
  925. static void release_iso_resource(struct client *client,
  926. struct client_resource *resource)
  927. {
  928. struct iso_resource *r =
  929. container_of(resource, struct iso_resource, resource);
  930. spin_lock_irq(&client->lock);
  931. r->todo = ISO_RES_DEALLOC;
  932. schedule_iso_resource(r);
  933. spin_unlock_irq(&client->lock);
  934. }
  935. static int init_iso_resource(struct client *client,
  936. struct fw_cdev_allocate_iso_resource *request, int todo)
  937. {
  938. struct iso_resource_event *e1, *e2;
  939. struct iso_resource *r;
  940. int ret;
  941. if ((request->channels == 0 && request->bandwidth == 0) ||
  942. request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
  943. request->bandwidth < 0)
  944. return -EINVAL;
  945. r = kmalloc(sizeof(*r), GFP_KERNEL);
  946. e1 = kmalloc(sizeof(*e1), GFP_KERNEL);
  947. e2 = kmalloc(sizeof(*e2), GFP_KERNEL);
  948. if (r == NULL || e1 == NULL || e2 == NULL) {
  949. ret = -ENOMEM;
  950. goto fail;
  951. }
  952. INIT_DELAYED_WORK(&r->work, iso_resource_work);
  953. r->client = client;
  954. r->todo = todo;
  955. r->generation = -1;
  956. r->channels = request->channels;
  957. r->bandwidth = request->bandwidth;
  958. r->e_alloc = e1;
  959. r->e_dealloc = e2;
  960. e1->resource.closure = request->closure;
  961. e1->resource.type = FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED;
  962. e2->resource.closure = request->closure;
  963. e2->resource.type = FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED;
  964. if (todo == ISO_RES_ALLOC) {
  965. r->resource.release = release_iso_resource;
  966. ret = add_client_resource(client, &r->resource, GFP_KERNEL);
  967. } else {
  968. r->resource.release = NULL;
  969. r->resource.handle = -1;
  970. ret = schedule_iso_resource(r) ? 0 : -ENOMEM;
  971. }
  972. if (ret < 0)
  973. goto fail;
  974. request->handle = r->resource.handle;
  975. return 0;
  976. fail:
  977. kfree(r);
  978. kfree(e1);
  979. kfree(e2);
  980. return ret;
  981. }
  982. static int ioctl_allocate_iso_resource(struct client *client, void *buffer)
  983. {
  984. struct fw_cdev_allocate_iso_resource *request = buffer;
  985. return init_iso_resource(client, request, ISO_RES_ALLOC);
  986. }
  987. static int ioctl_deallocate_iso_resource(struct client *client, void *buffer)
  988. {
  989. struct fw_cdev_deallocate *request = buffer;
  990. return release_client_resource(client, request->handle,
  991. release_iso_resource, NULL);
  992. }
  993. static int ioctl_allocate_iso_resource_once(struct client *client, void *buffer)
  994. {
  995. struct fw_cdev_allocate_iso_resource *request = buffer;
  996. return init_iso_resource(client, request, ISO_RES_ALLOC_ONCE);
  997. }
  998. static int ioctl_deallocate_iso_resource_once(struct client *client, void *buffer)
  999. {
  1000. struct fw_cdev_allocate_iso_resource *request = buffer;
  1001. return init_iso_resource(client, request, ISO_RES_DEALLOC_ONCE);
  1002. }
  1003. static int ioctl_get_speed(struct client *client, void *buffer)
  1004. {
  1005. struct fw_cdev_get_speed *request = buffer;
  1006. request->max_speed = client->device->max_speed;
  1007. return 0;
  1008. }
  1009. static int (* const ioctl_handlers[])(struct client *client, void *buffer) = {
  1010. ioctl_get_info,
  1011. ioctl_send_request,
  1012. ioctl_allocate,
  1013. ioctl_deallocate,
  1014. ioctl_send_response,
  1015. ioctl_initiate_bus_reset,
  1016. ioctl_add_descriptor,
  1017. ioctl_remove_descriptor,
  1018. ioctl_create_iso_context,
  1019. ioctl_queue_iso,
  1020. ioctl_start_iso,
  1021. ioctl_stop_iso,
  1022. ioctl_get_cycle_timer,
  1023. ioctl_allocate_iso_resource,
  1024. ioctl_deallocate_iso_resource,
  1025. ioctl_allocate_iso_resource_once,
  1026. ioctl_deallocate_iso_resource_once,
  1027. ioctl_get_speed,
  1028. };
  1029. static int dispatch_ioctl(struct client *client,
  1030. unsigned int cmd, void __user *arg)
  1031. {
  1032. char buffer[256];
  1033. int ret;
  1034. if (_IOC_TYPE(cmd) != '#' ||
  1035. _IOC_NR(cmd) >= ARRAY_SIZE(ioctl_handlers))
  1036. return -EINVAL;
  1037. if (_IOC_DIR(cmd) & _IOC_WRITE) {
  1038. if (_IOC_SIZE(cmd) > sizeof(buffer) ||
  1039. copy_from_user(buffer, arg, _IOC_SIZE(cmd)))
  1040. return -EFAULT;
  1041. }
  1042. ret = ioctl_handlers[_IOC_NR(cmd)](client, buffer);
  1043. if (ret < 0)
  1044. return ret;
  1045. if (_IOC_DIR(cmd) & _IOC_READ) {
  1046. if (_IOC_SIZE(cmd) > sizeof(buffer) ||
  1047. copy_to_user(arg, buffer, _IOC_SIZE(cmd)))
  1048. return -EFAULT;
  1049. }
  1050. return ret;
  1051. }
  1052. static long fw_device_op_ioctl(struct file *file,
  1053. unsigned int cmd, unsigned long arg)
  1054. {
  1055. struct client *client = file->private_data;
  1056. if (fw_device_is_shutdown(client->device))
  1057. return -ENODEV;
  1058. return dispatch_ioctl(client, cmd, (void __user *) arg);
  1059. }
  1060. #ifdef CONFIG_COMPAT
  1061. static long fw_device_op_compat_ioctl(struct file *file,
  1062. unsigned int cmd, unsigned long arg)
  1063. {
  1064. struct client *client = file->private_data;
  1065. if (fw_device_is_shutdown(client->device))
  1066. return -ENODEV;
  1067. return dispatch_ioctl(client, cmd, compat_ptr(arg));
  1068. }
  1069. #endif
  1070. static int fw_device_op_mmap(struct file *file, struct vm_area_struct *vma)
  1071. {
  1072. struct client *client = file->private_data;
  1073. enum dma_data_direction direction;
  1074. unsigned long size;
  1075. int page_count, ret;
  1076. if (fw_device_is_shutdown(client->device))
  1077. return -ENODEV;
  1078. /* FIXME: We could support multiple buffers, but we don't. */
  1079. if (client->buffer.pages != NULL)
  1080. return -EBUSY;
  1081. if (!(vma->vm_flags & VM_SHARED))
  1082. return -EINVAL;
  1083. if (vma->vm_start & ~PAGE_MASK)
  1084. return -EINVAL;
  1085. client->vm_start = vma->vm_start;
  1086. size = vma->vm_end - vma->vm_start;
  1087. page_count = size >> PAGE_SHIFT;
  1088. if (size & ~PAGE_MASK)
  1089. return -EINVAL;
  1090. if (vma->vm_flags & VM_WRITE)
  1091. direction = DMA_TO_DEVICE;
  1092. else
  1093. direction = DMA_FROM_DEVICE;
  1094. ret = fw_iso_buffer_init(&client->buffer, client->device->card,
  1095. page_count, direction);
  1096. if (ret < 0)
  1097. return ret;
  1098. ret = fw_iso_buffer_map(&client->buffer, vma);
  1099. if (ret < 0)
  1100. fw_iso_buffer_destroy(&client->buffer, client->device->card);
  1101. return ret;
  1102. }
  1103. static int shutdown_resource(int id, void *p, void *data)
  1104. {
  1105. struct client_resource *r = p;
  1106. struct client *client = data;
  1107. r->release(client, r);
  1108. client_put(client);
  1109. return 0;
  1110. }
  1111. static int fw_device_op_release(struct inode *inode, struct file *file)
  1112. {
  1113. struct client *client = file->private_data;
  1114. struct event *e, *next_e;
  1115. unsigned long flags;
  1116. mutex_lock(&client->device->client_list_mutex);
  1117. list_del(&client->link);
  1118. mutex_unlock(&client->device->client_list_mutex);
  1119. if (client->buffer.pages)
  1120. fw_iso_buffer_destroy(&client->buffer, client->device->card);
  1121. if (client->iso_context)
  1122. fw_iso_context_destroy(client->iso_context);
  1123. /* Freeze client->resource_idr and client->event_list */
  1124. spin_lock_irqsave(&client->lock, flags);
  1125. client->in_shutdown = true;
  1126. spin_unlock_irqrestore(&client->lock, flags);
  1127. idr_for_each(&client->resource_idr, shutdown_resource, client);
  1128. idr_remove_all(&client->resource_idr);
  1129. idr_destroy(&client->resource_idr);
  1130. list_for_each_entry_safe(e, next_e, &client->event_list, link)
  1131. kfree(e);
  1132. client_put(client);
  1133. return 0;
  1134. }
  1135. static unsigned int fw_device_op_poll(struct file *file, poll_table * pt)
  1136. {
  1137. struct client *client = file->private_data;
  1138. unsigned int mask = 0;
  1139. poll_wait(file, &client->wait, pt);
  1140. if (fw_device_is_shutdown(client->device))
  1141. mask |= POLLHUP | POLLERR;
  1142. if (!list_empty(&client->event_list))
  1143. mask |= POLLIN | POLLRDNORM;
  1144. return mask;
  1145. }
  1146. const struct file_operations fw_device_ops = {
  1147. .owner = THIS_MODULE,
  1148. .open = fw_device_op_open,
  1149. .read = fw_device_op_read,
  1150. .unlocked_ioctl = fw_device_op_ioctl,
  1151. .poll = fw_device_op_poll,
  1152. .release = fw_device_op_release,
  1153. .mmap = fw_device_op_mmap,
  1154. #ifdef CONFIG_COMPAT
  1155. .compat_ioctl = fw_device_op_compat_ioctl,
  1156. #endif
  1157. };