Skip to contentSkip to conversation

Way for platforms to alter built-in serial ports

RFC PATCH Bjorn Helgaas 4 participants 13 messages Sep 30, 2004 – Nov 3, 2004

lore
Share & tools
lore
#0 lore raw
Quoted 9 lines

What I propose is a way for the arch to provide it's own table along with the size of it via a function call. It's optional, based on a #ifdef defined by the arch in it's asm/serial.h. The only remaining tricky point is the fact that you used to size your static array of UART's based on the size of the table. So with my path, an arch that defines ARCH_HAS_GET_LEGACY_SERIAL_PORTS is supposed to provide both the new get_legacy_serial_ports() function, but also to define UART_NR to something sensible. I hope one day, we'll be able to convert 8250 to more dynamic allocation though.

This looks like a reasonable short-term fix, but I think the whole serial8250_isa_init_ports() should go away. I like dwmw2's suggestion of an 8250_platform.c that could use register_serial() for each port in some platform-supplied old_serial_port[] table, which is probably what you mean by moving to a more dynamic allocation.

AFAICS, the only reason for doing serial8250_isa_init_ports() early is for early serial consoles, and I think those should be done along the lines of this:
http://www.ussg.iu.edu/hypermail/linux/kernel/0409.1/1034.html
where the platform can specify a device by its MMIO or IO port address, and we automatically switch to the corresponding ttyS device later.

#1 lore raw
Quoted 5 lines · Bjorn Helgaas

This looks like a reasonable short-term fix, but I think the whole serial8250_isa_init_ports() should go away. I like dwmw2's suggestion of an 8250_platform.c that could use register_serial() for each port in some platform-supplied old_serial_port[] table, which is probably what you mean by moving to a more dynamic allocation.

What would this file look like ? a bunch of platform #ifdef's with different implementations each time ?

Quoted 6 lines

AFAICS, the only reason for doing serial8250_isa_init_ports() early is for early serial consoles, and I think those should be done along the lines of this:
http://www.ussg.iu.edu/hypermail/linux/kernel/0409.1/1034.html
where the platform can specify a device by its MMIO or IO port address, and we automatically switch to the corresponding ttyS device later.

Eventually...

In the meantime, that patch would fix urgent problems for ppc now so I'd appreciate if Russell would consider it for inclusion asap. This is the kind of subject on which everybody comes up with a different "better" way to do it and no code, and nothign ever gets implemented and we end up with no progress...

Ben.

#2 lore raw
Quoted 10 lines · Benjamin Herrenschmidt
Quoted 5 lines · Bjorn Helgaas

This looks like a reasonable short-term fix, but I think the whole serial8250_isa_init_ports() should go away. I like dwmw2's suggestion of an 8250_platform.c that could use register_serial() for each port in some platform-supplied old_serial_port[] table, which is probably what you mean by moving to a more dynamic allocation.

What would this file look like ? a bunch of platform #ifdef's with different implementations each time ?

My main point is that I think the early init stuff (i.e., serial8250_isa_init_ports()) should go away, so we don't have the dichotomy of having the compiled-in stuff handled differently than the run-time enumerated stuff.

It really doesn't matter for ia64, since we discover all the ports via either PCI enumeration or ACPI. We don't put anything in old_serial_port[] at all. For platforms that can't do that, there'd still have to be compiled-in tables, but the entries should be added using the standard register_serial() interface just like everything else.

Quoted 7 lines
Quoted 6 lines

AFAICS, the only reason for doing serial8250_isa_init_ports() early is for early serial consoles, and I think those should be done along the lines of this:
http://www.ussg.iu.edu/hypermail/linux/kernel/0409.1/1034.html
where the platform can specify a device by its MMIO or IO port address, and we automatically switch to the corresponding ttyS device later.

Quoted 7 lines

Eventually...

In the meantime, that patch would fix urgent problems for ppc now so I'd appreciate if Russell would consider it for inclusion asap. This is the kind of subject on which everybody comes up with a different "better" way to do it and no code, and nothign ever gets implemented and we end up with no progress...

