| 1 |
/* HW IRQ support */ |
| 2 |
#include <stdio.h> |
| 3 |
#include <sys/ioctl.h> |
| 4 |
#include <sys/mman.h> /* mlock */ |
| 5 |
#include <pthread.h> |
| 6 |
#include <errno.h> |
| 7 |
#include <unistd.h> |
| 8 |
#include <fcntl.h> |
| 9 |
#include "libdha.h" |
| 10 |
#include "kernelhelper/dhahelper.h" |
| 11 |
|
| 12 |
|
| 13 |
static int libdha_fd=-1; |
| 14 |
static int hwirq_locks=0; |
| 15 |
|
| 16 |
int hwirq_install(int bus, int dev, int func, |
| 17 |
int ar, u_long ao, uint32_t ad) |
| 18 |
{ |
| 19 |
int retval; |
| 20 |
if( libdha_fd == -1) libdha_fd = open("/dev/dhahelper",O_RDWR); |
| 21 |
hwirq_locks++; |
| 22 |
if (libdha_fd > 0) |
| 23 |
{ |
| 24 |
dhahelper_irq_t _irq; |
| 25 |
_irq.bus = bus; |
| 26 |
_irq.dev = dev; |
| 27 |
_irq.func = func; |
| 28 |
_irq.ack_region = ar; |
| 29 |
_irq.ack_offset = ao; |
| 30 |
_irq.ack_data = ad; |
| 31 |
retval = ioctl(libdha_fd, DHAHELPER_INSTALL_IRQ, &_irq); |
| 32 |
return retval; |
| 33 |
} |
| 34 |
return errno; |
| 35 |
} |
| 36 |
|
| 37 |
int hwirq_wait(unsigned irqnum) |
| 38 |
{ |
| 39 |
int retval; |
| 40 |
if (libdha_fd > 0) |
| 41 |
{ |
| 42 |
dhahelper_irq_t _irq; |
| 43 |
_irq.num = irqnum; |
| 44 |
retval = ioctl(libdha_fd, DHAHELPER_ACK_IRQ, &_irq); |
| 45 |
return retval; |
| 46 |
} |
| 47 |
return EINVAL; |
| 48 |
} |
| 49 |
|
| 50 |
int hwirq_uninstall(int bus, int dev, int func) |
| 51 |
{ |
| 52 |
if (libdha_fd > 0) |
| 53 |
{ |
| 54 |
dhahelper_irq_t _irq; |
| 55 |
_irq.bus = bus; |
| 56 |
_irq.dev = dev; |
| 57 |
_irq.func = func; |
| 58 |
ioctl(libdha_fd, DHAHELPER_FREE_IRQ, &_irq); |
| 59 |
} |
| 60 |
if(!hwirq_locks) { close(libdha_fd); libdha_fd=-1; } |
| 61 |
return 0; |
| 62 |
} |