1 /*
   2  * This file and its contents are supplied under the terms of the
   3  * Common Development and Distribution License ("CDDL"), version 1.0.
   4  * You may only use this file in accordance with the terms of version
   5  * 1.0 of the CDDL.
   6  *
   7  * A full copy of the text of the CDDL should have accompanied this
   8  * source.  A copy of the CDDL is also available via the Internet at
   9  * http://www.illumos.org/license/CDDL.
  10  */
  11 /*
  12  * Copyright (c) 2013, Joyent, Inc.  All rights reserved.
  13  */
  14 
  15 #ifndef _SYS_DDI_PERIODIC_H
  16 #define _SYS_DDI_PERIODIC_H
  17 
  18 #include <sys/list.h>
  19 #include <sys/taskq_impl.h>
  20 #include <sys/cyclic.h>
  21 
  22 #ifdef  __cplusplus
  23 extern "C" {
  24 #endif
  25 
  26 #ifdef _KERNEL
  27 
  28 /*
  29  * Opaque handle type for i_timeout() and i_untimeout().
  30  */
  31 typedef struct __timeout *timeout_t;
  32 
  33 typedef enum ddi_periodic_flags {
  34         DPF_DISPATCHED = 0x01,
  35         DPF_EXECUTING = 0x02,
  36         DPF_CANCELLED = 0x04
  37 } ddi_periodic_flags_t;
  38 
  39 /*
  40  * Each instance of this structure represents a single periodic handler
  41  * registered through ddi_periodic_add(9F).
  42  */
  43 typedef struct ddi_periodic_impl {
  44         struct list_node dpr_link; /* protected by periodics_lock */
  45         struct list_node dpr_softint_link; /* only used when DPF_DISPATCHED */
  46         id_t dpr_id;
  47         hrtime_t dpr_interval;
  48 
  49         kmutex_t dpr_lock;
  50         kcondvar_t dpr_cv;
  51         ddi_periodic_flags_t dpr_flags;
  52         uint_t dpr_level; /* 0 <= dpr_level <= 10 */
  53         taskq_ent_t dpr_taskq_ent; /* only used for level of 0 */
  54         uint64_t dpr_fire_count;
  55         kthread_t *dpr_thread;
  56 
  57         cyclic_id_t dpr_cyclic_id;
  58 
  59         void (*dpr_handler)(void *);
  60         void *dpr_arg;
  61 } ddi_periodic_impl_t;
  62 
  63 /*
  64  * Internal implementation functions for the DDI periodic interface.
  65  */
  66 void ddi_periodic_init(void);
  67 void ddi_periodic_fini(void);
  68 void ddi_periodic_softintr(int level);
  69 timeout_t i_timeout(void (*)(void *), void *, hrtime_t, int);
  70 void i_untimeout(timeout_t);
  71 
  72 #endif  /* _KERNEL */
  73 
  74 #ifdef  __cplusplus
  75 }
  76 #endif
  77 
  78 #endif  /* _SYS_DDI_PERIODIC_H */