We've both posted working code that are at least baby steps toward a better solution, so I hope we can make some progress.

#3 lore raw
Quoted 4 lines · Bjorn Helgaas

My main point is that I think the early init stuff (i.e., serial8250_isa_init_ports()) should go away, so we don't have the dichotomy of having the compiled-in stuff handled differently than the run-time enumerated stuff.

Right. But that's a long term goal ;)

Quoted 6 lines

It really doesn't matter for ia64, since we discover all the ports via either PCI enumeration or ACPI. We don't put anything in old_serial_port[] at all. For platforms that can't do that, there'd still have to be compiled-in tables, but the entries should be added using the standard register_serial() interface just like everything else.

I discover everything at boot time via Open Firmware, though on ppc32, embedded platforms have gazillion different ways of getting to them.

Quoted 8 lines
Quoted 5 lines

In the meantime, that patch would fix urgent problems for ppc now so I'd appreciate if Russell would consider it for inclusion asap. This is the kind of subject on which everybody comes up with a different "better" way to do it and no code, and nothign ever gets implemented and we end up with no progress...

We've both posted working code that are at least baby steps toward a better solution, so I hope we can make some progress.

Yes. Well, I suppose having a 8250_ppc{64}.c where I do the discovery a bit like it's done with ACPI would be ok for everything but serial console... I can do an OF plaform device that gets probed a bit late though, and that wouldn't help for embedded stuffs, but then, those people can always still use the hard coded table for a while ... :)

That would mean though having the kernel serial console for early boot be separate from the 8250 driver... like you proposed. That would work too... I have to ponder this approach, indeed probably better than my patch provided you get your early uart stuff upstream :)

Ben.

#4 lore raw
In reply to Bjorn Helgaas
Quoted 9 lines · Bjorn Helgaas
Quoted 8 lines · Benjamin Herrenschmidt
Quoted 5 lines · Bjorn Helgaas

This looks like a reasonable short-term fix, but I think the whole serial8250_isa_init_ports() should go away. I like dwmw2's suggestion of an 8250_platform.c that could use register_serial() for each port in some platform-supplied old_serial_port[] table, which is probably what you mean by moving to a more dynamic allocation.

Quoted 7 lines
Quoted 2 lines

What would this file look like ? a bunch of platform #ifdef's with different implementations each time ?

My main point is that I think the early init stuff (i.e., serial8250_isa_init_ports()) should go away, so we don't have the dichotomy of having the compiled-in stuff handled differently than the run-time enumerated stuff.

You're always going to have this. For instance, the standard ISA serial ports may not show up in any "enumerated stuff" on an x86 box - and x86 people expect that the port at 0x3f8 is ttyS0, 2f8 is ttyS1 etc.

Change that order and they'll scream at you.

Quoted 6 lines

It really doesn't matter for ia64, since we discover all the ports via either PCI enumeration or ACPI. We don't put anything in old_serial_port[] at all. For platforms that can't do that, there'd still have to be compiled-in tables, but the entries should be added using the standard register_serial() interface just like everything else.

See my previous mail why this doesn't work - x86 serial console requirements.

I think you'll do better to discuss this problem with Alan so that he can change his (and maybe others) points of view wrt when the serial console is initialised. Until then I'm going to continue sitting on the fence on this point.

Signature · 4 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 PCMCIA      - http://pcmcia.arm.linux.org.uk/
                 2.6 Serial core
#5 lore raw
Quoted 11 lines · Russell King
Quoted 4 lines · Bjorn Helgaas

My main point is that I think the early init stuff (i.e., serial8250_isa_init_ports()) should go away, so we don't have the dichotomy of having the compiled-in stuff handled differently than the run-time enumerated stuff.

You're always going to have this. For instance, the standard ISA serial ports may not show up in any "enumerated stuff" on an x86 box - and x86 people expect that the port at 0x3f8 is ttyS0, 2f8 is ttyS1 etc.

