Re: [PATCH v6 2/2] tty: add rpmsg driver

2019-09-05 Thread Arnaud Pouliquen

Hi Richard,

On 9/5/19 12:50 PM, Richard Genoud wrote:

Hi Arnaud,

Le 04/09/2019 à 15:09, Arnaud Pouliquen a écrit :

This driver exposes a standard tty interface on top of the rpmsg
framework through a rpmsg service.

This driver supports multi-instances, offering a /dev/ttyRPMSGx entry
per rpmsg endpoint.

Signed-off-by: Arnaud Pouliquen 
Signed-off-by: Fabien Dessenne 
---
  Documentation/serial/tty_rpmsg.rst |  45 
  drivers/tty/Kconfig|   9 +
  drivers/tty/Makefile   |   1 +
  drivers/tty/rpmsg_tty.c| 418 +
  4 files changed, 473 insertions(+)
  create mode 100644 Documentation/serial/tty_rpmsg.rst
  create mode 100644 drivers/tty/rpmsg_tty.c

diff --git a/Documentation/serial/tty_rpmsg.rst 
b/Documentation/serial/tty_rpmsg.rst
new file mode 100644
index ..fc1d3fba73c5
--- /dev/null
+++ b/Documentation/serial/tty_rpmsg.rst
@@ -0,0 +1,45 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+=
+The rpmsg TTY
+=
+
+The rpmsg tty driver implements serial communication on the RPMsg bus to makes 
possible for user-space programs to send and receive rpmsg messages as a 
standard tty protocol.
+
+The remote processor can instantiate a new tty by requesting:
+- a "rpmsg-tty-raw" RPMsg service, for TTY raw data support without flow 
control
+- a "rpmsg-tty-ctrl" RPMSg service, for TTY support with flow control.
+
+Information related to the RPMsg and associated tty device is available in
+/sys/bus/rpmsg/devices/.
+
+RPMsg TTY without control
+-
+
+The default end point associated with the "rpmsg-tty-raw" service is directly
+used for data exchange. No flow control is available.
+
+To be compliant with this driver, the remote firmware must create its data end point 
associated with the "rpmsg-tty-raw" service.
+
+RPMsg TTY with control
+-
+
+The default end point associated with the "rpmsg-tty-ctrl" service is reserved 
for
+the control. A second endpoint must be created for data exchange.
+
+The control channel is used to transmit to the remote processor the CTS status,
+as well as the end point address for data transfer.
+
+To be compatible with this driver, the remote firmware must create or use its end point 
associated with "rpmsg-tty-ctrl" service, plus a second endpoint for the data 
flow.
+On Linux rpmsg_tty probes, the data endpoint address and the CTS (set to 
disable)
+is sent to the remote processor.
+The remote processor has to respect following rules:
+- It only transmits data when Linux remote cts is enable, otherwise message
+  could be lost.
+- It can pause/resume reception by sending a control message (rely on CTS 
state).
+
+Control message structure:
+struct rpmsg_tty_ctrl {
+   u8 cts; /* remote reception status */
+   u16 d_ept_addr; /* data endpoint address */
+};

Correct me if I'm wrong, but I think this structure should be packed,
shouldn't it ?
It's working ok on the STM32MP127, between M4 and A7, but the alignment
may be not the same on another architecture ?

you are right, i have to fix this.

Thanks,
Arnaud






diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig
index c7623f99ac0f..1046bf4aa709 100644
--- a/drivers/tty/Kconfig
+++ b/drivers/tty/Kconfig
@@ -454,6 +454,15 @@ config VCC
help
  Support for Sun logical domain consoles.
  
+config RPMSG_TTY

+   tristate "RPMSG tty driver"
+   depends on RPMSG
+   help
+ Say y here to export rpmsg endpoints as tty devices, usually found
+ in /dev/ttyRPMSGx.
+ This makes it possible for user-space programs to send and receive
+ rpmsg messages as a standard tty protocol.
+
  config LDISC_AUTOLOAD
