Skip to content

Commit

Permalink
Merge tag 'tty-4.20-rc1' of git://git.kernel.org/pub/scm/linux/kernel…
Browse files Browse the repository at this point in the history
…/git/gregkh/tty

Pull tty/serial updates from Greg KH:
 "Here is the big tty and serial pull request for 4.20-rc1

  Lots of little things here, including a merge from the SPI tree in
  order to keep things simpler for everyone to sync around for one
  platform.

  Major stuff is:

   - tty buffer clearing after use

   - atmel_serial fixes and additions

   - xilinx uart driver updates

  and of course, lots of tiny fixes and additions to individual serial
  drivers.

  All of these have been in linux-next with no reported issues for a
  while"

* tag 'tty-4.20-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty: (66 commits)
  of: base: Change logic in of_alias_get_alias_list()
  of: base: Fix english spelling in of_alias_get_alias_list()
  serial: sh-sci: do not warn if DMA transfers are not supported
  serial: uartps: Do not allow use aliases >= MAX_UART_INSTANCES
  tty: check name length in tty_find_polling_driver()
  serial: sh-sci: Add r8a77990 support
  tty: wipe buffer if not echoing data
  tty: wipe buffer.
  serial: fsl_lpuart: Remove the alias node dependence
  TTY: sn_console: Replace spin_is_locked() with spin_trylock()
  Revert "serial:serial_core: Allow use of CTS for PPS line discipline"
  serial: 8250_uniphier: add auto-flow-control support
  serial: 8250_uniphier: flatten probe function
  serial: 8250_uniphier: remove unused "fifo-size" property
  dt-bindings: serial: sh-sci: Document r8a7744 bindings
  serial: uartps: Fix missing unlock on error in cdns_get_id()
  tty/serial: atmel: add ISO7816 support
  tty/serial_core: add ISO7816 infrastructure
  serial:serial_core: Allow use of CTS for PPS line discipline
  serial: docs: Fix filename for serial reference implementation
  ...
  • Loading branch information
torvalds committed Oct 29, 2018
2 parents 738b04f + 59eaeba commit 5bd4af3
Show file tree
Hide file tree
Showing 43 changed files with 977 additions and 380 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ Required properties:
- "renesas,scifa-r8a7743" for R8A7743 (RZ/G1M) SCIFA compatible UART.
- "renesas,scifb-r8a7743" for R8A7743 (RZ/G1M) SCIFB compatible UART.
- "renesas,hscif-r8a7743" for R8A7743 (RZ/G1M) HSCIF compatible UART.
- "renesas,scif-r8a7744" for R8A7744 (RZ/G1N) SCIF compatible UART.
- "renesas,scifa-r8a7744" for R8A7744 (RZ/G1N) SCIFA compatible UART.
- "renesas,scifb-r8a7744" for R8A7744 (RZ/G1N) SCIFB compatible UART.
- "renesas,hscif-r8a7744" for R8A7744 (RZ/G1N) HSCIF compatible UART.
- "renesas,scif-r8a7745" for R8A7745 (RZ/G1E) SCIF compatible UART.
- "renesas,scifa-r8a7745" for R8A7745 (RZ/G1E) SCIFA compatible UART.
- "renesas,scifb-r8a7745" for R8A7745 (RZ/G1E) SCIFB compatible UART.
Expand Down Expand Up @@ -50,6 +54,8 @@ Required properties:
- "renesas,hscif-r8a77970" for R8A77970 (R-Car V3M) HSCIF compatible UART.
- "renesas,scif-r8a77980" for R8A77980 (R-Car V3H) SCIF compatible UART.
- "renesas,hscif-r8a77980" for R8A77980 (R-Car V3H) HSCIF compatible UART.
- "renesas,scif-r8a77990" for R8A77990 (R-Car E3) SCIF compatible UART.
- "renesas,hscif-r8a77990" for R8A77990 (R-Car E3) HSCIF compatible UART.
- "renesas,scif-r8a77995" for R8A77995 (R-Car D3) SCIF compatible UART.
- "renesas,hscif-r8a77995" for R8A77995 (R-Car D3) HSCIF compatible UART.
- "renesas,scifa-sh73a0" for SH73A0 (SH-Mobile AG5) SCIFA compatible UART.
Expand Down
3 changes: 1 addition & 2 deletions Documentation/devicetree/bindings/serial/uniphier-uart.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Required properties:
- clocks: phandle to the input clock.

Optional properties:
- fifo-size: the RX/TX FIFO size. Defaults to 64 if not specified.
-auto-flow-control: enable automatic flow control support.

Example:
aliases {
Expand All @@ -19,5 +19,4 @@ Example:
reg = <0x54006800 0x40>;
interrupts = <0 33 4>;
clocks = <&uart_clk>;
fifo-size = <64>;
};
2 changes: 1 addition & 1 deletion Documentation/serial/driver
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This document is meant as a brief overview of some aspects of the new serial
driver. It is not complete, any questions you have should be directed to
<[email protected]>

The reference implementation is contained within amba_pl011.c.
The reference implementation is contained within amba-pl011.c.



Expand Down
83 changes: 83 additions & 0 deletions Documentation/serial/serial-iso7816.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
ISO7816 SERIAL COMMUNICATIONS

1. INTRODUCTION

ISO/IEC7816 is a series of standards specifying integrated circuit cards (ICC)
also known as smart cards.

2. HARDWARE-RELATED CONSIDERATIONS

Some CPUs/UARTs (e.g., Microchip AT91) contain a built-in mode capable of
handling communication with a smart card.

For these microcontrollers, the Linux driver should be made capable of
working in both modes, and proper ioctls (see later) should be made
available at user-level to allow switching from one mode to the other, and
vice versa.

3. DATA STRUCTURES ALREADY AVAILABLE IN THE KERNEL

The Linux kernel provides the serial_iso7816 structure (see [1]) to handle
ISO7816 communications. This data structure is used to set and configure
ISO7816 parameters in ioctls.

Any driver for devices capable of working both as RS232 and ISO7816 should
implement the iso7816_config callback in the uart_port structure. The
serial_core calls iso7816_config to do the device specific part in response
to TIOCGISO7816 and TIOCSISO7816 ioctls (see below). The iso7816_config
callback receives a pointer to struct serial_iso7816.

4. USAGE FROM USER-LEVEL

From user-level, ISO7816 configuration can be get/set using the previous
ioctls. For instance, to set ISO7816 you can use the following code:

#include <linux/serial.h>

/* Include definition for ISO7816 ioctls: TIOCSISO7816 and TIOCGISO7816 */
#include <sys/ioctl.h>

/* Open your specific device (e.g., /dev/mydevice): */
int fd = open ("/dev/mydevice", O_RDWR);
if (fd < 0) {
/* Error handling. See errno. */
}

struct serial_iso7816 iso7816conf;

/* Reserved fields as to be zeroed */
memset(&iso7816conf, 0, sizeof(iso7816conf));

/* Enable ISO7816 mode: */
iso7816conf.flags |= SER_ISO7816_ENABLED;

/* Select the protocol: */
/* T=0 */
iso7816conf.flags |= SER_ISO7816_T(0);
/* or T=1 */
iso7816conf.flags |= SER_ISO7816_T(1);

/* Set the guard time: */
iso7816conf.tg = 2;

/* Set the clock frequency*/
iso7816conf.clk = 3571200;

/* Set transmission factors: */
iso7816conf.sc_fi = 372;
iso7816conf.sc_di = 1;

if (ioctl(fd_usart, TIOCSISO7816, &iso7816conf) < 0) {
/* Error handling. See errno. */
}

/* Use read() and write() syscalls here... */

/* Close the device when finished: */
if (close (fd) < 0) {
/* Error handling. See errno. */
}

5. REFERENCES

[1] include/uapi/linux/serial.h
2 changes: 2 additions & 0 deletions arch/alpha/include/uapi/asm/ioctls.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@
#define TIOCGPTLCK _IOR('T', 0x39, int) /* Get Pty lock state */
#define TIOCGEXCL _IOR('T', 0x40, int) /* Get exclusive mode state */
#define TIOCGPTPEER _IO('T', 0x41) /* Safely open the slave */
#define TIOCGISO7816 _IOR('T', 0x42, struct serial_iso7816)
#define TIOCSISO7816 _IOWR('T', 0x43, struct serial_iso7816)

