ddekit_pci_irq_enable now translates the PCI interrupt line IRQ into the GSI

---
 libddekit/Makefile |  2 +-
 libddekit/pci.c    | 40 +++++++++++++++++++++++++++++++++++++++-
 2 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/libddekit/Makefile b/libddekit/Makefile
index c74ec1128..f31733c21 100644
--- a/libddekit/Makefile
+++ b/libddekit/Makefile
@@ -21,7 +21,7 @@ makemode := library
 libname = libddekit
 SRCS= condvar.c init.c interrupt.c lock.c malloc.c memory.c    \
       pci.c pgtab.c printf.c resources.c list.c panic.c \
-      thread.c timer.c initcall.c
+      thread.c timer.c initcall.c acpiUser.c
 installhdrs = ddekit/condvar.h ddekit/lock.h   \
          ddekit/semaphore.h ddekit/debug.h     \
          ddekit/inline.h ddekit/panic.h        \
diff --git a/libddekit/pci.c b/libddekit/pci.c
index ca16b6f9a..6655787e6 100644
--- a/libddekit/pci.c
+++ b/libddekit/pci.c
@@ -8,6 +8,10 @@
 #include "ddekit/pci.h"
 #include "config.h"
 
+#include <hurd.h>
+#include <device/device.h>
+#include "acpi_U.h"
+
 #define dbg_this 0
 
 /** PCI descriptor */
@@ -399,7 +403,41 @@ void ddekit_pci_set_master(struct ddekit_pci_dev *dev)
        //TODO l4io_pci_set_master(dev->l4dev.handle);
 }
 
+static error_t
+find_gsi_from_acpi(int bus, int slot, int func, int *irq)
+{
+  mach_port_t devices, acpi;
+
+  error_t err = get_privileged_ports(NULL, &devices);
+  if (err)
+    return err;
+
+  if (devices == MACH_PORT_NULL)
+    return ENODEV;
+
+  err = device_open(devices, D_READ, "acpi", &acpi);
+  mach_port_deallocate(mach_task_self(), devices);
+  if (!err)
+    {
+      err = acpi_get_pci_irq(acpi, bus, slot, func, irq);
+      device_close(acpi);
+    }
+
+  return err;
+}
+
 int ddekit_pci_irq_enable(int bus, int slot, int func, int pin, int *irq)
 {
-       return 0;
+  int gsi = -1;
+
+  if (find_gsi_from_acpi(bus, slot, func, &gsi))
+    {
+      ddekit_printf("Cannot find gsi for: %d:%d:%d\n", bus, slot, func);
+    }
+  else if (gsi >= 0)
+    {
+      *irq = gsi;
+    }
+
+  return 0;
 }
-- 
2.39.5


Reply via email to