Skip to contentSkip to conversation

serial: core: Start managing serial controllers to enable runtime PM

RFC PATCH Superseded Tony Lindgren 3 participants 12 messages Dec 7, 2022 – Dec 12, 2022 TTY layer and serial drivers

v4 of 12 Superseded Latest is v12 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH v4 1/1 serial: core: Start managing serial controllers to enable runtime PM

We want to enable runtime PM for serial port device drivers in a generic way. To do this, we want to have the serial core layer manage the registered physical serial controller devices.

To do this, let's set up a struct device for the serial core controller as suggested by Greg and Jiri. The serial core controller devices are children of the physical serial port device. The serial core controller device is needed to support multiple different kind of ports connected to single physical serial port device.

Let's also set up a struct device for the serial core port. The serial core port instances are children of the serial core controller device. With the serial core port device we can now flush pending TX on the runtime PM resume as suggested by Johan.

---

Changes since v3:

- Simplify things by adding a serial core control device as the child of the physical serial port as suggested by Jiri

- Drop the tinkering of the physical serial port device for runtime PM. Serial core just needs to manage port->port_dev with the addition of the serial core control device and the device hierarchy will keep the pysical serial port device enabled as needed

- Simplify patch description with all the runtime PM tinkering gone

- Coding style improvments as noted by Andy

- Post as a single RFC patch as we're close to the merge window

Changes since v2:

- Make each serial port a proper device as suggested by Greg. This is a separate patch that flushes the TX on runtime PM resume

Changes since v1:

- Use kref as suggested by Andy

- Fix memory leak on error as noted by Andy

- Use use unsigned char for supports_autosuspend as suggested by Andy

- Coding style improvments as suggested by Andy

---
 drivers/tty/serial/8250/8250_core.c |   1 +
 drivers/tty/serial/Makefile         |   2 +-
 drivers/tty/serial/serial_core.c    | 184 ++++++++++++++++++++++++++--
 drivers/tty/serial/serial_ctrl.c    |  61 +++++++++
 drivers/tty/serial/serial_ctrl.h    |  19 +++
 drivers/tty/serial/serial_port.c    | 108 ++++++++++++++++
 include/linux/serial_core.h         |   4 +-
 7 files changed, 370 insertions(+), 9 deletions(-)
 create mode 100644 drivers/tty/serial/serial_ctrl.c
 create mode 100644 drivers/tty/serial/serial_ctrl.h
 create mode 100644 drivers/tty/serial/serial_port.c
drivers/tty/serial/8250/8250_core.c +1 -0
@@ -995,6 +995,7 @@ int serial8250_register_8250_port(const struct uart_8250_port *up)
 		if (uart->port.dev)
 			uart_remove_one_port(&serial8250_reg, &uart->port);
 
+		uart->port.ctrl_id	= up->port.ctrl_id;
 		uart->port.iobase       = up->port.iobase;
 		uart->port.membase      = up->port.membase;
 		uart->port.irq          = up->port.irq;
drivers/tty/serial/Makefile +1 -1
@@ -3,7 +3,7 @@
 # Makefile for the kernel serial device drivers.
 #
 
-obj-$(CONFIG_SERIAL_CORE) += serial_core.o
+obj-$(CONFIG_SERIAL_CORE) += serial_core.o serial_ctrl.o serial_port.o
 
 obj-$(CONFIG_SERIAL_EARLYCON) += earlycon.o
 obj-$(CONFIG_SERIAL_EARLYCON_ARM_SEMIHOST) += earlycon-arm-semihost.o
drivers/tty/serial/serial_core.c +177 -7

242 lines not on this page · raw message

drivers/tty/serial/serial_ctrl.c new file +61 -0

61 lines not on this page · raw message

