2019-05-27 06:55:05 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* 32bit -> 64bit ioctl wrapper for timer API
|
|
|
|
* Copyright (c) by Takashi Iwai <tiwai@suse.de>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* This file included from timer.c */
|
|
|
|
|
|
|
|
#include <linux/compat.h>
|
|
|
|
|
2016-03-22 23:03:59 +00:00
|
|
|
/*
|
|
|
|
* ILP32/LP64 has different size for 'long' type. Additionally, the size
|
|
|
|
* of storage alignment differs depending on architectures. Here, '__packed'
|
|
|
|
* qualifier is used so that the size of this structure is multiple of 4 and
|
|
|
|
* it fits to any architectures with 32 bit storage alignment.
|
|
|
|
*/
|
|
|
|
struct snd_timer_gparams32 {
|
|
|
|
struct snd_timer_id tid;
|
|
|
|
u32 period_num;
|
|
|
|
u32 period_den;
|
|
|
|
unsigned char reserved[32];
|
|
|
|
} __packed;
|
|
|
|
|
2005-11-17 12:56:05 +00:00
|
|
|
struct snd_timer_info32 {
|
2005-04-16 22:20:36 +00:00
|
|
|
u32 flags;
|
|
|
|
s32 card;
|
|
|
|
unsigned char id[64];
|
|
|
|
unsigned char name[80];
|
|
|
|
u32 reserved0;
|
|
|
|
u32 resolution;
|
|
|
|
unsigned char reserved[64];
|
|
|
|
};
|
|
|
|
|
2016-03-22 23:03:59 +00:00
|
|
|
static int snd_timer_user_gparams_compat(struct file *file,
|
|
|
|
struct snd_timer_gparams32 __user *user)
|
|
|
|
{
|
|
|
|
struct snd_timer_gparams gparams;
|
|
|
|
|
|
|
|
if (copy_from_user(&gparams.tid, &user->tid, sizeof(gparams.tid)) ||
|
|
|
|
get_user(gparams.period_num, &user->period_num) ||
|
|
|
|
get_user(gparams.period_den, &user->period_den))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
return timer_set_gparams(&gparams);
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
static int snd_timer_user_info_compat(struct file *file,
|
2005-11-17 12:56:05 +00:00
|
|
|
struct snd_timer_info32 __user *_info)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-11-17 12:56:05 +00:00
|
|
|
struct snd_timer_user *tu;
|
|
|
|
struct snd_timer_info32 info;
|
|
|
|
struct snd_timer *t;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
tu = file->private_data;
|
2017-11-21 15:36:11 +00:00
|
|
|
if (!tu->timeri)
|
|
|
|
return -EBADFD;
|
2005-04-16 22:20:36 +00:00
|
|
|
t = tu->timeri->timer;
|
2017-11-21 15:36:11 +00:00
|
|
|
if (!t)
|
|
|
|
return -EBADFD;
|
2005-04-16 22:20:36 +00:00
|
|
|
memset(&info, 0, sizeof(info));
|
|
|
|
info.card = t->card ? t->card->number : -1;
|
|
|
|
if (t->hw.flags & SNDRV_TIMER_HW_SLAVE)
|
|
|
|
info.flags |= SNDRV_TIMER_FLG_SLAVE;
|
|
|
|
strlcpy(info.id, t->id, sizeof(info.id));
|
|
|
|
strlcpy(info.name, t->name, sizeof(info.name));
|
|
|
|
info.resolution = t->hw.resolution;
|
|
|
|
if (copy_to_user(_info, &info, sizeof(*_info)))
|
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 12:56:05 +00:00
|
|
|
struct snd_timer_status32 {
|
2005-04-16 22:20:36 +00:00
|
|
|
struct compat_timespec tstamp;
|
|
|
|
u32 resolution;
|
|
|
|
u32 lost;
|
|
|
|
u32 overrun;
|
|
|
|
u32 queue;
|
|
|
|
unsigned char reserved[64];
|
|
|
|
};
|
|
|
|
|
|
|
|
static int snd_timer_user_status_compat(struct file *file,
|
2005-11-17 12:56:05 +00:00
|
|
|
struct snd_timer_status32 __user *_status)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-11-17 12:56:05 +00:00
|
|
|
struct snd_timer_user *tu;
|
2016-02-28 10:36:14 +00:00
|
|
|
struct snd_timer_status32 status;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
tu = file->private_data;
|
2017-11-21 15:36:11 +00:00
|
|
|
if (!tu->timeri)
|
|
|
|
return -EBADFD;
|
2005-04-16 22:20:36 +00:00
|
|
|
memset(&status, 0, sizeof(status));
|
2016-02-28 10:36:14 +00:00
|
|
|
status.tstamp.tv_sec = tu->tstamp.tv_sec;
|
|
|
|
status.tstamp.tv_nsec = tu->tstamp.tv_nsec;
|
2005-04-16 22:20:36 +00:00
|
|
|
status.resolution = snd_timer_resolution(tu->timeri);
|
|
|
|
status.lost = tu->timeri->lost;
|
|
|
|
status.overrun = tu->overrun;
|
|
|
|
spin_lock_irq(&tu->qlock);
|
|
|
|
status.queue = tu->qused;
|
|
|
|
spin_unlock_irq(&tu->qlock);
|
|
|
|
if (copy_to_user(_status, &status, sizeof(status)))
|
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-02-28 10:41:47 +00:00
|
|
|
#ifdef CONFIG_X86_X32
|
|
|
|
/* X32 ABI has the same struct as x86-64 */
|
|
|
|
#define snd_timer_user_status_x32(file, s) \
|
|
|
|
snd_timer_user_status(file, s)
|
|
|
|
#endif /* CONFIG_X86_X32 */
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
*/
|
|
|
|
|
|
|
|
enum {
|
2016-03-22 23:03:59 +00:00
|
|
|
SNDRV_TIMER_IOCTL_GPARAMS32 = _IOW('T', 0x04, struct snd_timer_gparams32),
|
2005-11-17 12:56:05 +00:00
|
|
|
SNDRV_TIMER_IOCTL_INFO32 = _IOR('T', 0x11, struct snd_timer_info32),
|
|
|
|
SNDRV_TIMER_IOCTL_STATUS32 = _IOW('T', 0x14, struct snd_timer_status32),
|
2016-02-28 10:41:47 +00:00
|
|
|
#ifdef CONFIG_X86_X32
|
|
|
|
SNDRV_TIMER_IOCTL_STATUS_X32 = _IOW('T', 0x14, struct snd_timer_status),
|
|
|
|
#endif /* CONFIG_X86_X32 */
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
2017-10-29 10:02:04 +00:00
|
|
|
static long __snd_timer_user_ioctl_compat(struct file *file, unsigned int cmd,
|
|
|
|
unsigned long arg)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
void __user *argp = compat_ptr(arg);
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case SNDRV_TIMER_IOCTL_PVERSION:
|
|
|
|
case SNDRV_TIMER_IOCTL_TREAD:
|
|
|
|
case SNDRV_TIMER_IOCTL_GINFO:
|
|
|
|
case SNDRV_TIMER_IOCTL_GSTATUS:
|
|
|
|
case SNDRV_TIMER_IOCTL_SELECT:
|
|
|
|
case SNDRV_TIMER_IOCTL_PARAMS:
|
|
|
|
case SNDRV_TIMER_IOCTL_START:
|
2005-05-15 13:43:54 +00:00
|
|
|
case SNDRV_TIMER_IOCTL_START_OLD:
|
2005-04-16 22:20:36 +00:00
|
|
|
case SNDRV_TIMER_IOCTL_STOP:
|
2005-05-15 13:43:54 +00:00
|
|
|
case SNDRV_TIMER_IOCTL_STOP_OLD:
|
2005-04-16 22:20:36 +00:00
|
|
|
case SNDRV_TIMER_IOCTL_CONTINUE:
|
2005-05-15 13:43:54 +00:00
|
|
|
case SNDRV_TIMER_IOCTL_CONTINUE_OLD:
|
2005-05-15 13:04:14 +00:00
|
|
|
case SNDRV_TIMER_IOCTL_PAUSE:
|
2005-05-15 13:43:54 +00:00
|
|
|
case SNDRV_TIMER_IOCTL_PAUSE_OLD:
|
2005-04-16 22:20:36 +00:00
|
|
|
case SNDRV_TIMER_IOCTL_NEXT_DEVICE:
|
2017-10-29 10:02:04 +00:00
|
|
|
return __snd_timer_user_ioctl(file, cmd, (unsigned long)argp);
|
2016-03-22 23:03:59 +00:00
|
|
|
case SNDRV_TIMER_IOCTL_GPARAMS32:
|
|
|
|
return snd_timer_user_gparams_compat(file, argp);
|
2005-04-16 22:20:36 +00:00
|
|
|
case SNDRV_TIMER_IOCTL_INFO32:
|
|
|
|
return snd_timer_user_info_compat(file, argp);
|
|
|
|
case SNDRV_TIMER_IOCTL_STATUS32:
|
|
|
|
return snd_timer_user_status_compat(file, argp);
|
2016-02-28 10:41:47 +00:00
|
|
|
#ifdef CONFIG_X86_X32
|
|
|
|
case SNDRV_TIMER_IOCTL_STATUS_X32:
|
|
|
|
return snd_timer_user_status_x32(file, argp);
|
|
|
|
#endif /* CONFIG_X86_X32 */
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
return -ENOIOCTLCMD;
|
|
|
|
}
|
2017-10-29 10:02:04 +00:00
|
|
|
|
|
|
|
static long snd_timer_user_ioctl_compat(struct file *file, unsigned int cmd,
|
|
|
|
unsigned long arg)
|
|
|
|
{
|
|
|
|
struct snd_timer_user *tu = file->private_data;
|
|
|
|
long ret;
|
|
|
|
|
|
|
|
mutex_lock(&tu->ioctl_lock);
|
|
|
|
ret = __snd_timer_user_ioctl_compat(file, cmd, arg);
|
|
|
|
mutex_unlock(&tu->ioctl_lock);
|
|
|
|
return ret;
|
|
|
|
}
|