serial: explicitly request ttyS0-3 for COM1-4
cover serial: explicitly request ttyS0-3 for COM1-4
When 8250_pnp discovers COM ports, we only get the correct ttyS names by accident -- we rely on serial8250_isa_init_ports(), which discovers the COM ports earlier using the addresses in SERIAL_PORT_DFNS.
These two patches remove the dependency on SERIAL_PORT_DFNS by explicitly requesting the desired ttyS names.
PATCH 1/2 8250: add serial8250_register_port_at() for requesting specific ttyS lines
Add an interface for registering a new UART with a specific ttyS name.
include/linux/serial_8250.h +1 -0
@@ -56,6 +56,7 @@struct uart_port ;int serial8250_register_port (struct uart_port *); +int serial8250_register_port_at (struct uart_port *,int line);void serial8250_unregister_port (int line);void serial8250_suspend_port (int line);void serial8250_resume_port (int line);
drivers/serial/8250.c +63 -18
101 lines not on this page · raw message
PATCH 2/2 8250_pnp: register x86 COM ports at the conventional ttyS names
In reply to Bjorn Helgaasx86 users expect COM1-COM4 ports at the conventional ioport addresses to be named ttyS0-ttyS3. For PNP devices, the BIOS determines the order we discover them, so we might discover COM2 before COM1.
We currently always get the correct names, even without this patch. But that's only because serial8250_isa_init_ports() first registers the hard-coded list of COM port addresses from SERIAL_PORT_DFNS. When PNP rediscovers one of those ports, it gets the already-established line.
This patch removes the implicit dependency on SERIAL_PORT_DFNS by requesting the names we desire.
drivers/serial/8250_pnp.c +26 -1
@@ -427,6 +427,21 @@ }static int __devinit +serial_pnp_line (struct uart_port *port) +{ +#ifdef CONFIG_X86 +switch (port->iobase) { +case 0x3f8 :return 0 ;/* COM1 -> ttyS0 */ +case 0x2f8 :return 1 ;/* COM2 -> ttyS1 */ +case 0x3e8 :return 2 ;/* COM3 -> ttyS2 */ +case 0x2e8 :return 3 ;/* COM4 -> ttyS3 */ + } +#endif + +return -ENODEV ; +} + +static int __devinit serial_pnp_probe (struct pnp_dev *dev,const struct pnp_device_id *dev_id) {struct uart_port port;
@@ -462,7 +477,17 @@ port.uartclk =1843200 ; port.dev = &dev->dev; - line =serial8250_register_port (&port); + line =serial_pnp_line (&port); +if (line >=0 ) + line =serial8250_register_port_at (&port, line); + +/* +* If the desired line was busy, or if we don't care which line +* we get, use the regular registration. +*/ +if (line <0 ) + line =serial8250_register_port (&port); +if (line <0 )return -ENODEV ;
Re: [patch 2/2] 8250_pnp: register x86 COM ports at the conventional ttyS names
drivers/serial/8250_pnp.c line 439
Quoted 11 lines · Bjorn Helgaas
static int
__devinitdrivers/serial/8250_pnp.c +10
-0+serial_pnp_line(struct uart_port *port) +{ +#ifdef CONFIG_X86 +switch (port->iobase) { +case 0x3f8 :return 0 ;/* COM1 -> ttyS0 */ +case 0x2f8 :return 1 ;/* COM2 -> ttyS1 */ +case 0x3e8 :return 2 ;/* COM3 -> ttyS2 */ +case 0x2e8 :return 3 ;/* COM4 -> ttyS3 */ + } +#endif
So what if someone intentionally modifies SERIAL_DEFN_PORTS to point ttyS[0-3] somewhere else? They also have to modify this code as well.
Signature · 3 lines
Russell King Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/ maintainer of:
Re: [patch 2/2] 8250_pnp: register x86 COM ports at the conventional ttyS names
In reply to Bjorn HelgaasQuoted 15 lines · Bjorn Helgaas
x86 users expect COM1-COM4 ports at the conventional ioport addresses to be named ttyS0-ttyS3. For PNP devices, the BIOS determines the order we discover them, so we might discover COM2 before COM1.
We currently always get the correct names, even without this patch. But that's only because
serial8250_isa_init_ports()first registers the hard-coded list of COM port addresses fromSERIAL_PORT_DFNS. When PNP rediscovers one of those ports, it gets the already-established line.This patch removes the implicit dependency on
SERIAL_PORT_DFNSby requesting the names we desire.static int
__devinitdrivers/serial/8250_pnp.c +1
-0+serial_pnp_line(struct uart_port *port)
drivers/serial/8250_pnp.c line 440
Quoted 10 lines
drivers/serial/8250_pnp.c +10
-0+{ +#ifdef CONFIG_X86 +switch (port->iobase) { +case 0x3f8 :return 0 ;/* COM1 -> ttyS0 */ +case 0x2f8 :return 1 ;/* COM2 -> ttyS1 */ +case 0x3e8 :return 2 ;/* COM3 -> ttyS2 */ +case 0x2e8 :return 3 ;/* COM4 -> ttyS3 */ + } +#endif +
Arguably, the right thing is to use the addresses present in the array at address 0x400. In particular, COM3 and COM4 aren't always at those addresses.
-hpa
Re: [patch 2/2] 8250_pnp: register x86 COM ports at the conventional ttyS names
Quoted 14 lines · H. Peter Anvin
Quoted 13 lines · Bjorn Helgaas
x86 users expect COM1-COM4 ports at the conventional ioport addresses to be named ttyS0-ttyS3. For PNP devices, the BIOS determines the order we discover them, so we might discover COM2 before COM1.
We currently always get the correct names, even without this patch. But that's only because
serial8250_isa_init_ports()first registers the hard-coded list of COM port addresses fromSERIAL_PORT_DFNS. When PNP rediscovers one of those ports, it gets the already-established line.This patch removes the implicit dependency on
SERIAL_PORT_DFNSby requesting the names we desire.
Quoted 16 lines
drivers/serial/8250_pnp.c line 440
Quoted 12 lines
static int
__devinitdrivers/serial/8250_pnp.c +11
-0+serial_pnp_line(struct uart_port *port) +{ +#ifdef CONFIG_X86 +switch (port->iobase) { +case 0x3f8 :return 0 ;/* COM1 -> ttyS0 */ +case 0x2f8 :return 1 ;/* COM2 -> ttyS1 */ +case 0x3e8 :return 2 ;/* COM3 -> ttyS2 */ +case 0x2e8 :return 3 ;/* COM4 -> ttyS3 */ + } +#endif +Arguably, the right thing is to use the addresses present in the array at address
0x400. In particular, COM3 and COM4 aren't always at those addresses.
Wow. I bow before your storehouse of x86 arcana :-)
I guess you're referring to the "BIOS data area," which I'd never heard of before (but fortunately, Google knows).
What would you think about doing this only for COM1 and COM2? The only real value for doing this in the first place is so "console=ttyS0" always goes to COM1, even if we don't have SERIAL_PORT_DFNS. User- space ought to use some sort of udev magic if it cares about persistent naming.
Bjorn
Re: [patch 2/2] 8250_pnp: register x86 COM ports at the conventional ttyS names
Quoted 5 lines · Bjorn Helgaas
Quoted 2 lines
Quoted 1 line
+
Arguably, the right thing is to use the addresses present in the array at address
0x400. In particular, COM3 and COM4 aren't always at those addresses.Wow. I bow before your storehouse of x86 arcana :-)
Quoted 9 lines
I guess you're referring to the "BIOS data area," which I'd never heard of before (but fortunately, Google knows).
What would you think about doing this only for COM1 and COM2? The only real value for doing this in the first place is so "console=ttyS0" always goes to COM1, even if we don't have
SERIAL_PORT_DFNS. User- space ought to use some sort of udev magic if it cares about persistent naming.
Well, there are four ports that the BIOS have slots for, and if so, we probably should use them.
-hpa
Quoted 3 lines · Bjorn Helgaas
When 8250_pnp discovers COM ports, we only get the correct ttyS names by accident -- we rely on
serial8250_isa_init_ports(), which discovers the COM ports earlier using the addresses inSERIAL_PORT_DFNS.
It's not by accident but by design. It's quite intentional that it remembers the addresses of serial ports, and if another port is registered later with the same base address, it gets the same name.
Signature · 3 lines
Russell King Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/ maintainer of:
Quoted 8 lines · Russell King
Quoted 3 lines · Bjorn Helgaas
When 8250_pnp discovers COM ports, we only get the correct ttyS names by accident -- we rely on
serial8250_isa_init_ports(), which discovers the COM ports earlier using the addresses inSERIAL_PORT_DFNS.It's not by accident but by design. It's quite intentional that it remembers the addresses of serial ports, and if another port is registered later with the same base address, it gets the same name.
It's certainly by design that if we register a port twice, it gets the same name both times.
But that's not quite what I was referring to. I meant that I don't think 8250_pnp should depend on the fact that COM1-4 have been previously discovered to get the right names.
Bjorn
Quoted 6 lines · Bjorn Helgaas
Quoted 5 lines · Russell King
Quoted 3 lines · Bjorn Helgaas
When 8250_pnp discovers COM ports, we only get the correct ttyS names by accident -- we rely on
serial8250_isa_init_ports(), which discovers the COM ports earlier using the addresses inSERIAL_PORT_DFNS.
Quoted 6 lines
Quoted 3 lines
It's not by accident but by design. It's quite intentional that it remembers the addresses of serial ports, and if another port is registered later with the same base address, it gets the same name.
It's certainly by design that if we register a port twice, it gets the same name both times.
Incorrect - if it's not detected first time around (eg, the port isn't accessible at that time), its slot will still be reserved due to the way slots are given out.
Slots are given to users in order of:
1. does the IO type and base address of a previously known port match the new port? If so, use that.
2. do we have a slot which has never been used - use that.
3. find the first slot which is not currently in use.
So, the only way we'd get the first set of ttyS slots used is if all of the following are true:
a) the ISA probe doesn't detect them
b) some other driver registers many ports which don't correspond with any of the ISA listed addresses and we run out of empty slots
c) 8250_pnp initialises after this driver
(c) is unlikely, except in the modular case - we explicitly list 8250_pnp immediately after the 8250 driver so that it gets first call on the slots during initialisation time, before we probe for PCI devices.
Signature · 3 lines
Russell King Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/ maintainer of:
Quoted 28 lines · Russell King
Quoted 6 lines · Bjorn Helgaas
Quoted 5 lines · Russell King
Quoted 3 lines · Bjorn Helgaas
When 8250_pnp discovers COM ports, we only get the correct ttyS names by accident -- we rely on
serial8250_isa_init_ports(), which discovers the COM ports earlier using the addresses inSERIAL_PORT_DFNS.Quoted 6 lines
Quoted 3 lines
It's not by accident but by design. It's quite intentional that it remembers the addresses of serial ports, and if another port is registered later with the same base address, it gets the same name.
It's certainly by design that if we register a port twice, it gets the same name both times.
Incorrect - if it's not detected first time around (eg, the port isn't accessible at that time), its slot will still be reserved due to the way slots are given out.
Slots are given to users in order of:
1. does the IO type and base address of a previously known port match the new port? If so, use that.
2. do we have a slot which has never been used - use that.
3. find the first slot which is not currently in use.So, the only way we'd get the first set of ttyS slots used is if all of the following are true:
Quoted 8 lines
a) the ISA probe doesn't detect them
b) some other driver registers many ports which don't correspond with any of the ISA listed addresses and we run out of empty slots
c) 8250_pnp initialises after this driver(c) is unlikely, except in the modular case - we explicitly list 8250_pnp immediately after the 8250 driver so that it gets first call on the slots during initialisation time, before we probe for PCI devices.
Let me back up a minute. I was merely trying to make the point that if we skip the ISA probe (which uses SERIAL_PORT_DFNS), the 8250_pnp probe will discover the COM ports but won't necessarily name them the way we expect (e.g., http://lkml.org/lkml/2007/8/10/409).
Bjorn
Quoted 34 lines · Bjorn Helgaas
Quoted 33 lines · Russell King
Quoted 6 lines · Bjorn Helgaas
Quoted 5 lines · Russell King
Quoted 3 lines · Bjorn Helgaas
When 8250_pnp discovers COM ports, we only get the correct ttyS names by accident -- we rely on
serial8250_isa_init_ports(), which discovers the COM ports earlier using the addresses inSERIAL_PORT_DFNS.Quoted 6 lines
Quoted 3 lines
It's not by accident but by design. It's quite intentional that it remembers the addresses of serial ports, and if another port is registered later with the same base address, it gets the same name.
It's certainly by design that if we register a port twice, it gets the same name both times.
Incorrect - if it's not detected first time around (eg, the port isn't accessible at that time), its slot will still be reserved due to the way slots are given out.
Slots are given to users in order of:
1. does the IO type and base address of a previously known port match the new port? If so, use that.
2. do we have a slot which has never been used - use that.
3. find the first slot which is not currently in use.So, the only way we'd get the first set of ttyS slots used is if all of the following are true:
a) the ISA probe doesn't detect them
b) some other driver registers many ports which don't correspond with any of the ISA listed addresses and we run out of empty slots
c) 8250_pnp initialises after this driver
Quoted 8 lines
Quoted 3 lines
(c) is unlikely, except in the modular case - we explicitly list 8250_pnp immediately after the 8250 driver so that it gets first call on the slots during initialisation time, before we probe for PCI devices.
Let me back up a minute. I was merely trying to make the point that if we skip the ISA probe (which uses
SERIAL_PORT_DFNS), the 8250_pnp probe will discover the COM ports but won't necessarily name them the way we expect (e.g., http://lkml.org/lkml/2007/8/10/409).
It would be useful to see the full kernel messages to diagnose what's going on. Given that there's no changes to the serial probing code (or even the code which allocates slots) there's something fishy going on. Are they using mainline kernels or do the kernels they're using have some other changes which aren't in mainline?
Signature · 3 lines
Russell King Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/ maintainer of:
Quoted 44 lines · Russell King
Quoted 34 lines · Bjorn Helgaas
Quoted 33 lines · Russell King
Quoted 6 lines · Bjorn Helgaas
Quoted 5 lines · Russell King
Quoted 3 lines · Bjorn Helgaas
When 8250_pnp discovers COM ports, we only get the correct ttyS names by accident -- we rely on
serial8250_isa_init_ports(), which discovers the COM ports earlier using the addresses inSERIAL_PORT_DFNS.Quoted 6 lines
Quoted 3 lines
It's not by accident but by design. It's quite intentional that it remembers the addresses of serial ports, and if another port is registered later with the same base address, it gets the same name.
It's certainly by design that if we register a port twice, it gets the same name both times.
Incorrect - if it's not detected first time around (eg, the port isn't accessible at that time), its slot will still be reserved due to the way slots are given out.
Slots are given to users in order of:
1. does the IO type and base address of a previously known port match the new port? If so, use that.
2. do we have a slot which has never been used - use that.
3. find the first slot which is not currently in use.So, the only way we'd get the first set of ttyS slots used is if all of the following are true:
a) the ISA probe doesn't detect them
b) some other driver registers many ports which don't correspond with any of the ISA listed addresses and we run out of empty slots
c) 8250_pnp initialises after this driverQuoted 8 lines
Quoted 3 lines
(c) is unlikely, except in the modular case - we explicitly list 8250_pnp immediately after the 8250 driver so that it gets first call on the slots during initialisation time, before we probe for PCI devices.
Let me back up a minute. I was merely trying to make the point that if we skip the ISA probe (which uses
SERIAL_PORT_DFNS), the 8250_pnp probe will discover the COM ports but won't necessarily name them the way we expect (e.g., http://lkml.org/lkml/2007/8/10/409).
Quoted 5 lines
It would be useful to see the full kernel messages to diagnose what's going on. Given that there's no changes to the serial probing code (or even the code which allocates slots) there's something fishy going on. Are they using mainline kernels or do the kernels they're using have some other changes which aren't in mainline?
I'm not trying to fix a current problem. The URL I quoted was from 2.6.22, where we didn't do the ISA probe. We fixed that problem by putting the ISA probe back the way it was in 2.6.21.
But I do still want to remove the dependency between the ISA probe and the 8250_pnp probe because it seems like it's more complicated than it needs to be, and if we could figure out a way to safely remove the ISA probe, it would help solve the IRDA issues.
Bjorn