vmalloc: fix __GFP_HIGHMEM usage for vmalloc_32 on 32b systems
[linux/fpc-iii.git] / sound / firewire / bebob / bebob_hwdep.c
blob2b367c21b80c36e25ea105c8098ce0a9f38da496
1 /*
2 * bebob_hwdep.c - a part of driver for BeBoB based devices
4 * Copyright (c) 2013-2014 Takashi Sakamoto
6 * Licensed under the terms of the GNU General Public License, version 2.
7 */
9 /*
10 * This codes give three functionality.
12 * 1.get firewire node infomation
13 * 2.get notification about starting/stopping stream
14 * 3.lock/unlock stream
17 #include "bebob.h"
19 static long
20 hwdep_read(struct snd_hwdep *hwdep, char __user *buf, long count,
21 loff_t *offset)
23 struct snd_bebob *bebob = hwdep->private_data;
24 DEFINE_WAIT(wait);
25 union snd_firewire_event event;
27 spin_lock_irq(&bebob->lock);
29 while (!bebob->dev_lock_changed) {
30 prepare_to_wait(&bebob->hwdep_wait, &wait, TASK_INTERRUPTIBLE);
31 spin_unlock_irq(&bebob->lock);
32 schedule();
33 finish_wait(&bebob->hwdep_wait, &wait);
34 if (signal_pending(current))
35 return -ERESTARTSYS;
36 spin_lock_irq(&bebob->lock);
39 memset(&event, 0, sizeof(event));
40 if (bebob->dev_lock_changed) {
41 event.lock_status.type = SNDRV_FIREWIRE_EVENT_LOCK_STATUS;
42 event.lock_status.status = (bebob->dev_lock_count > 0);
43 bebob->dev_lock_changed = false;
45 count = min_t(long, count, sizeof(event.lock_status));
48 spin_unlock_irq(&bebob->lock);
50 if (copy_to_user(buf, &event, count))
51 return -EFAULT;
53 return count;
56 static unsigned int
57 hwdep_poll(struct snd_hwdep *hwdep, struct file *file, poll_table *wait)
59 struct snd_bebob *bebob = hwdep->private_data;
60 unsigned int events;
62 poll_wait(file, &bebob->hwdep_wait, wait);
64 spin_lock_irq(&bebob->lock);
65 if (bebob->dev_lock_changed)
66 events = POLLIN | POLLRDNORM;
67 else
68 events = 0;
69 spin_unlock_irq(&bebob->lock);
71 return events;
74 static int
75 hwdep_get_info(struct snd_bebob *bebob, void __user *arg)
77 struct fw_device *dev = fw_parent_device(bebob->unit);
78 struct snd_firewire_get_info info;
80 memset(&info, 0, sizeof(info));
81 info.type = SNDRV_FIREWIRE_TYPE_BEBOB;
82 info.card = dev->card->index;
83 *(__be32 *)&info.guid[0] = cpu_to_be32(dev->config_rom[3]);
84 *(__be32 *)&info.guid[4] = cpu_to_be32(dev->config_rom[4]);
85 strlcpy(info.device_name, dev_name(&dev->device),
86 sizeof(info.device_name));
88 if (copy_to_user(arg, &info, sizeof(info)))
89 return -EFAULT;
91 return 0;
94 static int
95 hwdep_lock(struct snd_bebob *bebob)
97 int err;
99 spin_lock_irq(&bebob->lock);
101 if (bebob->dev_lock_count == 0) {
102 bebob->dev_lock_count = -1;
103 err = 0;
104 } else {
105 err = -EBUSY;
108 spin_unlock_irq(&bebob->lock);
110 return err;
113 static int
114 hwdep_unlock(struct snd_bebob *bebob)
116 int err;
118 spin_lock_irq(&bebob->lock);
120 if (bebob->dev_lock_count == -1) {
121 bebob->dev_lock_count = 0;
122 err = 0;
123 } else {
124 err = -EBADFD;
127 spin_unlock_irq(&bebob->lock);
129 return err;
132 static int
133 hwdep_release(struct snd_hwdep *hwdep, struct file *file)
135 struct snd_bebob *bebob = hwdep->private_data;
137 spin_lock_irq(&bebob->lock);
138 if (bebob->dev_lock_count == -1)
139 bebob->dev_lock_count = 0;
140 spin_unlock_irq(&bebob->lock);
142 return 0;
145 static int
146 hwdep_ioctl(struct snd_hwdep *hwdep, struct file *file,
147 unsigned int cmd, unsigned long arg)
149 struct snd_bebob *bebob = hwdep->private_data;
151 switch (cmd) {
152 case SNDRV_FIREWIRE_IOCTL_GET_INFO:
153 return hwdep_get_info(bebob, (void __user *)arg);
154 case SNDRV_FIREWIRE_IOCTL_LOCK:
155 return hwdep_lock(bebob);
156 case SNDRV_FIREWIRE_IOCTL_UNLOCK:
157 return hwdep_unlock(bebob);
158 default:
159 return -ENOIOCTLCMD;
163 #ifdef CONFIG_COMPAT
164 static int
165 hwdep_compat_ioctl(struct snd_hwdep *hwdep, struct file *file,
166 unsigned int cmd, unsigned long arg)
168 return hwdep_ioctl(hwdep, file, cmd,
169 (unsigned long)compat_ptr(arg));
171 #else
172 #define hwdep_compat_ioctl NULL
173 #endif
175 int snd_bebob_create_hwdep_device(struct snd_bebob *bebob)
177 static const struct snd_hwdep_ops ops = {
178 .read = hwdep_read,
179 .release = hwdep_release,
180 .poll = hwdep_poll,
181 .ioctl = hwdep_ioctl,
182 .ioctl_compat = hwdep_compat_ioctl,
184 struct snd_hwdep *hwdep;
185 int err;
187 err = snd_hwdep_new(bebob->card, "BeBoB", 0, &hwdep);
188 if (err < 0)
189 goto end;
190 strcpy(hwdep->name, "BeBoB");
191 hwdep->iface = SNDRV_HWDEP_IFACE_FW_BEBOB;
192 hwdep->ops = ops;
193 hwdep->private_data = bebob;
194 hwdep->exclusive = true;
195 end:
196 return err;