bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH-3] A new irq device interface


From: Junling Ma
Subject: [PATCH-3] A new irq device interface
Date: Sat, 1 Aug 2020 19:06:02 -0700

In this patch, the old interface of device_intr_register and device_intr_ack is 
removed.

Junling Ma

---
 Makefrag.am                |   2 -
 device/ds_routines.c       |  62 ----------------------
 device/intr.c              | 104 ++++---------------------------------
 device/intr.h              |   4 +-
 include/device/device.defs |  19 -------
 include/device/notify.defs |  36 -------------
 include/device/notify.h    |  34 ------------
 7 files changed, 10 insertions(+), 251 deletions(-)
 delete mode 100644 include/device/notify.defs
 delete mode 100644 include/device/notify.h

diff --git a/Makefrag.am b/Makefrag.am
index ea612275..eb9eaa64 100644
--- a/Makefrag.am
+++ b/Makefrag.am
@@ -363,8 +363,6 @@ include_device_HEADERS = \
        include/device/device_types.h \
        include/device/disk_status.h \
        include/device/net_status.h \
-       include/device/notify.defs \
-       include/device/notify.h \
        include/device/tape_status.h \
        include/device/tty_status.h
 
diff --git a/device/ds_routines.c b/device/ds_routines.c
index 333b66c9..3a6921ec 100644
--- a/device/ds_routines.c
+++ b/device/ds_routines.c
@@ -320,68 +320,6 @@ ds_device_map (device_t dev, vm_prot_t prot, vm_offset_t 
offset,
                                offset, size, pager, unmap);
 }
 
-/* TODO: missing deregister support */
-io_return_t
-ds_device_intr_register (device_t dev, int id,
-                         int flags, ipc_port_t receive_port)
-{
-#if defined(MACH_XEN) || defined(__x86_64__)
-  return D_INVALID_OPERATION;
-#else /* MACH_XEN || __x86_64__ */
-  kern_return_t err;
-  mach_device_t mdev = dev->emul_data;
-
-  /* Refuse if device is dead or not completely open.  */
-  if (dev == DEVICE_NULL)
-    return D_NO_SUCH_DEVICE;
-
-  /* No flag is defined for now */
-  if (flags != 0)
-    return D_INVALID_OPERATION;
-
-  /* Must be called on the irq device only */
-  if (! name_equal(mdev->dev_ops->d_name, 3, "irq"))
-    return D_INVALID_OPERATION;
-
-  // TODO detect when the port get destroyed because the driver crashes and
-  // restart, to replace it when the same device driver calls it again.
-  err = install_user_intr_handler (id, receive_port, mdev, FALSE);
-  if (err == D_SUCCESS)
-    {
-      /* If the port is installed successfully, increase its reference by 1.
-       * Thus, the port won't be destroyed after its task is terminated. */
-      ip_reference (receive_port);
-    }
-  return err;
-#endif /* MACH_XEN || __x86_64__ */
-}
-
-kern_return_t
-ds_device_intr_ack (device_t dev, ipc_port_t receive_port)
-{
-#if defined(MACH_XEN) || defined(__x86_64__)
-  return D_INVALID_OPERATION;
-#else /* MACH_XEN || __x86_64__ */
-  mach_device_t mdev = dev->emul_data;
-  kern_return_t ret;
-
-  /* Refuse if device is dead or not completely open.  */
-  if (dev == DEVICE_NULL)
-    return D_NO_SUCH_DEVICE;
-
-  /* Must be called on the irq device only */
-  if (! name_equal(mdev->dev_ops->d_name, 3, "irq"))
-    return D_INVALID_OPERATION;
-
-  ret = irq_acknowledge(receive_port);
-
-  if (ret == D_SUCCESS)
-    ipc_port_release_send(receive_port);
-
-  return ret;
-#endif /* MACH_XEN || __x86_64__ */
-}
-
 boolean_t
 ds_notify (mach_msg_header_t *msg)
 {
diff --git a/device/intr.c b/device/intr.c
index e78f2193..509788e1 100644
--- a/device/intr.c
+++ b/device/intr.c
@@ -15,7 +15,6 @@
 #include <device/intr.h>
 #include <device/device_types.h>
 #include <device/device_port.h>
-#include <device/notify.h>
 #include <kern/printf.h>
 #include <machine/spl.h>
 #include <machine/irq.h>
@@ -30,7 +29,6 @@
 #define SA_INTERRUPT 0x20000000
 
 struct irqdev irqtab;
-static boolean_t deliver_intr (int id, ipc_port_t dst_port);
 struct pt_regs;
 extern int request_irq (unsigned int irq, void (*handler) (int, void *, struct 
pt_regs *),
             unsigned long flags, const char *device, void *dev_id);
@@ -67,38 +65,6 @@ search_notification (user_intr_t *handler, ipc_port_t 
dst_port)
   return n;
 }
 
