[PATCH] tty: serial: Replace deprecated PCI API

Philipp Stanner posted 1 patch 5 days, 13 hours ago
drivers/tty/serial/8250/8250_pcilib.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
[PATCH] tty: serial: Replace deprecated PCI API
Posted by Philipp Stanner 5 days, 13 hours ago
pcim_iomap_table() is deprecated. Moreover, its special usage in 8250,
causes a WARN_ON to fire (in pcim_add_mapping_to_legacy_table()).

8250's function serial8250_pci_setup_port() effectively maps the same
BAR multiple times and adds an offset to the start address. While
mapping and adding offsets is not a bug, it can be achieved in a far
more straightforward way by using the specialized function
pcim_iomap_range().

pcim_iomap_range() does not add the mapping addresses to the deprecated
iomap table - that's not a problem, however, because non of the users of
serial8250_pci_setup_port() uses pcim_iomap_table().

Replace the deprecated PCI functions with pcim_iomap_range().

Cc: Guenter Roeck <linux@roeck-us.net>
Link: https://lore.kernel.org/dri-devel/16cd212f-6ea0-471d-bf32-34f55d7292fe@roeck-us.net/
Signed-off-by: Philipp Stanner <phasta@kernel.org>
---
@Guenther: Can you please test this? I hope it fixes your issue.
---
 drivers/tty/serial/8250/8250_pcilib.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_pcilib.c b/drivers/tty/serial/8250/8250_pcilib.c
index d8d0ae0d7238..f98eb2ab1005 100644
--- a/drivers/tty/serial/8250/8250_pcilib.c
+++ b/drivers/tty/serial/8250/8250_pcilib.c
@@ -28,13 +28,14 @@ int serial8250_pci_setup_port(struct pci_dev *dev, struct uart_8250_port *port,
 		return -EINVAL;
 
 	if (pci_resource_flags(dev, bar) & IORESOURCE_MEM) {
-		if (!pcim_iomap(dev, bar, 0) && !pcim_iomap_table(dev))
-			return -ENOMEM;
-
 		port->port.iotype = UPIO_MEM;
 		port->port.iobase = 0;
 		port->port.mapbase = pci_resource_start(dev, bar) + offset;
-		port->port.membase = pcim_iomap_table(dev)[bar] + offset;
+
+		port->port.membase = pcim_iomap_range(dev, bar, offset, 0);
+		if (IS_ERR(port->port.membase))
+			return PTR_ERR(port->port.membase);
+
 		port->port.regshift = regshift;
 	} else if (IS_ENABLED(CONFIG_HAS_IOPORT)) {
 		port->port.iotype = UPIO_PORT;
-- 
2.49.0
Re: [PATCH] tty: serial: Replace deprecated PCI API
Posted by Guenter Roeck 5 days, 6 hours ago
On 11/26/25 01:10, Philipp Stanner wrote:
> pcim_iomap_table() is deprecated. Moreover, its special usage in 8250,
> causes a WARN_ON to fire (in pcim_add_mapping_to_legacy_table()).
> 
> 8250's function serial8250_pci_setup_port() effectively maps the same
> BAR multiple times and adds an offset to the start address. While
> mapping and adding offsets is not a bug, it can be achieved in a far
> more straightforward way by using the specialized function
> pcim_iomap_range().
> 
> pcim_iomap_range() does not add the mapping addresses to the deprecated
> iomap table - that's not a problem, however, because non of the users of
> serial8250_pci_setup_port() uses pcim_iomap_table().
> 
> Replace the deprecated PCI functions with pcim_iomap_range().
> 
> Cc: Guenter Roeck <linux@roeck-us.net>
> Link: https://lore.kernel.org/dri-devel/16cd212f-6ea0-471d-bf32-34f55d7292fe@roeck-us.net/
> Signed-off-by: Philipp Stanner <phasta@kernel.org>
> ---
> @Guenther: Can you please test this? I hope it fixes your issue.

Yes, it does. Thanks a lot for fixing this!

Tested-by: Guenter Roeck <linux@roeck-us.net>

> ---
>   drivers/tty/serial/8250/8250_pcilib.c | 9 +++++----
>   1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_pcilib.c b/drivers/tty/serial/8250/8250_pcilib.c
> index d8d0ae0d7238..f98eb2ab1005 100644
> --- a/drivers/tty/serial/8250/8250_pcilib.c
> +++ b/drivers/tty/serial/8250/8250_pcilib.c
> @@ -28,13 +28,14 @@ int serial8250_pci_setup_port(struct pci_dev *dev, struct uart_8250_port *port,
>   		return -EINVAL;
>   
>   	if (pci_resource_flags(dev, bar) & IORESOURCE_MEM) {
> -		if (!pcim_iomap(dev, bar, 0) && !pcim_iomap_table(dev))
> -			return -ENOMEM;
> -
>   		port->port.iotype = UPIO_MEM;
>   		port->port.iobase = 0;
>   		port->port.mapbase = pci_resource_start(dev, bar) + offset;
> -		port->port.membase = pcim_iomap_table(dev)[bar] + offset;
> +
> +		port->port.membase = pcim_iomap_range(dev, bar, offset, 0);
> +		if (IS_ERR(port->port.membase))
> +			return PTR_ERR(port->port.membase);
> +
>   		port->port.regshift = regshift;
>   	} else if (IS_ENABLED(CONFIG_HAS_IOPORT)) {
>   		port->port.iotype = UPIO_PORT;