libpciaccess question

Sebastian Kuzminsky seb at highlab.com
Wed Jul 2 12:25:52 PDT 2008


On Wed July 2 2008 12:16:12 Jesse Barnes wrote:
> On Wednesday, July 02, 2008 10:41 am Adam Jackson wrote:
> > On Wed, 2008-07-02 at 10:57 -0600, Sebastian Kuzminsky wrote:
> > > Hi there, sorry to mail you directly but I couldnt find the proper
> > > mailing list for asking about libpciaccess.
> >
> > xorg at lists.freedesktop.org is probably the best place.  I've cc'd the
> > list since this is probably a generally interesting question.

Ok thanks, i've joined.


> > > I'm trying to use libpciaccess to write a userspace utility to work
> > > with some PCI cards, and I need to peek & poke some IO BARs.  I'm on
> > > Ubuntu 7.10, which has libpciaccess 0.8.0.
...
> > The config space is supported through the normal read/write syscalls
> > though, and the same could reasonably be done for the IO BARs I suspect,
> > but right now there's no code for that in pciaccess.  Which seems like
> > failing.
...
> It would definitely be nice to extend libpciaccess to abstract this away a
> bit, but no one's done that yet, afaik.

I'm not able to cat the resource files (MEM or IO) on my 2.6.24 system
here.  read() gives EIO.  I can mmap the MEM resource files but not the
IO resource files (EINVAL, as noted).

So I think we should mmap the memory regions, and do ins and outs on
the IO regions (after iopl(3)).


Something like this maybe:

int pci_device_bar_read(struct pci_device *dev, int bar, void *data, pciaddr_t 
offset, pciaddr_t size, pciaddr_t *bytes_read);
int pci_device_bar_read_u8(struct pci_device *dev, int bar, uint8_t *data, 
pciaddr_t offset);
int pci_device_bar_read_u16(struct pci_device *dev, int bar, uint16_t *data, 
pciaddr_t offset);
int pci_device_bar_read_u32(struct pci_device *dev, int bar, uint32_t *data, 
pciaddr_t offset);

int pci_device_bar_write(struct pci_device *dev, int bar, const void *data, 
pciaddr_t offset, pciaddr_t size, pciaddr_t *bytes_written);
int pci_device_bar_write_u8(struct pci_device *dev, int bar, uint8_t data, 
pciaddr_t offset);
int pci_device_bar_write_u16(struct pci_device *dev, int bar, uint16_t data, 
pciaddr_t offset);
int pci_device_bar_write_u32(struct pci_device *dev, int bar, uint32_t data, 
pciaddr_t offset);

Modeled on the pci_device_cfg_* functions, obviously, just adding the
BAR index.

Internally it'd check to see if it's a MEM or IO BAR.  For MEM it'd mmap
(if not done already) and memcpy.  For IO it'd iopl and then do ins and
outs, ignoring the resource file.

Seem reasonable?


-- 
Sebastian Kuzminsky
my brothers are protons / my sisters are neurons
I stir it twice, it's instant family!  -- Gogol Bordello




More information about the xorg mailing list