bool "Automatically load TTY Line Disciplines"
default y
diff --git a/drivers/tty/Makefile b/drivers/tty/Makefile
index 020b1cd9294f..c2465e7ebc2a 100644
--- a/drivers/tty/Makefile
+++ b/drivers/tty/Makefile
@@ -34,5 +34,6 @@ obj-$(CONFIG_PPC_EPAPR_HV_BYTECHAN) += ehv_bytechan.o
  obj-$(CONFIG_GOLDFISH_TTY)+= goldfish.o
  obj-$(CONFIG_MIPS_EJTAG_FDC_TTY) += mips_ejtag_fdc.o
  obj-$(CONFIG_VCC) += vcc.o
+obj-$(CONFIG_RPMSG_TTY)+= rpmsg_tty.o
  
  obj-y += ipwireless/

diff --git a/drivers/tty/rpmsg_tty.c b/drivers/tty/rpmsg_tty.c
new file mode 100644
index ..3e4d0e1a6663
--- /dev/null
+++ b/drivers/tty/rpmsg_tty.c
@@ -0,0 +1,418 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) STMicroelectronics 2019 - All Rights Reserved
+ * Authors: Arnaud Pouliquen  for STMicroelectronics.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define MAX_TTY_RPMSG  32
+
+#define TTY_CH_NAME_RAW"rpmsg-tty-raw"
+#define TTY_CH_NAME_WITH_CTS   "rpmsg-tty-ctrl"
+
+static DEFINE_IDR(tty_idr);/* tty instance id */
+static DEFINE_MUTEX(idr_lock); /* protects tty_idr */
+
+static struct tty_driver *rpmsg_tty_driver;
+
+struct rp

Re: [PATCH v6 2/2] tty: add rpmsg driver

2019-09-05 Thread Richard Genoud
Hi Arnaud,

Le 04/09/2019 à 15:09, Arnaud Pouliquen a écrit :
> This driver exposes a standard tty interface on top of the rpmsg
> framework through a rpmsg service.
> 
> This driver supports multi-instances, offering a /dev/ttyRPMSGx entry
> per rpmsg endpoint.
> 
> Signed-off-by: Arnaud Pouliquen 
> Signed-off-by: Fabien Dessenne 
> ---
>  Documentation/serial/tty_rpmsg.rst |  45 
>  drivers/tty/Kconfig|   9 +
>  drivers/tty/Makefile   |   1 +
>  drivers/tty/rpmsg_tty.c| 418 
> +
>  4 files changed, 473 insertions(+)
>  create mode 100644 Documentation/serial/tty_rpmsg.rst
>  create mode 100644 drivers/tty/rpmsg_tty.c
> 
> diff --git a/Documentation/serial/tty_rpmsg.rst 
> b/Documentation/serial/tty_rpmsg.rst
> new file mode 100644
> index ..fc1d3fba73c5
> --- /dev/null
> +++ b/Documentation/serial/tty_rpmsg.rst
> @@ -0,0 +1,45 @@
> +.. SPDX-License-Identifier: GPL-2.0
> +
> +=
> +The rpmsg TTY
> +=
> +
> +The rpmsg tty driver implements serial communication on the RPMsg bus to 
> makes possible for user-space programs to send and receive rpmsg messages as 
> a standard tty protocol.
> +
> +The remote processor can instantiate a new tty by requesting:
> +- a "rpmsg-tty-raw" RPMsg service, for TTY raw data support without flow 
> control
> +- a "rpmsg-tty-ctrl" RPMSg service, for TTY support with flow control.
> +
> +Information related to the RPMsg and associated tty device is available in
> +/sys/bus/rpmsg/devices/.
> +
> +RPMsg TTY without control
> +-
> +
> +The default end point associated with the "rpmsg-tty-raw" service is directly
> +used for data exchange. No flow control is available.
> +
> +To be compliant with this driver, the remote firmware must create its data 
> end point associated with the "rpmsg-tty-raw" service.
> +
> +RPMsg TTY with control
> +-
> +
> +The default end point associated with the "rpmsg-tty-ctrl" service is 
> reserved for
> +the control. A second endpoint must be created for data exchange.
> +
> +The control channel is used to transmit to the remote processor the CTS 
> status,
> +as well as the end point address for data transfer.
> +
> +To be compatible with this driver, the remote firmware must create or use 
> its end point associated with "rpmsg-tty-ctrl" service, plus a second 
> endpoint for the data flow.
> +On Linux rpmsg_tty probes, the data endpoint address and the CTS (set to 
> disable)
> +is sent to the remote processor.
> +The remote processor has to respect following rules:
> +- It only transmits data when Linux remote cts is enable, otherwise message
> +  could be lost.
> +- It can pause/resume reception by sending a control message (rely on CTS 
> state).
> +
> +Control message structure:
> +struct rpmsg_tty_ctrl {
> + u8 cts; /* remote reception status */
> + u16 d_ept_addr; /* data endpoint address */
> +};
Correct me if I'm wrong, but I think this structure should be packed,
shouldn't it ?
It's working ok on the STM32MP127, between M4 and A7, but the alignment
may be not the same on another architecture ?



> diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig
> index c7623f99ac0f..1046bf4aa709 100644
> --- a/drivers/tty/Kconfig
> +++ b/drivers/tty/Kconfig
> @@ -454,6 +454,15 @@ config VCC
>   help
> Support for Sun logical domain consoles.
>  
> +config RPMSG_TTY
> + tristate "RPMSG tty driver"
> + depends on RPMSG
> + help
> +   Say y here to export rpmsg endpoints as tty devices, usually found
> +   in /dev/ttyRPMSGx.
> +   This makes it possible for user-space programs to send and receive
> +   rpmsg messages as a standard tty protocol.
> +
>  config LDISC_AUTOLOAD
>   bool "Automatically load TTY Line Disciplines"
>   default y
> diff --git a/drivers/tty/Makefile b/drivers/tty/Makefile
> index 020b1cd9294f..c2465e7ebc2a 100644
> --- a/drivers/tty/Makefile
> +++ b/drivers/tty/Makefile
> @@ -34,5 +34,6 @@ obj-$(CONFIG_PPC_EPAPR_HV_BYTECHAN) += ehv_bytechan.o
>  obj-$(CONFIG_GOLDFISH_TTY)   += goldfish.o
>  obj-$(CONFIG_MIPS_EJTAG_FDC_TTY) += mips_ejtag_fdc.o
>  obj-$(CONFIG_VCC)+= vcc.o
> +obj-$(CONFIG_RPMSG_TTY)  += rpmsg_tty.o
>  
>  obj-y += ipwireless/
> diff --git a/drivers/tty/rpmsg_tty.c b/drivers/tty/rpmsg_tty.c
> new file mode 100644
> index ..3e4d0e1a6663
> --- /dev/null
> +++ b/drivers/tty/rpmsg_tty.c
> @@ -0,0 +1,418 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright (C) STMicroelectronics 2019 - All Rights Reserved
> + * Authors: Arnaud Pouliquen  for 
> STMicroelectronics.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define MAX_TTY_RPMSG32
> +
> +#define TTY_CH_NAME_RAW  "rpmsg-tty-raw"
> +#define TTY_CH_NAME_WITH_CTS "rpmsg-tty-ctrl"
> +
> +static DEFINE_IDR(tty_idr);  /* tty instance id */

[PATCH v6 2/2] tty: add rpmsg driver

2019-09-04 Thread Arnaud Pouliquen
This driver exposes a standard tty interface on top of the rpmsg
framework through a rpmsg service.

This driver supports multi-instances, offering a /dev/ttyRPMSGx entry
per rpmsg endpoint.

Signed-off-by: Arnaud Pouliquen 
Signed-off-by: Fabien Dessenne 
---
 Documentation/serial/tty_rpmsg.rst |  45 
 drivers/tty/Kconfig|   9 +
 drivers/tty/Makefile   |   1 +
 drivers/tty/rpmsg_tty.c| 418 +
 4 files changed, 473 insertions(+)
 create mode 100644 Documentation/serial/tty_rpmsg.rst
 create mode 100644 drivers/tty/rpmsg_tty.c