#define TIOCSERCONFIG 0x5453
#define TIOCSERGWILD 0x5454
Expand Down
2 changes: 2 additions & 0 deletions arch/mips/include/uapi/asm/ioctls.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@
#define TIOCGPTLCK _IOR('T', 0x39, int) /* Get Pty lock state */
#define TIOCGEXCL _IOR('T', 0x40, int) /* Get exclusive mode state */
#define TIOCGPTPEER _IO('T', 0x41) /* Safely open the slave */
#define TIOCGISO7816 _IOR('T', 0x42, struct serial_iso7816)
#define TIOCSISO7816 _IOWR('T', 0x43, struct serial_iso7816)

/* I hope the range from 0x5480 on is free ... */
#define TIOCSCTTY 0x5480 /* become controlling tty */
Expand Down
2 changes: 2 additions & 0 deletions arch/parisc/include/uapi/asm/ioctls.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
#define TIOCGPTLCK _IOR('T', 0x39, int) /* Get Pty lock state */
#define TIOCGEXCL _IOR('T', 0x40, int) /* Get exclusive mode state */
#define TIOCGPTPEER _IO('T', 0x41) /* Safely open the slave */
#define TIOCGISO7816 _IOR('T', 0x42, struct serial_iso7816)
#define TIOCSISO7816 _IOWR('T', 0x43, struct serial_iso7816)

#define FIONCLEX 0x5450 /* these numbers need to be adjusted. */
#define FIOCLEX 0x5451
Expand Down
2 changes: 2 additions & 0 deletions arch/powerpc/include/uapi/asm/ioctls.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@
#define TIOCGPTLCK _IOR('T', 0x39, int) /* Get Pty lock state */
#define TIOCGEXCL _IOR('T', 0x40, int) /* Get exclusive mode state */
#define TIOCGPTPEER _IO('T', 0x41) /* Safely open the slave */
#define TIOCGISO7816 _IOR('T', 0x42, struct serial_iso7816)
#define TIOCSISO7816 _IOWR('T', 0x43, struct serial_iso7816)

#define TIOCSERCONFIG 0x5453
#define TIOCSERGWILD 0x5454
Expand Down
2 changes: 2 additions & 0 deletions arch/sh/include/uapi/asm/ioctls.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@
#define TIOCGPTLCK _IOR('T', 0x39, int) /* Get Pty lock state */
#define TIOCGEXCL _IOR('T', 0x40, int) /* Get exclusive mode state */
#define TIOCGPTPEER _IO('T', 0x41) /* Safely open the slave */
#define TIOCGISO7816 _IOR('T', 0x42, struct serial_iso7816)
#define TIOCSISO7816 _IOWR('T', 0x43, struct serial_iso7816)

#define TIOCSERCONFIG _IO('T', 83) /* 0x5453 */
#define TIOCSERGWILD _IOR('T', 84, int) /* 0x5454 */
Expand Down
2 changes: 2 additions & 0 deletions arch/sparc/include/uapi/asm/ioctls.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#define TIOCGEXCL _IOR('T', 0x40, int) /* Get exclusive mode state */
#define TIOCGRS485 _IOR('T', 0x41, struct serial_rs485)
#define TIOCSRS485 _IOWR('T', 0x42, struct serial_rs485)
#define TIOCGISO7816 _IOR('T', 0x43, struct serial_iso7816)
#define TIOCSISO7816 _IOWR('T', 0x44, struct serial_iso7816)

/* Note that all the ioctls that are not available in Linux have a
* double underscore on the front to: a) avoid some programs to
Expand Down
2 changes: 2 additions & 0 deletions arch/xtensa/include/uapi/asm/ioctls.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@
#define TIOCGPTLCK _IOR('T', 0x39, int) /* Get Pty lock state */
#define TIOCGEXCL _IOR('T', 0x40, int) /* Get exclusive mode state */
#define TIOCGPTPEER _IO('T', 0x41) /* Safely open the slave */
#define TIOCGISO7816 _IOR('T', 0x42, struct serial_iso7816)
#define TIOCSISO7816 _IOWR('T', 0x43, struct serial_iso7816)

#define TIOCSERCONFIG _IO('T', 83)
#define TIOCSERGWILD _IOR('T', 84, int)
Expand Down
54 changes: 54 additions & 0 deletions drivers/of/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#define pr_fmt(fmt) "OF: " fmt

#include <linux/bitmap.h>
#include <linux/console.h>
#include <linux/ctype.h>
#include <linux/cpu.h>
Expand Down Expand Up @@ -1985,6 +1986,59 @@ int of_alias_get_id(struct device_node *np, const char *stem)
}
EXPORT_SYMBOL_GPL(of_alias_get_id);

