How to use in16, out16?

I’m trying to do port I/O and am finding the docs somewhat ambiguous.
I do:

if (ThreadCtl (_NTO_TCTL_IO, 0) == -1)
printf (“ThreadCtl error: %s\n”, strerror(errno));
if ((ioptr = mmap_device_io (0x8, 0xcf8)) == -1)
printf (“mmap_device_io error: %s\n”, strerror(errno));
avail = (pci_attach (0) == -1 ? 0 : 1);

To map the PCI control registers. This works. In the documentation,
mmap_device_io() returns a uintptr_t type, which is unexplained. I
notice that in16 and out16 both require a unintptr_t as the port
number. Given my above example, what do I pass to in16 and out16 to
access port 0xcfb?

Do I:
i = in16 (0xcfb)
or:
i = in16 (ioptr + 3)

or are these two things equivalent?

Can I get the approximate behaviour of inw with:

ioptr = mmap_device_io (0x1000, 0x0)

and then use
i = in16 (0xcfb)

???

Thanks,
Andrew

“Andrew Thomas” <Andrew@cogent.ca> wrote in message
news:Voyager.010122222804.31723576A@andrewhome.cogent.ca

I’m trying to do port I/O and am finding the docs somewhat ambiguous.
I do:

if (ThreadCtl (_NTO_TCTL_IO, 0) == -1)
printf (“ThreadCtl error: %s\n”, strerror(errno));
if ((ioptr = mmap_device_io (0x8, 0xcf8)) == -1)
printf (“mmap_device_io error: %s\n”, strerror(errno));
avail = (pci_attach (0) == -1 ? 0 : 1);

On x86 mmap_device-IO does nothing, in the example above

it would return 0xcf8. This call is to insure compatibility
between processors.

To map the PCI control registers. This works. In the documentation,
mmap_device_io() returns a uintptr_t type, which is unexplained. I
notice that in16 and out16 both require a unintptr_t as the port
number. Given my above example, what do I pass to in16 and out16 to
access port 0xcfb?

Do I:
i = in16 (0xcfb)
or:
i = in16 (ioptr + 3)

or are these two things equivalent?

On x86 they are on PowerPC they are not.

Can I get the approximate behaviour of inw with:

ioptr = mmap_device_io (0x1000, 0x0)

On x86 don’t even need this call

and then use

i = in16 (0xcfb)

???

Thanks,
Andrew

“Mario Charest” <mcharest@void_zinformatic.com> wrote in message
news:94jvsb$qto$1@nntp.qnx.com

“Andrew Thomas” <> Andrew@cogent.ca> > wrote in message
news:> Voyager.010122222804.31723576A@andrewhome.cogent.ca> …
I’m trying to do port I/O and am finding the docs somewhat ambiguous.
I do:

if (ThreadCtl (_NTO_TCTL_IO, 0) == -1)
printf (“ThreadCtl error: %s\n”, strerror(errno));
if ((ioptr = mmap_device_io (0x8, 0xcf8)) == -1)
printf (“mmap_device_io error: %s\n”, strerror(errno));
avail = (pci_attach (0) == -1 ? 0 : 1);

On x86 mmap_device-IO does nothing, in the example above
it would return 0xcf8. This call is to insure compatibility
between processors.

Fair enough, but what is it intended to generalize? If I am writing
portable code, what is its return value used for? Am I supposed to
use the return value to pass to in16? Am I supposed to address ports
relative to this return value?

To map the PCI control registers. This works. In the documentation,
mmap_device_io() returns a uintptr_t type, which is unexplained. I
notice that in16 and out16 both require a unintptr_t as the port
number. Given my above example, what do I pass to in16 and out16 to
access port 0xcfb?

Do I:
i = in16 (0xcfb)
or:
i = in16 (ioptr + 3)

or are these two things equivalent?

On x86 they are on PowerPC they are not.

Which is portable? Is either of them correct according to the
Neutrino API?

Can I get the approximate behaviour of inw with:

ioptr = mmap_device_io (0x1000, 0x0)


On x86 don’t even need this call

The interesting problem I am facing is that I have code that works in
both QNX4 and Linux that uses inw/outw. That same code fails in
Neutrino, always returning -1 from all in16 calls. devx-pci is running.
Perhaps it shouldn’t be?

Cheers,
Andrew

Andrew Thomas <andrew-s-thomas@home.nospam.com> wrote:

On x86 mmap_device-IO does nothing, in the example above
it would return 0xcf8. This call is to insure compatibility
between processors.

Fair enough, but what is it intended to generalize? If I am writing
portable code, what is its return value used for? Am I supposed to
use the return value to pass to in16? Am I supposed to address ports
relative to this return value?

Right. On systems without a specific IO instruction it returns the
address you are supposed to use for poking around on the device. So
it will return the same value you pass in on x86, since it does have
io instructions, and that is what you should use if you want to be portable.

chris

cdm@qnx.com > “The faster I go, the behinder I get.”

Chris McKillop – Lewis Carroll –
Software Engineer, QSSL
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<