Skip to contentSkip to conversation

implement syscall pciconfig_iobase

RFC Zhang Le 2 participants 4 messages Feb 20, 2009 – Feb 21, 2009 MIPS

lore
Share & tools
lore

Zhang Le

author
#0 lore raw

This is for xorg-server support.

Currently, xorg-server on loongson need a patch:
http://www.gentoo-cn.org/gitweb/?p=loongson;a=blob;f=x11-base/xorg-server/files/xorg-server-1.5.3-loongson.patch;h=9c48b3752b7f14b6603524f46ae832f312e7c6fe;hb=HEAD#l37
Please note that line 37, the last parameter to mmap, which is the ioBase_phys, is hardcoded.

This patch no long applies to xorg-server git master.
So I took at look at the code trying to find out why. And then I found powerpc has implemented this syscall: pciconfig_iobase

Please take a look at the following code:
http://cgit.freedesktop.org/xorg/xserver/tree/hw/xfree86/os-support/linux/lnx_video.c#n517

At the first glance, it is absolutely a good idea to implement this for mips, too. However when I read pciconfig_iobase's manpage, I found this sentence:

Most of the interaction with PCI devices is already handled by the kernel PCI layer, and thus these calls should not normally need to be accessed from userspace.

So I decided to bring this issue here, so that you guys could give me some advice.

Thanks in advance!

Zhang, Le

#1 lore raw
Quoted 6 lines · Zhang Le

Currently, xorg-server on loongson need a patch:
http://www.gentoo-cn.org/gitweb/?p=loongson;a=blob;f=x11-base/xorg-server/files/xorg-server-1.5.3-loongson.patch;h=9c48b3752b7f14b6603524f46ae832f312e7c6fe;hb=HEAD#l37
Please note that line 37, the last parameter to mmap, which is the ioBase_phys, is hardcoded.

This patch no long applies to xorg-server git master.

It should have been rejected by the maintainer before. This was obviously fragile and had no fighting chance to ever work on anything but a Fulong.

Quoted 9 lines

So I took at look at the code trying to find out why. And then I found powerpc has implemented this syscall: pciconfig_iobase

Please take a look at the following code:
http://cgit.freedesktop.org/xorg/xserver/tree/hw/xfree86/os-support/linux/lnx_video.c#n517

At the first glance, it is absolutely a good idea to implement this for mips, too. However when I read pciconfig_iobase's manpage, I found this sentence:

Quoted 6 lines

Most of the interaction with PCI devices is already handled by the kernel PCI layer, and thus these calls should not normally need to be accessed from userspace.

So I decided to bring this issue here, so that you guys could give me some advice.

You can find the resources either by something like:

# lspci -vvv -s 1d.1
00:1d.1 USB Controller: Intel Corporation 82801H (ICH8 Family) USB UHCI Controller #2 (rev 02) (prog-if 00 [UHCI])
	Subsystem: Dell Device 01fe
	Control: I/O+ Mem- BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx-
	Status: Cap- 66MHz- UDF- FastB2B+ ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
	Latency: 0
	Interrupt: pin B routed to IRQ 21
	Region 4: I/O ports at 6f60 [size=32]
	Kernel driver in use: uhci_hcd

Now let's see how to find this in sysfs:

# ls -l /sys/bus/pci/devices/0000:00:1d.1/resource*
-r--r--r-- 1 root root 4096 2009-02-20 14:13 /sys/bus/pci/devices/0000:00:1d.1/resource
-rw------- 1 root root   32 2009-02-20 14:20 /sys/bus/pci/devices/0000:00:1d.1/resource4
# cat /sys/bus/pci/devices/0000:00:1d.1/resource
0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000006f60 0x0000000000006f7f 0x0000000000020101
0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 0x0000000000000000

So if you want to mmap the 4th resource, just mmap the file /sys/bus/pci/devices/0000:00:1d.1/resource4. This leaves how to obtain the "0000:00:1d.1" - you have to find it by looking at the vendor and device files in every file in /proc/bus/pci/devices/ which contain the PCI vendor and device ID as hex numbers. For my example device here:

[root@h5 0000:09:00.0]# cat device
0x1673
[root@h5 0000:09:00.0]# cat vendor
0x14e4
[root@h5 0000:09:00.0]#

Hopefully X finally has some nice infrastructure for this sort of stuff.

And for completeness sake, directly looking at the BARs in the PCI config space is another method but this one is deprecated these days as it may not work on some complex systems.