Change that order and they'll scream at you.

I don't forsee any order changing. I would expect to use link ordering so all the 8250_platform ports are registered first, then all the 8250_acpi, then all the 8250_pci.

The order WOULD change in some cases on ia64, because we'd get rid of the current wierdness where the device in the HCDP/PCDP firmware table always becomes ttyS0, regardless of where it lives. This would be an improvement, though, because the devices would stop changing names just because you selected a different firmware console.

Quoted 7 lines

See my previous mail why this doesn't work - x86 serial console requirements.

I think you'll do better to discuss this problem with Alan so that he can change his (and maybe others) points of view wrt when the serial console is initialised. Until then I'm going to continue sitting on the fence on this point.

Yeah, I'll poke him about "console=uart". I sent it to you because I think a clean solution requires minor 8250 hooks so we can look up the ttyS device that corresponds to an MMIO or IO address.

#6 lore raw
Quoted 9 lines · Bjorn Helgaas
Quoted 4 lines · Russell King

I think you'll do better to discuss this problem with Alan so that he can change his (and maybe others) points of view wrt when the serial console is initialised. Until then I'm going to continue sitting on the fence on this point.

Yeah, I'll poke him about "console=uart". I sent it to you because I think a clean solution requires minor 8250 hooks so we can look up the ttyS device that corresponds to an MMIO or IO address.

On second thought, I want the "console=uart" stuff regardless of what happens with early port registration, because it fixes the ia64 problem of port names changing based on firmware configuration.

I'd like to make forward progress on that. Do you have any comments on it? The (whitespace-mangled) patch is here:

    http://www.ussg.iu.edu/hypermail/linux/kernel/0409.1/1034.html
#7 lore raw
In reply to Bjorn Helgaas
Quoted 10 lines · Bjorn Helgaas
Quoted 9 lines

What I propose is a way for the arch to provide it's own table along with the size of it via a function call. It's optional, based on a #ifdef defined by the arch in it's asm/serial.h. The only remaining tricky point is the fact that you used to size your static array of UART's based on the size of the table. So with my path, an arch that defines ARCH_HAS_GET_LEGACY_SERIAL_PORTS is supposed to provide both the new get_legacy_serial_ports() function, but also to define UART_NR to something sensible. I hope one day, we'll be able to convert 8250 to more dynamic allocation though.

Quoted 5 lines

This looks like a reasonable short-term fix, but I think the whole serial8250_isa_init_ports() should go away. I like dwmw2's suggestion of an 8250_platform.c that could use register_serial() for each port in some platform-supplied old_serial_port[] table, which is probably what you mean by moving to a more dynamic allocation.

The only reason it exists in its current form is because Alan says we can't get rid of the serial port initialisation due to the x86 requirement for serial console to be initialised reasonably early.

Unfortunately the early console stuff (afaik) never made it in to the kernel, so we've had to keep this hanging around.

Maybe once this problem is solved we can consider dwmw2's suggestion.

Signature · 4 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 PCMCIA      - http://pcmcia.arm.linux.org.uk/
                 2.6 Serial core
#8 lore raw
Quoted 7 lines · Russell King
Quoted 5 lines · Bjorn Helgaas

This looks like a reasonable short-term fix, but I think the whole serial8250_isa_init_ports() should go away. I like dwmw2's suggestion of an 8250_platform.c that could use register_serial() for each port in some platform-supplied old_serial_port[] table, which is probably what you mean by moving to a more dynamic allocation.

Quoted 6 lines

The only reason it exists in its current form is because Alan says we can't get rid of the serial port initialisation due to the x86 requirement for serial console to be initialised reasonably early.

Unfortunately the early console stuff (afaik) never made it in to the kernel, so we've had to keep this hanging around.

My "console=uart" patch
http://www.ussg.iu.edu/hypermail/linux/kernel/0409.1/1034.html
is a start, I think. Relative to the current situation, it
- requires different syntax ("console=uart" vs "console=ttyS0"), though a platform could choose to translate "console=ttyS0" into "console=uart,io,0x3f8"
- can start working much earlier (no interrupts or clock calibration required)
- doesn't deal with all the wierd devices the full driver does
- transitions automatically to the matching ttyS device after the driver is initialized