-kern_return_t
-irq_acknowledge (ipc_port_t receive_port)
-{
-  user_intr_t *e;
-  user_intr_notification_t n = NULL;
-  unsigned id;
-       for (id = 0; id < NINTR; ++id)
-               {
-                       e = irqtab.handler[id];
-                       if (e && (n = search_notification (e, receive_port)) != 
NULL)
-                               break;
-               }
-       if (id == NINTR || n->device_port)
-               return D_INVALID_OPERATION;
-       /* cannot ack twice */
-       if (n->acked)
-               return D_INVALID_OPERATION;
-       n->acked = TRUE;
-  kern_return_t ret = D_SUCCESS;
-  PROTECT(e->lock, 
-       {
-                       if (!e->n_unacked)
-                               ret = D_INVALID_OPERATION;
-                       else {
-                               e->n_unacked--;
-                               if (e->n_unacked == 0) 
-                                       __enable_irq(id);
-                       }
-               });
-  return ret;
-}
-
 static void 
 deliver_user_intr (int id, void *dev_id, struct pt_regs *regs)
 {
@@ -141,13 +107,12 @@ intr_thread (void)
                                                                        
queue_iterate (&e->notification_queue, n, user_intr_notification_t, chain)
                                                                                
{
                                                                                
        /* check for dead port */
-                                                                               
        while (n && n->dst_port->ip_references == 1)
+                                                                               
        while (n && !n->dst_port->ip_references)
                                                                                
                {
                                                                                
                        /* dead, move it to the dead queue */
                                                                                
                        printf("dead port: %p\n", n->dst_port);
                                                                                
                        next = (user_intr_notification_t)queue_next(&n->chain);
                                                                                
                        queue_remove(&e->notification_queue, n, 
user_intr_notification_t, chain);
-                                                                               
                        //ipc_port_release (n->dst_port);
                                                                                
                        if (n->request)
                                                                                
                                io_req_free(n->request);
                                                                                
                        /* if waiting for acking, ack it */
@@ -157,8 +122,8 @@ intr_thread (void)
                                                                                
                                        if (e->n_unacked == 0)
                                                                                
                                                __enable_irq(id);
                                                                                
                                }
-                                                                               
                        kfree((vm_offset_t)n, sizeof(*n));
                                                                                
                        ds_device_close(&n->device->dev);
+                                                                               
                        kfree((vm_offset_t)n, sizeof(*n));
                                                                                
                        n = next;
                                                                                
                }
                                                                                
        if (!n) break;
@@ -166,15 +131,10 @@ intr_thread (void)
                                                                                
        /* the notification uses the old interface. is the notification port 
dead? */
                                                                                
        if (!e->interrupts)
                                                                                
                continue;
-                                                                               
        if (!n->device_port && !deliver_intr(id, n->dst_port))
-                                                                               
                continue; /* failed to delivery using the notification port */
-                                                                               
        if (n->device_port)
-                                                                               
                {
-                                                                               
                        if (!n->request)
-                                                                               
                                continue;
-                                                                               
                        ds_read_done(n->request);
-                                                                               
                        io_req_free(n->request);
-                                                                               
                }
+                                                                               
        if (!n->request)
+                                                                               
                continue;
+                                                                               
        ds_read_done(n->request);
+                                                                               
        io_req_free(n->request);
                                                                                
        n->request = NULL;
                                                                                
        e->n_unacked++;
                                                                                
        n->acked = FALSE;
@@ -199,52 +159,8 @@ intr_thread (void)
     }
 }
 
