1 /*-
  2  * Copyright (c) 2007 Ariff Abdullah <ariff@FreeBSD.org>
  3  * All rights reserved.
  4  *
  5  * Redistribution and use in source and binary forms, with or without
  6  * modification, are permitted provided that the following conditions
  7  * are met:
  8  * 1. Redistributions of source code must retain the above copyright
  9  *    notice, this list of conditions and the following disclaimer.
 10  * 2. Redistributions in binary form must reproduce the above copyright
 11  *    notice, this list of conditions and the following disclaimer in the
 12  *    documentation and/or other materials provided with the distribution.
 13  *
 14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 24  * SUCH DAMAGE.
 25  *
 26  * $FreeBSD$
 27  */
 28 
 29 #ifndef _SND_CLONE_H_
 30 #define _SND_CLONE_H_
 31 
 32 struct snd_clone_entry;
 33 struct snd_clone;
 34 
 35 /*
 36  * 750 milisecond default deadline. Short enough to not cause excessive
 37  * garbage collection, long enough to indicate stalled VFS.
 38  */
 39 #define SND_CLONE_DEADLINE      750
 40 
 41 /*
 42  * Fit within 24bit MAXMINOR.
 43  */
 44 #define SND_CLONE_MAXUNIT       0xffffff
 45 
 46 /*
 47  * Creation flags, mostly related to the behaviour of garbage collector.
 48  *
 49  * SND_CLONE_GC_ENABLE  - Enable garbage collector operation, automatically
 50  *                        or if explicitly called upon.
 51  * SND_CLONE_GC_UNREF   - Garbage collect during unref operation.
 52  * SND_CLONE_GC_LASTREF - Garbage collect during last reference
 53  *                        (refcount = 0)
 54  * SND_CLONE_GC_EXPIRED - Don't garbage collect unless the global clone
 55  *                        handler has been expired.
 56  * SND_CLONE_GC_REVOKE  - Revoke clone invocation status which has been
 57  *                        expired instead of removing and freeing it.
 58  */
 59 #define SND_CLONE_GC_ENABLE     0x00000001
 60 #define SND_CLONE_GC_UNREF      0x00000002
 61 #define SND_CLONE_GC_LASTREF    0x00000004
 62 #define SND_CLONE_GC_EXPIRED    0x00000008
 63 #define SND_CLONE_GC_REVOKE     0x00000010
 64 
 65 #define SND_CLONE_GC_MASK       (SND_CLONE_GC_ENABLE  |                 \
 66                                  SND_CLONE_GC_UNREF   |                 \
 67                                  SND_CLONE_GC_LASTREF |                 \
 68                                  SND_CLONE_GC_EXPIRED |                 \
 69                                  SND_CLONE_GC_REVOKE)
 70 
 71 #define SND_CLONE_MASK          SND_CLONE_GC_MASK
 72 
 73 /*
 74  * Runtime clone device flags
 75  *
 76  * These are mostly private to the clone manager operation:
 77  *
 78  * SND_CLONE_NEW    - New clone allocation in progress.
 79  * SND_CLONE_INVOKE - Cloning being invoked, waiting for next VFS operation.
 80  * SND_CLONE_BUSY   - In progress, being referenced by living thread/proc.
 81  */
 82 #define SND_CLONE_NEW           0x00000001
 83 #define SND_CLONE_INVOKE        0x00000002
 84 #define SND_CLONE_BUSY          0x00000004
 85 
 86 /*
 87  * Nothing important, just for convenience.
 88  */
 89 #define SND_CLONE_ALLOC         (SND_CLONE_NEW | SND_CLONE_INVOKE |     \
 90                                  SND_CLONE_BUSY)
 91 
 92 #define SND_CLONE_DEVMASK       SND_CLONE_ALLOC
 93 
 94 
 95 void snd_timestamp(struct timespec *);
 96 
 97 #ifdef SND_DIAGNOSTIC
 98 struct snd_clone *snd_clone_create(struct mtx *, int, int, int, uint32_t);
 99 #else
100 struct snd_clone *snd_clone_create(int, int, int, uint32_t);
101 #endif
102 int snd_clone_getsize(struct snd_clone *);
103 int snd_clone_getmaxunit(struct snd_clone *);
104 int snd_clone_setmaxunit(struct snd_clone *, int);
105 int snd_clone_getdeadline(struct snd_clone *);
106 int snd_clone_setdeadline(struct snd_clone *, int);
107 int snd_clone_gettime(struct snd_clone *, struct timespec *);
108 uint32_t snd_clone_getflags(struct snd_clone *);
109 uint32_t snd_clone_setflags(struct snd_clone *, uint32_t);
110 int snd_clone_getdevtime(struct cdev *, struct timespec *);
111 uint32_t snd_clone_getdevflags(struct cdev *);
112 uint32_t snd_clone_setdevflags(struct cdev *, uint32_t);
113 int snd_clone_gc(struct snd_clone *);
114 void snd_clone_destroy(struct snd_clone *);
115 int snd_clone_acquire(struct cdev *);
116 int snd_clone_release(struct cdev *);
117 int snd_clone_ref(struct cdev *);
118 int snd_clone_unref(struct cdev *);
119 void snd_clone_register(struct snd_clone_entry *, struct cdev *dev);
120 struct snd_clone_entry *snd_clone_alloc(struct snd_clone *, struct cdev **,
121     int *, int);
122 
123 #endif /* !_SND_CLONE_H */