References for writing PCI aware interrupt service routines

Hello,

I am entering the new world of writing a ISR that can handle interrupts from
a PCI device. Does anyone know of any good general references for this type
or code and any QNX4 specific guidelines?


Thanks
Mike

Below is the code that I wrote to setup a PCI digital I/O board. The
CA_PCI calls do not work from a Photon app, due to stack issues. So, there
is a free library on the QNX site that emulates these calls by sending
messages to a non-Photon server task, which when executes the actual call.
This is in /usr/free/qnx4/os/samples/misc/ca_pci_msg.tgz. Finally, you will
need to get the PCI vendor and device IDs. If the vendor does not provide
them, try http://www.yourvote.com/pci.

  • Kevin

//+s
// findInt32 find the PCI-INT32 board
//
void findInt32
(
int *irq, // returned IRQ
int *ioAddress // returned I/O address
)
//-
{
int pci_index = 0; // we want the first device
unsigned busnum, devfuncnum; // bus number, device function
number
unsigned char myIrq; // irq number
long io_base; // I/O space base address

// search for device

sysCall(PCI_SUCCESS !=
_CA_PCI_Find_Device(ID_DEVICE, ID_VENDOR, pci_index, &busnum,
&devfuncnum),
“findInt32: Can not find device\n”, 0);

// determine device interrupt

sysCall(PCI_SUCCESS !=
_CA_PCI_Read_Config_Byte(busnum, devfuncnum,
offsetof(struct _pci_config_regs, Interrupt_Line),
1, &myIrq),
“findInt32: Error reading interrupt\n”, 0);

// determine device I/O base address

sysCall(PCI_SUCCESS != _CA_PCI_Read_Config_DWord(busnum, devfuncnum,
offsetof(struct _pci_config_regs, Base_Address_Regs[2]),
1, (char *)&io_base),
“findInt32: Error reading I/O address\n”, 1);

// return values

*ioAddress = PCI_IO_ADDR(io_base);
*irq = myIrq;
}


“Mike Seeberger” <mseeberger@mail.com> wrote in message
news:aqp9sc$5d8$1@inn.qnx.com

Hello,

I am entering the new world of writing a ISR that can handle interrupts
from
a PCI device. Does anyone know of any good general references for this
type
or code and any QNX4 specific guidelines?


Thanks
Mike

Mike Seeberger <mseeberger@mail.com> wrote:

Hello,

I am entering the new world of writing a ISR that can handle interrupts
from a PCI device. Does anyone know of any good general references for
this type or code and any QNX4 specific guidelines?

The PCI bus uses level trigggered interrupts and can share an interrupt
level between 2 or more devices. This means you can’t get away with
a minimal interrupt handler that just returns a proxy. In the ISR,
you need to check with your hardware device to see if it generated the
interrupt, and if it did acknowledge that interrupt and return a proxy.
If it did not generate the interrupt, just return 0 from your ISR.

In general, the “check with your hardware” is usually a read (inp/inpw/inpd)
of a status register. On some hardware, this will also acknowledge the
interrupt, on others you will also have to write (outp/outpw/outpd) a
control register with an appropriate value to acknowledge.

You can also do any further processing you might need at interrupt time.

See the docs to qnx_hint_attach() for more details, and don’t call any
function from the ISR that makes a kernel call – this will crash the
operating system.

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.