Skip to contentSkip to conversation

how to list pci devices from userpace? anything better than /proc/bus/pci/devices?

DISCUSSION Chris Friesen 7 participants 7 messages Nov 27, 2002 – Nov 28, 2002

lore
Share & tools
lore
#0 lore raw

I have a situation where the userspace app needs to be able to deal with
two different models of hardware, each of which uses a slightly
different api.

Is there any way that I can query the pci vendor/device numbers without having to parse ascii files in /proc?

Thanks,

Chris

Signature · 4 lines
Chris Friesen                    | MailStop: 043/33/F10
Nortel Networks                  | work: (613) 765-0557
3500 Carling Avenue              | fax:  (613) 765-2986
Nepean, ON K2H 8E9 Canada        | email: [email protected]
#1 lore raw
Quoted 11 lines · Chris Friesen

I have a situation where the userspace app needs to be able to deal with
two different models of hardware, each of which uses a slightly
different api.

Is there any way that I can query the pci vendor/device numbers without having to parse ascii files in /proc?

Thanks,

Chris

Red Hat distributions after 7.0 provide lspci. You still have to parse ASCII. FYI, it's not hard to write a 'C' program that directly accessed the PCI bus from its ports at 0xCF8 (index) and 0xCFC (data). You need to do 32-bit port accesses and you can set iopl(3) from user-space.

If you want to 'roll-your-own', I can send you some code to use as a template.

Cheers,
Dick Johnson
Penguin : Linux version 2.4.18 on an i686 machine (797.90 BogoMips).
Bush : The Fourth Reich of America

#2 lore raw

On Wed, 2002-11-27 16:41:18 -0500, Richard B. Johnson <[email protected]> wrote in message <[email protected]>:

Quoted 1 line · Chris Friesen

[Doing PCI config stuff from userland]

Quoted 2 lines

If you want to 'roll-your-own', I can send you some code to use as a template.

It would be nice if you'd post an URI. I think that many people could make use of it, and this would be nice for the archive:-)

MfG, JBG

Signature · 4 lines
   Jan-Benedict Glaw       [email protected]    . +49-172-7608481
   "Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur
    fuer einen Freien Staat voll Freier Bürger" | im Internet!
   Shell Script APT-Proxy: http://lug-owl.de/~jbglaw/software/ap2/
#3 lore raw
In reply to Richard B. Johnson

Hi!

Quoted 5 lines

Red Hat distributions after 7.0 provide lspci. You still have to parse ASCII. FYI, it's not hard to write a 'C' program that directly accessed the PCI bus from its ports at 0xCF8 (index) and 0xCFC (data). You need to do 32-bit port accesses and you can set iopl(3) from user-space.

Please DON'T do that -- not all machines support this access mechanism and even on them directly poking the I/O ports would lead to races with other programs and as well with the kernel.

Either use lspci (which has a nice machine-parseable output mode) or parse /proc/bus/pci/devices or use the libpci library (part of the pciutils package).

Have a nice fortnight

Signature · 3 lines
Martin `MJ' Mares   <[email protected]>   http://atrey.karlin.mff.cuni.cz/~mj/
Faculty of Math and Physics, Charles University, Prague, Czech Rep., Earth
A LISP programmer knows value of everything, but cost of nothing.
#4 lore raw
In reply to Richard B. Johnson
Quoted 5 lines · Richard B. Johnson

Red Hat distributions after 7.0 provide lspci. You still have to parse ASCII. FYI, it's not hard to write a 'C' program that directly accessed the PCI bus from its ports at 0xCF8 (index) and 0xCFC (data). You need to do 32-bit port accesses and you can set iopl(3) from user-space.

That wont work portably. lspci comes with a pci access library that uses the kernel interfaces and does the job correctly

#5 lore raw
In reply to Chris Friesen
Quoted 7 lines · Chris Friesen

I have a situation where the userspace app needs to be able to deal with
two different models of hardware, each of which uses a slightly
different api.

Is there any way that I can query the pci vendor/device numbers without having to parse ascii files in /proc?

See pcilib. Part of pciutils. (Its on freshmeat)

Dave

Signature · 2 lines
| Dave Jones.        http://www.codemonkey.org.uk
| SuSE Labs