diff --git a/Documentation/serial/tty_rpmsg.rst 
b/Documentation/serial/tty_rpmsg.rst
new file mode 100644
index ..fc1d3fba73c5
--- /dev/null
+++ b/Documentation/serial/tty_rpmsg.rst
@@ -0,0 +1,45 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+=
+The rpmsg TTY
+=
+
+The rpmsg tty driver implements serial communication on the RPMsg bus to makes 
possible for user-space programs to send and receive rpmsg messages as a 
standard tty protocol.
+
+The remote processor can instantiate a new tty by requesting:
+- a "rpmsg-tty-raw" RPMsg service, for TTY raw data support without flow 
control
+- a "rpmsg-tty-ctrl" RPMSg service, for TTY support with flow control.
+
+Information related to the RPMsg and associated tty device is available in
+/sys/bus/rpmsg/devices/.
+
+RPMsg TTY without control
+-
+
+The default end point associated with the "rpmsg-tty-raw" service is directly
+used for data exchange. No flow control is available.
+
+To be compliant with this driver, the remote firmware must create its data end 
point associated with the "rpmsg-tty-raw" service.
+
+RPMsg TTY with control
+-
+
+The default end point associated with the "rpmsg-tty-ctrl" service is reserved 
for
+the control. A second endpoint must be created for data exchange.
+
+The control channel is used to transmit to the remote processor the CTS status,
+as well as the end point address for data transfer.
+
+To be compatible with this driver, the remote firmware must create or use its 
end point associated with "rpmsg-tty-ctrl" service, plus a second endpoint for 
the data flow.
+On Linux rpmsg_tty probes, the data endpoint address and the CTS (set to 
disable)
+is sent to the remote processor.
+The remote processor has to respect following rules:
+- It only transmits data when Linux remote cts is enable, otherwise message
+  could be lost.
+- It can pause/resume reception by sending a control message (rely on CTS 
state).
+
+Control message structure:
+struct rpmsg_tty_ctrl {
+   u8 cts; /* remote reception status */
+   u16 d_ept_addr; /* data endpoint address */
+};
diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig
index c7623f99ac0f..1046bf4aa709 100644
--- a/drivers/tty/Kconfig
+++ b/drivers/tty/Kconfig
@@ -454,6 +454,15 @@ config VCC
help
  Support for Sun logical domain consoles.
 
+config RPMSG_TTY
+   tristate "RPMSG tty driver"
+   depends on RPMSG
+   help
+ Say y here to export rpmsg endpoints as tty devices, usually found
+ in /dev/ttyRPMSGx.
+ This makes it possible for user-space programs to send and receive
+ rpmsg messages as a standard tty protocol.
+
 config LDISC_AUTOLOAD
bool "Automatically load TTY Line Disciplines"
default y
diff --git a/drivers/tty/Makefile b/drivers/tty/Makefile
index 020b1cd9294f..c2465e7ebc2a 100644
--- a/drivers/tty/Makefile
+++ b/drivers/tty/Makefile
@@ -34,5 +34,6 @@ obj-$(CONFIG_PPC_EPAPR_HV_BYTECHAN) += ehv_bytechan.o
 obj-$(CONFIG_GOLDFISH_TTY) += goldfish.o
 obj-$(CONFIG_MIPS_EJTAG_FDC_TTY) += mips_ejtag_fdc.o
 obj-$(CONFIG_VCC)  += vcc.o
+obj-$(CONFIG_RPMSG_TTY)+= rpmsg_tty.o
 
 obj-y += ipwireless/
diff --git a/drivers/tty/rpmsg_tty.c b/drivers/tty/rpmsg_tty.c
new file mode 100644
index ..3e4d0e1a6663
--- /dev/null
+++ b/drivers/tty/rpmsg_tty.c
@@ -0,0 +1,418 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) STMicroelectronics 2019 - All Rights Reserved
+ * Authors: Arnaud Pouliquen  for STMicroelectronics.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define MAX_TTY_RPMSG  32
+
+#define TTY_CH_NAME_RAW"rpmsg-tty-raw"
+#define TTY_CH_NAME_WITH_CTS   "rpmsg-tty-ctrl"
+
+static DEFINE_IDR(tty_idr);/* tty instance id */
+static DEFINE_MUTEX(idr_lock); /* protects tty_idr */
+
+static struct tty_driver *rpmsg_tty_driver;
+
+struct rpmsg_tty_ctrl {
+   u8 cts; /* remote reception status */
+   u16 d_ept_addr; /* data endpoint address */
+};
+
+struct rpmsg_tty_port {
+   struct tty_port port;/* TTY port data */
+   int id;  /* TTY rpmsg index */
+   boolcts; /* remote reception status */
+   struct rpmsg_device *