sigio.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com)
  3. * Licensed under the GPL
  4. */
  5. #include <linux/interrupt.h>
  6. #include "irq_kern.h"
  7. #include "os.h"
  8. #include "sigio.h"
  9. /* Protected by sigio_lock() called from write_sigio_workaround */
  10. static int sigio_irq_fd = -1;
  11. static irqreturn_t sigio_interrupt(int irq, void *data)
  12. {
  13. char c;
  14. os_read_file(sigio_irq_fd, &c, sizeof(c));
  15. reactivate_fd(sigio_irq_fd, SIGIO_WRITE_IRQ);
  16. return IRQ_HANDLED;
  17. }
  18. int write_sigio_irq(int fd)
  19. {
  20. int err;
  21. err = um_request_irq(SIGIO_WRITE_IRQ, fd, IRQ_READ, sigio_interrupt,
  22. IRQF_SAMPLE_RANDOM, "write sigio",
  23. NULL);
  24. if (err) {
  25. printk(KERN_ERR "write_sigio_irq : um_request_irq failed, "
  26. "err = %d\n", err);
  27. return -1;
  28. }
  29. sigio_irq_fd = fd;
  30. return 0;
  31. }
  32. /* These are called from os-Linux/sigio.c to protect its pollfds arrays. */
  33. static DEFINE_SPINLOCK(sigio_spinlock);
  34. void sigio_lock(void)
  35. {
  36. spin_lock(&sigio_spinlock);
  37. }
  38. void sigio_unlock(void)
  39. {
  40. spin_unlock(&sigio_spinlock);
  41. }