blob: e05802ae6e1b1e240a187a43c9f5308fcf7145c0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * 32bit -> 64bit ioctl wrapper for timer API
3 * Copyright (c) by Takashi Iwai <tiwai@suse.de>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 */
20
21/* This file included from timer.c */
22
23#include <linux/compat.h>
24
Takashi Iwai53d2f742005-11-17 13:56:05 +010025struct snd_timer_info32 {
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 u32 flags;
27 s32 card;
28 unsigned char id[64];
29 unsigned char name[80];
30 u32 reserved0;
31 u32 resolution;
32 unsigned char reserved[64];
33};
34
35static int snd_timer_user_info_compat(struct file *file,
Takashi Iwai53d2f742005-11-17 13:56:05 +010036 struct snd_timer_info32 __user *_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -070037{
Takashi Iwai53d2f742005-11-17 13:56:05 +010038 struct snd_timer_user *tu;
39 struct snd_timer_info32 info;
40 struct snd_timer *t;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42 tu = file->private_data;
Takashi Iwai7eaa9432008-08-08 17:09:09 +020043 if (snd_BUG_ON(!tu->timeri))
44 return -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 t = tu->timeri->timer;
Takashi Iwai7eaa9432008-08-08 17:09:09 +020046 if (snd_BUG_ON(!t))
47 return -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 memset(&info, 0, sizeof(info));
49 info.card = t->card ? t->card->number : -1;
50 if (t->hw.flags & SNDRV_TIMER_HW_SLAVE)
51 info.flags |= SNDRV_TIMER_FLG_SLAVE;
52 strlcpy(info.id, t->id, sizeof(info.id));
53 strlcpy(info.name, t->name, sizeof(info.name));
54 info.resolution = t->hw.resolution;
55 if (copy_to_user(_info, &info, sizeof(*_info)))
56 return -EFAULT;
57 return 0;
58}
59
Takashi Iwai53d2f742005-11-17 13:56:05 +010060struct snd_timer_status32 {
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 struct compat_timespec tstamp;
62 u32 resolution;
63 u32 lost;
64 u32 overrun;
65 u32 queue;
66 unsigned char reserved[64];
67};
68
69static int snd_timer_user_status_compat(struct file *file,
Takashi Iwai53d2f742005-11-17 13:56:05 +010070 struct snd_timer_status32 __user *_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071{
Takashi Iwai53d2f742005-11-17 13:56:05 +010072 struct snd_timer_user *tu;
73 struct snd_timer_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
75 tu = file->private_data;
Takashi Iwai7eaa9432008-08-08 17:09:09 +020076 if (snd_BUG_ON(!tu->timeri))
77 return -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 memset(&status, 0, sizeof(status));
79 status.tstamp = tu->tstamp;
80 status.resolution = snd_timer_resolution(tu->timeri);
81 status.lost = tu->timeri->lost;
82 status.overrun = tu->overrun;
83 spin_lock_irq(&tu->qlock);
84 status.queue = tu->qused;
85 spin_unlock_irq(&tu->qlock);
86 if (copy_to_user(_status, &status, sizeof(status)))
87 return -EFAULT;
88 return 0;
89}
90
91/*
92 */
93
94enum {
Takashi Iwai53d2f742005-11-17 13:56:05 +010095 SNDRV_TIMER_IOCTL_INFO32 = _IOR('T', 0x11, struct snd_timer_info32),
96 SNDRV_TIMER_IOCTL_STATUS32 = _IOW('T', 0x14, struct snd_timer_status32),
Linus Torvalds1da177e2005-04-16 15:20:36 -070097};
98
99static long snd_timer_user_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg)
100{
101 void __user *argp = compat_ptr(arg);
102
103 switch (cmd) {
104 case SNDRV_TIMER_IOCTL_PVERSION:
105 case SNDRV_TIMER_IOCTL_TREAD:
106 case SNDRV_TIMER_IOCTL_GINFO:
107 case SNDRV_TIMER_IOCTL_GPARAMS:
108 case SNDRV_TIMER_IOCTL_GSTATUS:
109 case SNDRV_TIMER_IOCTL_SELECT:
110 case SNDRV_TIMER_IOCTL_PARAMS:
111 case SNDRV_TIMER_IOCTL_START:
Takashi Iwai8c50b372005-05-15 15:43:54 +0200112 case SNDRV_TIMER_IOCTL_START_OLD:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 case SNDRV_TIMER_IOCTL_STOP:
Takashi Iwai8c50b372005-05-15 15:43:54 +0200114 case SNDRV_TIMER_IOCTL_STOP_OLD:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 case SNDRV_TIMER_IOCTL_CONTINUE:
Takashi Iwai8c50b372005-05-15 15:43:54 +0200116 case SNDRV_TIMER_IOCTL_CONTINUE_OLD:
Takashi Iwai15790a62005-05-15 15:04:14 +0200117 case SNDRV_TIMER_IOCTL_PAUSE:
Takashi Iwai8c50b372005-05-15 15:43:54 +0200118 case SNDRV_TIMER_IOCTL_PAUSE_OLD:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 case SNDRV_TIMER_IOCTL_NEXT_DEVICE:
120 return snd_timer_user_ioctl(file, cmd, (unsigned long)argp);
121 case SNDRV_TIMER_IOCTL_INFO32:
122 return snd_timer_user_info_compat(file, argp);
123 case SNDRV_TIMER_IOCTL_STATUS32:
124 return snd_timer_user_status_compat(file, argp);
125 }
126 return -ENOIOCTLCMD;
127}