1 #include <linux/cdev.h>
3 #include <linux/list.h>
4 #include <linux/kernel.h>
5 #include <linux/module.h>
6 #include <linux/slab.h>
8 #include <linux/tapi/tapi.h>
9 #include <linux/tapi/tapi-ioctl.h>
11 static inline struct tapi_port *tapi_char_device_to_port(struct tapi_char_device *chrdev)
13 return container_of(chrdev, struct tapi_port, chrdev);
16 static int tapi_port_open(struct inode *inode, struct file *file)
18 struct tapi_device *tdev = cdev_to_tapi_char_device(inode->i_cdev)->tdev;
20 get_device(&tdev->dev);
21 file->private_data = cdev_to_tapi_char_device(inode->i_cdev);
26 static int tapi_port_release(struct inode *inode, struct file *file)
28 struct tapi_device *tdev = cdev_to_tapi_char_device(inode->i_cdev)->tdev;
30 put_device(&tdev->dev);
35 static long tapi_port_ioctl_get_endpoint(struct tapi_device *tdev,
36 struct tapi_port *port, unsigned long arg)
41 static long tapi_port_ioctl_set_ring(struct tapi_device *tdev,
42 struct tapi_port *port, unsigned long arg)
44 tapi_port_set_ring(tdev, port, arg);
48 static long tapi_port_ioctl(struct file *file, unsigned int cmd,
52 struct tapi_char_device *tchrdev = file->private_data;
53 struct tapi_device *tdev = tchrdev->tdev;
54 struct tapi_port *port = tapi_char_device_to_port(tchrdev);
57 case TAPI_PORT_IOCTL_GET_ENDPOINT:
58 ret = tapi_port_ioctl_get_endpoint(tdev, port, arg);
60 case TAPI_PORT_IOCTL_SET_RING:
61 ret = tapi_port_ioctl_set_ring(tdev, port, arg);
71 static const struct file_operations tapi_port_file_ops = {
73 .open = tapi_port_open,
74 .release = tapi_port_release,
75 .unlocked_ioctl = tapi_port_ioctl,
78 int tapi_register_port_device(struct tapi_device* tdev, struct tapi_port *port)
80 dev_set_name(&port->chrdev.dev, "tapi%uP%u", tdev->id, port->id);
81 return tapi_char_device_register(tdev, &port->chrdev, &tapi_port_file_ops);