Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tty: serial: handle HAS_IOPORT dependencies

In a future patch HAS_IOPORT=n will disable inb()/outb() and friends at
compile time. We thus need to add HAS_IOPORT as dependency for those
drivers using them unconditionally. Some 8250 serial drivers support
MMIO only use, so fence only the parts requiring I/O ports and print an
error message if a device can't be supported with the current
configuration.

Co-developed-by: Arnd Bergmann <arnd@kernel.org>
Signed-off-by: Arnd Bergmann <arnd@kernel.org>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Maciej W. Rozycki <macro@orcam.me.uk>
Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>

authored by

Niklas Schnelle and committed by
Arnd Bergmann
7c7e6c89 f663c6ae

+89 -10
+2 -2
drivers/tty/Kconfig
··· 220 220 221 221 config MOXA_SMARTIO 222 222 tristate "Moxa SmartIO support v. 2.0" 223 - depends on SERIAL_NONSTANDARD && PCI 223 + depends on SERIAL_NONSTANDARD && PCI && HAS_IOPORT 224 224 help 225 225 Say Y here if you have a Moxa SmartIO multiport serial card and/or 226 226 want to help develop a new version of this driver. ··· 302 302 303 303 config IPWIRELESS 304 304 tristate "IPWireless 3G UMTS PCMCIA card support" 305 - depends on PCMCIA && NETDEVICES 305 + depends on PCMCIA && NETDEVICES && HAS_IOPORT 306 306 select PPP 307 307 help 308 308 This is a driver for 3G UMTS PCMCIA card from IPWireless company. In
+4
drivers/tty/serial/8250/8250_early.c
··· 46 46 return readl(port->membase + offset); 47 47 case UPIO_MEM32BE: 48 48 return ioread32be(port->membase + offset); 49 + #ifdef CONFIG_HAS_IOPORT 49 50 case UPIO_PORT: 50 51 return inb(port->iobase + offset); 52 + #endif 51 53 default: 52 54 return 0; 53 55 } ··· 72 70 case UPIO_MEM32BE: 73 71 iowrite32be(value, port->membase + offset); 74 72 break; 73 + #ifdef CONFIG_HAS_IOPORT 75 74 case UPIO_PORT: 76 75 outb(value, port->iobase + offset); 77 76 break; 77 + #endif 78 78 } 79 79 } 80 80
+40
drivers/tty/serial/8250/8250_pci.c
··· 964 964 struct resource *iobase = NULL; 965 965 u32 miscr, uartbar, ioport; 966 966 967 + if (!IS_ENABLED(CONFIG_HAS_IOPORT)) 968 + return serial_8250_warn_need_ioport(dev); 969 + 967 970 /* search for the base-ioport */ 968 971 for (i = 0; i < ARRAY_SIZE(inta_addr); i++) { 969 972 iobase = request_region(inta_addr[i], ITE_887x_IOSIZE, ··· 1517 1514 const struct pci_device_id *match; 1518 1515 bool amcc = false; 1519 1516 1517 + if (!IS_ENABLED(CONFIG_HAS_IOPORT)) 1518 + return serial_8250_warn_need_ioport(dev); 1519 + 1520 1520 match = pci_match_id(quatech_cards, dev); 1521 1521 if (match) 1522 1522 amcc = match->driver_data; ··· 1544 1538 const struct pciserial_board *board, 1545 1539 struct uart_8250_port *port, int idx) 1546 1540 { 1541 + if (!IS_ENABLED(CONFIG_HAS_IOPORT)) 1542 + return serial_8250_warn_need_ioport(priv->dev); 1543 + 1547 1544 /* Needed by pci_quatech calls below */ 1548 1545 port->port.iobase = pci_resource_start(priv->dev, FL_GET_BASE(board->flags)); 1549 1546 /* Set up the clocking */ ··· 1664 1655 u8 config_base; 1665 1656 u16 iobase; 1666 1657 1658 + if (!IS_ENABLED(CONFIG_HAS_IOPORT)) 1659 + return serial_8250_warn_need_ioport(pdev); 1660 + 1667 1661 config_base = 0x40 + 0x08 * idx; 1668 1662 1669 1663 /* Get the io address from configuration space */ ··· 1697 1685 resource_size_t bar_data[3]; 1698 1686 u8 config_base; 1699 1687 struct serial_private *priv = pci_get_drvdata(dev); 1688 + 1689 + if (!IS_ENABLED(CONFIG_HAS_IOPORT)) 1690 + return serial_8250_warn_need_ioport(dev); 1700 1691 1701 1692 if (!(pci_resource_flags(dev, 5) & IORESOURCE_IO) || 1702 1693 !(pci_resource_flags(dev, 4) & IORESOURCE_IO) || ··· 1879 1864 const struct pciserial_board *board, 1880 1865 struct uart_8250_port *port, int idx) 1881 1866 { 1867 + if (!IS_ENABLED(CONFIG_HAS_IOPORT)) 1868 + return serial_8250_warn_need_ioport(priv->dev); 1869 + 1882 1870 port->port.flags |= UPF_BUG_THRE; 1883 1871 port->port.serial_in = kt_serial_in; 1884 1872 port->port.handle_break = kt_handle_break; ··· 1902 1884 const struct pciserial_board *board, 1903 1885 struct uart_8250_port *port, int idx) 1904 1886 { 1887 + if (!IS_ENABLED(CONFIG_HAS_IOPORT)) 1888 + return serial_8250_warn_need_ioport(priv->dev); 1889 + 1905 1890 port->port.flags |= UPF_FIXED_TYPE; 1906 1891 port->port.type = PORT_16550A; 1907 1892 return pci_default_setup(priv, board, port, idx); ··· 1915 1894 const struct pciserial_board *board, 1916 1895 struct uart_8250_port *port, int idx) 1917 1896 { 1897 + if (!IS_ENABLED(CONFIG_HAS_IOPORT)) 1898 + return serial_8250_warn_need_ioport(priv->dev); 1899 + 1918 1900 port->port.flags |= UPF_FIXED_TYPE; 1919 1901 port->port.type = PORT_16550A; 1920 1902 return pci_default_setup(priv, board, port, idx); ··· 1928 1904 const struct pciserial_board *board, 1929 1905 struct uart_8250_port *port, int idx) 1930 1906 { 1907 + if (!IS_ENABLED(CONFIG_HAS_IOPORT)) 1908 + return serial_8250_warn_need_ioport(priv->dev); 1909 + 1931 1910 port->port.flags |= UPF_FIXED_TYPE; 1932 1911 port->port.type = PORT_16850; 1933 1912 return pci_default_setup(priv, board, port, idx); ··· 1945 1918 int max_port; 1946 1919 unsigned long iobase; 1947 1920 1921 + if (!IS_ENABLED(CONFIG_HAS_IOPORT)) 1922 + return serial_8250_warn_need_ioport(dev); 1948 1923 1949 1924 switch (dev->device) { 1950 1925 case 0x3853: /* 8 ports */ ··· 1965 1936 static void pci_wch_ch38x_exit(struct pci_dev *dev) 1966 1937 { 1967 1938 unsigned long iobase; 1939 + 1940 + if (!IS_ENABLED(CONFIG_HAS_IOPORT)) { 1941 + serial_8250_warn_need_ioport(dev); 1942 + return; 1943 + } 1968 1944 1969 1945 iobase = pci_resource_start(dev, 0); 1970 1946 outb(0x0, iobase + CH384_XINT_ENABLE_REG); ··· 2086 2052 unsigned int i, num_ports = moxa_get_nports(device); 2087 2053 u8 val, init_mode = MOXA_RS232; 2088 2054 2055 + if (!IS_ENABLED(CONFIG_HAS_IOPORT)) 2056 + return serial_8250_warn_need_ioport(dev); 2057 + 2089 2058 if (!(pci_moxa_supported_rs(dev) & MOXA_SUPP_RS232)) { 2090 2059 init_mode = MOXA_RS422; 2091 2060 } ··· 2120 2083 { 2121 2084 unsigned int bar = FL_GET_BASE(board->flags); 2122 2085 int offset; 2086 + 2087 + if (!IS_ENABLED(CONFIG_HAS_IOPORT)) 2088 + return serial_8250_warn_need_ioport(priv->dev); 2123 2089 2124 2090 if (board->num_ports == 4 && idx == 3) 2125 2091 offset = 7 * board->uart_offset;
+11 -1
drivers/tty/serial/8250/8250_pcilib.c
··· 12 12 #include "8250.h" 13 13 #include "8250_pcilib.h" 14 14 15 + int serial_8250_warn_need_ioport(struct pci_dev *dev) 16 + { 17 + dev_warn(&dev->dev, 18 + "Serial port not supported because of missing I/O resource\n"); 19 + 20 + return -ENXIO; 21 + } 22 + 15 23 int serial8250_pci_setup_port(struct pci_dev *dev, struct uart_8250_port *port, 16 24 u8 bar, unsigned int offset, int regshift) 17 25 { ··· 35 27 port->port.mapbase = pci_resource_start(dev, bar) + offset; 36 28 port->port.membase = pcim_iomap_table(dev)[bar] + offset; 37 29 port->port.regshift = regshift; 38 - } else { 30 + } else if (IS_ENABLED(CONFIG_HAS_IOPORT)) { 39 31 port->port.iotype = UPIO_PORT; 40 32 port->port.iobase = pci_resource_start(dev, bar) + offset; 41 33 port->port.mapbase = 0; 42 34 port->port.membase = NULL; 43 35 port->port.regshift = 0; 36 + } else { 37 + return serial_8250_warn_need_ioport(dev); 44 38 } 45 39 return 0; 46 40 }
+2
drivers/tty/serial/8250/8250_pcilib.h
··· 13 13 14 14 int serial8250_pci_setup_port(struct pci_dev *dev, struct uart_8250_port *port, u8 bar, 15 15 unsigned int offset, int regshift); 16 + 17 + int serial_8250_warn_need_ioport(struct pci_dev *dev);
+23 -4
drivers/tty/serial/8250/8250_port.c
··· 338 338 serial_out(up, UART_DLM, value >> 8 & 0xff); 339 339 } 340 340 341 + #ifdef CONFIG_HAS_IOPORT 341 342 static unsigned int hub6_serial_in(struct uart_port *p, int offset) 342 343 { 343 344 offset = offset << p->regshift; ··· 352 351 outb(p->hub6 - 1 + offset, p->iobase); 353 352 outb(value, p->iobase + 1); 354 353 } 354 + #endif /* CONFIG_HAS_IOPORT */ 355 355 356 356 static unsigned int mem_serial_in(struct uart_port *p, int offset) 357 357 { ··· 402 400 return ioread32be(p->membase + offset); 403 401 } 404 402 403 + #ifdef CONFIG_HAS_IOPORT 405 404 static unsigned int io_serial_in(struct uart_port *p, int offset) 406 405 { 407 406 offset = offset << p->regshift; ··· 413 410 { 414 411 offset = offset << p->regshift; 415 412 outb(value, p->iobase + offset); 413 + } 414 + #endif 415 + static unsigned int no_serial_in(struct uart_port *p, int offset) 416 + { 417 + return (unsigned int)-1; 418 + } 419 + 420 + static void no_serial_out(struct uart_port *p, int offset, int value) 421 + { 416 422 } 417 423 418 424 static int serial8250_default_handle_irq(struct uart_port *port); ··· 434 422 up->dl_write = default_serial_dl_write; 435 423 436 424 switch (p->iotype) { 425 + #ifdef CONFIG_HAS_IOPORT 437 426 case UPIO_HUB6: 438 427 p->serial_in = hub6_serial_in; 439 428 p->serial_out = hub6_serial_out; 440 429 break; 430 + #endif 441 431 442 432 case UPIO_MEM: 443 433 p->serial_in = mem_serial_in; ··· 460 446 p->serial_in = mem32be_serial_in; 461 447 p->serial_out = mem32be_serial_out; 462 448 break; 463 - 464 - default: 449 + #ifdef CONFIG_HAS_IOPORT 450 + case UPIO_PORT: 465 451 p->serial_in = io_serial_in; 466 452 p->serial_out = io_serial_out; 467 453 break; 454 + #endif 455 + default: 456 + WARN(1, "Unsupported UART type %x\n", p->iotype); 457 + p->serial_in = no_serial_in; 458 + p->serial_out = no_serial_out; 468 459 } 469 460 /* Remember loaded iotype */ 470 461 up->cur_iotype = p->iotype; ··· 1193 1174 */ 1194 1175 scratch = serial_in(up, UART_IER); 1195 1176 serial_out(up, UART_IER, 0); 1196 - #ifdef __i386__ 1177 + #if defined(__i386__) && defined(CONFIG_HAS_IOPORT) 1197 1178 outb(0xff, 0x080); 1198 1179 #endif 1199 1180 /* ··· 1202 1183 */ 1203 1184 scratch2 = serial_in(up, UART_IER) & UART_IER_ALL_INTR; 1204 1185 serial_out(up, UART_IER, UART_IER_ALL_INTR); 1205 - #ifdef __i386__ 1186 + #if defined(__i386__) && defined(CONFIG_HAS_IOPORT) 1206 1187 outb(0, 0x080); 1207 1188 #endif 1208 1189 scratch3 = serial_in(up, UART_IER) & UART_IER_ALL_INTR;
+2 -2
drivers/tty/serial/8250/Kconfig
··· 72 72 73 73 config SERIAL_8250_FINTEK 74 74 bool "Support for Fintek variants" 75 - depends on SERIAL_8250 75 + depends on SERIAL_8250 && HAS_IOPORT 76 76 help 77 77 Selecting this option will add support for the RS232 and RS485 78 78 capabilities of the Fintek F81216A LPC to 4 UART as well similar ··· 163 163 164 164 config SERIAL_8250_CS 165 165 tristate "8250/16550 PCMCIA device support" 166 - depends on PCMCIA && SERIAL_8250 166 + depends on PCMCIA && SERIAL_8250 && HAS_IOPORT 167 167 help 168 168 Say Y here to enable support for 16-bit PCMCIA serial devices, 169 169 including serial port cards, modems, and the modem functions of
+1 -1
drivers/tty/serial/Kconfig
··· 877 877 878 878 config SERIAL_JSM 879 879 tristate "Digi International NEO and Classic PCI Support" 880 - depends on PCI 880 + depends on PCI && HAS_IOPORT 881 881 select SERIAL_CORE 882 882 help 883 883 This is a driver for Digi International's Neo and Classic series
+4
include/linux/serial_core.h
··· 505 505 * The remaining bits are serial-core specific and not modifiable by 506 506 * userspace. 507 507 */ 508 + #ifdef CONFIG_HAS_IOPORT 508 509 #define UPF_FOURPORT ((__force upf_t) ASYNC_FOURPORT /* 1 */ ) 510 + #else 511 + #define UPF_FOURPORT 0 512 + #endif 509 513 #define UPF_SAK ((__force upf_t) ASYNC_SAK /* 2 */ ) 510 514 #define UPF_SPD_HI ((__force upf_t) ASYNC_SPD_HI /* 4 */ ) 511 515 #define UPF_SPD_VHI ((__force upf_t) ASYNC_SPD_VHI /* 5 */ )