# od -A x -t x4 -j 0x10 -N 0x20 /proc/bus/pci/00/1d.1 
000010 00000000 00000000 00000000 00000000
000020 00006f61 00000000 00000000 01fe1028
000030
#

Ralf

author
#2 lore raw
Quoted 11 lines · Ralf Baechle
Quoted 6 lines · Zhang Le

Currently, xorg-server on loongson need a patch:
http://www.gentoo-cn.org/gitweb/?p=loongson;a=blob;f=x11-base/xorg-server/files/xorg-server-1.5.3-loongson.patch;h=9c48b3752b7f14b6603524f46ae832f312e7c6fe;hb=HEAD#l37
Please note that line 37, the last parameter to mmap, which is the ioBase_phys, is hardcoded.

This patch no long applies to xorg-server git master.

It should have been rejected by the maintainer before. This was obviously fragile and had no fighting chance to ever work on anything but a Fulong.

Exactly.

[snip]

Quoted 42 lines
# lspci -vvv -s 1d.1
00:1d.1 USB Controller: Intel Corporation 82801H (ICH8 Family) USB UHCI Controller #2 (rev 02) (prog-if 00 [UHCI])
	Subsystem: Dell Device 01fe
	Control: I/O+ Mem- BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx-
	Status: Cap- 66MHz- UDF- FastB2B+ ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
	Latency: 0
	Interrupt: pin B routed to IRQ 21
	Region 4: I/O ports at 6f60 [size=32]
	Kernel driver in use: uhci_hcd

Now let's see how to find this in sysfs:

# ls -l /sys/bus/pci/devices/0000:00:1d.1/resource*
(quoted diff) +0 -2
-r--r--r-- 1 root root 4096 2009-02-20 14:13 /sys/bus/pci/devices/0000:00:1d.1/resource
-rw------- 1 root root   32 2009-02-20 14:20 /sys/bus/pci/devices/0000:00:1d.1/resource4
# cat /sys/bus/pci/devices/0000:00:1d.1/resource
0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000006f60 0x0000000000006f7f 0x0000000000020101
0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 0x0000000000000000

So if you want to mmap the 4th resource, just mmap the file /sys/bus/pci/devices/0000:00:1d.1/resource4. This leaves how to obtain the "0000:00:1d.1" - you have to find it by looking at the vendor and device files in every file in /proc/bus/pci/devices/ which contain the PCI vendor and device ID as hex numbers. For my example device here:

[root@h5 0000:09:00.0]# cat device
0x1673
[root@h5 0000:09:00.0]# cat vendor
0x14e4
[root@h5 0000:09:00.0]#

Hopefully X finally has some nice infrastructure for this sort of stuff.

And for completeness sake, directly looking at the BARs in the PCI config space is another method but this one is deprecated these days as it may not work on some complex systems.

Quoted 5 lines
# od -A x -t x4 -j 0x10 -N 0x20 /proc/bus/pci/00/1d.1 
000010 00000000 00000000 00000000 00000000
000020 00006f61 00000000 00000000 01fe1028
000030
#

Thank you for the above comment! It is very informative! I will try to make a new patch.

Zhang, Le

author
#3 lore raw
In reply to Ralf Baechle
Quoted 12 lines · Ralf Baechle

You can find the resources either by something like:

# lspci -vvv -s 1d.1
00:1d.1 USB Controller: Intel Corporation 82801H (ICH8 Family) USB UHCI Controller #2 (rev 02) (prog-if 00 [UHCI])
	Subsystem: Dell Device 01fe
	Control: I/O+ Mem- BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx-
	Status: Cap- 66MHz- UDF- FastB2B+ ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
	Latency: 0
	Interrupt: pin B routed to IRQ 21
	Region 4: I/O ports at 6f60 [size=32]
	Kernel driver in use: uhci_hcd
Quoted 1 line

Now let's see how to find this in sysfs:

[snip]

Hi, Ralf,

After careful thought, I think this may be not what I need. Actually libpciaccess, which is a integral component of X now, need this mmap-able resourceN (N=1,2,3..) file. And previously mips don't have these file. This patch just solved this problem.
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=98873f53becea9a8a46972ff252e96fe575b120d

What I need is access to this address in userspace:
#define LOONGSON2E_IO_PORT_BASE 0x1fd00000UL
which is defined in arch/mips/include/asm/mach-lemote/pci.h

Or maybe a better idea is to implement ioperm/iopl for mips, as discussed 7 years ago:
http://www.linux-mips.org/archives/linux-mips/2002-04/msg00085.html

Zhang, Le