Commit 7e4e8e68 authored by Jiri Slaby's avatar Jiri Slaby Committed by Linus Torvalds

Misc: phantom, add compat ioctl

Openhaptics uses pointers in _IOC() macros, implement compat for them. Also
add _IOC alternatives which are not 32/64 bit dependent (structures
passed through aren't yet) -- libphantom will use them.

[akpm@linux-foundation.org: coding-style fixes]
Signed-off-by: default avatarJiri Slaby <jirislaby@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent eb0f1c44
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
* or alternatively, you might use OpenHaptics provided by Sensable. * or alternatively, you might use OpenHaptics provided by Sensable.
*/ */
#include <linux/compat.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/device.h> #include <linux/device.h>
...@@ -91,11 +92,8 @@ static long phantom_ioctl(struct file *file, unsigned int cmd, ...@@ -91,11 +92,8 @@ static long phantom_ioctl(struct file *file, unsigned int cmd,
unsigned long flags; unsigned long flags;
unsigned int i; unsigned int i;
if (_IOC_TYPE(cmd) != PH_IOC_MAGIC ||
_IOC_NR(cmd) > PH_IOC_MAXNR)
return -ENOTTY;
switch (cmd) { switch (cmd) {
case PHN_SETREG:
case PHN_SET_REG: case PHN_SET_REG:
if (copy_from_user(&r, argp, sizeof(r))) if (copy_from_user(&r, argp, sizeof(r)))
return -EFAULT; return -EFAULT;
...@@ -126,6 +124,7 @@ static long phantom_ioctl(struct file *file, unsigned int cmd, ...@@ -126,6 +124,7 @@ static long phantom_ioctl(struct file *file, unsigned int cmd,
phantom_status(dev, dev->status & ~PHB_RUNNING); phantom_status(dev, dev->status & ~PHB_RUNNING);
spin_unlock_irqrestore(&dev->regs_lock, flags); spin_unlock_irqrestore(&dev->regs_lock, flags);
break; break;
case PHN_SETREGS:
case PHN_SET_REGS: case PHN_SET_REGS:
if (copy_from_user(&rs, argp, sizeof(rs))) if (copy_from_user(&rs, argp, sizeof(rs)))
return -EFAULT; return -EFAULT;
...@@ -143,6 +142,7 @@ static long phantom_ioctl(struct file *file, unsigned int cmd, ...@@ -143,6 +142,7 @@ static long phantom_ioctl(struct file *file, unsigned int cmd,
} }
spin_unlock_irqrestore(&dev->regs_lock, flags); spin_unlock_irqrestore(&dev->regs_lock, flags);
break; break;
case PHN_GETREG:
case PHN_GET_REG: case PHN_GET_REG:
if (copy_from_user(&r, argp, sizeof(r))) if (copy_from_user(&r, argp, sizeof(r)))
return -EFAULT; return -EFAULT;
...@@ -155,6 +155,7 @@ static long phantom_ioctl(struct file *file, unsigned int cmd, ...@@ -155,6 +155,7 @@ static long phantom_ioctl(struct file *file, unsigned int cmd,
if (copy_to_user(argp, &r, sizeof(r))) if (copy_to_user(argp, &r, sizeof(r)))
return -EFAULT; return -EFAULT;
break; break;
case PHN_GETREGS:
case PHN_GET_REGS: { case PHN_GET_REGS: {
u32 m; u32 m;
...@@ -191,6 +192,20 @@ static long phantom_ioctl(struct file *file, unsigned int cmd, ...@@ -191,6 +192,20 @@ static long phantom_ioctl(struct file *file, unsigned int cmd,
return 0; return 0;
} }
#ifdef CONFIG_COMPAT
static long phantom_compat_ioctl(struct file *filp, unsigned int cmd,
unsigned long arg)
{
if (_IOC_NR(cmd) <= 3 && _IOC_SIZE(cmd) == sizeof(compat_uptr_t)) {
cmd &= ~(_IOC_SIZEMASK << _IOC_SIZESHIFT);
cmd |= sizeof(void *) << _IOC_SIZESHIFT;
}
return phantom_ioctl(filp, cmd, (unsigned long)compat_ptr(arg));
}
#else
#define phantom_compat_ioctl NULL
#endif
static int phantom_open(struct inode *inode, struct file *file) static int phantom_open(struct inode *inode, struct file *file)
{ {
struct phantom_device *dev = container_of(inode->i_cdev, struct phantom_device *dev = container_of(inode->i_cdev,
...@@ -253,6 +268,7 @@ static struct file_operations phantom_file_ops = { ...@@ -253,6 +268,7 @@ static struct file_operations phantom_file_ops = {
.open = phantom_open, .open = phantom_open,
.release = phantom_release, .release = phantom_release,
.unlocked_ioctl = phantom_ioctl, .unlocked_ioctl = phantom_ioctl,
.compat_ioctl = phantom_compat_ioctl,
.poll = phantom_poll, .poll = phantom_poll,
}; };
......
...@@ -34,7 +34,10 @@ struct phm_regs { ...@@ -34,7 +34,10 @@ struct phm_regs {
* use improved registers update (no more phantom switchoffs when using * use improved registers update (no more phantom switchoffs when using
* libphantom) */ * libphantom) */
#define PHN_NOT_OH _IO (PH_IOC_MAGIC, 4) #define PHN_NOT_OH _IO (PH_IOC_MAGIC, 4)
#define PH_IOC_MAXNR 4 #define PHN_GETREG _IOWR(PH_IOC_MAGIC, 5, struct phm_reg)
#define PHN_SETREG _IOW(PH_IOC_MAGIC, 6, struct phm_reg)
#define PHN_GETREGS _IOWR(PH_IOC_MAGIC, 7, struct phm_regs)
#define PHN_SETREGS _IOW(PH_IOC_MAGIC, 8, struct phm_regs)
#define PHN_CONTROL 0x6 /* control byte in iaddr space */ #define PHN_CONTROL 0x6 /* control byte in iaddr space */
#define PHN_CTL_AMP 0x1 /* switch after torques change */ #define PHN_CTL_AMP 0x1 /* switch after torques change */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment