blob: d2b867f44348787e7176bc7a3a14df0880c99917 [file] [log] [blame]
Kristian Høgsberg19a15b92006-12-19 19:58:31 -05001/* -*- c-basic-offset: 8 -*-
2 *
3 * fw-device-cdev.c - Char device for device raw access
4 *
5 * Copyright (C) 2005-2006 Kristian Hoegsberg <krh@bitplanet.net>
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 Foundation,
19 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22#include <linux/module.h>
23#include <linux/kernel.h>
24#include <linux/wait.h>
25#include <linux/errno.h>
26#include <linux/device.h>
27#include <linux/vmalloc.h>
28#include <linux/poll.h>
29#include <linux/delay.h>
30#include <linux/mm.h>
Kristian Høgsberga3aca3d2007-03-07 12:12:44 -050031#include <linux/idr.h>
Kristian Høgsberg19a15b92006-12-19 19:58:31 -050032#include <linux/compat.h>
33#include <asm/uaccess.h>
34#include "fw-transaction.h"
35#include "fw-topology.h"
36#include "fw-device.h"
37#include "fw-device-cdev.h"
38
Kristian Høgsberg19a15b92006-12-19 19:58:31 -050039/* dequeue_event() just kfree()'s the event, so the event has to be
40 * the first field in the struct. */
41
Kristian Høgsberg3964a442007-03-27 01:43:41 -040042struct client;
43struct client_resource {
44 struct list_head link;
45 void (*release)(struct client *client, struct client_resource *r);
46 u32 handle;
47};
48
Kristian Høgsberg19a15b92006-12-19 19:58:31 -050049struct event {
50 struct { void *data; size_t size; } v[2];
51 struct list_head link;
52};
53
Kristian Høgsberg97bd9ef2007-03-07 12:12:41 -050054struct bus_reset {
55 struct event event;
56 struct fw_cdev_event_bus_reset reset;
57};
58
Kristian Høgsberg19a15b92006-12-19 19:58:31 -050059struct response {
60 struct event event;
61 struct fw_transaction transaction;
62 struct client *client;
Kristian Høgsberg3964a442007-03-27 01:43:41 -040063 struct client_resource resource;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -050064 struct fw_cdev_event_response response;
65};
66
67struct iso_interrupt {
68 struct event event;
69 struct fw_cdev_event_iso_interrupt interrupt;
70};
71
72struct client {
Kristian Høgsberg344bbc42007-03-07 12:12:43 -050073 u32 version;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -050074 struct fw_device *device;
75 spinlock_t lock;
Kristian Høgsberg66dea3e2007-03-28 21:26:42 +020076 u32 resource_handle;
Kristian Høgsberg3964a442007-03-27 01:43:41 -040077 struct list_head resource_list;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -050078 struct list_head event_list;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -050079 wait_queue_head_t wait;
Kristian Høgsbergda8ecff2007-03-27 01:43:39 -040080 u64 bus_reset_closure;
Kristian Høgsberg9aad8122007-02-16 17:34:38 -050081
Kristian Høgsberg19a15b92006-12-19 19:58:31 -050082 struct fw_iso_context *iso_context;
Kristian Høgsberg9aad8122007-02-16 17:34:38 -050083 struct fw_iso_buffer buffer;
84 unsigned long vm_start;
Kristian Høgsberg97bd9ef2007-03-07 12:12:41 -050085
86 struct list_head link;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -050087};
88
89static inline void __user *
90u64_to_uptr(__u64 value)
91{
92 return (void __user *)(unsigned long)value;
93}
94
95static inline __u64
96uptr_to_u64(void __user *ptr)
97{
98 return (__u64)(unsigned long)ptr;
99}
100
101static int fw_device_op_open(struct inode *inode, struct file *file)
102{
103 struct fw_device *device;
104 struct client *client;
Kristian Høgsberg97bd9ef2007-03-07 12:12:41 -0500105 unsigned long flags;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500106
Kristian Høgsberga3aca3d2007-03-07 12:12:44 -0500107 device = fw_device_from_devt(inode->i_rdev);
108 if (device == NULL)
109 return -ENODEV;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500110
111 client = kzalloc(sizeof *client, GFP_KERNEL);
112 if (client == NULL)
113 return -ENOMEM;
114
115 client->device = fw_device_get(device);
116 INIT_LIST_HEAD(&client->event_list);
Kristian Høgsberg3964a442007-03-27 01:43:41 -0400117 INIT_LIST_HEAD(&client->resource_list);
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500118 spin_lock_init(&client->lock);
119 init_waitqueue_head(&client->wait);
120
121 file->private_data = client;
122
Kristian Høgsberg97bd9ef2007-03-07 12:12:41 -0500123 spin_lock_irqsave(&device->card->lock, flags);
124 list_add_tail(&client->link, &device->client_list);
125 spin_unlock_irqrestore(&device->card->lock, flags);
126
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500127 return 0;
128}
129
130static void queue_event(struct client *client, struct event *event,
131 void *data0, size_t size0, void *data1, size_t size1)
132{
133 unsigned long flags;
134
135 event->v[0].data = data0;
136 event->v[0].size = size0;
137 event->v[1].data = data1;
138 event->v[1].size = size1;
139
140 spin_lock_irqsave(&client->lock, flags);
141
142 list_add_tail(&event->link, &client->event_list);
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500143 wake_up_interruptible(&client->wait);
144
145 spin_unlock_irqrestore(&client->lock, flags);
146}
147
Kristian Høgsberg2603bf22007-03-07 12:12:48 -0500148static int
149dequeue_event(struct client *client, char __user *buffer, size_t count)
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500150{
151 unsigned long flags;
152 struct event *event;
153 size_t size, total;
Kristian Høgsberg2603bf22007-03-07 12:12:48 -0500154 int i, retval;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500155
Kristian Høgsberg2603bf22007-03-07 12:12:48 -0500156 retval = wait_event_interruptible(client->wait,
157 !list_empty(&client->event_list) ||
158 fw_device_is_shutdown(client->device));
159 if (retval < 0)
160 return retval;
161
162 if (list_empty(&client->event_list) &&
163 fw_device_is_shutdown(client->device))
164 return -ENODEV;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500165
166 spin_lock_irqsave(&client->lock, flags);
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500167 event = container_of(client->event_list.next, struct event, link);
168 list_del(&event->link);
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500169 spin_unlock_irqrestore(&client->lock, flags);
170
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500171 total = 0;
172 for (i = 0; i < ARRAY_SIZE(event->v) && total < count; i++) {
173 size = min(event->v[i].size, count - total);
Kristian Høgsberg2603bf22007-03-07 12:12:48 -0500174 if (copy_to_user(buffer + total, event->v[i].data, size)) {
175 retval = -EFAULT;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500176 goto out;
Kristian Høgsberg2603bf22007-03-07 12:12:48 -0500177 }
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500178 total += size;
179 }
180 retval = total;
181
182 out:
183 kfree(event);
184
185 return retval;
186}
187
188static ssize_t
189fw_device_op_read(struct file *file,
190 char __user *buffer, size_t count, loff_t *offset)
191{
192 struct client *client = file->private_data;
193
194 return dequeue_event(client, buffer, count);
195}
196
Kristian Høgsberg97bd9ef2007-03-07 12:12:41 -0500197static void
Kristian Høgsberg344bbc42007-03-07 12:12:43 -0500198fill_bus_reset_event(struct fw_cdev_event_bus_reset *event,
Kristian Høgsbergda8ecff2007-03-27 01:43:39 -0400199 struct client *client)
Kristian Høgsberg344bbc42007-03-07 12:12:43 -0500200{
Kristian Høgsbergda8ecff2007-03-27 01:43:39 -0400201 struct fw_card *card = client->device->card;
Kristian Høgsberg344bbc42007-03-07 12:12:43 -0500202
Kristian Høgsbergda8ecff2007-03-27 01:43:39 -0400203 event->closure = client->bus_reset_closure;
Kristian Høgsberg344bbc42007-03-07 12:12:43 -0500204 event->type = FW_CDEV_EVENT_BUS_RESET;
Kristian Høgsbergda8ecff2007-03-27 01:43:39 -0400205 event->node_id = client->device->node_id;
Kristian Høgsberg344bbc42007-03-07 12:12:43 -0500206 event->local_node_id = card->local_node->node_id;
207 event->bm_node_id = 0; /* FIXME: We don't track the BM. */
208 event->irm_node_id = card->irm_node->node_id;
209 event->root_node_id = card->root_node->node_id;
210 event->generation = card->generation;
211}
212
213static void
Kristian Høgsberg2603bf22007-03-07 12:12:48 -0500214for_each_client(struct fw_device *device,
215 void (*callback)(struct client *client))
216{
217 struct fw_card *card = device->card;
218 struct client *c;
219 unsigned long flags;
220
221 spin_lock_irqsave(&card->lock, flags);
222
223 list_for_each_entry(c, &device->client_list, link)
224 callback(c);
225
226 spin_unlock_irqrestore(&card->lock, flags);
227}
228
229static void
Kristian Høgsberg97bd9ef2007-03-07 12:12:41 -0500230queue_bus_reset_event(struct client *client)
231{
232 struct bus_reset *bus_reset;
Kristian Høgsberg97bd9ef2007-03-07 12:12:41 -0500233
234 bus_reset = kzalloc(sizeof *bus_reset, GFP_ATOMIC);
235 if (bus_reset == NULL) {
236 fw_notify("Out of memory when allocating bus reset event\n");
237 return;
238 }
239
Kristian Høgsbergda8ecff2007-03-27 01:43:39 -0400240 fill_bus_reset_event(&bus_reset->reset, client);
Kristian Høgsberg97bd9ef2007-03-07 12:12:41 -0500241
242 queue_event(client, &bus_reset->event,
243 &bus_reset->reset, sizeof bus_reset->reset, NULL, 0);
244}
245
246void fw_device_cdev_update(struct fw_device *device)
247{
Kristian Høgsberg2603bf22007-03-07 12:12:48 -0500248 for_each_client(device, queue_bus_reset_event);
249}
Kristian Høgsberg97bd9ef2007-03-07 12:12:41 -0500250
Kristian Høgsberg2603bf22007-03-07 12:12:48 -0500251static void wake_up_client(struct client *client)
252{
253 wake_up_interruptible(&client->wait);
254}
Kristian Høgsberg97bd9ef2007-03-07 12:12:41 -0500255
Kristian Høgsberg2603bf22007-03-07 12:12:48 -0500256void fw_device_cdev_remove(struct fw_device *device)
257{
258 for_each_client(device, wake_up_client);
Kristian Høgsberg97bd9ef2007-03-07 12:12:41 -0500259}
260
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400261static int ioctl_get_info(struct client *client, void *buffer)
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500262{
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400263 struct fw_cdev_get_info *get_info = buffer;
Kristian Høgsberg344bbc42007-03-07 12:12:43 -0500264 struct fw_cdev_event_bus_reset bus_reset;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500265
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400266 client->version = get_info->version;
267 get_info->version = FW_CDEV_VERSION;
Kristian Høgsberg344bbc42007-03-07 12:12:43 -0500268
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400269 if (get_info->rom != 0) {
270 void __user *uptr = u64_to_uptr(get_info->rom);
271 size_t want = get_info->rom_length;
Stefan Richterd84702a2007-03-20 19:42:15 +0100272 size_t have = client->device->config_rom_length * 4;
Kristian Høgsberg344bbc42007-03-07 12:12:43 -0500273
Stefan Richterd84702a2007-03-20 19:42:15 +0100274 if (copy_to_user(uptr, client->device->config_rom,
275 min(want, have)))
Kristian Høgsberg344bbc42007-03-07 12:12:43 -0500276 return -EFAULT;
277 }
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400278 get_info->rom_length = client->device->config_rom_length * 4;
Kristian Høgsberg344bbc42007-03-07 12:12:43 -0500279
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400280 client->bus_reset_closure = get_info->bus_reset_closure;
281 if (get_info->bus_reset != 0) {
282 void __user *uptr = u64_to_uptr(get_info->bus_reset);
Kristian Høgsberg344bbc42007-03-07 12:12:43 -0500283
Kristian Høgsbergda8ecff2007-03-27 01:43:39 -0400284 fill_bus_reset_event(&bus_reset, client);
Kristian Høgsberg344bbc42007-03-07 12:12:43 -0500285 if (copy_to_user(uptr, &bus_reset, sizeof bus_reset))
286 return -EFAULT;
287 }
288
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400289 get_info->card = client->device->card->index;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500290
291 return 0;
292}
293
294static void
Kristian Høgsberg3964a442007-03-27 01:43:41 -0400295add_client_resource(struct client *client, struct client_resource *resource)
296{
297 unsigned long flags;
298
299 spin_lock_irqsave(&client->lock, flags);
300 list_add_tail(&resource->link, &client->resource_list);
301 resource->handle = client->resource_handle++;
302 spin_unlock_irqrestore(&client->lock, flags);
303}
304
305static int
306release_client_resource(struct client *client, u32 handle,
307 struct client_resource **resource)
308{
309 struct client_resource *r;
310 unsigned long flags;
311
312 spin_lock_irqsave(&client->lock, flags);
313 list_for_each_entry(r, &client->resource_list, link) {
314 if (r->handle == handle) {
315 list_del(&r->link);
316 break;
317 }
318 }
319 spin_unlock_irqrestore(&client->lock, flags);
320
321 if (&r->link == &client->resource_list)
322 return -EINVAL;
323
324 if (resource)
325 *resource = r;
326 else
327 r->release(client, r);
328
329 return 0;
330}
331
332static void
333release_transaction(struct client *client, struct client_resource *resource)
334{
335 struct response *response =
336 container_of(resource, struct response, resource);
337
338 fw_cancel_transaction(client->device->card, &response->transaction);
339}
340
341static void
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500342complete_transaction(struct fw_card *card, int rcode,
343 void *payload, size_t length, void *data)
344{
345 struct response *response = data;
346 struct client *client = response->client;
Kristian Høgsberg28cf6a02007-03-07 12:12:50 -0500347 unsigned long flags;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500348
349 if (length < response->response.length)
350 response->response.length = length;
351 if (rcode == RCODE_COMPLETE)
352 memcpy(response->response.data, payload,
353 response->response.length);
354
Kristian Høgsberg28cf6a02007-03-07 12:12:50 -0500355 spin_lock_irqsave(&client->lock, flags);
Kristian Høgsberg3964a442007-03-27 01:43:41 -0400356 list_del(&response->resource.link);
Kristian Høgsberg28cf6a02007-03-07 12:12:50 -0500357 spin_unlock_irqrestore(&client->lock, flags);
358
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500359 response->response.type = FW_CDEV_EVENT_RESPONSE;
360 response->response.rcode = rcode;
361 queue_event(client, &response->event,
362 &response->response, sizeof response->response,
363 response->response.data, response->response.length);
364}
365
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400366static ssize_t ioctl_send_request(struct client *client, void *buffer)
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500367{
368 struct fw_device *device = client->device;
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400369 struct fw_cdev_send_request *request = buffer;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500370 struct response *response;
371
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500372 /* What is the biggest size we'll accept, really? */
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400373 if (request->length > 4096)
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500374 return -EINVAL;
375
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400376 response = kmalloc(sizeof *response + request->length, GFP_KERNEL);
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500377 if (response == NULL)
378 return -ENOMEM;
379
380 response->client = client;
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400381 response->response.length = request->length;
382 response->response.closure = request->closure;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500383
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400384 if (request->data &&
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500385 copy_from_user(response->response.data,
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400386 u64_to_uptr(request->data), request->length)) {
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500387 kfree(response);
388 return -EFAULT;
389 }
390
Kristian Høgsberg3964a442007-03-27 01:43:41 -0400391 response->resource.release = release_transaction;
392 add_client_resource(client, &response->resource);
Kristian Høgsberg28cf6a02007-03-07 12:12:50 -0500393
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500394 fw_send_request(device->card, &response->transaction,
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400395 request->tcode & 0x1f,
Stefan Richter907293d2007-01-23 21:11:43 +0100396 device->node->node_id,
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400397 request->generation,
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500398 device->node->max_speed,
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400399 request->offset,
400 response->response.data, request->length,
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500401 complete_transaction, response);
402
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400403 if (request->data)
404 return sizeof request + request->length;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500405 else
406 return sizeof request;
407}
408
409struct address_handler {
410 struct fw_address_handler handler;
411 __u64 closure;
412 struct client *client;
Kristian Høgsberg3964a442007-03-27 01:43:41 -0400413 struct client_resource resource;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500414};
415
416struct request {
417 struct fw_request *request;
418 void *data;
419 size_t length;
Kristian Høgsberg3964a442007-03-27 01:43:41 -0400420 struct client_resource resource;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500421};
422
423struct request_event {
424 struct event event;
425 struct fw_cdev_event_request request;
426};
427
428static void
Kristian Høgsberg3964a442007-03-27 01:43:41 -0400429release_request(struct client *client, struct client_resource *resource)
430{
431 struct request *request =
432 container_of(resource, struct request, resource);
433
434 fw_send_response(client->device->card, request->request,
435 RCODE_CONFLICT_ERROR);
436 kfree(request);
437}
438
439static void
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500440handle_request(struct fw_card *card, struct fw_request *r,
441 int tcode, int destination, int source,
442 int generation, int speed,
443 unsigned long long offset,
444 void *payload, size_t length, void *callback_data)
445{
446 struct address_handler *handler = callback_data;
447 struct request *request;
448 struct request_event *e;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500449 struct client *client = handler->client;
450
451 request = kmalloc(sizeof *request, GFP_ATOMIC);
452 e = kmalloc(sizeof *e, GFP_ATOMIC);
453 if (request == NULL || e == NULL) {
454 kfree(request);
455 kfree(e);
456 fw_send_response(card, r, RCODE_CONFLICT_ERROR);
457 return;
458 }
459
460 request->request = r;
461 request->data = payload;
462 request->length = length;
463
Kristian Høgsberg3964a442007-03-27 01:43:41 -0400464 request->resource.release = release_request;
465 add_client_resource(client, &request->resource);
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500466
467 e->request.type = FW_CDEV_EVENT_REQUEST;
468 e->request.tcode = tcode;
469 e->request.offset = offset;
470 e->request.length = length;
Kristian Høgsberg3964a442007-03-27 01:43:41 -0400471 e->request.handle = request->resource.handle;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500472 e->request.closure = handler->closure;
473
474 queue_event(client, &e->event,
475 &e->request, sizeof e->request, payload, length);
476}
477
Kristian Høgsberg3964a442007-03-27 01:43:41 -0400478static void
479release_address_handler(struct client *client,
480 struct client_resource *resource)
481{
482 struct address_handler *handler =
483 container_of(resource, struct address_handler, resource);
484
485 fw_core_remove_address_handler(&handler->handler);
486 kfree(handler);
487}
488
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400489static int ioctl_allocate(struct client *client, void *buffer)
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500490{
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400491 struct fw_cdev_allocate *request = buffer;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500492 struct address_handler *handler;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500493 struct fw_address_region region;
494
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500495 handler = kmalloc(sizeof *handler, GFP_KERNEL);
496 if (handler == NULL)
497 return -ENOMEM;
498
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400499 region.start = request->offset;
500 region.end = request->offset + request->length;
501 handler->handler.length = request->length;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500502 handler->handler.address_callback = handle_request;
503 handler->handler.callback_data = handler;
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400504 handler->closure = request->closure;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500505 handler->client = client;
506
507 if (fw_core_add_address_handler(&handler->handler, &region) < 0) {
508 kfree(handler);
509 return -EBUSY;
510 }
511
Kristian Høgsberg3964a442007-03-27 01:43:41 -0400512 handler->resource.release = release_address_handler;
513 add_client_resource(client, &handler->resource);
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400514 request->handle = handler->resource.handle;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500515
516 return 0;
517}
518
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400519static int ioctl_deallocate(struct client *client, void *buffer)
Kristian Høgsberg94723162007-03-14 17:34:55 -0400520{
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400521 struct fw_cdev_deallocate *request = buffer;
Kristian Høgsberg94723162007-03-14 17:34:55 -0400522
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400523 return release_client_resource(client, request->handle, NULL);
Kristian Høgsberg94723162007-03-14 17:34:55 -0400524}
525
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400526static int ioctl_send_response(struct client *client, void *buffer)
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500527{
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400528 struct fw_cdev_send_response *request = buffer;
Kristian Høgsberg3964a442007-03-27 01:43:41 -0400529 struct client_resource *resource;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500530 struct request *r;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500531
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400532 if (release_client_resource(client, request->handle, &resource) < 0)
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500533 return -EINVAL;
Kristian Høgsberg3964a442007-03-27 01:43:41 -0400534 r = container_of(resource, struct request, resource);
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400535 if (request->length < r->length)
536 r->length = request->length;
537 if (copy_from_user(r->data, u64_to_uptr(request->data), r->length))
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500538 return -EFAULT;
539
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400540 fw_send_response(client->device->card, r->request, request->rcode);
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500541 kfree(r);
542
543 return 0;
544}
545
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400546static int ioctl_initiate_bus_reset(struct client *client, void *buffer)
Kristian Høgsberg53718422007-03-07 12:12:42 -0500547{
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400548 struct fw_cdev_initiate_bus_reset *request = buffer;
Kristian Høgsberg53718422007-03-07 12:12:42 -0500549 int short_reset;
550
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400551 short_reset = (request->type == FW_CDEV_SHORT_RESET);
Kristian Høgsberg53718422007-03-07 12:12:42 -0500552
553 return fw_core_initiate_bus_reset(client->device->card, short_reset);
554}
555
Kristian Høgsberg66dea3e2007-03-28 21:26:42 +0200556struct descriptor {
557 struct fw_descriptor d;
Kristian Høgsberg3964a442007-03-27 01:43:41 -0400558 struct client_resource resource;
Kristian Høgsberg66dea3e2007-03-28 21:26:42 +0200559 u32 data[0];
560};
561
Kristian Høgsberg3964a442007-03-27 01:43:41 -0400562static void release_descriptor(struct client *client,
563 struct client_resource *resource)
564{
565 struct descriptor *descriptor =
566 container_of(resource, struct descriptor, resource);
567
568 fw_core_remove_descriptor(&descriptor->d);
569 kfree(descriptor);
570}
571
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400572static int ioctl_add_descriptor(struct client *client, void *buffer)
Kristian Høgsberg66dea3e2007-03-28 21:26:42 +0200573{
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400574 struct fw_cdev_add_descriptor *request = buffer;
Kristian Høgsberg66dea3e2007-03-28 21:26:42 +0200575 struct descriptor *descriptor;
Kristian Høgsberg66dea3e2007-03-28 21:26:42 +0200576 int retval;
577
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400578 if (request->length > 256)
Kristian Høgsberg66dea3e2007-03-28 21:26:42 +0200579 return -EINVAL;
580
581 descriptor =
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400582 kmalloc(sizeof *descriptor + request->length * 4, GFP_KERNEL);
Kristian Høgsberg66dea3e2007-03-28 21:26:42 +0200583 if (descriptor == NULL)
584 return -ENOMEM;
585
586 if (copy_from_user(descriptor->data,
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400587 u64_to_uptr(request->data), request->length * 4)) {
Kristian Høgsberg66dea3e2007-03-28 21:26:42 +0200588 kfree(descriptor);
589 return -EFAULT;
590 }
591
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400592 descriptor->d.length = request->length;
593 descriptor->d.immediate = request->immediate;
594 descriptor->d.key = request->key;
Kristian Høgsberg66dea3e2007-03-28 21:26:42 +0200595 descriptor->d.data = descriptor->data;
596
597 retval = fw_core_add_descriptor(&descriptor->d);
598 if (retval < 0) {
599 kfree(descriptor);
600 return retval;
601 }
602
Kristian Høgsberg3964a442007-03-27 01:43:41 -0400603 descriptor->resource.release = release_descriptor;
604 add_client_resource(client, &descriptor->resource);
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400605 request->handle = descriptor->resource.handle;
Kristian Høgsberg66dea3e2007-03-28 21:26:42 +0200606
607 return 0;
608}
609
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400610static int ioctl_remove_descriptor(struct client *client, void *buffer)
Kristian Høgsberg66dea3e2007-03-28 21:26:42 +0200611{
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400612 struct fw_cdev_remove_descriptor *request = buffer;
Kristian Høgsberg66dea3e2007-03-28 21:26:42 +0200613
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400614 return release_client_resource(client, request->handle, NULL);
Kristian Høgsberg66dea3e2007-03-28 21:26:42 +0200615}
616
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500617static void
Kristian Høgsberg9b32d5f2007-02-16 17:34:44 -0500618iso_callback(struct fw_iso_context *context, u32 cycle,
619 size_t header_length, void *header, void *data)
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500620{
621 struct client *client = data;
622 struct iso_interrupt *interrupt;
623
Kristian Høgsberg9b32d5f2007-02-16 17:34:44 -0500624 interrupt = kzalloc(sizeof *interrupt + header_length, GFP_ATOMIC);
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500625 if (interrupt == NULL)
626 return;
627
628 interrupt->interrupt.type = FW_CDEV_EVENT_ISO_INTERRUPT;
629 interrupt->interrupt.closure = 0;
630 interrupt->interrupt.cycle = cycle;
Kristian Høgsberg9b32d5f2007-02-16 17:34:44 -0500631 interrupt->interrupt.header_length = header_length;
632 memcpy(interrupt->interrupt.header, header, header_length);
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500633 queue_event(client, &interrupt->event,
Kristian Høgsberg9b32d5f2007-02-16 17:34:44 -0500634 &interrupt->interrupt,
635 sizeof interrupt->interrupt + header_length, NULL, 0);
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500636}
637
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400638static int ioctl_create_iso_context(struct client *client, void *buffer)
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500639{
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400640 struct fw_cdev_create_iso_context *request = buffer;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500641
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400642 if (request->channel > 63)
Kristian Høgsberg21efb3c2007-02-16 17:34:50 -0500643 return -EINVAL;
644
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400645 switch (request->type) {
Kristian Høgsbergc70dc782007-03-14 17:34:53 -0400646 case FW_ISO_CONTEXT_RECEIVE:
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400647 if (request->header_size < 4 || (request->header_size & 3))
Kristian Høgsbergc70dc782007-03-14 17:34:53 -0400648 return -EINVAL;
649
650 break;
651
652 case FW_ISO_CONTEXT_TRANSMIT:
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400653 if (request->speed > SCODE_3200)
Kristian Høgsbergc70dc782007-03-14 17:34:53 -0400654 return -EINVAL;
655
656 break;
657
658 default:
Kristian Høgsberg21efb3c2007-02-16 17:34:50 -0500659 return -EINVAL;
Kristian Høgsbergc70dc782007-03-14 17:34:53 -0400660 }
661
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500662 client->iso_context = fw_iso_context_create(client->device->card,
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400663 request->type,
664 request->channel,
665 request->speed,
666 request->header_size,
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500667 iso_callback, client);
668 if (IS_ERR(client->iso_context))
669 return PTR_ERR(client->iso_context);
670
671 return 0;
672}
673
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400674static int ioctl_queue_iso(struct client *client, void *buffer)
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500675{
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400676 struct fw_cdev_queue_iso *request = buffer;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500677 struct fw_cdev_iso_packet __user *p, *end, *next;
Kristian Høgsberg9b32d5f2007-02-16 17:34:44 -0500678 struct fw_iso_context *ctx = client->iso_context;
Kristian Høgsbergef370ee2007-03-28 20:46:23 +0200679 unsigned long payload, buffer_end, header_length;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500680 int count;
681 struct {
682 struct fw_iso_packet packet;
683 u8 header[256];
684 } u;
685
Kristian Høgsberg9b32d5f2007-02-16 17:34:44 -0500686 if (ctx == NULL)
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500687 return -EINVAL;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500688
689 /* If the user passes a non-NULL data pointer, has mmap()'ed
690 * the iso buffer, and the pointer points inside the buffer,
691 * we setup the payload pointers accordingly. Otherwise we
Kristian Høgsberg9aad8122007-02-16 17:34:38 -0500692 * set them both to 0, which will still let packets with
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500693 * payload_length == 0 through. In other words, if no packets
694 * use the indirect payload, the iso buffer need not be mapped
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400695 * and the request->data pointer is ignored.*/
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500696
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400697 payload = (unsigned long)request->data - client->vm_start;
Kristian Høgsbergef370ee2007-03-28 20:46:23 +0200698 buffer_end = client->buffer.page_count << PAGE_SHIFT;
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400699 if (request->data == 0 || client->buffer.pages == NULL ||
Kristian Høgsbergef370ee2007-03-28 20:46:23 +0200700 payload >= buffer_end) {
Kristian Høgsberg9aad8122007-02-16 17:34:38 -0500701 payload = 0;
Kristian Høgsbergef370ee2007-03-28 20:46:23 +0200702 buffer_end = 0;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500703 }
704
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400705 if (!access_ok(VERIFY_READ, request->packets, request->size))
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500706 return -EFAULT;
707
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400708 p = (struct fw_cdev_iso_packet __user *)u64_to_uptr(request->packets);
709 end = (void __user *)p + request->size;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500710 count = 0;
711 while (p < end) {
712 if (__copy_from_user(&u.packet, p, sizeof *p))
713 return -EFAULT;
Kristian Høgsberg295e3fe2007-02-16 17:34:40 -0500714
Kristian Høgsberg9b32d5f2007-02-16 17:34:44 -0500715 if (ctx->type == FW_ISO_CONTEXT_TRANSMIT) {
Kristian Høgsberg295e3fe2007-02-16 17:34:40 -0500716 header_length = u.packet.header_length;
717 } else {
718 /* We require that header_length is a multiple of
719 * the fixed header size, ctx->header_size */
Kristian Høgsberg9b32d5f2007-02-16 17:34:44 -0500720 if (ctx->header_size == 0) {
721 if (u.packet.header_length > 0)
722 return -EINVAL;
723 } else if (u.packet.header_length % ctx->header_size != 0) {
Kristian Høgsberg295e3fe2007-02-16 17:34:40 -0500724 return -EINVAL;
Kristian Høgsberg9b32d5f2007-02-16 17:34:44 -0500725 }
Kristian Høgsberg295e3fe2007-02-16 17:34:40 -0500726 header_length = 0;
727 }
728
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500729 next = (struct fw_cdev_iso_packet __user *)
Kristian Høgsberg295e3fe2007-02-16 17:34:40 -0500730 &p->header[header_length / 4];
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500731 if (next > end)
732 return -EINVAL;
733 if (__copy_from_user
Kristian Høgsberg295e3fe2007-02-16 17:34:40 -0500734 (u.packet.header, p->header, header_length))
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500735 return -EFAULT;
Kristian Høgsberg98b6cbe2007-02-16 17:34:51 -0500736 if (u.packet.skip && ctx->type == FW_ISO_CONTEXT_TRANSMIT &&
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500737 u.packet.header_length + u.packet.payload_length > 0)
738 return -EINVAL;
Kristian Høgsbergef370ee2007-03-28 20:46:23 +0200739 if (payload + u.packet.payload_length > buffer_end)
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500740 return -EINVAL;
741
Kristian Høgsberg9b32d5f2007-02-16 17:34:44 -0500742 if (fw_iso_context_queue(ctx, &u.packet,
743 &client->buffer, payload))
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500744 break;
745
746 p = next;
747 payload += u.packet.payload_length;
748 count++;
749 }
750
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400751 request->size -= uptr_to_u64(p) - request->packets;
752 request->packets = uptr_to_u64(p);
753 request->data = client->vm_start + payload;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500754
755 return count;
756}
757
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400758static int ioctl_start_iso(struct client *client, void *buffer)
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500759{
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400760 struct fw_cdev_start_iso *request = buffer;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500761
Kristian Høgsbergeb0306e2007-03-14 17:34:54 -0400762 if (client->iso_context->type == FW_ISO_CONTEXT_RECEIVE) {
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400763 if (request->tags == 0 || request->tags > 15)
Kristian Høgsbergeb0306e2007-03-14 17:34:54 -0400764 return -EINVAL;
765
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400766 if (request->sync > 15)
Kristian Høgsbergeb0306e2007-03-14 17:34:54 -0400767 return -EINVAL;
768 }
769
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400770 return fw_iso_context_start(client->iso_context, request->cycle,
771 request->sync, request->tags);
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500772}
773
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400774static int ioctl_stop_iso(struct client *client, void *buffer)
Kristian Høgsbergb8295662007-02-16 17:34:42 -0500775{
776 return fw_iso_context_stop(client->iso_context);
777}
778
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400779static int (* const ioctl_handlers[])(struct client *client, void *buffer) = {
780 ioctl_get_info,
781 ioctl_send_request,
782 ioctl_allocate,
783 ioctl_deallocate,
784 ioctl_send_response,
785 ioctl_initiate_bus_reset,
786 ioctl_add_descriptor,
787 ioctl_remove_descriptor,
788 ioctl_create_iso_context,
789 ioctl_queue_iso,
790 ioctl_start_iso,
791 ioctl_stop_iso,
792};
793
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500794static int
795dispatch_ioctl(struct client *client, unsigned int cmd, void __user *arg)
796{
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400797 char buffer[256];
798 int retval;
799
800 if (_IOC_TYPE(cmd) != '#' ||
801 _IOC_NR(cmd) >= ARRAY_SIZE(ioctl_handlers))
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500802 return -EINVAL;
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400803
804 if (_IOC_DIR(cmd) & _IOC_WRITE) {
805 if (_IOC_SIZE(cmd) > sizeof buffer ||
806 copy_from_user(buffer, arg, _IOC_SIZE(cmd)))
807 return -EFAULT;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500808 }
Kristian Høgsberg4f259222007-04-30 15:03:13 -0400809
810 retval = ioctl_handlers[_IOC_NR(cmd)](client, buffer);
811 if (retval < 0)
812 return retval;
813
814 if (_IOC_DIR(cmd) & _IOC_READ) {
815 if (_IOC_SIZE(cmd) > sizeof buffer ||
816 copy_to_user(arg, buffer, _IOC_SIZE(cmd)))
817 return -EFAULT;
818 }
819
820 return 0;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500821}
822
823static long
824fw_device_op_ioctl(struct file *file,
825 unsigned int cmd, unsigned long arg)
826{
827 struct client *client = file->private_data;
828
829 return dispatch_ioctl(client, cmd, (void __user *) arg);
830}
831
832#ifdef CONFIG_COMPAT
833static long
834fw_device_op_compat_ioctl(struct file *file,
835 unsigned int cmd, unsigned long arg)
836{
837 struct client *client = file->private_data;
838
839 return dispatch_ioctl(client, cmd, compat_ptr(arg));
840}
841#endif
842
843static int fw_device_op_mmap(struct file *file, struct vm_area_struct *vma)
844{
845 struct client *client = file->private_data;
Kristian Høgsberg9aad8122007-02-16 17:34:38 -0500846 enum dma_data_direction direction;
847 unsigned long size;
848 int page_count, retval;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500849
Kristian Høgsberg9aad8122007-02-16 17:34:38 -0500850 /* FIXME: We could support multiple buffers, but we don't. */
851 if (client->buffer.pages != NULL)
852 return -EBUSY;
853
854 if (!(vma->vm_flags & VM_SHARED))
855 return -EINVAL;
856
857 if (vma->vm_start & ~PAGE_MASK)
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500858 return -EINVAL;
859
860 client->vm_start = vma->vm_start;
Kristian Høgsberg9aad8122007-02-16 17:34:38 -0500861 size = vma->vm_end - vma->vm_start;
862 page_count = size >> PAGE_SHIFT;
863 if (size & ~PAGE_MASK)
864 return -EINVAL;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500865
Kristian Høgsberg9aad8122007-02-16 17:34:38 -0500866 if (vma->vm_flags & VM_WRITE)
867 direction = DMA_TO_DEVICE;
868 else
869 direction = DMA_FROM_DEVICE;
870
871 retval = fw_iso_buffer_init(&client->buffer, client->device->card,
872 page_count, direction);
873 if (retval < 0)
874 return retval;
875
876 retval = fw_iso_buffer_map(&client->buffer, vma);
877 if (retval < 0)
878 fw_iso_buffer_destroy(&client->buffer, client->device->card);
879
880 return retval;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500881}
882
883static int fw_device_op_release(struct inode *inode, struct file *file)
884{
885 struct client *client = file->private_data;
Kristian Høgsberg2603bf22007-03-07 12:12:48 -0500886 struct event *e, *next_e;
Kristian Høgsberg3964a442007-03-27 01:43:41 -0400887 struct client_resource *r, *next_r;
Kristian Høgsberg97bd9ef2007-03-07 12:12:41 -0500888 unsigned long flags;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500889
Kristian Høgsberg9aad8122007-02-16 17:34:38 -0500890 if (client->buffer.pages)
891 fw_iso_buffer_destroy(&client->buffer, client->device->card);
892
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500893 if (client->iso_context)
894 fw_iso_context_destroy(client->iso_context);
895
Kristian Høgsberg3964a442007-03-27 01:43:41 -0400896 list_for_each_entry_safe(r, next_r, &client->resource_list, link)
897 r->release(client, r);
Kristian Høgsberg66dea3e2007-03-28 21:26:42 +0200898
Kristian Høgsberg28cf6a02007-03-07 12:12:50 -0500899 /* FIXME: We should wait for the async tasklets to stop
900 * running before freeing the memory. */
901
Kristian Høgsberg2603bf22007-03-07 12:12:48 -0500902 list_for_each_entry_safe(e, next_e, &client->event_list, link)
903 kfree(e);
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500904
Kristian Høgsberg97bd9ef2007-03-07 12:12:41 -0500905 spin_lock_irqsave(&client->device->card->lock, flags);
906 list_del(&client->link);
907 spin_unlock_irqrestore(&client->device->card->lock, flags);
908
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500909 fw_device_put(client->device);
910 kfree(client);
911
912 return 0;
913}
914
915static unsigned int fw_device_op_poll(struct file *file, poll_table * pt)
916{
917 struct client *client = file->private_data;
Kristian Høgsberg2603bf22007-03-07 12:12:48 -0500918 unsigned int mask = 0;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500919
920 poll_wait(file, &client->wait, pt);
921
Kristian Høgsberg2603bf22007-03-07 12:12:48 -0500922 if (fw_device_is_shutdown(client->device))
923 mask |= POLLHUP | POLLERR;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500924 if (!list_empty(&client->event_list))
Kristian Høgsberg2603bf22007-03-07 12:12:48 -0500925 mask |= POLLIN | POLLRDNORM;
926
927 return mask;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500928}
929
Stefan Richter21ebcd12007-01-14 15:29:07 +0100930const struct file_operations fw_device_ops = {
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500931 .owner = THIS_MODULE,
932 .open = fw_device_op_open,
933 .read = fw_device_op_read,
934 .unlocked_ioctl = fw_device_op_ioctl,
935 .poll = fw_device_op_poll,
936 .release = fw_device_op_release,
937 .mmap = fw_device_op_mmap,
938
939#ifdef CONFIG_COMPAT
Stefan Richter5af4e5e2007-01-21 20:45:32 +0100940 .compat_ioctl = fw_device_op_compat_ioctl,
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500941#endif
942};