Usenet comp.os.linux.alpha (1997-2013)
 help / color / mirror / Atom feed
* User mode IO acces - PCI A/D card - Alpha station XP900
@ 2005-10-11 12:07 patrice.lespagnol
  2005-10-11 12:53 ` Mathieu Chouquet-Stringer
  0 siblings, 1 reply; 20+ messages in thread
From: patrice.lespagnol @ 2005-10-11 12:07 UTC (permalink / raw)


Hi,

I'am trying to access an A/D PCI card : Advantech PCI1713
http://www.advantech.com/products/Model_Detail.asp?model_id=1-D6GDX&PD=
I want to read and write IO registers from a user process.

My system : Gentoo Alpha, kernel 2.6.11.4 on Hardware : Alpha Station
XP900
http://h18002.www1.hp.com/products/quickspecs/soc_archives/80013.html

What I've already done is mmap 1 page of physical memory from /dev/mem
(lspci -vv giving me the IO address of my card = offset for mmap
/dev/mem) to my process memory.

My problem is when I write a byte on a read-only register of my card,
and then read it, it seems to really have been writen. So I doubt it
actually works.

Am I missing something on mmap and /dev/mem for linux alpha ?

Is there a clever way to acces my card ?

thanks for help !



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: User mode IO acces - PCI A/D card - Alpha station XP900
  2005-10-11 12:07 User mode IO acces - PCI A/D card - Alpha station XP900 patrice.lespagnol
@ 2005-10-11 12:53 ` Mathieu Chouquet-Stringer
  2005-10-11 12:55   ` Mathieu Chouquet-Stringer
  2005-10-11 14:10   ` lpgl
  0 siblings, 2 replies; 20+ messages in thread
From: Mathieu Chouquet-Stringer @ 2005-10-11 12:53 UTC (permalink / raw)


patrice.lespagnol@obs-nancay.fr writes:
> I'am trying to access an A/D PCI card : Advantech PCI1713
> http://www.advantech.com/products/Model_Detail.asp?model_id=1-D6GDX&PD=
> I want to read and write IO registers from a user process.
> [...]

You mean IO registers or memory? Because later on you talk about memory,
these are two different things and are accessed differently.
I guess giving us the output of lspci would answer this question.

-- 
Mathieu Chouquet-Stringer             
    "Le disparu, si l'on v�n�re sa m�moire, est plus pr�sent et
                 plus puissant que le vivant".
           -- Antoine de Saint-Exup�ry, Citadelle --


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: User mode IO acces - PCI A/D card - Alpha station XP900
  2005-10-11 12:53 ` Mathieu Chouquet-Stringer
@ 2005-10-11 12:55   ` Mathieu Chouquet-Stringer
  2005-10-11 14:10   ` lpgl
  1 sibling, 0 replies; 20+ messages in thread
From: Mathieu Chouquet-Stringer @ 2005-10-11 12:55 UTC (permalink / raw)


Mathieu Chouquet-Stringer <mchouque_@_online_._fr> writes:
> You mean IO registers or memory?

IE ports vs memory! ;-)
-- 
Mathieu Chouquet-Stringer             
    "Le disparu, si l'on v�n�re sa m�moire, est plus pr�sent et
                 plus puissant que le vivant".
           -- Antoine de Saint-Exup�ry, Citadelle --


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: User mode IO acces - PCI A/D card - Alpha station XP900
  2005-10-11 12:53 ` Mathieu Chouquet-Stringer
  2005-10-11 12:55   ` Mathieu Chouquet-Stringer
@ 2005-10-11 14:10   ` lpgl
  2005-10-11 14:57     ` Mathieu Chouquet-Stringer
  1 sibling, 1 reply; 20+ messages in thread
From: lpgl @ 2005-10-11 14:10 UTC (permalink / raw)


Here is the output of lspci -vv

0000:00:11.0 Class ff00: Advantech Co. Ltd: Unknown device 1713 (rev
02)
        Subsystem: PLX Technology, Inc.: Unknown device 9050
        Control: I/O+ Mem+ BusMaster- SpecCycle- MemWINV- VGASnoop-
ParErr- Stepping- SERR- FastB2B-
        Status: Cap- 66Mhz- UDF- FastB2B+ ParErr- DEVSEL=medium
>TAbort- <TAbort- <MAbort- >SERR- <PERR-
        Interrupt: pin A routed to IRQ 47
        Region 0: Memory at 000000000a0f3000 (32-bit, non-prefetchable)
        Region 2: I/O ports at 8800 [size=32]

What I've done is :

fd_mem = open("/dev/mem", O_RDWR);
baseIO = (char *) mmap(0, 32, PROT_WRITE | PROT_READ, MAP_SHARED,
fd_mem, 0x8000);
baseIO += 0x800;

then I simply access or change what is at baseIO + the register number
I want on the advantech card



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: User mode IO acces - PCI A/D card - Alpha station XP900
  2005-10-11 14:10   ` lpgl
