Skip to content

Commit

Permalink
drivers/tty: port from N9 OSRC
Browse files Browse the repository at this point in the history
  • Loading branch information
duhansysl committed Sep 26, 2024
1 parent 5fae0e2 commit 5470218
Show file tree
Hide file tree
Showing 45 changed files with 292 additions and 809 deletions.
23 changes: 0 additions & 23 deletions drivers/tty/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -455,27 +455,4 @@ config MIPS_EJTAG_FDC_KGDB_CHAN
help
FDC channel number to use for KGDB.

config LDISC_AUTOLOAD
bool "Automatically load TTY Line Disciplines"
default y
help
Historically the kernel has always automatically loaded any
line discipline that is in a kernel module when a user asks
for it to be loaded with the TIOCSETD ioctl, or through other
means. This is not always the best thing to do on systems
where you know you will not be using some of the more
"ancient" line disciplines, so prevent the kernel from doing
this unless the request is coming from a process with the
CAP_SYS_MODULE permissions.

Say 'Y' here if you trust your userspace users to do the right
thing, or if you have only provided the line disciplines that
you know you will be using, or if you wish to continue to use
the traditional method of on-demand loading of these modules
by any user.

This functionality can be changed at runtime with the
dev.tty.ldisc_autoload sysctl, this configuration option will
only set the default value of this functionality.

endif # TTY
8 changes: 0 additions & 8 deletions drivers/tty/ipwireless/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,6 @@ static int ipwireless_probe(struct pcmcia_device *p_dev, void *priv_data)

