summaryrefslogtreecommitdiff
path: root/src/video_out/libdha/irq.c
blob: abccaf74cff49ecc45b45ee26695e0305d90693b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* HW IRQ support */
#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/mman.h> /* mlock */
#include <pthread.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include "libdha.h"
#include "kernelhelper/dhahelper.h"


static int libdha_fd=-1;
static int hwirq_locks=0;

int	hwirq_install(int bus, int dev, int func,
		      int ar, u_long ao, uint32_t ad)
{
  int retval;
  if( libdha_fd == -1) libdha_fd = open("/dev/dhahelper",O_RDWR);
  hwirq_locks++;
  if (libdha_fd > 0)
  {
	dhahelper_irq_t _irq;
	_irq.bus = bus;
	_irq.dev = dev;
	_irq.func = func;
	_irq.ack_region = ar;
	_irq.ack_offset = ao;
	_irq.ack_data = ad;
	retval = ioctl(libdha_fd, DHAHELPER_INSTALL_IRQ, &_irq);
	return retval;
  }
  return errno;
}

int	hwirq_wait(unsigned irqnum)
{
  int retval;
  if (libdha_fd > 0)
  {
	dhahelper_irq_t _irq;
	_irq.num = irqnum;
	retval = ioctl(libdha_fd, DHAHELPER_ACK_IRQ, &_irq);
	return retval;
  }
  return EINVAL;
}

int	hwirq_uninstall(int bus, int dev, int func)
{
  if (libdha_fd > 0)
  {
	dhahelper_irq_t _irq;
	_irq.bus = bus;
	_irq.dev = dev;
	_irq.func = func;
	ioctl(libdha_fd, DHAHELPER_FREE_IRQ, &_irq);
  }
  if(!hwirq_locks) { close(libdha_fd); libdha_fd=-1; }
  return 0;
}