@ 2005-10-11 14:57     ` Mathieu Chouquet-Stringer
  2005-10-11 16:04       ` lpgl
  0 siblings, 1 reply; 20+ messages in thread
From: Mathieu Chouquet-Stringer @ 2005-10-11 14:57 UTC (permalink / raw)


"lpgl" <patrice.lespagnol@obs-nancay.fr> writes:
> Here is the output of lspci -vv
> 
> 0000:00:11.0 Class ff00: Advantech Co. Ltd: Unknown device 1713 (rev
> 02)
>         Subsystem: PLX Technology, Inc.: Unknown device 9050
>         Control: I/O+ Mem+ BusMaster- SpecCycle- MemWINV- VGASnoop-
> ParErr- Stepping- SERR- FastB2B-
>         Status: Cap- 66Mhz- UDF- FastB2B+ ParErr- DEVSEL=medium
> >TAbort- <TAbort- <MAbort- >SERR- <PERR-
>         Interrupt: pin A routed to IRQ 47
>         Region 0: Memory at 000000000a0f3000 (32-bit, non-prefetchable)
>         Region 2: I/O ports at 8800 [size=32]
> 
> What I've done is :
> 
> fd_mem = open("/dev/mem", O_RDWR);
> baseIO = (char *) mmap(0, 32, PROT_WRITE | PROT_READ, MAP_SHARED,
> fd_mem, 0x8000);
> baseIO += 0x800;
> 
> then I simply access or change what is at baseIO + the register number
> I want on the advantech card

Unless I'm wrong, these are I/O ports and they are accessed using
outb/inb/outw/inw/...

