]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/isdn/hardware/eicon/divamnt.c
Replace <asm/uaccess.h> with <linux/uaccess.h> globally
[mirror_ubuntu-bionic-kernel.git] / drivers / isdn / hardware / eicon / divamnt.c
CommitLineData
1da177e4
LT
1/* $Id: divamnt.c,v 1.32.6.10 2005/02/11 19:40:25 armin Exp $
2 *
3 * Driver for Eicon DIVA Server ISDN cards.
4 * Maint module
5 *
6 * Copyright 2000-2003 by Armin Schindler (mac@melware.de)
7 * Copyright 2000-2003 Cytronics & Melware (info@melware.de)
8 *
9 * This software may be used and distributed according to the terms
10 * of the GNU General Public License, incorporated herein by reference.
11 */
12
1da177e4
LT
13#include <linux/module.h>
14#include <linux/init.h>
15#include <linux/kernel.h>
1da177e4 16#include <linux/poll.h>
76a64921 17#include <linux/mutex.h>
7c0f6ba6 18#include <linux/uaccess.h>
1da177e4
LT
19
20#include "platform.h"
21#include "di_defs.h"
22#include "divasync.h"
23#include "debug_if.h"
24
76a64921 25static DEFINE_MUTEX(maint_mutex);
1da177e4
LT
26static char *main_revision = "$Revision: 1.32.6.10 $";
27
28static int major;
29
30MODULE_DESCRIPTION("Maint driver for Eicon DIVA Server cards");
31MODULE_AUTHOR("Cytronics & Melware, Eicon Networks");
32MODULE_SUPPORTED_DEVICE("DIVA card driver");
33MODULE_LICENSE("GPL");
34
35static int buffer_length = 128;
36module_param(buffer_length, int, 0);
37static unsigned long diva_dbg_mem = 0;
38module_param(diva_dbg_mem, ulong, 0);
39
40static char *DRIVERNAME =
475be4d8 41 "Eicon DIVA - MAINT module (http://www.melware.net)";
1da177e4
LT
42static char *DRIVERLNAME = "diva_mnt";
43static char *DEVNAME = "DivasMAINT";
44char *DRIVERRELEASE_MNT = "2.0";
45
46static wait_queue_head_t msgwaitq;
47static unsigned long opened;
1da177e4
LT
48
49extern int mntfunc_init(int *, void **, unsigned long);
50extern void mntfunc_finit(void);
51extern int maint_read_write(void __user *buf, int count);
52
53/*
54 * helper functions
55 */
56static char *getrev(const char *revision)
57{
58 char *rev;
59 char *p;
60
61 if ((p = strchr(revision, ':'))) {
62 rev = p + 2;
63 p = strchr(rev, '$');
64 *--p = 0;
65 } else
66 rev = "1.0";
67
68 return rev;
69}
70
71/*
72 * kernel/user space copy functions
73 */
74int diva_os_copy_to_user(void *os_handle, void __user *dst, const void *src,
75 int length)
76{
77 return (copy_to_user(dst, src, length));
78}
79int diva_os_copy_from_user(void *os_handle, void *dst, const void __user *src,
80 int length)
81{
82 return (copy_from_user(dst, src, length));
83}
84
85/*
86 * get time
87 */
475be4d8 88void diva_os_get_time(dword *sec, dword *usec)
1da177e4 89{
096f6262
AS
90 struct timespec64 time;
91
92 ktime_get_ts64(&time);
93
94 *sec = (dword) time.tv_sec;
95 *usec = (dword) (time.tv_nsec / NSEC_PER_USEC);
1da177e4
LT
96}
97
98/*
99 * device node operations
100 */
475be4d8 101static unsigned int maint_poll(struct file *file, poll_table *wait)
1da177e4
LT
102{
103 unsigned int mask = 0;
104
105 poll_wait(file, &msgwaitq, wait);
106 mask = POLLOUT | POLLWRNORM;
107 if (file->private_data || diva_dbg_q_length()) {
108 mask |= POLLIN | POLLRDNORM;
109 }
110 return (mask);
111}
112
113static int maint_open(struct inode *ino, struct file *filep)
114{
3462032d
JC
115 int ret;
116
76a64921 117 mutex_lock(&maint_mutex);
1da177e4
LT
118 /* only one open is allowed, so we test
119 it atomically */
120 if (test_and_set_bit(0, &opened))
3462032d
JC
121 ret = -EBUSY;
122 else {
123 filep->private_data = NULL;
124 ret = nonseekable_open(ino, filep);
125 }
76a64921 126 mutex_unlock(&maint_mutex);
3462032d 127 return ret;
1da177e4
LT
128}
129
130static int maint_close(struct inode *ino, struct file *filep)
131{
132 if (filep->private_data) {
133 diva_os_free(0, filep->private_data);
134 filep->private_data = NULL;
135 }
136
137 /* clear 'used' flag */
138 clear_bit(0, &opened);
475be4d8 139
1da177e4
LT
140 return (0);
141}
142
143static ssize_t divas_maint_write(struct file *file, const char __user *buf,
475be4d8 144 size_t count, loff_t *ppos)
1da177e4
LT
145{
146 return (maint_read_write((char __user *) buf, (int) count));
147}
148
149static ssize_t divas_maint_read(struct file *file, char __user *buf,
475be4d8 150 size_t count, loff_t *ppos)
1da177e4
LT
151{
152 return (maint_read_write(buf, (int) count));
153}
154
2b8693c0 155static const struct file_operations divas_maint_fops = {
1da177e4
LT
156 .owner = THIS_MODULE,
157 .llseek = no_llseek,
158 .read = divas_maint_read,
159 .write = divas_maint_write,
160 .poll = maint_poll,
161 .open = maint_open,
162 .release = maint_close
163};
164
165static void divas_maint_unregister_chrdev(void)
166{
1da177e4
LT
167 unregister_chrdev(major, DEVNAME);
168}
169
d7398892 170static int __init divas_maint_register_chrdev(void)
1da177e4
LT
171{
172 if ((major = register_chrdev(0, DEVNAME, &divas_maint_fops)) < 0)
173 {
174 printk(KERN_ERR "%s: failed to create /dev entry.\n",
175 DRIVERLNAME);
176 return (0);
177 }
1da177e4
LT
178
179 return (1);
180}
181
182/*
183 * wake up reader
184 */
185void diva_maint_wakeup_read(void)
186{
187 wake_up_interruptible(&msgwaitq);
188}
189
190/*
191 * Driver Load
192 */
d7398892 193static int __init maint_init(void)
1da177e4
LT
194{
195 char tmprev[50];
196 int ret = 0;
197 void *buffer = NULL;
198
1da177e4
LT
199 init_waitqueue_head(&msgwaitq);
200
201 printk(KERN_INFO "%s\n", DRIVERNAME);
202 printk(KERN_INFO "%s: Rel:%s Rev:", DRIVERLNAME, DRIVERRELEASE_MNT);
203 strcpy(tmprev, main_revision);
204 printk("%s Build: %s \n", getrev(tmprev), DIVA_BUILD);
205
206 if (!divas_maint_register_chrdev()) {
207 ret = -EIO;
208 goto out;
209 }
210
211 if (!(mntfunc_init(&buffer_length, &buffer, diva_dbg_mem))) {
212 printk(KERN_ERR "%s: failed to connect to DIDD.\n",
213 DRIVERLNAME);
214 divas_maint_unregister_chrdev();
215 ret = -EIO;
216 goto out;
217 }
218
219 printk(KERN_INFO "%s: trace buffer = %p - %d kBytes, %s (Major: %d)\n",
220 DRIVERLNAME, buffer, (buffer_length / 1024),
221 (diva_dbg_mem == 0) ? "internal" : "external", major);
222
475be4d8 223out:
1da177e4
LT
224 return (ret);
225}
226
227/*
228** Driver Unload
229*/
d7398892 230static void __exit maint_exit(void)
1da177e4
LT
231{
232 divas_maint_unregister_chrdev();
233 mntfunc_finit();
234
235 printk(KERN_INFO "%s: module unloaded.\n", DRIVERLNAME);
236}
237
238module_init(maint_init);
239module_exit(maint_exit);