#9 lore raw
In reply to Russell King
Quoted 8 lines · Russell King

The only reason it exists in its current form is because Alan says we can't get rid of the serial port initialisation due to the x86 requirement for serial console to be initialised reasonably early.

Unfortunately the early console stuff (afaik) never made it in to the kernel, so we've had to keep this hanging around.

Maybe once this problem is solved we can consider dwmw2's suggestion.

Serial console working really early isn't just a requirement for x86. It's useful elsewhere too.

The problem is that 'console=ttySx' doesn't actually do anything unless port numer 'x' is already registered and working. We should fix that -- we ought to be able to use 'console=ttySx' on the command line and have the console get registered with the core printk code later, when some 8250 sub-driver (8250_platform, 8250_pci, etc.) actually registers the port which becomes number 'x'.

That would allow 'early' serial consoles to have none of the horrible special-cased 'earlyconsole' crap -- we just call register_serial() (or early_serial_setup() or whatever) as soon as it's actually possible to poke at the port.

It also fixes the case of serial console on a PCI device.

Signature · 1 line
dwmw2
#10 lore raw
Quoted 6 lines · David Woodhouse

The problem is that 'console=ttySx' doesn't actually do anything unless port numer 'x' is already registered and working. We should fix that -- we ought to be able to use 'console=ttySx' on the command line and have the console get registered with the core printk code later, when some 8250 sub-driver (8250_platform, 8250_pci, etc.) actually registers the port which becomes number 'x'.

See serial8250_late_console_init(); does this do what you want?

Quoted 4 lines

That would allow 'early' serial consoles to have none of the horrible special-cased 'earlyconsole' crap -- we just call register_serial() (or early_serial_setup() or whatever) as soon as it's actually possible to poke at the port.

ftp://ftp.kernel.org/pub/linux/kernel/people/akpm/patches/2.6/2.6.10-rc1/2.6.10-rc1-mm2/broken-out/early-uart-console-support.patch ftp://ftp.kernel.org/pub/linux/kernel/people/akpm/patches/2.6/2.6.10-rc1/2.6.10-rc1-mm2/broken-out/move-hcdp-pcdp-to-early-uart-console.patch

For platforms that define SERIAL_PORT_DFNS, early boot code could easily recognize "console=ttyS0" and use SERIAL_PORT_DFNS to register "console=uart,io,0x3f8".

If you don't have SERIAL_PORT_DFNS, early boot code doesn't know anything about 'ttySx', so you need some other mechanism to find the device (the user could specify it directly, or firmware could supply it).

#11 lore raw
Quoted 9 lines · Bjorn Helgaas
Quoted 6 lines · David Woodhouse

The problem is that 'console=ttySx' doesn't actually do anything unless port numer 'x' is already registered and working. We should fix that -- we ought to be able to use 'console=ttySx' on the command line and have the console get registered with the core printk code later, when some 8250 sub-driver (8250_platform, 8250_pci, etc.) actually registers the port which becomes number 'x'.

See serial8250_late_console_init(); does this do what you want?

This call can now be removed - for any serial device, we keep registering the console each time a new port is added until it successfully registers.

Signature · 4 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 PCMCIA      - http://pcmcia.arm.linux.org.uk/
                 2.6 Serial core
#12 lore raw
Quoted 2 lines · Russell King

This call can now be removed - for any serial device, we keep registering the console each time a new port is added until it successfully registers.

Er, if we already fixed that, then what was it which still needed to be fixed? If the console is registered when the port is registered, what stops us from dropping the static table and letting the i386 setup_arch() code register the port?

You'd still get the console working a lot earlier than it does today -- currently I think we wait for the console_initcalls to start the 8250 console on most platforms, including i386.

Signature · 1 line
dwmw2