Right now, it looks like you're just poking bytes at random memory places
(ie you can't do that this way).

-- 
Mathieu Chouquet-Stringer             
    "Le disparu, si l'on v�n�re sa m�moire, est plus pr�sent et
                 plus puissant que le vivant".
           -- Antoine de Saint-Exup�ry, Citadelle --


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: User mode IO acces - PCI A/D card - Alpha station XP900
  2005-10-11 14:57     ` Mathieu Chouquet-Stringer
@ 2005-10-11 16:04       ` lpgl
  2005-10-11 16:22         ` Mathieu Chouquet-Stringer
  2005-10-11 18:13         ` Måns Rullgård
  0 siblings, 2 replies; 20+ messages in thread
From: lpgl @ 2005-10-11 16:04 UTC (permalink / raw)


Isn't accessing I/O ports, from user space, using outb/inb/outw/inw/
after an initial  ioperm() or iopl(), an i386 only  feature ?
I thought everything was memory mapped on alpha, and so were PCI
devices.



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: User mode IO acces - PCI A/D card - Alpha station XP900
  2005-10-11 16:04       ` lpgl
@ 2005-10-11 16:22         ` Mathieu Chouquet-Stringer
  2005-10-11 18:03           ` lpgl
  2005-10-11 18:13         ` Måns Rullgård
  1 sibling, 1 reply; 20+ messages in thread
From: Mathieu Chouquet-Stringer @ 2005-10-11 16:22 UTC (permalink / raw)


"lpgl" <patrice.lespagnol@obs-nancay.fr> writes:
> Isn't accessing I/O ports, from user space, using outb/inb/outw/inw/
> after an initial  ioperm() or iopl(), an i386 only  feature ?

Well I wrote a device driver for a LCD display/keyboard on an Alpha box and
it is definitely I/O port based.

Moreover if you grep the source under arch/alpha you'll find plenty of
inb/outb and friends...

-- 
Mathieu Chouquet-Stringer             
    "Le disparu, si l'on v�n�re sa m�moire, est plus pr�sent et
                 plus puissant que le vivant".
           -- Antoine de Saint-Exup�ry, Citadelle --


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: User mode IO acces - PCI A/D card - Alpha station XP900
  2005-10-11 16:22         ` Mathieu Chouquet-Stringer
@ 2005-10-11 18:03           ` lpgl
  2005-10-11 18:16             ` Mathieu Chouquet-Stringer
  0 siblings, 1 reply; 20+ messages in thread
From: lpgl @ 2005-10-11 18:03 UTC (permalink / raw)


>Well I wrote a device driver for a LCD display/keyboard on an Alpha box and
>it is definitely I/O port based.
>Moreover if you grep the source under arch/alpha you'll find plenty of
>inb/outb and friends...

OK.  So from a purely user space point of view you suggest :
- get the right to acess IO port 0x8800,
- then use in/out family fuctions to do my stuff with the card
registers ?
Do you know what is the way to get the IO ports permission ? I've at
first time (before trying mmap on /dev/mem/ in fact)  done an iopl()
but got a segfault with inb then cause i was accessing 0x0 ! Perhaps
something with /dev/port so ?
Thanks.



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: User mode IO acces - PCI A/D card - Alpha station XP900
  2005-10-11 16:04       ` lpgl
  2005-10-11 16:22         ` Mathieu Chouquet-Stringer
@ 2005-10-11 18:13         ` Måns Rullgård
  2005-10-12  8:34           ` lpgl
  1 sibling, 1 reply; 20+ messages in thread
From: Måns Rullgård @ 2005-10-11 18:13 UTC (permalink / raw)


"lpgl" <patrice.lespagnol@obs-nancay.fr> writes:

> Isn't accessing I/O ports, from user space, using outb/inb/outw/inw/
> after an initial  ioperm() or iopl(), an i386 only  feature ?
> I thought everything was memory mapped on alpha, and so were PCI
> devices.

The PCI I/O space is mapped to some high memory regions on Alpha.  The
outb/inb functions simply access these memory addresses.  These
functions are used for at least two reasons: 1) different machine
types map the I/O space at different addresses, and 2) for portability
to other architectures.

Another thing to be aware of on the Alpha is that the PCI memory is
mapped at a high offset as well.  You need to add a large number to
values listed by lspci to get the real address where a card can be
found, and use that when accessing /dev/mem.  Again, this offset
varies between machine types.  The function bus_base(), declared in
sys/io.h, will return the correct value.

It gets even more complicated.  Both PCI memory and I/O are mapped
to several CPU address regions.  Some of these are sparse, meaning
that a 32-bit write in that region will perform an 8-bit or 16-bit
write to the PCI bus.  The reason for this is that the first Alpha
models only had instructions to access memory 32 or 64 bits at a
time.

Then there's the IOMMU, but that's a different story, involving bus
mastering.

-- 
M�ns Rullg�rd
mru@inprovide.com


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: User mode IO acces - PCI A/D card - Alpha station XP900
  2005-10-11 18:03           ` lpgl
@ 2005-10-11 18:16             ` Mathieu Chouquet-Stringer
  2005-10-11 19:43               ` Måns Rullgård
  2005-10-12  7:56               ` lpgl
  0 siblings, 2 replies; 20+ messages in thread
From: Mathieu Chouquet-Stringer @ 2005-10-11 18:16 UTC (permalink / raw)


"lpgl" <patrice.lespagnol@obs-nancay.fr> writes:
> OK.  So from a purely user space point of view you suggest :
> - get the right to acess IO port 0x8800,
> - then use in/out family fuctions to do my stuff with the card
> registers ?

Yeah.

> Do you know what is the way to get the IO ports permission ? I've at
> first time (before trying mmap on /dev/mem/ in fact)  done an iopl()
> but got a segfault with inb then cause i was accessing 0x0 ! Perhaps
> something with /dev/port so ?

Well, I've done this in user space on intel but never on alpha as my driver
is kernel based (and my alpha is down atm).

As iopl seems to be an i386 thing, have you tried without? And when you say
you were trying to access 0x0, what do you mean? inb(0x0)?

-- 
Mathieu Chouquet-Stringer             
    "Le disparu, si l'on v�n�re sa m�moire, est plus pr�sent et
                 plus puissant que le vivant".
           -- Antoine de Saint-Exup�ry, Citadelle --


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: User mode IO acces - PCI A/D card - Alpha station XP900
  2005-10-11 18:16             ` Mathieu Chouquet-Stringer
@ 2005-10-11 19:43               ` Måns Rullgård
  2005-10-12  8:11                 ` lpgl
  2005-10-12  7:56               ` lpgl
  1 sibling, 1 reply; 20+ messages in thread
From: Måns Rullgård @ 2005-10-11 19:43 UTC (permalink / raw)


Mathieu Chouquet-Stringer <mchouque_@_online_._fr> writes:

> "lpgl" <patrice.lespagnol@obs-nancay.fr> writes:
>> OK.  So from a purely user space point of view you suggest :
>> - get the right to acess IO port 0x8800,
>> - then use in/out family fuctions to do my stuff with the card
>> registers ?
>
> Yeah.
>
>> Do you know what is the way to get the IO ports permission ? I've at
>> first time (before trying mmap on /dev/mem/ in fact)  done an iopl()
>> but got a segfault with inb then cause i was accessing 0x0 ! Perhaps
>> something with /dev/port so ?
>
> Well, I've done this in user space on intel but never on alpha as my driver
> is kernel based (and my alpha is down atm).
>
> As iopl seems to be an i386 thing, have you tried without? And when you say
> you were trying to access 0x0, what do you mean? inb(0x0)?

iopl() or ioperm() should both work.  Obviously, you need root
privileges to do it.

-- 
M�ns Rullg�rd
mru@inprovide.com


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: User mode IO acces - PCI A/D card - Alpha station XP900
  2005-10-11 18:16             ` Mathieu Chouquet-Stringer
  2005-10-11 19:43               ` Måns Rullgård
@ 2005-10-12  7:56               ` lpgl
  1 sibling, 0 replies; 20+ messages in thread
From: lpgl @ 2005-10-12  7:56 UTC (permalink / raw)


Mathieu Chouquet-Stringer a écrit :

> And when you say
> you were trying to access 0x0, what do you mean? inb(0x0)?

No, it was the error message : something as "can't acces 0x0"



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: User mode IO acces - PCI A/D card - Alpha station XP900
  2005-10-11 19:43               ` Måns Rullgård
@ 2005-10-12  8:11                 ` lpgl
  2005-10-12 12:29                   ` Mathieu Chouquet-Stringer
  0 siblings, 1 reply; 20+ messages in thread
From: lpgl @ 2005-10-12  8:11 UTC (permalink / raw)


As of what I've allready tried, It works !
Thanks both of you for your help !



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: User mode IO acces - PCI A/D card - Alpha station XP900
  2005-10-11 18:13         ` Måns Rullgård
@ 2005-10-12  8:34           ` lpgl
  2005-10-12 20:49             ` Måns Rullgård
  0 siblings, 1 reply; 20+ messages in thread
From: lpgl @ 2005-10-12  8:34 UTC (permalink / raw)


Måns Rullgård a écrit :

> The PCI I/O space is mapped to some high memory regions on Alpha.  The
> outb/inb functions simply access these memory addresses.  These
> functions are used for at least two reasons: 1) different machine
> types map the I/O space at different addresses, and 2) for portability
> to other architectures.
>
> Another thing to be aware of on the Alpha is that the PCI memory is
> mapped at a high offset as well.  You need to add a large number to
> values listed by lspci to get the real address where a card can be
> found, and use that when accessing /dev/mem.  Again, this offset
> varies between machine types.  The function bus_base(), declared in
> sys/io.h, will return the correct value.

