* hurd/documentation.mdwn: add link to libirqhelp
* hurd/libirqhelp.mdwn: new file
---
 hurd/documentation.mdwn |  1 +
 hurd/libirqhelp.mdwn    | 66 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+)
 create mode 100644 hurd/libirqhelp.mdwn

diff --git a/hurd/documentation.mdwn b/hurd/documentation.mdwn
index 68914697..3a662ca4 100644
--- a/hurd/documentation.mdwn
+++ b/hurd/documentation.mdwn
@@ -78,6 +78,7 @@ is included in the section entitled
   * [[libnetfs]] -- short introductory material
   * [[libdiskfs]]
   * [[libihash]]
+  * [[libirqhelp]]
   * [[libpthread]]
   * [[libfshelp]]
   * [[libps]]
diff --git a/hurd/libirqhelp.mdwn b/hurd/libirqhelp.mdwn
new file mode 100644
index 00000000..e68a4812
--- /dev/null
+++ b/hurd/libirqhelp.mdwn
@@ -0,0 +1,66 @@
+[[!meta copyright="Copyright © 2024 Free Software Foundation,
+Inc."]]
+
+[[!meta license="""[[!toggle id="license" text="GFDL 1.2+"]][[!toggleable
+id="license" text="Permission is granted to copy, distribute and/or modify this
+document under the terms of the GNU Free Documentation License, Version 1.2 or
+any later version published by the Free Software Foundation; with no Invariant
+Sections, no Front-Cover Texts, and no Back-Cover Texts.  A copy of the license
+is included in the section entitled [[GNU Free Documentation
+License|/fdl]]."]]"""]]
+
+[[!tag stable_URL]]
+
+Damien Zammit authored libirqhelp, which lets userspace attach and
+handle interupts.  Suppose, a user presses a key on his keyboard, then
+the keyboard can send an interrupt request (an IRQ), to the the
+processor.  The CPU will try to interupt the program, so that a
+callback handler can run instead.  A brief overview of `x86` interrupt
+information can be found on
+[[wikipedia|https://en.wikipedia.org/wiki/Interrupt_request]].  The
+[[osdev wiki|https://wiki.osdev.org/IOAPIC]] has more technical
+information.  The source for `libirqhelp` can be found in
+`$hurd-src/libirqhelp/`.
+
+First you must call `irqhelp_init ();`  Then you can install an
+interupt handler with this function:
+
+       struct irc *
+       irqhelp_install_interrupt_handler (int gsi, int bus, int dev,
+                                          int fun, void (*handler)(void*),
+                                                                          void 
*context);
+
+If `gsi` is `-1`, then ACPI will look up the global system interrupt.
+If `bus`, `dev`, and `fun` are `-1`, then you must define `gsi`
+(global system interrupt).  You then use the returned `struct irc *`
+to call the other functions.
+
+`struct irq`'s definition is:
+
+       struct irq {
+         void (*handler)(void *);
+         void *context;
+         int gsi;
+         mach_port_t port;
+         bool enabled;
+         bool shutdown;
+         pthread_mutex_t irqlock;
+         pthread_cond_t irqcond;
+    };
+
+If you want to use pthread, then set up this function, which installs
+the handlers via pthread.  `arg` is a `struct irc *`.
+
+       void * irqhelp_server_loop (void *arg);
+
+You can enable an irq via:
+
+       void irqhelp_enable_irq (struct irq *irq);
+
+You can disable an irq via:
+
+       void irqhelp_disable_irq (struct irq *irq);
+
+You can deregister a handler via:
+
+       error_t irqhelp_remove_interrupt_handler (struct irq *irq);
-- 
2.45.2


Reply via email to