/**
* of_alias_get_alias_list - Get alias list for the given device driver
* @matches: Array of OF device match structures to search in
* @stem: Alias stem of the given device_node
* @bitmap: Bitmap field pointer
* @nbits: Maximum number of alias IDs which can be recorded in bitmap
*
* The function travels the lookup table to record alias ids for the given
* device match structures and alias stem.
*
* Return: 0 or -ENOSYS when !CONFIG_OF or
* -EOVERFLOW if alias ID is greater then allocated nbits
*/
int of_alias_get_alias_list(const struct of_device_id *matches,
const char *stem, unsigned long *bitmap,
unsigned int nbits)
{
struct alias_prop *app;
int ret = 0;

/* Zero bitmap field to make sure that all the time it is clean */
bitmap_zero(bitmap, nbits);

mutex_lock(&of_mutex);
pr_debug("%s: Looking for stem: %s\n", __func__, stem);
list_for_each_entry(app, &aliases_lookup, link) {
pr_debug("%s: stem: %s, id: %d\n",
__func__, app->stem, app->id);

if (strcmp(app->stem, stem) != 0) {
pr_debug("%s: stem comparison didn't pass %s\n",
__func__, app->stem);
continue;
}

if (of_match_node(matches, app->np)) {
pr_debug("%s: Allocated ID %d\n", __func__, app->id);

if (app->id >= nbits) {
pr_warn("%s: ID %d >= than bitmap field %d\n",
__func__, app->id, nbits);
ret = -EOVERFLOW;
} else {
set_bit(app->id, bitmap);
}
}
}
mutex_unlock(&of_mutex);

return ret;
}
EXPORT_SYMBOL_GPL(of_alias_get_alias_list);

/**
* of_alias_get_highest_id - Get highest alias id for the given stem
* @stem: Alias stem to be examined
Expand Down
12 changes: 6 additions & 6 deletions drivers/tty/ehv_bytechan.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ static int find_console_handle(void)
*/
iprop = of_get_property(np, "hv-handle", NULL);
if (!iprop) {
pr_err("ehv-bc: no 'hv-handle' property in %s node\n",
np->name);
pr_err("ehv-bc: no 'hv-handle' property in %pOFn node\n",
np);
return 0;
}
stdout_bc = be32_to_cpu(*iprop);
Expand Down Expand Up @@ -661,8 +661,8 @@ static int ehv_bc_tty_probe(struct platform_device *pdev)

iprop = of_get_property(np, "hv-handle", NULL);
if (!iprop) {
dev_err(&pdev->dev, "no 'hv-handle' property in %s node\n",
np->name);
dev_err(&pdev->dev, "no 'hv-handle' property in %pOFn node\n",
np);
return -ENODEV;
}

Expand All @@ -682,8 +682,8 @@ static int ehv_bc_tty_probe(struct platform_device *pdev)
bc->rx_irq = irq_of_parse_and_map(np, 0);
bc->tx_irq = irq_of_parse_and_map(np, 1);
if ((bc->rx_irq == NO_IRQ) || (bc->tx_irq == NO_IRQ)) {
dev_err(&pdev->dev, "no 'interrupts' property in %s node\n",
np->name);
dev_err(&pdev->dev, "no 'interrupts' property in %pOFn node\n",
np);
ret = -ENODEV;
goto error;
}
Expand Down
20 changes: 17 additions & 3 deletions drivers/tty/n_tty.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,28 @@ 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;
const void *from = read_buf_addr(ldata, tail);
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 @@ -171,7 +182,9 @@ static int tty_copy_to_user(struct tty_struct *tty, void __user *to,
}

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

/**
Expand Down Expand Up @@ -1960,11 +1973,12 @@ 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) {
const unsigned char *from = read_buf_addr(ldata, tail);
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
6 changes: 1 addition & 5 deletions drivers/tty/serial/8250/8250_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,8 @@ static irqreturn_t serial8250_interrupt(int irq, void *dev_id)

l = l->next;

if (l == i->head && pass_counter++ > PASS_LIMIT) {
/* If we hit this, we're dead. */
printk_ratelimited(KERN_ERR
"serial8250: too much work for irq%d\n", irq);
if (l == i->head && pass_counter++ > PASS_LIMIT)
break;
}
} while (l != end);

spin_unlock(&i->lock);
Expand Down
Loading

0 comments on commit 5bd4af3

Please sign in to comment.