OK, that's good to know

> It gets even more complicated.  Both PCI memory and I/O are mapped
> to several CPU address regions.  Some of these are sparse, meaning
> that a 32-bit write in that region will perform an 8-bit or 16-bit
> write to the PCI bus.  The reason for this is that the first Alpha
> models only had instructions to access memory 32 or 64 bits at a
> time.
>
> Then there's the IOMMU, but that's a different story, involving bus
> mastering.

Ouch... It's saying me I'm not at the end of my tests...
Is there any docs somewhere to learn about all this good things : PCI,
hardware access on Alpha ?



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: User mode IO acces - PCI A/D card - Alpha station XP900
  2005-10-12  8:11                 ` lpgl
@ 2005-10-12 12:29                   ` Mathieu Chouquet-Stringer
  2005-10-13  7:24                     ` lpgl
  0 siblings, 1 reply; 20+ messages in thread
From: Mathieu Chouquet-Stringer @ 2005-10-12 12:29 UTC (permalink / raw)


"lpgl" <patrice.lespagnol@obs-nancay.fr> writes:
> As of what I've allready tried, It works !
> Thanks both of you for your help !

Do you mind showing me/us what you did to get it working?
-- 
Mathieu Chouquet-Stringer             
    "Le disparu, si l'on v�n�re sa m�moire, est plus pr�sent et
                 plus puissant que le vivant".
           -- Antoine de Saint-Exup�ry, Citadelle --


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: User mode IO acces - PCI A/D card - Alpha station XP900
  2005-10-12  8:34           ` lpgl
@ 2005-10-12 20:49             ` Måns Rullgård
  2005-10-13  7:53               ` lpgl
  0 siblings, 1 reply; 20+ messages in thread
From: Måns Rullgård @ 2005-10-12 20:49 UTC (permalink / raw)


"lpgl" <patrice.lespagnol@obs-nancay.fr> writes:

> Ouch... It's saying me I'm not at the end of my tests...
> Is there any docs somewhere to learn about all this good things : PCI,
> hardware access on Alpha ?