-static boolean_t
-deliver_intr (int id, ipc_port_t dst_port)
-{
-  ipc_kmsg_t kmsg;
-  device_intr_notification_t *n;
-  mach_port_t dest = (mach_port_t) dst_port;
-
-  if (dest == MACH_PORT_NULL)
-    return FALSE;
-
-  kmsg = ikm_alloc(sizeof *n);
-  if (kmsg == IKM_NULL)
-    return FALSE;
-
-  ikm_init(kmsg, sizeof *n);
-  n = (device_intr_notification_t *) &kmsg->ikm_header;
-
-  mach_msg_header_t *m = &n->intr_header;
-  mach_msg_type_t *t = &n->intr_type;
-
-  m->msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_PORT_SEND, 0);
-  m->msgh_size = sizeof *n;
-  m->msgh_seqno = DEVICE_NOTIFY_MSGH_SEQNO;
-  m->msgh_local_port = MACH_PORT_NULL;
-  m->msgh_remote_port = MACH_PORT_NULL;
-  m->msgh_id = DEVICE_INTR_NOTIFY;
-
-  t->msgt_name = MACH_MSG_TYPE_INTEGER_32;
-  t->msgt_size = 32;
-  t->msgt_number = 1;
-  t->msgt_inline = TRUE;
-  t->msgt_longform = FALSE;
-  t->msgt_deallocate = FALSE;
-  t->msgt_unused = 0;
-
-  n->intr_header.msgh_remote_port = dest;
-  n->id = id;
-
-  ipc_port_copy_send (dst_port);
-  ipc_mqueue_send_always(kmsg);
-
-  return TRUE;
-}
-
 int