ipw->common_memory = ioremap(p_dev->resource[2]->start,
resource_size(p_dev->resource[2]));
if (!ipw->common_memory) {
ret = -ENOMEM;
goto exit1;
}
if (!request_mem_region(p_dev->resource[2]->start,
resource_size(p_dev->resource[2]),
IPWIRELESS_PCCARD_NAME)) {
Expand All @@ -137,10 +133,6 @@ static int ipwireless_probe(struct pcmcia_device *p_dev, void *priv_data)

ipw->attr_memory = ioremap(p_dev->resource[3]->start,
resource_size(p_dev->resource[3]));
if (!ipw->attr_memory) {
ret = -ENOMEM;
goto exit3;
}
if (!request_mem_region(p_dev->resource[3]->start,
resource_size(p_dev->resource[3]),
IPWIRELESS_PCCARD_NAME)) {
Expand Down
1 change: 0 additions & 1 deletion drivers/tty/n_hdlc.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,6 @@ static ssize_t n_hdlc_tty_read(struct tty_struct *tty, struct file *file,
/* too large for caller's buffer */
ret = -EOVERFLOW;
} else {
__set_current_state(TASK_RUNNING);
if (copy_to_user(buf, rbuf->buf, rbuf->count))
ret = -EFAULT;
else
Expand Down
33 changes: 7 additions & 26 deletions drivers/tty/n_tty.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
* unthrottling the TTY driver. These watermarks are used for
* controlling the space in the read buffer.
*/
#define TTY_THRESHOLD_THROTTLE 512 /* now based on remaining room */
#define TTY_THRESHOLD_UNTHROTTLE 512
#define TTY_THRESHOLD_THROTTLE 128 /* now based on remaining room */
#define TTY_THRESHOLD_UNTHROTTLE 128

/*
* Special byte codes used in the echo buffer to represent operations
Expand All @@ -87,8 +87,6 @@
# define n_tty_trace(f, args...)
#endif

#define BLUETOOTH_UART_PORT_LINE 1

struct n_tty_data {
/* producer-published */
size_t read_head;
Expand Down Expand Up @@ -156,28 +154,17 @@ static inline unsigned char *echo_buf_addr(struct n_tty_data *ldata, size_t i)
return &ldata->echo_buf[i & (N_TTY_BUF_SIZE - 1)];
}

/* If we are not echoing the data, perhaps this is a secret so erase it */
static void zero_buffer(struct tty_struct *tty, u8 *buffer, int size)
{
bool icanon = !!L_ICANON(tty);
bool no_echo = !L_ECHO(tty);

if (icanon && no_echo)
memset(buffer, 0x00, size);
}

static int tty_copy_to_user(struct tty_struct *tty, void __user *to,
size_t tail, size_t n)
{
struct n_tty_data *ldata = tty->disc_data;
size_t size = N_TTY_BUF_SIZE - tail;
void *from = read_buf_addr(ldata, tail);
const void *from = read_buf_addr(ldata, tail);
int uncopied;

if (n > size) {
tty_audit_add_data(tty, from, size);
uncopied = copy_to_user(to, from, size);
zero_buffer(tty, from, size - uncopied);
if (uncopied)
return uncopied;
to += size;
Expand All @@ -186,9 +173,7 @@ static int tty_copy_to_user(struct tty_struct *tty, void __user *to,
}

tty_audit_add_data(tty, from, n);
uncopied = copy_to_user(to, from, n);
zero_buffer(tty, from, n - uncopied);
return uncopied;
return copy_to_user(to, from, n);
}

/**
Expand Down Expand Up @@ -1977,12 +1962,11 @@ static int copy_from_read_buf(struct tty_struct *tty,
n = min(head - ldata->read_tail, N_TTY_BUF_SIZE - tail);
n = min(*nr, n);
if (n) {
unsigned char *from = read_buf_addr(ldata, tail);
const unsigned char *from = read_buf_addr(ldata, tail);
retval = copy_to_user(*b, from, n);
n -= retval;
is_eof = n == 1 && *from == EOF_CHAR(tty);
tty_audit_add_data(tty, from, n);
zero_buffer(tty, from, n);
smp_store_release(&ldata->read_tail, ldata->read_tail + n);
/* Turn single EOF into zero-length read */
if (L_EXTPROC(tty) && ldata->icanon && is_eof &&
Expand Down Expand Up @@ -2323,11 +2307,8 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,
add_wait_queue(&tty->write_wait, &wait);
while (1) {
if (signal_pending(current)) {
pr_err("%s TTY-%d signal_pending\n", __func__, tty->index);
if (tty->index != BLUETOOTH_UART_PORT_LINE) {
retval = -ERESTARTSYS;
break;
}
retval = -ERESTARTSYS;
break;
}
if (tty_hung_up_p(file) || (tty->link && !tty->link->count)) {
retval = -EIO;
Expand Down
4 changes: 2 additions & 2 deletions drivers/tty/rocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ MODULE_PARM_DESC(pc104_3, "set interface types for ISA(PC104) board #3 (e.g. pc1
module_param_array(pc104_4, ulong, NULL, 0);
MODULE_PARM_DESC(pc104_4, "set interface types for ISA(PC104) board #4 (e.g. pc104_4=232,232,485,485,...");

static int __init rp_init(void);
static int rp_init(void);
static void rp_cleanup_module(void);

module_init(rp_init);
Expand Down Expand Up @@ -1913,7 +1913,7 @@ static __init int register_PCI(int i, struct pci_dev *dev)
ByteIO_t UPCIRingInd = 0;

if (!dev || !pci_match_id(rocket_pci_ids, dev) ||
pci_enable_device(dev) || i >= NUM_BOARDS)
pci_enable_device(dev))
return 0;

rcktpt_io_addr[i] = pci_resource_start(dev, 0);
Expand Down
7 changes: 3 additions & 4 deletions drivers/tty/serial/8250/8250_dw.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ static void dw8250_set_termios(struct uart_port *p, struct ktermios *termios,
unsigned int rate;
int ret;

if (IS_ERR(d->clk))
if (IS_ERR(d->clk) || !old)
goto out;

clk_disable_unprepare(d->clk);
Expand Down Expand Up @@ -269,7 +269,7 @@ static bool dw8250_fallback_dma_filter(struct dma_chan *chan, void *param)

static bool dw8250_idma_filter(struct dma_chan *chan, void *param)
{
return param == chan->device->dev;
return param == chan->device->dev->parent;
}

static void dw8250_quirks(struct uart_port *p, struct dw8250_data *data)
Expand Down Expand Up @@ -311,7 +311,7 @@ static void dw8250_quirks(struct uart_port *p, struct dw8250_data *data)
p->set_termios = dw8250_set_termios;
}

/* Platforms with iDMA 64-bit */
/* Platforms with iDMA */
if (platform_get_resource_byname(to_platform_device(p->dev),
IORESOURCE_MEM, "lpss_priv")) {
p->set_termios = dw8250_set_termios;
Expand Down Expand Up @@ -626,7 +626,6 @@ static const struct acpi_device_id dw8250_acpi_match[] = {
{ "APMC0D08", 0},
{ "AMD0020", 0 },
{ "AMDI0020", 0 },
{ "BRCM2032", 0 },
{ "HISI0031", 0 },
{ },
};
Expand Down
16 changes: 9 additions & 7 deletions drivers/tty/serial/8250/8250_mtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,17 +225,17 @@ static int mtk8250_probe(struct platform_device *pdev)

platform_set_drvdata(pdev, data);

err = mtk8250_runtime_resume(&pdev->dev);
if (err)
return err;
pm_runtime_enable(&pdev->dev);
if (!pm_runtime_enabled(&pdev->dev)) {
err = mtk8250_runtime_resume(&pdev->dev);
if (err)
return err;
}

data->line = serial8250_register_8250_port(&uart);
if (data->line < 0)
return data->line;

pm_runtime_set_active(&pdev->dev);
pm_runtime_enable(&pdev->dev);

return 0;
}

Expand All @@ -246,11 +246,13 @@ static int mtk8250_remove(struct platform_device *pdev)
pm_runtime_get_sync(&pdev->dev);

serial8250_unregister_port(data->line);
mtk8250_runtime_suspend(&pdev->dev);

pm_runtime_disable(&pdev->dev);
pm_runtime_put_noidle(&pdev->dev);

if (!pm_runtime_status_suspended(&pdev->dev))
mtk8250_runtime_suspend(&pdev->dev);

return 0;
}

Expand Down
4 changes: 0 additions & 4 deletions drivers/tty/serial/8250/8250_of.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ static int of_platform_serial_setup(struct platform_device *ofdev,
if (of_property_read_u32(np, "reg-offset", &prop) == 0)
port->mapbase += prop;

/* Compatibility with the deprecated pxa driver and 8250_pxa drivers. */
if (of_device_is_compatible(np, "mrvl,mmp-uart"))
port->regshift = 2;

/* Check for registers offset within the devices address range */
if (of_property_read_u32(np, "reg-shift", &prop) == 0)
port->regshift = prop;
Expand Down
Loading

0 comments on commit 5470218

Please sign in to comment.