Hmm... try the Linux kernel source ;-)

-- 
M�ns Rullg�rd
mru@inprovide.com


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: User mode IO acces - PCI A/D card - Alpha station XP900
  2005-10-12 12:29                   ` Mathieu Chouquet-Stringer
@ 2005-10-13  7:24                     ` lpgl
  0 siblings, 0 replies; 20+ messages in thread
From: lpgl @ 2005-10-13  7:24 UTC (permalink / raw)


Sorry it was not clear : I've just done (being superuser) an iopl
(doesn't work without) and then used inb and outb on 0x8800 (+ register
number). 0x8800 is the address that lspci give me for the advantech
card's IO ports.
What I've understood is that thanks to linux portability there's no
difference in using IO ports on i386 and Alpha arch, although on the
low levels it differs, the inb/outb functions hides all "dificulties".
I've not already tried to access the card's memory (4ksamples FIFO) but
I think the /dev/mem-mmap method will work, in condition of finding the
offset for mmap with bus_base() in sys/io.h as Måns Rullgård told
previously.

Thanks again.



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: User mode IO acces - PCI A/D card - Alpha station XP900
  2005-10-12 20:49             ` Måns Rullgård
@ 2005-10-13  7:53               ` lpgl
  2005-10-13  8:23                 ` Måns Rullgård
  0 siblings, 1 reply; 20+ messages in thread
From: lpgl @ 2005-10-13  7:53 UTC (permalink / raw)


Måns Rullgård a écrit :

> Hmm... try the Linux kernel source ;-)

...and coffee.

Thanks.



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: User mode IO acces - PCI A/D card - Alpha station XP900
  2005-10-13  7:53               ` lpgl
@ 2005-10-13  8:23                 ` Måns Rullgård
  2005-10-13 10:40                   ` lpgl
  0 siblings, 1 reply; 20+ messages in thread
From: Måns Rullgård @ 2005-10-13  8:23 UTC (permalink / raw)


"lpgl" <patrice.lespagnol@obs-nancay.fr> writes:

> M�ns Rullg�rd a �crit :
>
>> Hmm... try the Linux kernel source ;-)
>
> ...and coffee.

There are various documents freely available from Digital/Compaq/HP
describing the Alpha architecture.  These may be useful for
understanding things, but they (obviously) do not tell how to do
things under Linux.

-- 
M�ns Rullg�rd
mru@inprovide.com


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: User mode IO acces - PCI A/D card - Alpha station XP900
  2005-10-13  8:23                 ` Måns Rullgård
@ 2005-10-13 10:40                   ` lpgl
  0 siblings, 0 replies; 20+ messages in thread
From: lpgl @ 2005-10-13 10:40 UTC (permalink / raw)


Måns Rullgård a écrit :

> "lpgl" <patrice.lespagnol@obs-nancay.fr> writes:
>
> > Måns Rullgård a écrit :
> >
> >> Hmm... try the Linux kernel source ;-)
> >
> > ...and coffee.
>
> There are various documents freely available from Digital/Compaq/HP
> describing the Alpha architecture.  These may be useful for
> understanding things, but they (obviously) do not tell how to do
> things under Linux.
>
> --
> Måns Rullgård
> mru@inprovide.com

I'll try a look at that too.

Anyway a budget for a Linux project allow buying much coffee ;-)
(Not to say time saved thanks to free help from people on the web)



^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2005-10-13 10:40 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-11 12:07 User mode IO acces - PCI A/D card - Alpha station XP900 patrice.lespagnol
2005-10-11 12:53 ` Mathieu Chouquet-Stringer
2005-10-11 12:55   ` Mathieu Chouquet-Stringer
2005-10-11 14:10   ` lpgl
2005-10-11 14:57     ` Mathieu Chouquet-Stringer
2005-10-11 16:04       ` lpgl
2005-10-11 16:22         ` Mathieu Chouquet-Stringer
2005-10-11 18:03           ` lpgl
2005-10-11 18:16             ` Mathieu Chouquet-Stringer
2005-10-11 19:43               ` Måns Rullgård
2005-10-12  8:11                 ` lpgl
2005-10-12 12:29                   ` Mathieu Chouquet-Stringer
2005-10-13  7:24                     ` lpgl
2005-10-12  7:56               ` lpgl
2005-10-11 18:13         ` Måns Rullgård
2005-10-12  8:34           ` lpgl
2005-10-12 20:49             ` Måns Rullgård
2005-10-13  7:53               ` lpgl
2005-10-13  8:23                 ` Måns Rullgård
2005-10-13 10:40                   ` lpgl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox