Skip to content

Commit 7c7e6c8

Browse files
niklas88arndb
authored andcommitted
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>
1 parent f663c6a commit 7c7e6c8

9 files changed

Lines changed: 89 additions & 10 deletions

File tree

drivers/tty/Kconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ config MOXA_INTELLIO
220220

221221
config MOXA_SMARTIO
222222
tristate "Moxa SmartIO support v. 2.0"
223-
depends on SERIAL_NONSTANDARD && PCI
223+
depends on SERIAL_NONSTANDARD && PCI && HAS_IOPORT
224224
help
225225
Say Y here if you have a Moxa SmartIO multiport serial card and/or
226226
want to help develop a new version of this driver.
@@ -302,7 +302,7 @@ config GOLDFISH_TTY_EARLY_CONSOLE
302302

303303
config IPWIRELESS
304304
tristate "IPWireless 3G UMTS PCMCIA card support"
305-
depends on PCMCIA && NETDEVICES
305+
depends on PCMCIA && NETDEVICES && HAS_IOPORT
306306
select PPP
307307
help
308308
This is a driver for 3G UMTS PCMCIA card from IPWireless company. In

drivers/tty/serial/8250/8250_early.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ static unsigned int serial8250_early_in(struct uart_port *port, int offset)
4646
return readl(port->membase + offset);
4747
case UPIO_MEM32BE:
4848
return ioread32be(port->membase + offset);
49+
#ifdef CONFIG_HAS_IOPORT
4950
case UPIO_PORT:
5051
return inb(port->iobase + offset);
52+
#endif
5153
default:
5254
return 0;
5355
}
@@ -70,9 +72,11 @@ static void serial8250_early_out(struct uart_port *port, int offset, int value)
7072
case UPIO_MEM32BE:
7173
iowrite32be(value, port->membase + offset);
7274
break;
75+
#ifdef CONFIG_HAS_IOPORT
7376
case UPIO_PORT:
7477
outb(value, port->iobase + offset);
7578
break;
79+
#endif
7680
}
7781
}
7882

drivers/tty/serial/8250/8250_pci.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,9 @@ static int pci_ite887x_init(struct pci_dev *dev)
964964
struct resource *iobase = NULL;
965965
u32 miscr, uartbar, ioport;
966966

967+
if (!IS_ENABLED(CONFIG_HAS_IOPORT))
968+
return serial_8250_warn_need_ioport(dev);
969+
967970
/* search for the base-ioport */
968971
for (i = 0; i < ARRAY_SIZE(inta_addr); i++) {
969972
iobase = request_region(inta_addr[i], ITE_887x_IOSIZE,
@@ -1514,6 +1517,9 @@ static int pci_quatech_init(struct pci_dev *dev)
15141517
const struct pci_device_id *match;
15151518
bool amcc = false;
15161519

1520+
if (!IS_ENABLED(CONFIG_HAS_IOPORT))
1521+
return serial_8250_warn_need_ioport(dev);
1522+
15171523
match = pci_match_id(quatech_cards, dev);
15181524
if (match)
15191525
amcc = match->driver_data;
@@ -1538,6 +1544,9 @@ static int pci_quatech_setup(struct serial_private *priv,
15381544
const struct pciserial_board *board,
15391545
struct uart_8250_port *port, int idx)
15401546
{
1547+
if (!IS_ENABLED(CONFIG_HAS_IOPORT))
1548+
return serial_8250_warn_need_ioport(priv->dev);
1549+
15411550
/* Needed by pci_quatech calls below */
15421551
port->port.iobase = pci_resource_start(priv->dev, FL_GET_BASE(board->flags));
15431552
/* Set up the clocking */
@@ -1655,6 +1664,9 @@ static int pci_fintek_setup(struct serial_private *priv,
16551664
u8 config_base;
16561665
u16 iobase;
16571666

1667+
if (!IS_ENABLED(CONFIG_HAS_IOPORT))
1668+
return serial_8250_warn_need_ioport(pdev);
1669+
16581670
config_base = 0x40 + 0x08 * idx;
16591671

16601672
/* Get the io address from configuration space */
@@ -1686,6 +1698,9 @@ static int pci_fintek_init(struct pci_dev *dev)
16861698
u8 config_base;
16871699
struct serial_private *priv = pci_get_drvdata(dev);
16881700

1701+
if (!IS_ENABLED(CONFIG_HAS_IOPORT))
1702+
return serial_8250_warn_need_ioport(dev);
1703+
16891704
if (!(pci_resource_flags(dev, 5) & IORESOURCE_IO) ||
16901705
!(pci_resource_flags(dev, 4) & IORESOURCE_IO) ||
16911706
!(pci_resource_flags(dev, 3) & IORESOURCE_IO))
@@ -1864,6 +1879,9 @@ static int kt_serial_setup(struct serial_private *priv,
18641879
const struct pciserial_board *board,
18651880
struct uart_8250_port *port, int idx)
18661881
{
1882+
if (!IS_ENABLED(CONFIG_HAS_IOPORT))
1883+
return serial_8250_warn_need_ioport(priv->dev);
1884+
18671885
port->port.flags |= UPF_BUG_THRE;
18681886
port->port.serial_in = kt_serial_in;
18691887
port->port.handle_break = kt_handle_break;
@@ -1884,6 +1902,9 @@ pci_wch_ch353_setup(struct serial_private *priv,
18841902
const struct pciserial_board *board,
18851903
struct uart_8250_port *port, int idx)
18861904
{
1905+
if (!IS_ENABLED(CONFIG_HAS_IOPORT))
1906+
return serial_8250_warn_need_ioport(priv->dev);
1907+
18871908
port->port.flags |= UPF_FIXED_TYPE;
18881909
port->port.type = PORT_16550A;
18891910
return pci_default_setup(priv, board, port, idx);
@@ -1894,6 +1915,9 @@ pci_wch_ch355_setup(struct serial_private *priv,
18941915
const struct pciserial_board *board,
18951916
struct uart_8250_port *port, int idx)
18961917
{
1918+
if (!IS_ENABLED(CONFIG_HAS_IOPORT))
1919+
return serial_8250_warn_need_ioport(priv->dev);
1920+
18971921
port->port.flags |= UPF_FIXED_TYPE;
18981922
port->port.type = PORT_16550A;
18991923
return pci_default_setup(priv, board, port, idx);
@@ -1904,6 +1928,9 @@ pci_wch_ch38x_setup(struct serial_private *priv,
19041928
const struct pciserial_board *board,
19051929
struct uart_8250_port *port, int idx)
19061930
{
1931+
if (!IS_ENABLED(CONFIG_HAS_IOPORT))
1932+
return serial_8250_warn_need_ioport(priv->dev);
1933+
19071934
port->port.flags |= UPF_FIXED_TYPE;
19081935
port->port.type = PORT_16850;
19091936
return pci_default_setup(priv, board, port, idx);
@@ -1918,6 +1945,8 @@ static int pci_wch_ch38x_init(struct pci_dev *dev)
19181945
int max_port;
19191946
unsigned long iobase;
19201947

1948+
if (!IS_ENABLED(CONFIG_HAS_IOPORT))
1949+
return serial_8250_warn_need_ioport(dev);
19211950

19221951
switch (dev->device) {
19231952
case 0x3853: /* 8 ports */
@@ -1937,6 +1966,11 @@ static void pci_wch_ch38x_exit(struct pci_dev *dev)
19371966
{
19381967
unsigned long iobase;
19391968

1969+
if (!IS_ENABLED(CONFIG_HAS_IOPORT)) {
1970+
serial_8250_warn_need_ioport(dev);
1971+
return;
1972+
}
1973+
19401974
iobase = pci_resource_start(dev, 0);
19411975
outb(0x0, iobase + CH384_XINT_ENABLE_REG);
19421976
}
@@ -2052,6 +2086,9 @@ static int pci_moxa_init(struct pci_dev *dev)
20522086
unsigned int i, num_ports = moxa_get_nports(device);
20532087
u8 val, init_mode = MOXA_RS232;
20542088

2089+
if (!IS_ENABLED(CONFIG_HAS_IOPORT))
2090+
return serial_8250_warn_need_ioport(dev);
2091+
20552092
if (!(pci_moxa_supported_rs(dev) & MOXA_SUPP_RS232)) {
20562093
init_mode = MOXA_RS422;
20572094
}
@@ -2084,6 +2121,9 @@ pci_moxa_setup(struct serial_private *priv,
20842121
unsigned int bar = FL_GET_BASE(board->flags);
20852122
int offset;
20862123

2124+
if (!IS_ENABLED(CONFIG_HAS_IOPORT))
2125+
return serial_8250_warn_need_ioport(priv->dev);
2126+
20872127
if (board->num_ports == 4 && idx == 3)
20882128
offset = 7 * board->uart_offset;
20892129
else

drivers/tty/serial/8250/8250_pcilib.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
#include "8250.h"
1313
#include "8250_pcilib.h"
1414

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+
1523
int serial8250_pci_setup_port(struct pci_dev *dev, struct uart_8250_port *port,
1624
u8 bar, unsigned int offset, int regshift)
1725
{
@@ -27,12 +35,14 @@ int serial8250_pci_setup_port(struct pci_dev *dev, struct uart_8250_port *port,
2735
port->port.mapbase = pci_resource_start(dev, bar) + offset;
2836
port->port.membase = pcim_iomap_table(dev)[bar] + offset;
2937
port->port.regshift = regshift;
30-
} else {
38+
} else if (IS_ENABLED(CONFIG_HAS_IOPORT)) {
3139
port->port.iotype = UPIO_PORT;
3240
port->port.iobase = pci_resource_start(dev, bar) + offset;
3341
port->port.mapbase = 0;
3442
port->port.membase = NULL;
3543
port->port.regshift = 0;
44+
} else {
45+
return serial_8250_warn_need_ioport(dev);
3646
}
3747
return 0;
3848
}

drivers/tty/serial/8250/8250_pcilib.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ struct uart_8250_port;
1313

1414
int serial8250_pci_setup_port(struct pci_dev *dev, struct uart_8250_port *port, u8 bar,
1515
unsigned int offset, int regshift);
16+
17+
int serial_8250_warn_need_ioport(struct pci_dev *dev);

drivers/tty/serial/8250/8250_port.c

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ static void default_serial_dl_write(struct uart_8250_port *up, u32 value)
338338
serial_out(up, UART_DLM, value >> 8 & 0xff);
339339
}
340340

341+
#ifdef CONFIG_HAS_IOPORT
341342
static unsigned int hub6_serial_in(struct uart_port *p, int offset)
342343
{
343344
offset = offset << p->regshift;
@@ -351,6 +352,7 @@ static void hub6_serial_out(struct uart_port *p, int offset, int value)
351352
outb(p->hub6 - 1 + offset, p->iobase);
352353
outb(value, p->iobase + 1);
353354
}
355+
#endif /* CONFIG_HAS_IOPORT */
354356

355357
static unsigned int mem_serial_in(struct uart_port *p, int offset)
356358
{
@@ -400,6 +402,7 @@ static unsigned int mem32be_serial_in(struct uart_port *p, int offset)
400402
return ioread32be(p->membase + offset);
401403
}
402404

405+
#ifdef CONFIG_HAS_IOPORT
403406
static unsigned int io_serial_in(struct uart_port *p, int offset)
404407
{
405408
offset = offset << p->regshift;
@@ -411,6 +414,15 @@ static void io_serial_out(struct uart_port *p, int offset, int value)
411414
offset = offset << p->regshift;
412415
outb(value, p->iobase + offset);
413416
}
417+
#endif
418+
static unsigned int no_serial_in(struct uart_port *p, int offset)
419+
{
420+
return (unsigned int)-1;
421+
}
422+
423+
static void no_serial_out(struct uart_port *p, int offset, int value)
424+
{
425+
}
414426

415427
static int serial8250_default_handle_irq(struct uart_port *port);
416428

@@ -422,10 +434,12 @@ static void set_io_from_upio(struct uart_port *p)
422434
up->dl_write = default_serial_dl_write;
423435

424436
switch (p->iotype) {
437+
#ifdef CONFIG_HAS_IOPORT
425438
case UPIO_HUB6:
426439
p->serial_in = hub6_serial_in;
427440
p->serial_out = hub6_serial_out;
428441
break;
442+
#endif
429443

430444
case UPIO_MEM:
431445
p->serial_in = mem_serial_in;
@@ -446,11 +460,16 @@ static void set_io_from_upio(struct uart_port *p)
446460
p->serial_in = mem32be_serial_in;
447461
p->serial_out = mem32be_serial_out;
448462
break;
449-
450-
default:
463+
#ifdef CONFIG_HAS_IOPORT
464+
case UPIO_PORT:
451465
p->serial_in = io_serial_in;
452466
p->serial_out = io_serial_out;
453467
break;
468+
#endif
469+
default:
470+
WARN(1, "Unsupported UART type %x\n", p->iotype);
471+
p->serial_in = no_serial_in;
472+
p->serial_out = no_serial_out;
454473
}
455474
/* Remember loaded iotype */
456475
up->cur_iotype = p->iotype;
@@ -1174,7 +1193,7 @@ static void autoconfig(struct uart_8250_port *up)
11741193
*/
11751194
scratch = serial_in(up, UART_IER);
11761195
serial_out(up, UART_IER, 0);
1177-
#ifdef __i386__
1196+
#if defined(__i386__) && defined(CONFIG_HAS_IOPORT)
11781197
outb(0xff, 0x080);
11791198
#endif
11801199
/*
@@ -1183,7 +1202,7 @@ static void autoconfig(struct uart_8250_port *up)
11831202
*/
11841203
scratch2 = serial_in(up, UART_IER) & UART_IER_ALL_INTR;
11851204
serial_out(up, UART_IER, UART_IER_ALL_INTR);
1186-
#ifdef __i386__
1205+
#if defined(__i386__) && defined(CONFIG_HAS_IOPORT)
11871206
outb(0, 0x080);
11881207
#endif
11891208
scratch3 = serial_in(up, UART_IER) & UART_IER_ALL_INTR;

drivers/tty/serial/8250/Kconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ config SERIAL_8250_16550A_VARIANTS
7272

7373
config SERIAL_8250_FINTEK
7474
bool "Support for Fintek variants"
75-
depends on SERIAL_8250
75+
depends on SERIAL_8250 && HAS_IOPORT
7676
help
7777
Selecting this option will add support for the RS232 and RS485
7878
capabilities of the Fintek F81216A LPC to 4 UART as well similar
@@ -163,7 +163,7 @@ config SERIAL_8250_HP300
163163

164164
config SERIAL_8250_CS
165165
tristate "8250/16550 PCMCIA device support"
166-
depends on PCMCIA && SERIAL_8250
166+
depends on PCMCIA && SERIAL_8250 && HAS_IOPORT
167167
help
168168
Say Y here to enable support for 16-bit PCMCIA serial devices,
169169
including serial port cards, modems, and the modem functions of

drivers/tty/serial/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ config SERIAL_TXX9_STDSERIAL
877877

878878
config SERIAL_JSM
879879
tristate "Digi International NEO and Classic PCI Support"
880-
depends on PCI
880+
depends on PCI && HAS_IOPORT
881881
select SERIAL_CORE
882882
help
883883
This is a driver for Digi International's Neo and Classic series

include/linux/serial_core.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,11 @@ struct uart_port {
505505
* The remaining bits are serial-core specific and not modifiable by
506506
* userspace.
507507
*/
508+
#ifdef CONFIG_HAS_IOPORT
508509
#define UPF_FOURPORT ((__force upf_t) ASYNC_FOURPORT /* 1 */ )
510+
#else
511+
#define UPF_FOURPORT 0
512+
#endif
509513
#define UPF_SAK ((__force upf_t) ASYNC_SAK /* 2 */ )
510514
#define UPF_SPD_HI ((__force upf_t) ASYNC_SPD_HI /* 4 */ )
511515
#define UPF_SPD_VHI ((__force upf_t) ASYNC_SPD_VHI /* 5 */ )

0 commit comments

Comments
 (0)