-install_user_intr_handler (int id, ipc_port_t dst_port, mach_device_t device, 
boolean_t device_port)
+install_user_intr_handler (int id, ipc_port_t dst_port, mach_device_t device)
 {
        if (id > NINTR || device == NULL)
                return D_INVALID_OPERATION;
@@ -278,9 +194,7 @@ install_user_intr_handler (int id, ipc_port_t dst_port, 
mach_device_t device, bo
                return D_NO_MEMORY;
 
   n->dst_port = dst_port;
-  ipc_port_reference(dst_port);
   n->device = device;
-  n->device_port = device_port;
   n->request = NULL;
   n->acked = TRUE;
   PROTECT(e->lock, queue_enter (&e->notification_queue, n, 
user_intr_notification_t, chain));
@@ -308,7 +222,7 @@ extern int irqopen(dev_t dev, int flag, io_req_t ior)
        if (e)
                return D_SUCCESS;
        ior->io_error = D_SUCCESS;
-       return install_user_intr_handler (id, ior->io_reply_port, 
ior->io_device, TRUE);
+       return install_user_intr_handler (id, ior->io_reply_port, 
ior->io_device);
 }
 
 void irqclose(dev_t dev, int flags)
@@ -327,7 +241,7 @@ extern int irqread(dev_t dev, io_req_t ior)
        n = search_notification(e, ior->io_reply_port);
   if (!n)
        {
-               int err = install_user_intr_handler(id, ior->io_reply_port, 
ior->io_device, TRUE);
+               int err = install_user_intr_handler(id, ior->io_reply_port, 
ior->io_device);
                if (err)
                        return err;
                e = irqtab.handler[id];
diff --git a/device/intr.h b/device/intr.h
index 88b40516..07863026 100644
--- a/device/intr.h
+++ b/device/intr.h
@@ -37,7 +37,6 @@ struct user_intr_notification {
   boolean_t acked;
   mach_device_t device;
   ipc_port_t dst_port; /* Notification port */
-  boolean_t device_port; /* whether dst_port is a device port, i.e, using the 
new interface */
 };
 typedef struct user_intr_notification * user_intr_notification_t;
 
@@ -53,11 +52,10 @@ struct irqdev {
        user_intr_t *handler[NINTR]; /* irq handlers for device_open */
 };
 
-extern int install_user_intr_handler (int id, ipc_port_t dst_port, 
mach_device_t device, boolean_t device_port);
+extern int install_user_intr_handler (int id, ipc_port_t dst_port, 
mach_device_t device);
 extern void irq_init();
 
 void intr_thread (void);
-kern_return_t irq_acknowledge (ipc_port_t receive_port);
 
 extern int     irqopen(dev_t dev, int flag, io_req_t ior);
 extern void    irqclose(dev_t dev, int flags);
diff --git a/include/device/device.defs b/include/device/device.defs
index ec4b5bf8..31ed42e2 100644
--- a/include/device/device.defs
+++ b/include/device/device.defs
@@ -141,22 +141,3 @@ routine device_set_filter(
        in      priority        : int;
        in      filter          : filter_array_t
        );
-
-routine device_intr_register(
-               device          : device_t;
-       in      id              : int;
-       in      flags           : int;
-       in      receive_port    : mach_port_send_t
-       );
-
-/*
- *     Acknowledge the specified interrupt notification.
- */
-/*
- * When an IRQ happens and an intr notification is thus sent, the IRQ line
- * is kept disabled until the notification is acknowledged with this RPC
- */
-routine device_intr_ack(
-               device          : device_t;
-       in      receive_port    : mach_port_send_t);
-
diff --git a/include/device/notify.defs b/include/device/notify.defs
deleted file mode 100644
index 7919b339..00000000
--- a/include/device/notify.defs
+++ /dev/null
@@ -1,36 +0,0 @@
-/* 
- * Mach Operating System
- * Copyright (c) 1991,1990,1989 Carnegie Mellon University
- * All Rights Reserved.
- * 
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- * 
- * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
- * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
- * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- * 
- * Carnegie Mellon requests users of this software to return to
- * 
- *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
- *  School of Computer Science
- *  Carnegie Mellon University
- *  Pittsburgh PA 15213-3890
- * 
- * any improvements or extensions that they make and grant Carnegie Mellon
- * the rights to redistribute these changes.
- */
-
-subsystem notify 100;
-
-#include <mach/std_types.defs>
-
-serverprefix do_;
-serverdemux device_intr_notify_server;
-
-simpleroutine device_intr_notify(
-               notify  : notify_port_t;
-               id      : int);
diff --git a/include/device/notify.h b/include/device/notify.h
deleted file mode 100644
index addf9114..00000000
--- a/include/device/notify.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (c) 2010 Free Software Foundation, Inc.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE FREE SOFTWARE FOUNDATIONALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
- * CONDITION.  THE FREE SOFTWARE FOUNDATION DISCLAIMS ANY LIABILITY OF ANY KIND
- * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- */
-
-/*
- * Device notification definitions.
- */
-
-#ifndef        _MACH_DEVICE_NOTIFY_H_
-#define _MACH_DEVICE_NOTIFY_H_
-
-#include <mach/port.h>
-#include <mach/message.h>
-
-typedef struct
-{
-  mach_msg_header_t intr_header;
-  mach_msg_type_t   intr_type;
-  int              id;
-} device_intr_notification_t;
-
-#define DEVICE_INTR_NOTIFY 100
-
-#endif /* _MACH_DEVICE_NOTIFY_H_ */
-- 
2.28.0.rc1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]