Source
214
214
static void MoxaPortFlowCtrl(struct moxa_port *, int, int, int, int, int);
215
215
static int MoxaPortLineStatus(struct moxa_port *);
216
216
static void MoxaPortFlushData(struct moxa_port *, int);
217
217
static int MoxaPortWriteData(struct tty_struct *, const unsigned char *, int);
218
218
static int MoxaPortReadData(struct moxa_port *);
219
219
static int MoxaPortTxQueue(struct moxa_port *);
220
220
static int MoxaPortRxQueue(struct moxa_port *);
221
221
static int MoxaPortTxFree(struct moxa_port *);
222
222
static void MoxaPortTxDisable(struct moxa_port *);
223
223
static void MoxaPortTxEnable(struct moxa_port *);
224
-
static int moxa_get_serial_info(struct moxa_port *, struct serial_struct __user *);
225
-
static int moxa_set_serial_info(struct moxa_port *, struct serial_struct __user *);
224
+
static int moxa_get_serial_info(struct tty_struct *, struct serial_struct *);
225
+
static int moxa_set_serial_info(struct tty_struct *, struct serial_struct *);
226
226
static void MoxaSetFifo(struct moxa_port *port, int enable);
227
227
228
228
/*
229
229
* I/O functions
230
230
*/
231
231
232
232
static DEFINE_SPINLOCK(moxafunc_lock);
233
233
234
234
static void moxa_wait_finish(void __iomem *ofsAddr)
235
235
{
368
368
else
369
369
tmp.cflag = ttyp->termios.c_cflag;
370
370
tty_kref_put(ttyp);
371
371
copy:
372
372
if (copy_to_user(argm, &tmp, sizeof(tmp)))
373
373
return -EFAULT;
374
374
}
375
375
}
376
376
break;
377
377
}
378
-
case TIOCGSERIAL:
379
-
mutex_lock(&ch->port.mutex);
380
-
ret = moxa_get_serial_info(ch, argp);
381
-
mutex_unlock(&ch->port.mutex);
382
-
break;
383
-
case TIOCSSERIAL:
384
-
mutex_lock(&ch->port.mutex);
385
-
ret = moxa_set_serial_info(ch, argp);
386
-
mutex_unlock(&ch->port.mutex);
387
-
break;
388
378
default:
389
379
ret = -ENOIOCTLCMD;
390
380
}
391
381
return ret;
392
382
}
393
383
394
384
static int moxa_break_ctl(struct tty_struct *tty, int state)
395
385
{
396
386
struct moxa_port *port = tty->driver_data;
397
387
408
398
.flush_buffer = moxa_flush_buffer,
409
399
.chars_in_buffer = moxa_chars_in_buffer,
410
400
.ioctl = moxa_ioctl,
411
401
.set_termios = moxa_set_termios,
412
402
.stop = moxa_stop,
413
403
.start = moxa_start,
414
404
.hangup = moxa_hangup,
415
405
.break_ctl = moxa_break_ctl,
416
406
.tiocmget = moxa_tiocmget,
417
407
.tiocmset = moxa_tiocmset,
408
+
.set_serial = moxa_set_serial_info,
409
+
.get_serial = moxa_get_serial_info,
418
410
};
419
411
420
412
static const struct tty_port_operations moxa_port_ops = {
421
413
.carrier_raised = moxa_carrier_raised,
422
414
.dtr_rts = moxa_dtr_rts,
423
415
.shutdown = moxa_shutdown,
424
416
};
425
417
426
418
static struct tty_driver *moxaDriver;
427
419
static DEFINE_TIMER(moxaTimer, moxa_poll);
2027
2019
static void MoxaPortTxDisable(struct moxa_port *port)
2028
2020
{
2029
2021
moxafunc(port->tableAddr, FC_SetXoffState, Magic_code);
2030
2022
}
2031
2023
2032
2024
static void MoxaPortTxEnable(struct moxa_port *port)
2033
2025
{
2034
2026
moxafunc(port->tableAddr, FC_SetXonState, Magic_code);
2035
2027
}
2036
2028
2037
-
static int moxa_get_serial_info(struct moxa_port *info,
2038
-
struct serial_struct __user *retinfo)
2029
+
static int moxa_get_serial_info(struct tty_struct *tty,
2030
+
struct serial_struct *ss)
2039
2031
{
2040
-
struct serial_struct tmp = {
2041
-
.type = info->type,
2042
-
.line = info->port.tty->index,
2043
-
.flags = info->port.flags,
2044
-
.baud_base = 921600,
2045
-
.close_delay = info->port.close_delay
2046
-
};
2047
-
return copy_to_user(retinfo, &tmp, sizeof(*retinfo)) ? -EFAULT : 0;
2032
+
struct moxa_port *info = tty->driver_data;
2033
+
2034
+
if (tty->index == MAX_PORTS)
2035
+
return -EINVAL;
2036
+
if (!info)
2037
+
return -ENODEV;
2038
+
mutex_lock(&info->port.mutex);
2039
+
ss->type = info->type,
2040
+
ss->line = info->port.tty->index,
2041
+
ss->flags = info->port.flags,
2042
+
ss->baud_base = 921600,
2043
+
ss->close_delay = info->port.close_delay;
2044
+
mutex_unlock(&info->port.mutex);
2045
+
return 0;
2048
2046
}
2049
2047
2050
2048
2051
-
static int moxa_set_serial_info(struct moxa_port *info,
2052
-
struct serial_struct __user *new_info)
2049
+
static int moxa_set_serial_info(struct tty_struct *tty,
2050
+
struct serial_struct *ss)
2053
2051
{
2054
-
struct serial_struct new_serial;
2052
+
struct moxa_port *info = tty->driver_data;
2055
2053
2056
-
if (copy_from_user(&new_serial, new_info, sizeof(new_serial)))
2057
-
return -EFAULT;
2054
+
if (tty->index == MAX_PORTS)
2055
+
return -EINVAL;
2056
+
if (!info)
2057
+
return -ENODEV;
2058
2058
2059
-
if (new_serial.irq != 0 || new_serial.port != 0 ||
2060
-
new_serial.custom_divisor != 0 ||
2061
-
new_serial.baud_base != 921600)
2059
+
if (ss->irq != 0 || ss->port != 0 ||
2060
+
ss->custom_divisor != 0 ||
2061
+
ss->baud_base != 921600)
2062
2062
return -EPERM;
2063
2063
2064
+
mutex_lock(&info->port.mutex);
2064
2065
if (!capable(CAP_SYS_ADMIN)) {
2065
-
if (((new_serial.flags & ~ASYNC_USR_MASK) !=
2066
-
(info->port.flags & ~ASYNC_USR_MASK)))
2066
+
if (((ss->flags & ~ASYNC_USR_MASK) !=
2067
+
(info->port.flags & ~ASYNC_USR_MASK))) {
2068
+
mutex_unlock(&info->port.mutex);
2067
2069
return -EPERM;
2068
-
} else
2069
-
info->port.close_delay = new_serial.close_delay * HZ / 100;
2070
-
2071
-
new_serial.flags = (new_serial.flags & ~ASYNC_FLAGS);
2072
-
new_serial.flags |= (info->port.flags & ASYNC_FLAGS);
2070
+
}
2071
+
}
2072
+
info->port.close_delay = ss->close_delay * HZ / 100;
2073
2073
2074
-
MoxaSetFifo(info, new_serial.type == PORT_16550A);
2074
+
MoxaSetFifo(info, ss->type == PORT_16550A);
2075
2075
2076
-
info->type = new_serial.type;
2076
+
info->type = ss->type;
2077
+
mutex_unlock(&info->port.mutex);
2077
2078
return 0;
2078
2079
}
2079
2080
2080
2081
2081
2082
2082
2083
/*****************************************************************************
2083
2084
* Static local functions: *
2084
2085
*****************************************************************************/
2085
2086
2086
2087
static void MoxaSetFifo(struct moxa_port *port, int enable)