2009-01-12 11:30:53

by Daniel Drake

[permalink] [raw]
Subject: can't mmap PCI legacy_mem on Powerbook G4

Hi,

Dave reports a 2.6.28 regression here:
https://bugs.gentoo.org/show_bug.cgi?id=253149

X (server v1.5.3) no longer starts, it aborts with a mmap() error.


This is because X tries to use sysfs pci legacy_mem to map the VGA frame
buffer if it is available, and this became available in 2.6.28 for ppc,
but the mmap() fails with -ENXIO.

(Arguably, xserver should fallback on the old /proc approach when mmap
fails, we're working on that too)

The memory map for the system is:
Found UniNorth PCI host bridge at 0x00000000f0000000. Firmware bus
number: 0->0
PCI host bridge /pci@f0000000 ranges:
MEM 0x00000000f1000000..0x00000000f1ffffff -> 0x00000000f1000000
IO 0x00000000f0000000..0x00000000f07fffff -> 0x0000000000000000
MEM 0x0000000090000000..0x00000000afffffff -> 0x0000000090000000
Found UniNorth PCI host bridge at 0x00000000f2000000. Firmware bus
number: 0->0
PCI host bridge /pci@f2000000 (primary) ranges:
MEM 0x00000000f3000000..0x00000000f3ffffff -> 0x00000000f3000000
IO 0x00000000f2000000..0x00000000f27fffff -> 0x0000000000000000
MEM 0x0000000080000000..0x000000008fffffff -> 0x0000000080000000
Found UniNorth PCI host bridge at 0x00000000f4000000. Firmware bus
number: 0->0
PCI host bridge /pci@f4000000 ranges:
MEM 0x00000000f5000000..0x00000000f5ffffff -> 0x00000000f5000000
IO 0x00000000f4000000..0x00000000f47fffff -> 0x0000000000000000

Full dmesg here:
https://bugs.gentoo.org/attachment.cgi?id=178141&action=view


strace excerpt from X:
open("/sys/class/pci_bus/0000:00/legacy_mem", O_RDWR) = 9
mmap(NULL, 131072, PROT_READ|PROT_WRITE, MAP_SHARED, 9, 0xa0000) = -1
ENXIO (No such device or address)


Confirmed with printk debugging, the code that produces the -ENXIO
condition can be found in arch/powerpc/kernel/pci-common.c
pci_mmap_legacy_page_range()

if ((offset + size) > hose->isa_mem_size)
return -ENXIO;

In this case, hose->isa_mem_size=0 (and offset=655360, size=65536)

As far as I can see, isa_mem_size only ever gets set if a PCI memory
space is addressed to address 0, which it is not on this system (only IO
regions get mapped there).

Is this a bug, or is mmap doing the correct thing by failing here?

Given the comment in pci-bridge.h:
/* Some machines have a special region to forward the ISA
* "memory" cycles such as VGA memory regions. Left to 0
* if unsupported
*/

Should this check instead be:
if (hose->isa_mem_size && ((offset + size) > hose->isa_mem_size)) ?

cheers
Daniel


2009-01-12 21:41:43

by Benjamin Herrenschmidt

[permalink] [raw]
Subject: Re: can't mmap PCI legacy_mem on Powerbook G4

On Mon, 2009-01-12 at 11:29 +0000, Daniel Drake wrote:
> Hi,
>
> Dave reports a 2.6.28 regression here:
> https://bugs.gentoo.org/show_bug.cgi?id=253149
>
> X (server v1.5.3) no longer starts, it aborts with a mmap() error.
>
>
> This is because X tries to use sysfs pci legacy_mem to map the VGA frame
> buffer if it is available, and this became available in 2.6.28 for ppc,
> but the mmap() fails with -ENXIO.

Argh... Can the X folks stop being full of sh*t ? I'll have to have a
look there, fortunately, I'm occasionally one of them :-)

I made the files available on all powerpc, however, not all platforms
support legacy mem access. The PowerBook doesn't, which is why it
returns the error. It would be more complicated to make the file's
existence conditional instead, but I'll loo kat it.

In the meantime, please file an X bug. It shouldn't fallback to /proc or
whatever junk it did with /dev/mem, it should understand that as "the
kernel supports the legacy interfaces, and tells you this machine has no
access to legacy mem" and thus disable all attempts at whacking VGA text
mode.

Ben.