drivers/tty/serial/serial_ctrl.h new file +19 -0
new file mode 100644
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/* Serial core controller data. Serial port device drivers do not need this. */
+
+/**
+ * struct serial_port_platdata - Serial port platform data
+ * @state: serial port state
+ *
+ * Used by serial_core and serial_port only. Allocated on uart_add_one_port(),
+ * and freed on uart_remove_one_port().
+ */
+struct serial_port_platdata {
+	struct uart_port *port;
+};
+
+extern int serial_ctrl_register_port(struct uart_driver *drv, struct uart_port *port);
+extern void serial_ctrl_unregister_port(struct uart_driver *drv, struct uart_port *port);
+extern int serial_core_register_port(struct uart_driver *drv, struct uart_port *port);
+extern void serial_core_unregister_port(struct uart_driver *drv, struct uart_port *port);
drivers/tty/serial/serial_port.c new file +108 -0

108 lines not on this page · raw message

include/linux/serial_core.h +3 -1
@@ -458,6 +458,7 @@ struct uart_port {
 						struct serial_rs485 *rs485);
 	int			(*iso7816_config)(struct uart_port *,
 						  struct serial_iso7816 *iso7816);
+	int			ctrl_id;		/* optional serial core controller id */
 	unsigned int		irq;			/* irq number */
 	unsigned long		irqflags;		/* irq flags  */
 	unsigned int		uartclk;		/* base uart clock */
@@ -563,7 +564,8 @@ struct uart_port {
 	unsigned int		minor;
 	resource_size_t		mapbase;		/* for ioremap */
 	resource_size_t		mapsize;
-	struct device		*dev;			/* parent device */
+	struct device		*dev;			/* serial port physical parent device */
+	struct device		*port_dev;		/* serial core port device */
 
 	unsigned long		sysrq;			/* sysrq timeout */
 	unsigned int		sysrq_ch;		/* char for sysrq */
Signature · 1 line
2.38.1
#1 lore raw
Quoted 14 lines · Tony Lindgren

We want to enable runtime PM for serial port device drivers in a generic way. To do this, we want to have the serial core layer manage the registered physical serial controller devices.

To do this, let's set up a struct device for the serial core controller as suggested by Greg and Jiri. The serial core controller devices are children of the physical serial port device. The serial core controller device is needed to support multiple different kind of ports connected to single physical serial port device.

Let's also set up a struct device for the serial core port. The serial core port instances are children of the serial core controller device. With the serial core port device we can now flush pending TX on the runtime PM resume as suggested by Johan.

...

drivers/tty/serial/serial_core.c bool uart_match_port(const struct uart_port *port1, · line 3310

Quoted 7 lines
drivers/tty/serial/serial_core.c +7 -0
+static struct platform_device *serial_core_device_add(struct uart_port *port,
+						      const char *name,
+						      struct device *parent_dev,
+						      void *pdata,
+						      int pdata_size)
+{
+	struct platform_device_info pinfo;

' = {}' can also work instead of memset(), but up to you.

Quoted 9 lines
drivers/tty/serial/serial_core.c +9 -0
+	memset(&pinfo, 0, sizeof(pinfo));
+	pinfo.name = name;
+	pinfo.id = PLATFORM_DEVID_AUTO;
+	pinfo.parent = parent_dev;
+	pinfo.data = pdata;
+	pinfo.size_data = pdata_size;
+
+	return platform_device_register_full(&pinfo);
+}

...

drivers/tty/serial/serial_core.c bool uart_match_port(const struct uart_port *port1, · line 3335

Quoted 1 line
drivers/tty/serial/serial_core.c +1 -0
+	struct serial_port_platdata pdata;

Ditto.

Quoted 1 line
drivers/tty/serial/serial_core.c +1 -0
+	memset(&pdata, 0, sizeof(pdata));

...

drivers/tty/serial/serial_core.c bool uart_match_port(const struct uart_port *port1, · line 3356

Quoted 4 lines
drivers/tty/serial/serial_core.c +3 -0
+int serial_core_register_port(struct uart_driver *drv, struct uart_port *port)
+{
 
+	bool allocated = false;

Not sure why this is needed.

Quoted 7 lines
drivers/tty/serial/serial_core.c +7 -0
+	struct device *ctrl_dev;
+	int ret;
+
+	ret = serial_core_add_one_port(drv, port);
+	if (ret)
+		return ret;
+

drivers/tty/serial/serial_core.c bool uart_match_port(const struct uart_port *port1, · line 3373

Quoted 10 lines
drivers/tty/serial/serial_core.c +10 -0
+	mutex_lock(&port_mutex);
+
+	/* Inititalize a serial core controller device if needed */
+	ctrl_dev = serial_core_ctrl_find(drv, port->dev, port->ctrl_id);
+	if (!ctrl_dev) {
+		ctrl_dev = serial_core_ctrl_device_add(port);
+		if (!ctrl_dev)
+			goto err_remove_port;
+		allocated = true;
+	}

Wouldn't be slightly better

	ctrl_dev = serial_core_ctrl_find(drv, port->dev, port->ctrl_id);
	if (!ctrl_dev)
		ctrl_dev = serial_core_ctrl_device_add(port);
	if (!ctrl_dev)
		goto err_remove_port;

?

drivers/tty/serial/serial_core.c bool uart_match_port(const struct uart_port *port1, · line 3386

Quoted 12 lines
drivers/tty/serial/serial_core.c +12 -0
+	/* Initialize a serial core port device */
+	ret = serial_core_port_device_add(ctrl_dev, port);
+	if (ret)
+		goto err_del_ctrl_dev;
+
+	mutex_unlock(&port_mutex);
+
+	return 0;
+
+err_del_ctrl_dev:
+	if (allocated)
+		platform_device_del(to_platform_device(ctrl_dev));

Shouldn't you call platform_device_unregister()?

Quoted 5 lines
drivers/tty/serial/serial_core.c +5 -0
+err_remove_port:
+	mutex_unlock(&port_mutex);
+
+	return serial_core_remove_one_port(drv, port);
+}

...

drivers/tty/serial/serial_core.c bool uart_match_port(const struct uart_port *port1, · line 3406

Quoted 1 line
drivers/tty/serial/serial_core.c +1 -0
+	platform_device_del(to_platform_device(port_dev));

Ditto?

...

drivers/tty/serial/serial_core.c bool uart_match_port(const struct uart_port *port1, · line 3417

Quoted 3 lines
drivers/tty/serial/serial_core.c +3 -0
+	/* Drop the serial core controller device if no ports are using it */
+	if (!serial_core_ctrl_find(drv, port->dev, port->ctrl_id))
+		platform_device_del(to_platform_device(ctrl_dev));

Ditto?

...

Quoted 1 line

+/* Serial core controller data. Serial port device drivers do not need this. */

Some missing forward declarations?

struct uart_driver:
struct uart_port;

?

...

drivers/tty/serial/serial_port.c line 44

Quoted 2 lines
drivers/tty/serial/serial_port.c new file +2 -0
+static DEFINE_RUNTIME_DEV_PM_OPS(serial_port_pm, NULL,
+				 serial_port_runtime_resume, NULL);

Wouldn't be more logical to indent like

static DEFINE_RUNTIME_DEV_PM_OPS(serial_port_pm,

				 NULL, serial_port_runtime_resume,
				 NULL);

?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
Quoted 1 line · Andy Shevchenko

On Wed, Dec 07, 2022 at 02:43:05PM +0200, Tony Lindgren wrote:

...

Quoted 6 lines

drivers/tty/serial/serial_core.c bool uart_match_port(const struct uart_port *port1, · line 3356

Quoted 4 lines
drivers/tty/serial/serial_core.c +3 -0
+int serial_core_register_port(struct uart_driver *drv, struct uart_port *port)
+{
 
+	bool allocated = false;

Not sure why this is needed.

Okay, I got it.
Still, see below.

Quoted 28 lines
Quoted 7 lines
drivers/tty/serial/serial_core.c +7 -0
+	struct device *ctrl_dev;
+	int ret;
+
+	ret = serial_core_add_one_port(drv, port);
+	if (ret)
+		return ret;
+

drivers/tty/serial/serial_core.c bool uart_match_port(const struct uart_port *port1, · line 3373

Quoted 10 lines
drivers/tty/serial/serial_core.c +10 -0
+	mutex_lock(&port_mutex);
+
+	/* Inititalize a serial core controller device if needed */
+	ctrl_dev = serial_core_ctrl_find(drv, port->dev, port->ctrl_id);
+	if (!ctrl_dev) {
+		ctrl_dev = serial_core_ctrl_device_add(port);
+		if (!ctrl_dev)
+			goto err_remove_port;
+		allocated = true;
+	}

Wouldn't be slightly better

	ctrl_dev = serial_core_ctrl_find(drv, port->dev, port->ctrl_id);
	if (!ctrl_dev)
		ctrl_dev = serial_core_ctrl_device_add(port);
	if (!ctrl_dev)
		goto err_remove_port;

?

Quoted 11 lines

drivers/tty/serial/serial_core.c bool uart_match_port(const struct uart_port *port1, · line 3385

Quoted 11 lines
drivers/tty/serial/serial_core.c +11 -0
+	/* Initialize a serial core port device */
+	ret = serial_core_port_device_add(ctrl_dev, port);
+	if (ret)
+		goto err_del_ctrl_dev;
+
+	mutex_unlock(&port_mutex);
+
+	return 0;
+
+err_del_ctrl_dev:
+	if (allocated)

We can avoid this check by caching the platform device.

	struct platform_device *ctrl_pdev = NULL;

	if (...) {
		ctrl_pdev = to_platform_device(ctrl_dev);
	}

	platform_device_del(ctrl_pdev);
Quoted 9 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+		platform_device_del(to_platform_device(ctrl_dev));

Shouldn't you call platform_device_unregister()?

Quoted 5 lines
drivers/tty/serial/serial_core.c +5 -0
+err_remove_port:
+	mutex_unlock(&port_mutex);
+
+	return serial_core_remove_one_port(drv, port);
+}
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw
Quoted 9 lines · Andy Shevchenko

We can avoid this check by caching the platform device.

	struct platform_device *ctrl_pdev = NULL;

	if (...) {
		ctrl_pdev = to_platform_device(ctrl_dev);
	}

	platform_device_del(ctrl_pdev);

OK yeah that's nicer :)

Quoted 1 line
Quoted 1 line

Shouldn't you call platform_device_unregister()?

Outside the error path it should be platform_device_unregister(), I'll check. Thanks also for your other comments.

Regards,

Tony

#4 lore raw
Quoted 9 lines · Tony Lindgren
Quoted 8 lines · Andy Shevchenko

We can avoid this check by caching the platform device.

	struct platform_device *ctrl_pdev = NULL;

	if (...) {
		ctrl_pdev = to_platform_device(ctrl_dev);
	}
Quoted 8 lines
Quoted 1 line
	platform_device_del(ctrl_pdev);

OK yeah that's nicer :)

Quoted 1 line
Quoted 1 line

Shouldn't you call platform_device_unregister()?

Outside the error path it should be platform_device_unregister(), I'll check. Thanks also for your other comments.

To me looks like we should just use platform_device_unregister() in call cases here like you noted.

Regards,

Tony

#5 lore raw
In reply to Tony Lindgren
Quoted 61 lines · Tony Lindgren

We want to enable runtime PM for serial port device drivers in a generic way. To do this, we want to have the serial core layer manage the registered physical serial controller devices.

To do this, let's set up a struct device for the serial core controller as suggested by Greg and Jiri. The serial core controller devices are children of the physical serial port device. The serial core controller device is needed to support multiple different kind of ports connected to single physical serial port device.

Let's also set up a struct device for the serial core port. The serial core port instances are children of the serial core controller device. With the serial core port device we can now flush pending TX on the runtime PM resume as suggested by Johan.

---

Changes since v3:

- Simplify things by adding a serial core control device as the child of the physical serial port as suggested by Jiri

- Drop the tinkering of the physical serial port device for runtime PM. Serial core just needs to manage port->port_dev with the addition of the serial core control device and the device hierarchy will keep the pysical serial port device enabled as needed

- Simplify patch description with all the runtime PM tinkering gone

- Coding style improvments as noted by Andy

- Post as a single RFC patch as we're close to the merge window

Changes since v2:

- Make each serial port a proper device as suggested by Greg. This is a separate patch that flushes the TX on runtime PM resume

Changes since v1:

- Use kref as suggested by Andy

- Fix memory leak on error as noted by Andy

- Use use unsigned char for supports_autosuspend as suggested by Andy

- Coding style improvments as suggested by Andy

---

drivers/tty/serial/serial_core.c +7 -0
+	ret = serial_core_add_one_port(drv, port);
+	if (ret)
+		return ret;
+
+	mutex_lock(&port_mutex);
+
+	/* Inititalize a serial core controller device if needed */

drivers/tty/serial/serial_core.c bool uart_match_port(const struct uart_port *port1, · line 3376

Quoted 10 lines
drivers/tty/serial/serial_core.c +10 -0
+	ctrl_dev = serial_core_ctrl_find(drv, port->dev, port->ctrl_id);
+	if (!ctrl_dev) {
+		ctrl_dev = serial_core_ctrl_device_add(port);
+		if (!ctrl_dev)
+			goto err_remove_port;
+		allocated = true;
+	}
+
+	/* Initialize a serial core port device */
+	ret = serial_core_port_device_add(ctrl_dev, port);

How is ->port_dev supposed to work here?

->port_dev is not set until in serial_core_port_device_add() but you made serial_core_add_one_port() call before that.

Signature · 1 line
 i.
Quoted 17 lines
drivers/tty/serial/serial_core.c +17 -0
+	if (ret)
+		goto err_del_ctrl_dev;
+
+	mutex_unlock(&port_mutex);
+
+	return 0;
+
+err_del_ctrl_dev:
+	if (allocated)
+		platform_device_del(to_platform_device(ctrl_dev));
+
+err_remove_port:
+	mutex_unlock(&port_mutex);
+
+	return serial_core_remove_one_port(drv, port);
+}
+EXPORT_SYMBOL_NS(serial_core_register_port, SERIAL_CORE);
#6 lore raw
Quoted 21 lines · Ilpo Järvinen
Quoted 7 lines · Tony Lindgren
drivers/tty/serial/serial_core.c +7 -0
+	ret = serial_core_add_one_port(drv, port);
+	if (ret)
+		return ret;
+
+	mutex_lock(&port_mutex);
+
+	/* Inititalize a serial core controller device if needed */

drivers/tty/serial/serial_core.c bool uart_match_port(const struct uart_port *port1, · line 3376

Quoted 10 lines
drivers/tty/serial/serial_core.c +10 -0
+	ctrl_dev = serial_core_ctrl_find(drv, port->dev, port->ctrl_id);
+	if (!ctrl_dev) {
+		ctrl_dev = serial_core_ctrl_device_add(port);
+		if (!ctrl_dev)
+			goto err_remove_port;
+		allocated = true;
+	}
+
+	/* Initialize a serial core port device */
+	ret = serial_core_port_device_add(ctrl_dev, port);

How is ->port_dev supposed to work here?

Quoted 2 lines

->port_dev is not set until in serial_core_port_device_add() but you made serial_core_add_one_port() call before that.

Hmm do you mean you want to call serial_core_add_one_port() later after serial_core_port_device_add()?

Or are you seeing some uninitialized use of port->port_dev (and not port->dev)?

Regards,

Tony

#7 lore raw
Quoted 22 lines · Tony Lindgren
Quoted 21 lines · Ilpo Järvinen
Quoted 7 lines · Tony Lindgren
drivers/tty/serial/serial_core.c +7 -0
+	ret = serial_core_add_one_port(drv, port);
+	if (ret)
+		return ret;
+
+	mutex_lock(&port_mutex);
+
+	/* Inititalize a serial core controller device if needed */

drivers/tty/serial/serial_core.c bool uart_match_port(const struct uart_port *port1, · line 3376

Quoted 10 lines
drivers/tty/serial/serial_core.c +10 -0
+	ctrl_dev = serial_core_ctrl_find(drv, port->dev, port->ctrl_id);
+	if (!ctrl_dev) {
+		ctrl_dev = serial_core_ctrl_device_add(port);
+		if (!ctrl_dev)
+			goto err_remove_port;
+		allocated = true;
+	}
+
+	/* Initialize a serial core port device */
+	ret = serial_core_port_device_add(ctrl_dev, port);

How is ->port_dev supposed to work here?

Quoted 8 lines
Quoted 2 lines

->port_dev is not set until in serial_core_port_device_add() but you made serial_core_add_one_port() call before that.

Hmm do you mean you want to call serial_core_add_one_port() later after serial_core_port_device_add()?

Or are you seeing some uninitialized use of port->port_dev (and not port->dev)?

With the other patch on top of this, yes, I did see uninitialized port->port_dev already in serial_core_add_one_port()->uart_configure_port(). While that could be solved by removing the pm_runtime_*() calls from there, I think it's a generic problem because after serial_core_add_one_port() the port can have anything happening on it, no?

Signature · 1 line
 i.
#8 lore raw
Quoted 30 lines · Ilpo Järvinen
Quoted 28 lines · Tony Lindgren
Quoted 21 lines · Ilpo Järvinen
Quoted 7 lines · Tony Lindgren
drivers/tty/serial/serial_core.c +7 -0
+	ret = serial_core_add_one_port(drv, port);
+	if (ret)
+		return ret;
+
+	mutex_lock(&port_mutex);
+
+	/* Inititalize a serial core controller device if needed */

drivers/tty/serial/serial_core.c bool uart_match_port(const struct uart_port *port1, · line 3376

Quoted 10 lines
drivers/tty/serial/serial_core.c +10 -0
+	ctrl_dev = serial_core_ctrl_find(drv, port->dev, port->ctrl_id);
+	if (!ctrl_dev) {
+		ctrl_dev = serial_core_ctrl_device_add(port);
+		if (!ctrl_dev)
+			goto err_remove_port;
+		allocated = true;
+	}
+
+	/* Initialize a serial core port device */
+	ret = serial_core_port_device_add(ctrl_dev, port);

How is ->port_dev supposed to work here?

Quoted 2 lines

->port_dev is not set until in serial_core_port_device_add() but you made serial_core_add_one_port() call before that.

Hmm do you mean you want to call serial_core_add_one_port() later after serial_core_port_device_add()?

Quoted 8 lines
Quoted 2 lines

Or are you seeing some uninitialized use of port->port_dev (and not port->dev)?

With the other patch on top of this, yes, I did see uninitialized port->port_dev already in serial_core_add_one_port()->uart_configure_port(). While that could be solved by removing the pm_runtime_*() calls from there, I think it's a generic problem because after serial_core_add_one_port() the port can have anything happening on it, no?

OK. Sounds like it should get sorted out by moving the call to serial_core_add_one_port() to happen after the devices are created.

Regards,

Tony

#9 lore raw

Hi Ilpo,

Quoted 9 lines · Tony Lindgren
Quoted 5 lines · Ilpo Järvinen

With the other patch on top of this, yes, I did see uninitialized port->port_dev already in serial_core_add_one_port()->uart_configure_port(). While that could be solved by removing the pm_runtime_*() calls from there, I think it's a generic problem because after serial_core_add_one_port() the port can have anything happening on it, no?

OK. Sounds like it should get sorted out by moving the call to serial_core_add_one_port() to happen after the devices are created.

Can you give a try with the patch below and see if it works for you?

Regards,

Tony

8< --------------------

drivers/tty/serial/8250/8250_core.c +1 -0
@@ -995,6 +995,7 @@ int serial8250_register_8250_port(const struct uart_8250_port *up)
 		if (uart->port.dev)
 			uart_remove_one_port(&serial8250_reg, &uart->port);
 
+		uart->port.ctrl_id	= up->port.ctrl_id;
 		uart->port.iobase       = up->port.iobase;
 		uart->port.membase      = up->port.membase;
 		uart->port.irq          = up->port.irq;
drivers/tty/serial/Makefile +1 -1
@@ -3,7 +3,7 @@
 # Makefile for the kernel serial device drivers.
 #
 
-obj-$(CONFIG_SERIAL_CORE) += serial_core.o
+obj-$(CONFIG_SERIAL_CORE) += serial_core.o serial_ctrl.o serial_port.o
 
 obj-$(CONFIG_SERIAL_EARLYCON) += earlycon.o
 obj-$(CONFIG_SERIAL_EARLYCON_ARM_SEMIHOST) += earlycon-arm-semihost.o
drivers/tty/serial/serial_core.c +182 -7

253 lines not on this page · raw message

drivers/tty/serial/serial_ctrl.c new file +61 -0

61 lines not on this page · raw message

drivers/tty/serial/serial_ctrl.h new file +22 -0
new file mode 100644
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/* Serial core controller data. Serial port device drivers do not need this. */
+
+struct uart_driver;
+struct uart_port;
+
+/**
+ * struct serial_port_platdata - Serial port platform data
+ * @state: serial port state
+ *
+ * Used by serial_core and serial_port only. Allocated on uart_add_one_port(),
+ * and freed on uart_remove_one_port().
+ */
+struct serial_port_platdata {
+	struct uart_port *port;
+};
+
+extern int serial_ctrl_register_port(struct uart_driver *drv, struct uart_port *port);
+extern void serial_ctrl_unregister_port(struct uart_driver *drv, struct uart_port *port);
+extern int serial_core_register_port(struct uart_driver *drv, struct uart_port *port);
+extern void serial_core_unregister_port(struct uart_driver *drv, struct uart_port *port);
drivers/tty/serial/serial_port.c new file +109 -0

109 lines not on this page · raw message

include/linux/serial_core.h +3 -1
@@ -458,6 +458,7 @@ struct uart_port {
 						struct serial_rs485 *rs485);
 	int			(*iso7816_config)(struct uart_port *,
 						  struct serial_iso7816 *iso7816);
+	int			ctrl_id;		/* optional serial core controller id */
 	unsigned int		irq;			/* irq number */
 	unsigned long		irqflags;		/* irq flags  */
 	unsigned int		uartclk;		/* base uart clock */
@@ -563,7 +564,8 @@ struct uart_port {
 	unsigned int		minor;
 	resource_size_t		mapbase;		/* for ioremap */
 	resource_size_t		mapsize;
-	struct device		*dev;			/* parent device */
+	struct device		*dev;			/* serial port physical parent device */
+	struct device		*port_dev;		/* serial core port device */
 
 	unsigned long		sysrq;			/* sysrq timeout */
 	unsigned int		sysrq_ch;		/* char for sysrq */
Signature · 1 line
2.38.1
#10 lore raw
Quoted 10 lines · Tony Lindgren

Hi Ilpo,

Quoted 7 lines · Tony Lindgren
Quoted 5 lines · Ilpo Järvinen

With the other patch on top of this, yes, I did see uninitialized port->port_dev already in serial_core_add_one_port()->uart_configure_port(). While that could be solved by removing the pm_runtime_*() calls from there, I think it's a generic problem because after serial_core_add_one_port() the port can have anything happening on it, no?

Quoted 4 lines
Quoted 2 lines

OK. Sounds like it should get sorted out by moving the call to serial_core_add_one_port() to happen after the devices are created.

Can you give a try with the patch below and see if it works for you?

This one worked, yes.

Signature · 1 line
 i.
#11 lore raw
Quoted 12 lines · Ilpo Järvinen
Quoted 10 lines · Tony Lindgren

Hi Ilpo,

Quoted 7 lines · Tony Lindgren
Quoted 5 lines · Ilpo Järvinen

With the other patch on top of this, yes, I did see uninitialized port->port_dev already in serial_core_add_one_port()->uart_configure_port(). While that could be solved by removing the pm_runtime_*() calls from there, I think it's a generic problem because after serial_core_add_one_port() the port can have anything happening on it, no?

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

OK. Sounds like it should get sorted out by moving the call to serial_core_add_one_port() to happen after the devices are created.

Can you give a try with the patch below and see if it works for you?

This one worked, yes.

OK good to hear. I'll send out v5 after -rc1 then.

Thanks,

Tony